function checkCR(evt) {
    var evt  = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
  }
document.onkeypress = checkCR;

function trim(stringa) {
		while (stringa.substring(0,1) == ' ') {
			stringa = stringa.substring(1, stringa.length);
		}
		while (stringa.substring(stringa.length-1, stringa.length) == ' ') {
			stringa = stringa.substring(0,stringa.length-1);
		}
	return stringa;
}

function popup(src,nome,w,h) {
  mia_finestra = window.open(src,nome,'scrollbars=no,resizable=no,width='+w+',height='+h+',status=no,location=0,locationBar=0,menuBar=0,resizable=0,toolbar=0');
  mia_finestra.moveTo(0,0);
}

function refreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}



function Validator_starrater() {
	var checkbox_check = false;
  var lng            = trim(document.starrater.lng.value);
  
  if (lng == "eng") {
    msg  = "Select the vote for the recipe!!";
  } else {
    msg  = "Seleziona il voto da dare alla ricetta!!";
  }

	for (i=1;i<=5;i++) {
		if ((checkbox_check) || (document.starrater["voto"+i].checked)) {
			checkbox_check=true;
		}
	}
	if (!checkbox_check) {
		alert(msg);
	return false;
	}	

return (true);
}



function popup(indirizzo,nome_finestra,caratteristiche,x,y) {
  finestra_popup = window.open(indirizzo,nome_finestra,caratteristiche);
  finestra_popup.moveTo(x,y);
}



function Validator_contatti() {
	var nome          = trim(document.contatti.nome.value);
	var cognome       = trim(document.contatti.cognome.value);
	var telefono      = trim(document.contatti.telefono.value);
	var email         = trim(document.contatti.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var lng           = trim(document.contatti.lng.value);
  var captchacode   = trim(document.contatti.captchacode.value);
  
  if (lng == "eng") {
    msg  = "Fields marked by * are mandatory!!";
    msg2 = "Please provide a valid email address!!";
    msg3 = "Please insert the verification code!!";
  } else if (lng == "rus") {
    msg  = "поля, отмеченные * обязательны для заполнения!!";
    msg2 = "Укажите действительный адрес электронной почты!!";
    msg3 = "Пожалуйста, введите проверочный код!!";
  } else {
    msg  = "I campi contrassegnati da * sono obbligatori!!";
    msg2 = "Inserire un indirizzo email corretto!!";
    msg3 = "Inserire il codice di verifica!!";
  }

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg);
	   document.contatti.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert(msg);
	   document.contatti.cognome.focus();
	return false;
	}
	
	if ((telefono == "") || (telefono == "undefined")) {
	   alert(msg);
	   document.contatti.telefono.focus();
	return false;
	}
	
	if (email != "") {
		if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
			alert(msg2);
			document.contatti.email.select();
		return false;
		}
	}
  
	if ((captchacode == "") || (captchacode == "undefined")) {
	   alert(msg3);
	   document.contatti.captchacode.focus();
	return false;
	}

return (true);
}



function Validator_newsletter() {
	var nome          = trim(document.contatti.nome.value);
	var cognome       = trim(document.contatti.cognome.value);
	var email         = trim(document.contatti.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var lng           = trim(document.contatti.lng.value);
  var captchacode   = trim(document.contatti.captchacode.value);
  
  if (lng == "eng") {
    msg  = "Fields marked by * are mandatory!!";
    msg2 = "Please provide a valid email address!!";
    msg3 = "Please insert the verification code!!";
  } else if (lng == "rus") {
    msg  = "поля, отмеченные * обязательны для заполнения!!";
    msg2 = "Укажите действительный адрес электронной почты!!";
    msg3 = "Пожалуйста, введите проверочный код!!";
  } else {
    msg  = "I campi contrassegnati da * sono obbligatori!!";
    msg2 = "Inserire un indirizzo email corretto!!";
    msg3 = "Inserire il codice di verifica!!";
  }

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg);
	   document.contatti.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert(msg);
	   document.contatti.cognome.focus();
	return false;
	}
	
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert(msg2);
		document.contatti.email.select();
	return false;
	}
  
	if ((captchacode == "") || (captchacode == "undefined")) {
	   alert(msg3);
	   document.contatti.captchacode.focus();
	return false;
	}

return (true);
}



function Validator_lavora() {
	var nome          = trim(document.contatti.nome.value);
	var cognome       = trim(document.contatti.cognome.value);
	var telefono      = trim(document.contatti.telefono.value);
	var email         = trim(document.contatti.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	var curriculum    = trim(document.contatti.curriculum.value);
  var lng           = trim(document.contatti.lng.value);
  
  if (lng == "eng") {
    msg  = "Fields marked by * are mandatory!!";
    msg2 = "Please provide a valid email address!!";
  } else if (lng == "rus") {
    msg  = "поля, отмеченные * обязательны для заполнения!!";
    msg2 = "Укажите действительный адрес электронной почты!!";
  } else {
    msg  = "I campi contrassegnati da * sono obbligatori!!";
    msg2 = "Inserire un indirizzo email corretto!!";
  }

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg);
	   document.contatti.nome.focus();
	return false;
	}

	if ((cognome == "") || (cognome == "undefined")) {
	   alert(msg);
	   document.contatti.cognome.focus();
	return false;
	}
	
	if ((telefono == "") || (telefono == "undefined")) {
	   alert(msg);
	   document.contatti.telefono.focus();
	return false;
	}
	
	if (email != "") {
		if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
			alert(msg2);
			document.contatti.email.select();
		return false;
		}
	}
	
	if ((curriculum == "") || (curriculum == "undefined")) {
	   alert(msg);
	   document.contatti.curriculum.focus();
	return false;
	}

return (true);
}



function Validator_suggerisci() {
	var nome          = trim(document.contatti.nome.value);
	var email         = trim(document.contatti.email.value);
	var email2        = trim(document.contatti.email2.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var lng           = trim(document.contatti.lng.value);
  
  if (lng == "eng") {
    msg  = "Fill all the requested fields!!";
    msg2 = "Please provide a valid email address!!";
  } else if (lng == "rus") {
    msg  = "поля, отмеченные * обязательны для заполнения!!";
    msg2 = "Укажите действительный адрес электронной почты!!";
  } else {
    msg  = "Compilare tutti i campi necessari!!";
    msg2 = "Inserire un indirizzo email corretto!!";
  }

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg);
	   document.contatti.nome.focus();
	return false;
	}
	
	if (email != "") {
		if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
			alert(msg2);
			document.contatti.email.select();
		return false;
		}
	}
	
	if (email2 != "") {
		if (!email_reg_exp.test(email2) || (email2 == "") || (email2 == "undefined")) {
			alert(msg2);
			document.contatti.email2.select();
		return false;
		}
	}

return (true);
}



function Validator_eshop(rivenditori) {
	var controllo = false;
  var lng       = trim(document.getElementById("lng").value);
  
  if (lng == "eng") {
    msg  = "You must insert a numeric value!!";
	  msg2 = "You must choose at least one product!!";
  } else {
    msg  = "È obbligatorio inserire un valore numerico!!";
	  msg2 = "È obbligatorio inserire almeno una quantità!!";
  }

	for (i=1;i<=26;i++) {
    if (document.getElementById("quantita"+i)) {
  	  quantita = document.getElementById("quantita"+i).value;
  		if ((controllo) || (quantita != "")) {
  		  if (isNaN(quantita)) {
          alert(msg);
          return false;
        } else {
          if (quantita > 0) {
      			controllo=true;
          }
        }
  		}
    }
	}
	
	if (rivenditori == "si") {
    if (document.getElementById("quantitaB"+i)) {
    	for (i=1;i<=22;i++) {
    	  quantita = document.getElementById("quantitaB"+i).value;
    		if ((controllo) || (quantita != "")) {
    		  if (isNaN(quantita)) {
            alert(msg);
            return false;
          } else {
            if (quantita > 0) {
        			controllo=true;
            }
          }
    		}
    	}
    }
  }
	
	if (!controllo) {
    alert(msg2);
    return false;
	}

return (true);
}



function eshop(quale,forzatura,lng) {
  if (lng) {
    var lang = lng+"/";
  } else {
    var lang = "";
  }
  
  numero_categorie = 6
  if (forzatura == "si") {
    for (x=1;x<=numero_categorie;x++) {
      document.getElementById("tabella"+x).style.display = 'block';
      document.getElementById("tit"+x).src = '../_img/'+lang+'tit_pagine/eshop/titolo'+x+'_att.png';
    }
  } else {
    if (document.getElementById("tabella"+quale).style.display == "block") {
      document.getElementById("tabella"+quale).style.display = 'none';
      document.getElementById("tit"+quale).src = '../_img/'+lang+'tit_pagine/eshop/titolo'+quale+'.png';
    } else {
      document.getElementById("tabella"+quale).style.display = 'block';
      document.getElementById("tit"+quale).src = '../_img/'+lang+'tit_pagine/eshop/titolo'+quale+'_att.png'; 
    }  
  }
}



function mostra() {
  if (document.getElementById("fattura").checked) {
    document.getElementById("nascondi1").style.display = 'block';
  } else {
    document.getElementById("nascondi1").style.display = 'none';
  }
}



function Validator_spedizione() {
	var nome            = trim(document.spedizione.nome.value);
	var cognome         = trim(document.spedizione.cognome.value);
	var indirizzo       = trim(document.spedizione.indirizzo.value);
	var citta           = trim(document.spedizione.citta.value);
	var telefono        = trim(document.spedizione.telefono.value);
	var email           = trim(document.spedizione.email.value);
	var email_reg_exp   = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
  var lng             = trim(document.spedizione.lng.value);
  
  if (lng == "eng") {
  	var stato = trim(document.spedizione.citta.value);
  
    msg  = "Fields marked by * are mandatory!!";
    msg2 = "Please provide a valid email address!!";
    var stato = trim(document.spedizione.stato.value);
  } else {
    var cap = trim(document.spedizione.cap.value);
    var provincia = trim(document.spedizione.provincia.value);
  	var ragione_sociale = trim(document.spedizione.ragione_sociale.value);
  	var codice_fiscale  = trim(document.spedizione.codice_fiscale.value);
  	var partita_iva     = trim(document.spedizione.partita_iva.value);
  
    msg  = "I campi contrassegnati da * sono obbligatori!!";
    msg2 = "Inserire un indirizzo email corretto!!";
  }

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg);
	   document.spedizione.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert(msg);
	   document.spedizione.cognome.focus();
	return false;
	}
	
	if ((indirizzo == "") || (indirizzo == "undefined")) {
	   alert(msg);
	   document.spedizione.indirizzo.focus();
	return false;
	}
  
	if ((cap == "") || (cap == "undefined")) {
	   alert(msg);
	   document.spedizione.cap.focus();
	return false;
	}
	
	if ((citta == "") || (citta == "undefined")) {
	   alert(msg);
	   document.spedizione.citta.focus();
	return false;
	}
	
	if (lng == "eng") {
  	if ((stato == "") || (stato == "undefined")) {
  	   alert(msg);
  	   document.spedizione.stato.focus();
  	return false;
  	}
  } else {
  	if ((codice_fiscale == "") || (codice_fiscale == "undefined")) {
  	   alert(msg);
  	   document.spedizione.codice_fiscale.focus();
  	return false;
  	}
  
  	if ((cap == "") || (cap == "undefined")) {
  	   alert(msg);
  	   document.spedizione.cap.focus();
  	return false;
  	}
  	
  	if ((provincia == "") || (provincia == "undefined")) {
  	   alert(msg);
  	   document.spedizione.provincia.focus();
  	return false;
  	}
    
  	if (document.getElementById("fattura").checked) {
    	if ((ragione_sociale == "") || (ragione_sociale == "undefined")) {
    	   alert(msg);
    	   document.spedizione.ragione_sociale.focus();
    	return false;
    	}
    
    	if ((partita_iva == "") || (partita_iva == "undefined")) {
    	   alert(msg);
    	   document.spedizione.partita_iva.focus();
    	return false;
    	}
    }
  }
	
	if ((telefono == "") || (telefono == "undefined")) {
	   alert(msg);
	   document.spedizione.telefono.focus();
	return false;
	}
	
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert(msg2);
		document.spedizione.email.select();
	return false;
	}

document.spedizione.submit();
}



function Validator_pagamento() {
	var checkbox_check = false;
  var lng            = trim(document.pagamento.lng.value);
  
  if (lng == "eng") {
    msg  = "You must choose a payment method!!";
  } else {
    msg  = "È obbligatorio selezionare un metodo di pagamento!!";
  }

	for (i=1;i<=5;i++) {
    if (document.getElementById("metodo"+i)) {
  		if ((checkbox_check) || (document.getElementById("metodo"+i).checked)) {
  			checkbox_check=true;
  		}
    }
	}
	if (!checkbox_check) {
		alert(msg);
	return false;
	}	

return (true);
}



function Validator_area_rivenditori() {
	var login = trim(document.area_rivenditori.login.value);
	var pass  = trim(document.area_rivenditori.pass.value);
  var lng   = trim(document.area_rivenditori.lng.value);
  
  if (lng == "eng") {
    msg  = "All fields are mandatory!!";
  } else {
    msg  = "Tutti i campi sono obbligatori!!";
  }

	if ((login == "") || (login == "undefined")) {
	   alert(msg);
	   document.area_rivenditori.login.focus();
	return false;
	}
	
	if ((pass == "") || (pass == "undefined")) {
	   alert(msg);
	   document.area_rivenditori.pass.focus();
	return false;
	}

return (true);
}



function Validator_login_utente() {
	var login = trim(document.login_utente.login.value);
	var pass  = trim(document.login_utente.pass.value);
  var lng   = trim(document.login_utente.lng.value);
  
  if (lng == "eng") {
    msg  = "All fields are mandatory!!";
  } else {
    msg  = "Tutti i campi sono obbligatori!!";
  }

	if ((login == "") || (login == "undefined")) {
	   alert(msg);
	   document.login_utente.login.focus();
	return false;
	}
	
	if ((pass == "") || (pass == "undefined")) {
	   alert(msg);
	   document.login_utente.pass.focus();
	return false;
	}

return (true);
}



function Validator_recupero_acquirente() {
	var email_login   = trim(document.recupero_acquirente.email_login.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var lng           = trim(document.recupero_acquirente.lng.value);

  if (lng == "eng") {
    msg = "Please provide a valid email address!!";
  } else {
    msg = "Inserire un indirizzo email corretto!!";
  }

	if (!email_reg_exp.test(email_login) || (email_login == "") || (email_login == "undefined")) {
		alert(msg);
		document.recupero_acquirente.email_login.select();
	return false;
	}

return (true);
}



function Validator_recupero_utente() {
	var email_login   = trim(document.recupero_utente.email_login.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var lng           = trim(document.recupero_utente.lng.value);

  if (lng == "eng") {
    msg = "Please provide a valid email address!!";
  } else {
    msg = "Inserire un indirizzo email corretto!!";
  }

	if (!email_reg_exp.test(email_login) || (email_login == "") || (email_login == "undefined")) {
		alert(msg);
		document.recupero_utente.email_login.select();
	return false;
	}

return (true);
}



function Validator_suggerisci_ricetta() {	
	var nome          = trim(document.suggerisci.nome.value);
	var cognome       = trim(document.suggerisci.cognome.value);
	var indirizzo     = trim(document.suggerisci.indirizzo.value);
	var telefono      = trim(document.suggerisci.telefono.value);
	var email         = trim(document.suggerisci.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var ingredienti   = trim(document.suggerisci.ingredienti.value);
  var preparazione  = trim(document.suggerisci.preparazione.value);
	var fotografia    = trim(document.suggerisci.fotografia.value);
	var persone       = trim(document.suggerisci.persone.value);
  var difficolta    = trim(document.suggerisci.difficolta.value);
  var minuti        = trim(document.suggerisci.minuti.value);
  var lng           = trim(document.suggerisci.lng.value);
  
  if (lng == "eng") {
    msg  = "All fields are mandatory!!";
    msg2 = "Please provide a valid email address!!";
  } else {
    msg  = "Tutti i campi sono obbligatori!!";
    msg2 = "Inserire un indirizzo email corretto!!";
  }  	

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg);
	   document.suggerisci.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert(msg);
	   document.suggerisci.cognome.focus();
	return false;
	}
	
	if ((indirizzo == "") || (indirizzo == "undefined")) {
	   alert(msg);
	   document.suggerisci.indirizzo.focus();
	return false;
	}
	
	if ((telefono == "") || (telefono == "undefined")) {
	   alert(msg);
	   document.suggerisci.telefono.focus();
	return false;
	}
	
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
	   alert(msg2);
		document.suggerisci.email.select();
	return false;
	}
	
	if ((ingredienti == "") || (ingredienti == "undefined")) {
	   alert(msg);
	   document.suggerisci.ingredienti.focus();
	return false;
	}
	
	if ((preparazione == "") || (preparazione == "undefined")) {
	   alert(msg);
	   document.suggerisci.preparazione.focus();
	return false;
	}
	
	if ((fotografia == "") || (fotografia == "undefined")) {
	   alert(msg);
	   document.suggerisci.fotografia.focus();
	return false;
	}
	
	if ((persone == "") || (persone == "undefined")) {
	   alert(msg);
	   document.suggerisci.persone.focus();
	return false;
	}
	
	if ((difficolta == "") || (difficolta == "undefined")) {
	   alert(msg);
	   document.suggerisci.difficolta.focus();
	return false;
	}
	
	if ((minuti == "") || (minuti == "undefined")) {
	   alert(msg);
	   document.suggerisci.minuti.focus();
	return false;
	}

return (true);
}
