/** * @author Cristiano */ function Register() { this.server_page = "/include_user/php/subscribe.php"; this.fields = new Array(); this.fields.push({id:"username", required:true, pattern:/^[a-zA-Z0-9_-]{3,}$/, message:"Invalid username (min. 3 characters)."}); this.fields.push({id:"userpass", required:true, pattern:/^[a-zA-Z0-9\u00C0-\u00F6\u00F8-\u00FF]{8,}$/, message:"Invalid password (min. 8 alphanumeric characters)."}); this.fields.push({id:"email", required:true, pattern:/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})){1}$/, message:"Invalid e-mail address."}); this.fields.push({id:"nome", required:true, pattern:/^[A-Za-z\u00C0-\u00F6\u00F8-\u00FF ]{3,}$/, message:"Invalid name."}); this.fields.push({id:"cognome", required:true, pattern:/^[A-Za-z\u00C0-\u00F6\u00F8-\u00FF' ]{3,}$/, message:"Invalid surname."}); this.fields.push({id:"ragionesociale", required:false, pattern:/^[A-Za-z\u00C0-\u00F6\u00F8-\u00FF ]{3,}$/, message:"Invalid company name."}); this.fields.push({id:"partitaiva", required:false, pattern:/^[0-9]{11}$/, message:"Invalid VAT number."}); this.fields.push({id:"codicefiscale", required:true, pattern:/^[a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1}$/, message:"Invalid fiscal code."}); this.fields.push({id:"indirizzo", required:true, pattern:/^[a-zA-Z0-9, ]{5,}$/, message:"Invalid address."}); this.fields.push({id:"cap", required:true, pattern:/^[0-9]{5}$/, message:"Invalid zip code."}); this.fields.push({id:"localita", required:true, pattern:/^[A-Za-z0-9\u00C0-\u00F6\u00F8-\u00FF' ]{2,}$/, message:"Invalid city."}); this.fields.push({id:"provincia", required:true, pattern:/^[A-Za-z0-9\u00C0-\u00F6\u00F8-\u00FF' ]{2,}$/, message:"Invalid district."}); this.fields.push({id:"telefonoprincipale", required:true, pattern:/^.{0,}$/, message:"Invalid phone."}); this.fields.push({id:"telefonocellulare", required:true, pattern:/.*\S.*/, message:"Invalid mobile phone."}); this.fields.push({id:"fax", required:false, pattern:/^.{0,}$/, message:"Invalid fax number."}); this.fields.push({id:"id_circolo", required:true, pattern:/.*\S.*/, message:"Circolo non valido."}); this.fields.push({id:"numtesserafig", required:false, pattern:/.*\S.*/, message:"Num. tessera FIG non valido."}); this.fields.push({id:"pec", required:false, pattern:/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})){1}$/, message:"InvalidPEC address"}); this.fields.push({id:"codice_sdi", required:false, pattern:/^[A-Za-z0-9]{7}$/, message:"Invalid SDI unique code. Must be composed by 7 alphanumeric chars."}); //Campi Social e WEB this.fields.push({id:"sito_web", required:false, pattern:'', message:""}); this.fields.push({id:"facebook", required:false, pattern:'', message:""}); this.fields.push({id:"twitter", required:false, pattern:'', message:""}); this.fields.push({id:"instagram", required:false, pattern:'', message:""}); this.fields.push({id:"youtube", required:false, pattern:'', message:""}); this.fields.push({id:"linkedin", required:false, pattern:'', message:""}); this.submit = function() { var htmlError = new String('

Errore

'); var errors = false; for (var i = 0; i < this.fields.length; i++) { var element = document.getElementById(this.fields[i].id); //Verifica che l'elemento sia realmente nel Form if(element){ console.log(this.fields[i].id); var check = new String(element.value); if (this.fields[i].required && !check.match(this.fields[i].pattern)) { element.style.borderColor = "red"; htmlError += '

' + this.fields[i].message + '

'; errors = true; } else { //Controlla che i campi Codice SDI e PEC siano verificati solo se valorizzati if(check != '' && (this.fields[i].id == 'pec' || this.fields[i].id == 'codice_sdi')) { if(!check.match(this.fields[i].pattern)){ element.style.color = "red"; htmlError += '

' + this.fields[i].message + '

'; errors = true; field_error = true; }else{ element.style.borderColor = "initial"; this.params[this.fields[i].id] = check; } }else{ element.style.borderColor = "initial"; this.params[this.fields[i].id] = check; } } } } var cond = document.getElementById('condizioni'); if (cond && !cond.checked) { errors = true; htmlError += '

You must agree to the terms and conditions of sale.

'; } var privacy = document.getElementById('privacy'); if (privacy && !privacy.checked) { errors = true; htmlError += '

Is necessary to authorize the processing of personal data.

'; } htmlError += '
'; if (errors) { // SCROLL TOP $('html,body').animate({scrollTop: 130}, 1200, function () { $.fancybox.open(htmlError, {type: 'inline', autoSize: true, autoWidth: true, autoHeight: true, autoResize: true}); }); return; } this.params["profilo"] = document.getElementById("profilo").value; this.params["condizioni"] = 1; this.params["privacy"] = 1; var newslett = document.getElementById('newslett'); if (!newslett.checked) { this.params["newslett"] = 0; }else{ this.params["newslett"] = 1; } document.getElementById("php_response").style.backgroundColor = ''; this.setLoadingTarget(document.getElementById("php_response")); this.setTarget(this.handle_response); this.makeRequest(this.server_page); } this.handle_response = function(response) { var vars = decodeUrlVars(response); var message = decodeURIComponent(vars['message']); var success = decodeURIComponent(vars['success']) == true ? true : false; var htmlMessage = new String('
'); document.getElementById("php_response").innerHTML = ''; if (!success) { //htmlMessage += '

Errore

'; htmlMessage += '

' + message + '

'; // SCROLL TOP $('html,body').animate({scrollTop: 130}, 1200, function () { $.fancybox.open(htmlMessage, {type: 'inline', autoSize: true, autoWidth: true, autoHeight: true, autoResize: true}); }); } else { htmlMessage += message + ''; $.fancybox.open(htmlMessage, { type: 'inline', autoSize: true, autoWidth: true, autoHeight: true, autoResize: true, afterClose: function() { window.location.replace("/") } }); } } } Register.prototype = new AjaxModule(); Register.prototype.constructor = Register; var regobj = new Register(); function Iscriviti() { this.server_page = "/include_user/php/iscriviti.php"; this.fields = new Array(); this.fields.push({id:"username", pattern:/^[a-zA-Z0-9_-]{3,}$/, message:"Invalid username (min. 3 characters)."}); this.fields.push({id:"userpass", pattern:/^[a-zA-Z0-9\u00C0-\u00F6\u00F8-\u00FF]{8,}$/, message:"Invalid password (min. 8 alphanumeric characters)."}); this.fields.push({id:"email", pattern:/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})){1}$/, message:"Invalid e-mail address."}); this.fields.push({id:"nome", pattern:/^[A-Za-z\u00C0-\u00F6\u00F8-\u00FF ]{3,}$/, message:"Invalid name."}); this.fields.push({id:"cognome", pattern:/^[A-Za-z\u00C0-\u00F6\u00F8-\u00FF' ]{3,}$/, message:"Invalid surname."}); this.fields.push({id:"codicefiscale", pattern:/^[a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1}$/, message:"Invalid fiscal code."}); this.fields.push({id:"indirizzo", pattern:/^[a-zA-Z0-9, ]{5,}$/, message:"Invalid address."}); this.fields.push({id:"cap", pattern:/^[0-9]{5}$/, message:"Invalid zip code."}); this.fields.push({id:"localita", pattern:/^[A-Za-z0-9\u00C0-\u00F6\u00F8-\u00FF' ]{2,}$/, message:"Invalid city."}); this.fields.push({id:"provincia", pattern:/^[A-Za-z0-9\u00C0-\u00F6\u00F8-\u00FF' ]{2,}$/, message:"Invalid district."}); this.fields.push({id:"telefonoprincipale", pattern:/^.{0,}$/, message:"Invalid phone."}); this.fields.push({id:"telefonocellulare", pattern:/^.{0,}$/, message:"Invalid mobile phone."}); this.submit = function() { for (var i = 0; i < this.fields.length; i++) { var check = new String(document.getElementById(this.fields[i].id).value); if (!check.match(this.fields[i].pattern)) { document.getElementById(this.fields[i].id).style.borderColor = "red"; document.getElementById(this.fields[i].id).style.color = "black"; document.getElementById(this.fields[i].id).focus(); document.getElementById(this.fields[i].id + "_response").style.color = "black"; document.getElementById(this.fields[i].id + "_response").innerHTML = this.fields[i].message; // SCROLL TOP $('html,body').animate({scrollTop:180}, 500); return; } else { document.getElementById(this.fields[i].id).style.borderColor = "green"; document.getElementById(this.fields[i].id).style.color = "black"; document.getElementById(this.fields[i].id + "_response").innerHTML = ""; this.params[this.fields[i].id] = check; } } var cond = document.getElementById('condizioni'); if (!cond.checked) { alert("You must agree to the terms and conditions of sale."); return; } var privacy = document.getElementById('privacy'); if (!privacy.checked) { alert("Is necessary to authorize the processing of personal data."); return; } this.params["ragionesociale"] = document.getElementById("ragionesociale").value; this.params["partitaiva"] = document.getElementById("partitaiva").value; this.params["fax"] = document.getElementById("fax").value; this.params["profilo"] = document.getElementById("profilo").value; this.params["condizioni"] = 1; this.params["privacy"] = 1; document.getElementById("php_response").style.backgroundColor = ''; this.setLoadingTarget(document.getElementById("php_response")); this.setTarget(this.handle_response); this.makeRequest(this.server_page); } this.handle_response = function(response) { response = decodeUrlVars(response); if (response['success'] == 'no') { document.getElementById("php_response").innerHTML = ''; if (document.getElementById(response['fieldid'])) document.getElementById(response['fieldid']).style.borderColor = 'red'; // SCROLL TOP $('html,body').animate({scrollTop:180}, 500); } document.getElementById(response['fieldid'] + "_response").innerHTML = decodeURIComponent(response['message']); } } Iscriviti.prototype = new AjaxModule(); Iscriviti.prototype.constructor = Iscriviti; var iscobj = new Iscriviti();