// JavaScript Document

var digitsOnly = /[1234567890]/g;
var importoOnly = /[1234567890,]/g;
var integerOnly = /[0-9\.]/g;
var alphaOnly = /[A-Z]/g;
var alphadigitsOnly = /[1234567890ABCDEFGHILMNOPQRSTUVZWYKXJabcdefghilmnopqrstuvzwyjkx]/g;

function restrictCharacters(myfield, e, restrictionType) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	if (code==27) { this.blur(); return false; }
	if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
		if (character.match(restrictionType)) {
			return true;
		} else {
			return false;
		}
		
	}
}

function changeURL(){
window.location = "fidelity" + "?" +
document.getElementById('txtbx').value;
}

function PopupCentrata(volantinoId) {
   var w = 775;
   var h = 623;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open("volantino.asp?volantinoId=" + volantinoId,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + "status=no, menubar=no, toolbar=no scrollbar=no");
}

function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
  } catch(e) {
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}

function myHandlerColonnaSX() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
		var e = document.getElementById("COLONNA_SX");
    	e.innerHTML = myRequest.responseText;
    }
}

function colonnaSX(namePage,varsGet) {
	myRequest = CreateXmlHttpReq(myHandlerColonnaSX);
    myRequest.open("GET", namePage + ".asp" + varsGet);
    myRequest.send(null);
}

function ConvalidaParlaConNoi(path) {
     var email = document.form_modulo.email.value;
	 var puntoVendita = document.form_modulo.puntoVendita.value;
     var localita = document.form_modulo.localita.value;
	 var subject = document.form_modulo.subject.options[document.form_modulo.subject.selectedIndex].text;
	 var body = document.form_modulo.body.value;
	 var strCAPTCHA = document.form_modulo.strCAPTCHA.value;
	 if(document.form_modulo.privacy[0].checked){
		var privacy = true;
	 } else {
		var privacy = false;
	 }
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Inserire un indirizzo email corretto.";
           //document.form_modulo.email.select();
        } else if ((puntoVendita == "") || (puntoVendita == "undefined")) {
          var e = document.getElementById("alertBox");
    	  e.innerHTML = "Il campo Punto vendita di riferimento &eacute; obbligatorio.";
          //document.form_modulo.citta.focus();
        } else if ((localita == "") || (localita == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Localita &eacute; obbligatorio.";
           //document.form_modulo.localita.focus();
        } else if ((subject == "") || (subject == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Oggetto &eacute; obbligatorio.";
           //document.form_modulo.localita.focus();
        } else if ((body == "") || (body == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Messaggio &eacute; obbligatorio.";
           //document.form_modulo.localita.focus();
        } else if ((privacy == false) || (privacy == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Accettare l'informativa sulla privacy del sito &eacute; obbligatorio.";
           //document.form_modulo.privacy.focus();
        } else if ((strCAPTCHA == "") || (strCAPTCHA == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "L'inserimento del Codice visualizzato &eacute; obbligatorio.";
           //document.form_modulo.localita.focus();
        }  else {
		   document.form_modulo.action = path;
           document.form_modulo.submit();
           //colonnaSX("parlaConNoiSX","?strCAPTCHA="+document.form_modulo.strCAPTCHA.value);
        }
}

function ConvalidaAnnunciForm(path) {
	 var nome = document.form_modulo.nome.value;
	 var cognome = document.form_modulo.cognome.value;
	 var citta = document.form_modulo.citta.value;
     var email = document.form_modulo.email.value;
	 var argomento = document.form_modulo.argomento.options[document.form_modulo.argomento.selectedIndex].text;
	 var titolo = document.form_modulo.titolo.value;
	 var descrizione = document.form_modulo.descrizione.value;
	 var strCAPTCHA = document.form_modulo.strCAPTCHA.value;
	 if(document.form_modulo.privacy[0].checked){
		var privacy = true;
	 } else {
		var privacy = false;
	 }
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if ((nome == "") || (nome == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Nome &eacute; obbligatorio.";
        } else if ((cognome == "") || (cognome == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Cognome &eacute; obbligatorio.";
        } else if ((citta == "") || (citta == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Citt&aacute; &eacute; obbligatorio.";
        } else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
          var e = document.getElementById("alertBox");
    	  e.innerHTML = "Inserire un indirizzo email corretto.";
        } else if ((argomento == "") || (argomento == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Argomento &eacute; obbligatorio.";
        } else if ((titolo == "") || (titolo == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Titolo &eacute; obbligatorio.";
        } else if ((descrizione == "") || (descrizione == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Descrizione &eacute; obbligatorio.";
        } else if ((privacy == false) || (privacy == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Accettare l'informativa &eacute; obbligatorio.";
           //document.form_modulo.privacy.focus();
        } else if ((strCAPTCHA == "") || (strCAPTCHA == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "L'inserimento del Codice &eacute; obbligatorio.";
           //document.form_modulo.localita.focus();
        } else {
		   document.form_modulo.action = path;
           document.form_modulo.submit();
        }
}

function ConvalidaAffiliarsi(path) {
	 
	 var disponibilitaLocali = getCheckedValue(document.form_modulo.disponibilitaLocali);
	 var licenze = getCheckedValue(document.form_modulo.licenze);
	 var abilitazione = getCheckedValue(document.form_modulo.abilitazione);
	 var esercizioAvviato = getCheckedValue(document.form_modulo.esercizioAvviato);
	 
	 var dimensioni = document.form_modulo.dimensioni.value;
     var piva = document.form_modulo.piva.value;
	 var localita = document.form_modulo.localita.value;
	 var telefono = document.form_modulo.telefono.value;
	 var email = document.form_modulo.email.value;
	 if(document.form_modulo.privacy[0].checked){
		var privacy = true;
	 } else {
		var privacy = false;
	 }
	 var strCAPTCHA = document.form_modulo.strCAPTCHA.value;
	 
	 
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	 	if ((disponibilitaLocali == "") || (disponibilitaLocali == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Disponibilit&aacute; locali &eacute; obbligatorio.";
        } else if ((licenze == "") || (licenze == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Licenze &eacute; obbligatorio.";
        } else if ((abilitazione == "") || (abilitazione == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Abilitazione &eacute; obbligatorio.";
        } else if ((esercizioAvviato == "") || (esercizioAvviato == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Esercizio avviato &eacute; obbligatorio.";
        } else if ((dimensioni == "") || (dimensioni == "undefined")) {
		   var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Dimensioni &eacute; obbligatorio.";
        } else if ((piva == "") || (piva == "undefined")) {
          var e = document.getElementById("alertBox");
    	  e.innerHTML = "Il campo Partita IVA &eacute; obbligatorio.";
        } else if ((localita == "") || (localita == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Localita &eacute; obbligatorio.";
        } else if ((telefono == "") || (telefono == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Telefono &eacute; obbligatorio.";
        } else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Inserire un indirizzo email corretto.";
        } else if ((privacy == false) || (privacy == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Accettare l'informativa sulla privacy del sito &eacute; obbligatorio.";
        } else if ((strCAPTCHA == "") || (strCAPTCHA == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "L'inserimento del Codice visualizzato &eacute; obbligatorio.";
        }  else {
		   document.form_modulo.action = path;
           document.form_modulo.submit();
           //colonnaSX("parlaConNoiSX","?strCAPTCHA="+document.form_modulo.strCAPTCHA.value);
        }
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function ConvalidaComarketing(path) {
	
     var user = document.form_modulo.user.value;
	 var password = document.form_modulo.password.value;
	 
        if ((user == "") || (user == "undefined")) {
          var e = document.getElementById("alertBox");
    	  e.innerHTML = "Il campo User &eacute; obbligatorio.";
        } else if ((password == "") || (password == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Password &eacute; obbligatorio.";
        } else {
		   document.form_modulo.action = path;
           document.form_modulo.submit();
        }
}

function ConvalidaRecuperaPasswordComarketing(path) {
	
     var codice = document.form_modulo.codice.value;
	 var strCAPTCHA = document.form_modulo.strCAPTCHA.value;
        if ((codice == "") || (codice == "undefined")) {
          var e = document.getElementById("alertBox");
    	  e.innerHTML = "Il campo Codice &eacute; obbligatorio.";
        } else if ((strCAPTCHA == "") || (strCAPTCHA == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Codice immagine &eacute; obbligatorio.";
        } else {
		   document.form_modulo.action = path;
           document.form_modulo.submit();
        }
}

function ConvalidaComarketingLogIn(path) {
	
     var card = document.form_modulo.card.value;
	 var importo = document.form_modulo.importo.value;
	 var scontrino = document.form_modulo.scontrino.value;
        if ((card == "") || (card == "undefined")) {
          var e = document.getElementById("alertBox");
    	  e.innerHTML = "Il campo Card &eacute; obbligatorio.";
        } else if ((importo == "") || (importo == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Importo &eacute; obbligatorio.";
        } else if ((scontrino == "") || (scontrino == "undefined")) {
           var e = document.getElementById("alertBox");
    	   e.innerHTML = "Il campo Scontrino &eacute; obbligatorio.";
        } else {
		   document.form_modulo.action = path;
           document.form_modulo.submit();
        }
}