 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO EMAIL (PER TUTTI I FORM)
 ///////////////////////////////////////////////////////////////////////////////////

var whitespace = " \t\n\r";
function isEmail (s){
	if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")){
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")){
		i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}







 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO LOGIN
 ///////////////////////////////////////////////////////////////////////////////////
 
function sendAccesso() {
	
	u=document.getElementById("username");
	if(u.value==""){
		alert("Inserire l\'email");
		u.focus();
		return;
	}
	
	if (!isEmail(u.value)){
		alert("Inserisci l\'indirizzo email corretto");
		u.focus();
		return 1;
	}

	c=document.getElementById("password");
	if(c.value==""){
		alert("Inserire la password");
		c.focus();
		return;
	}

	controllo_login(u.value,c.value);

	/*document.getElementById('invia').value="Si";
	document.getElementById('frmLogin').action="#";
	document.getElementById('frmLogin').submit();*/
}




/*function messaggio(){
	//document.getElementById('messaggio').innerHTML="";
	document.getElementById('username').focus();
}
function annulla(){
	//document.getElementById('messaggio').innerHTML="";
	document.getElementById('username').value="";
	document.getElementById('password').value="";
}*/






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO CONTATTI
 ///////////////////////////////////////////////////////////////////////////////////
function send(){

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Inserire il nome");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Inserire il cognome");
		c.focus();
		return;
	}

	c=document.getElementById("email");
	if(c.value==""){
		alert("Inserire la mail");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserisci l'indirizzo e-mail corretto");
		c.focus();
		return 1;
	}
	
	c=document.getElementById("messaggio");
	if(c.value==""){
		alert("Inserire un messaggio");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Leggi l\'informativa sulla privacy e spunta la casella \'Acconsento il trattamento dei dati personali\'");
		c.focus();
		return;
	}
	
	document.getElementById("formDati").azione.value='send';
	document.getElementById("formDati").action='contatti_ita.php';
	document.getElementById("formDati").submit();
}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO LOGIN ORDINE
 ///////////////////////////////////////////////////////////////////////////////////
function loginOrdine(){

	c=document.getElementById("email");
	if(c.value==""){
		alert("Inserire la mail");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserisci l'indirizzo e-mail corretto");
		c.focus();
		return 1;
	}
	
	c=document.getElementById("pass");
	if(c.value==""){
		alert("Inserire la password");
		//c.focus();
		return;
	}
	
	
	
	document.getElementById("azione").value='login';
	document.getElementById("formDatiFatturazione").action='carrello_dati_cliente_ita.php';
	document.getElementById("formDatiFatturazione").submit();
}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO REGISTRAZIONE
 ///////////////////////////////////////////////////////////////////////////////////
function send_registrazione(){
	c=document.getElementById("email");
	if(c.value==""){
		alert("Inserire la mail");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserisci l'indirizzo e-mail corretto");
		c.focus();
		return 1;
	}

	c=document.getElementById("pass");	
	if(c.value=="" || c.value.length<8){	
		alert("Inserisci la password con un minimo di 8 caratteri");
		c.focus();
		return;
	
	}

	c2=document.getElementById("conferma");	
	if(c.value!=c2.value ){	
		alert("I valori delle due password sono differenti");
		c2.focus();
		return;
	
	}

	c=document.getElementById("piva");
	if(c.value==""){
		alert("Inserire la Partita IVA o il Codice Fiscale");
		c.focus();
		return;
	}

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Inserire il nome");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Inserire il cognome");
		c.focus();
		return;
	}

	c=document.getElementById("indirizzo");
	if(c.value==""){
		alert("Inserire l'indirizzo");
		c.focus();
		return;
	}
		c=document.getElementById("civico");
	if(c.value==""){
		alert("Inserire il numero civico");
		c.focus();
		return;
	}
		c=document.getElementById("citta");
	if(c.value==""){
		alert("Inserire la città");
		c.focus();
		return;
	}

	c=document.getElementById("cap");
	if(c.value==""){
		alert("Inserire il CAP");
		c.focus();
		return;
	}
	c=document.getElementById("provincia");
	if(c.value==""){
		alert("Inserire la provincia");
		c.focus();
		return;
	}
	c=document.getElementById("nazione");
	if(c.value==""){
		alert("Inserire la nazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefono");
	c2=document.getElementById("cellulare");
	if(c.value=="" && c2.value==""){
		alert("Inserire almeno un numero di cellulare o di telefono");
		c.focus();
		return;
	}




	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Leggi l\'informativa sulla privacy e spunta la casella \'Acconsento il trattamento dei dati personali\'");
		c.focus();
		return;
	}
	
	document.getElementById("azionex").value='iscrizione';
	document.getElementById("formDati").action='registrati_ita.php';
	document.getElementById("formDati").submit();
}







 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO CANCELLAZIONE REGISTRAZIONE
 ///////////////////////////////////////////////////////////////////////////////////
function cancella_registrazione(){

	c=document.getElementById("email_cancella");
	if(c.value==""){
		alert("Inserire l'email");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserisci l'indirizzo email corretto");
		c.focus();
		return;
	}
	
	c=document.getElementById("formCancella");
	c.azione_cancella.value='cancella';
	c.action='registrati_ita.php';
	c.submit();
}







 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO RECUPERO PASSWORD
 ///////////////////////////////////////////////////////////////////////////////////
function send_recupero_password(){

	c=document.getElementById("email");
	if(c.value==""){
		alert("Inserire l'email");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserisci l'indirizzo email corretto");
		c.focus();
		return;
	}
	
	c=document.getElementById("formRecuperoPassword");
	c.azione.value='send';
	c.action='password_recovery_ita.php';
	c.submit();
}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO CAMBIA EMAIL
 ///////////////////////////////////////////////////////////////////////////////////
function sendCambiaEmail(){

	c=document.getElementById("email_cambia");
	if(c.value==""){
		alert("Inserire la nuova email nel campo 'cambia email'");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserisci l'indirizzo email corretto nel campo 'cambia email'");
		c.focus();
		return;
	}
	
	if(confirm("Stai per cambiare la tua email per accedere al sito ChampagneOnline.\nCliccare OK per confermare.")){
		c=document.getElementById("formCambiaEmail");
		c.azione_cambia_email.value='aggiorna';
		c.action='dati_utente_ita.php';
		c.submit();
	}
}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO CAMBIA PASSWORD
 ///////////////////////////////////////////////////////////////////////////////////
function sendCambiaPass(){

	c=document.getElementById("pass_nuova");	
	if(c.value=="" || c.value.length<8){	
		alert("Inserisci la nuova password con un minimo di 8 caratteri");
		c.focus();
		return;
	
	}

	c2=document.getElementById("conferma_pass_nuova");	
	if(c.value!=c2.value ){	
		alert("I valori delle due password sono differenti");
		c2.focus();
		return;
	
	}
	
	if(confirm("Stai per cambiare la tua password per accedere al sito ChampagneOnline.\nCliccare OK per confermare.")){
		c=document.getElementById("formCambiaPass");
		c.azione_cambia_pass.value='aggiorna';
		c.action='dati_utente_ita.php';
		c.submit();
	}
}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO AGGIORNA DATI FATTURAZIONE
 ///////////////////////////////////////////////////////////////////////////////////
function sendAggiornaDatiFatturazione(){

	c=document.getElementById("nomeDatiFatturazione");
	if(c.value==""){
		alert("Inserire il nome per la fatturazione");
		c.focus();
		return;
	}

	c=document.getElementById("cognomeDatiFatturazione");
	if(c.value==""){
		alert("Inserire il cognome per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("pivacfDatiFatturazione");
	if(c.value==""){
		alert("Inserire la Partita IVA o il Codice Fiscale per la fatturazione");
		c.focus();
		return;
	}

	c=document.getElementById("indirizzoDatiFatturazione");
	if(c.value==""){
		alert("Inserire l'indirizzo per la fatturazione");
		c.focus();
		return;
	}
		c=document.getElementById("civicoDatiFatturazione");
	if(c.value==""){
		alert("Inserire il numero civico per la fatturazione");
		c.focus();
		return;
	}
		c=document.getElementById("cittaDatiFatturazione");
	if(c.value==""){
		alert("Inserire la città per la fatturazione");
		c.focus();
		return;
	}

	c=document.getElementById("capDatiFatturazione");
	if(c.value==""){
		alert("Inserire il CAP per la fatturazione");
		c.focus();
		return;
	}
	c=document.getElementById("provinciaDatiFatturazione");
	if(c.value==""){
		alert("Inserire la provincia per la fatturazione");
		c.focus();
		return;
	}
	c=document.getElementById("nazioneDatiFatturazione");
	if(c.value==""){
		alert("Inserire la nazione per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefonoDatiFatturazione");
	c2=document.getElementById("cellulareDatiFatturazione");
	if(c.value=="" && c2.value==""){
		alert("Inserire almeno un numero di cellulare o di telefono per la fatturazione");
		c.focus();
		return;
	}
	
	if(confirm("Stai per aggiornare i dati relativi alla fatturazione.\nCliccare OK per confermare.")){
		c=document.getElementById("formAggiornaDatiFatturazione");
		c.azione_cambia_dati_fatturazione.value='aggiorna';
		c.action='dati_utente_ita.php';
		c.submit();
	}

}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO AGGIORNA DATI SPEDIZIONE
 ///////////////////////////////////////////////////////////////////////////////////
function sendAggiornaDatiSpedizione(){

	c=document.getElementById("nomeDatiSpedizione");
	if(c.value==""){
		alert("Inserire il nome per la spedizione");
		c.focus();
		return;
	}

	c=document.getElementById("cognomeDatiSpedizione");
	if(c.value==""){
		alert("Inserire il cognome per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("campanelloDatiSpedizione");
	if(c.value==""){
		alert("Inserire un Nome per il campo 'Nome sul campanello' per la spedizione");
		c.focus();
		return;
	}

	c=document.getElementById("indirizzoDatiSpedizione");
	if(c.value==""){
		alert("Inserire l'indirizzo per la spedizione");
		c.focus();
		return;
	}
		c=document.getElementById("civicoDatiSpedizione");
	if(c.value==""){
		alert("Inserire il numero civico per la spedizione");
		c.focus();
		return;
	}
		c=document.getElementById("cittaDatiSpedizione");
	if(c.value==""){
		alert("Inserire la città per la spedizione");
		c.focus();
		return;
	}

	c=document.getElementById("capDatiSpedizione");
	if(c.value==""){
		alert("Inserire il CAP per la spedizione");
		c.focus();
		return;
	}
	c=document.getElementById("provinciaDatiSpedizione");
	if(c.value==""){
		alert("Inserire la provincia per la spedizione");
		c.focus();
		return;
	}
	c=document.getElementById("nazioneDatiSpedizione");
	if(c.value==""){
		alert("Inserire la nazione per la spedizione");
		c.focus();
		return;
	}
	
	if(confirm("Stai per aggiornare i dati relativi alla spedizione.\nCliccare OK per confermare.")){
		c=document.getElementById("formAggiornaDatiSpedizione");
		c.azione_cambia_dati_spedizione.value='aggiorna';
		c.action='dati_utente_ita.php';
		c.submit();
	}

}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO COMMENTO
 ///////////////////////////////////////////////////////////////////////////////////
 
function sendCommento(){

	c=document.getElementById("campo_commento_titolo");
	if(c.value==""){
		alert("Inserire un titolo");
		c.focus();
		return;
	}

	c=document.getElementById("campo_commento_testo");
	if(c.value==""){
		alert("Inserire un commento");
		c.focus();
		return;
	}
	
	// Definisco il numero di radio disponibili!
	var n_opt = 5;
	var n = (n_opt - 1);
	c=document.getElementById("campo_commento_voto");
	for (i=0; i<=n; i++){
	if (document.formCommento.campo_commento_voto[i].checked){
			//alert("Ok un voto");
      		break;
    	}else{
	  		if(i == n){
				alert("Selezionare un voto");
				c.focus();
				return;
	  		}
		}
	}

	
	document.getElementById("formCommento").azione.value='inviacommento';
	document.getElementById("formCommento").action='prodotti_scheda_ita.php';
	document.getElementById("formCommento").submit();
}







 ///////////////////////////////////////////////////////////////////////////////////
 // RIMUOVI PRODOTTO CARRELLO
 ///////////////////////////////////////////////////////////////////////////////////

function RimuoviProdottoCarrello(idrimuovi){
	if(confirm("Rimuovere questo prodotto dal carrello?\nCliccare OK per confermare.")){
	document.getElementById("formCarrello").azione.value='rimuovi';
	document.getElementById("formCarrello").action='carrello_ita.php';
	document.getElementById("formCarrello").idrimuovi.value=idrimuovi;
	document.getElementById("formCarrello").submit();
	}
}

 ///////////////////////////////////////////////////////////////////////////////////
 // AGGIORNA PRODOTTO CARRELLO
 ///////////////////////////////////////////////////////////////////////////////////
function AggiornaProdottoCarrello(idaggiorna){
	if(confirm("Aggiornare la quantità di questo prodotto?\nCliccare OK per confermare.")){
	document.getElementById("formCarrello").azione.value='aggiorna';
	document.getElementById("formCarrello").action='carrello_ita.php';
	document.getElementById("formCarrello").idaggiorna.value=idaggiorna;
	document.getElementById("formCarrello").submit();
	}




}







 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO DATI FATTURAZIONE
 ///////////////////////////////////////////////////////////////////////////////////
 
function sendDatiFatturazione(){

	c=document.getElementById("nomeDatiFatturazione");
	if(c.value==""){
		alert("Inserire un nome per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("cognomeDatiFatturazione");
	if(c.value==""){
		alert("Inserire un cognome per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("pivacfDatiFatturazione");
	if(c.value==""){
		alert("Inserire una Partita IVA se una azienda o Codice Fiscale se una persona fisica per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("indirizzoDatiFatturazione");
	if(c.value==""){
		alert("Inserire un indirizzo per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("civicoDatiFatturazione");
	if(c.value==""){
		alert("Inserire un civico per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("cittaDatiFatturazione");
	if(c.value==""){
		alert("Inserire una città per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("capDatiFatturazione");
	if(c.value==""){
		alert("Inserire un CAP per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("provinciaDatiFatturazione");
	if(c.value==""){
		alert("Inserire una provincia per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("nazioneDatiFatturazione");
	if(c.value==""){
		alert("Inserire un nazione per la fatturazione");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefonoDatiFatturazione");
	c2=document.getElementById("cellulareDatiFatturazione");
	if(c.value=="" && c2.value==""){
		alert("Inserire almeno un numero di cellulare o di telefono");
		c.focus();
		return;
	}
	
	c=document.getElementById("emailDatiFatturazione");
	if(c.value==""){
		alert("Inserire una email per la fatturazione");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Inserire un indirizzo email corretto per la fatturazione");
		c.focus();
		return 1;
	}

	document.getElementById("controlloDatiFatturazione").value='aggiorna';
	document.getElementById("formDatiFatturazione").action='carrello_spedizione_ita.php';
	document.getElementById("formDatiFatturazione").submit();
}






 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO DATI SPEDIZIONE
 ///////////////////////////////////////////////////////////////////////////////////
 
function sendDatiSpedizione(){

	c=document.getElementById("nomeDatiSpedizione");
	if(c.value==""){
		alert("Inserire un nome per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("cognomeDatiSpedizione");
	if(c.value==""){
		alert("Inserire un cognome per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("campanelloDatiSpedizione");
	if(c.value==""){
		alert("Inserire un nome per il campo 'Nome sul campanello'");
		c.focus();
		return;
	}
	
	c=document.getElementById("indirizzoDatiSpedizione");
	if(c.value==""){
		alert("Inserire un indirizzo per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("civicoDatiSpedizione");
	if(c.value==""){
		alert("Inserire una civico per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("cittaDatiSpedizione");
	if(c.value==""){
		alert("Inserire una città per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("capDatiSpedizione");
	if(c.value==""){
		alert("Inserire un CAP per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("provinciaDatiSpedizione");
	if(c.value==""){
		alert("Inserire una provincia per la spedizione");
		c.focus();
		return;
	}
	
	c=document.getElementById("nazioneDatiSpedizione");
	if(c.value==""){
		alert("Inserire un nazione per la spedizione");
		c.focus();
		return;
	}

	c=document.getElementById("giornoDatiSpedizione");
	if(c.value==""){
		alert("Inserire un giorno preferito per la ricezione del pacco");
		c.focus();
		return;
	}
	
	// Definisco il numero di radio disponibili!
	var n_opt = 2;
	var n = (n_opt - 1);
	c=document.getElementById("ampmDatiSpedizione");
	for (i=0; i<=n; i++){
	if (document.formDatiSpedizione.ampmDatiSpedizione[i].checked){
			//alert("Ok un voto");
      		break;
    	}else{
	  		if(i == n){
				alert("Selezionare una preferenza per la consegna: mattino o pomeriggio");
				c.focus();
				return;
	  		}
		}
	}
	
	c=document.getElementById("orarioDatiSpedizione");
	if(c.value==""){
		alert("Inserire un orario preferito per la ricezione del pacco");
		c.focus();
		return;
	}

	document.getElementById("controlloDatiSpedizione").value='aggiorna';
	document.getElementById("formDatiSpedizione").action='carrello_pagamento_ita.php';
	document.getElementById("formDatiSpedizione").submit();
}


 ///////////////////////////////////////////////////////////////////////////////////
 // CONTROLLO TIPO PAGAMENTO
 ///////////////////////////////////////////////////////////////////////////////////
 
function sendTipoPagamento(){

	
	
	// Definisco il numero di radio disponibili!
	var n_opt = 3;
	var metodo = "";
	var n = (n_opt - 1);
	c=document.getElementById("pagamento");
	for (i=0; i<=n; i++){
	if (document.formDatiPagamento.pagamento[i].checked){
			//alert("Ok un voto");
			metodo=document.formDatiPagamento.pagamento[i].value;
      		break;
    	}else{
	  		if(i == n){
				alert("Selezionare una preferenza per il pagamento");
				c.focus();
				return;
	  		}
		}
	}
	
	

	//document.getElementById("formDatiSpedizione").azione.value='inviacommento';
	
		document.getElementById("formDatiPagamento").action='carrello_riepilogo_ita.php';

		document.getElementById("formDatiPagamento").submit();
}