/*function init() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
alert(e.pageX)
alert(event.clientX + document.body.scrollLeft)
  MouseX = (window.Event) ? e.pageX : event.clientX + document.body.scrollLeft;
  MouseY = (window.Event) ? e.pageY : event.clientY + document.body.scrollTop;
}*/



// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var MouseX = 0
var MouseY = 0
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    MouseX = event.clientX + document.body.scrollLeft
    MouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    MouseX = e.pageX
    MouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (MouseX < 0){MouseX = 0}
  if (MouseY < 0){MouseY = 0}  
  return true
}





function Pagine(Pag) {
    var Filtro=ImpostaFiltro();
    if (Pag>0) {
        //Pagina avanti
        self.location="index.php?PaginaCorrente="+PaginaCorrente+"&CodMerc="+CodMerc+"&PagCorrente="+(PagCorrente+1)+"&PagTotali="+PagTotali+"&ArtPerPag="+document.forms["naviga1"].cmbArtPerPag.value+Filtro;
    } else {
        //Pagina indietro
        self.location="index.php?PaginaCorrente="+PaginaCorrente+"&CodMerc="+CodMerc+"&PagCorrente="+(PagCorrente-1)+"&PagTotali="+PagTotali+"&ArtPerPag="+document.forms["naviga1"].cmbArtPerPag.value+Filtro;
    }
}
function cmbArtPerPag_OnChange() {
    var Filtro=ImpostaFiltro();
    self.location="index.php?PaginaCorrente="+PaginaCorrente+"&CodMerc="+CodMerc+"&ArtPerPag="+document.forms["naviga1"].cmbArtPerPag.value+Filtro;
}
function cmbArtPerPag2_OnChange() {
    var Filtro=ImpostaFiltro();
    self.location="index.php?PaginaCorrente="+PaginaCorrente+"&CodMerc="+CodMerc+"&ArtPerPag="+document.forms["naviga2"].cmbArtPerPag2.value+Filtro;
}
function SelVar(CodVar,CodArt,Immagine) {
    SelezioneVariante=true;
    var Art=CodArt.substr(0,CodArt.lastIndexOf("_"));
    var Variante=CodArt.substr(CodArt.lastIndexOf("_")+1);
    
    var Cod=document.getElementById("txtVar"+Variante+"_"+Art)
    Cod.value=CodVar;

    var Img=document.getElementById("imgVar"+Variante+"_"+Art)
    Img.src="immagini_sito/varianti/"+Immagine;
    
    var box=document.getElementById(Art+"_"+Variante);
    box.style.visibility="hidden";
    
    //Visualizzo bollino disponibilità
    var Salta=false;
    if (document.getElementById("txtVar1_"+Art)&&document.getElementById("txtVar2_"+Art)) {
        var CodVar1=document.getElementById("txtVar1_"+Art)
        var CodVar2=document.getElementById("txtVar2_"+Art)
        if (CodVar1.value!=""&&CodVar2.value!="") PHPCheck('VisDispo',Art,CodVar1.value,CodVar2.value);
    } else {
        var CodVar1=document.getElementById("txtVar1_"+Art)
        if (CodVar1.value!="") PHPCheck('VisDispo',Art,CodVar1.value,"");
    }
}
function ApriPopVariante(IdLayer) {
    AperturaInCorso=true;
    PopVarAperto=IdLayer;
    var box=document.getElementById(IdLayer);
    box.style.left=(MouseX-280)+"px";
    box.style.top=(MouseY)+"px";
    box.style.visibility="visible";
}
function OrdineMultiplo(CodArticolo,DaCarrello) {
//BAO    var wOM=window.open("ordine-multiplo.php?CodArt="+CodArticolo+"&DaCarrello="+DaCarrello,"OM","width=400,height=220,scroll=yes,status=yes,resizable=yes");
    var wOM=window.open("ordine-multiplo.php?CodArt="+CodArticolo+"&DaCarrello="+DaCarrello,"OM","width=640,height=220,scroll=yes,status=yes,resizable=yes");
}
function popClose(IdLayer) {
    PopVarAperto="";
    var box=document.getElementById(IdLayer);
    box.style.visibility = "hidden";
}
function popCloseAll() {
    if (AperturaInCorso) AperturaInCorso=false;
    else if (SelezioneVariante) SelezioneVariante=false;
    else {
        if (PopVarAperto!="") {
            var box=document.getElementById(PopVarAperto);
            box.style.visibility = "hidden";
            PopVarAperto="";
        }
    }
}
function OpenZoom(Immagine) {
    if (Immagine!="") {
        var wZoom=window.open("popup.php?Immagine="+Immagine,"pop","width=100,height=100,scrollbars=yes,resizable=yes")
    }
}
function VerificaQta(CodArt) {
    var auxQta=parseInt(document.forms["articoli"].elements["txtQta_"+CodArt].value+0);
    if (auxQta==0) {
        alert("Indica il numero di pezzi da acquistare");
        document.forms["articoli"].elements["txtQta_"+CodArt].focus();
    } else AggCarrello(CodArt);
}
function MostraPopImg(Thumb,Tipo) {
    if (Thumb!="") {
        var popbox=document.getElementById("PopImg");
        var popimg=document.getElementById("ImgPop");
        if (Tipo==1) {
            popimg.src=Thumb;
            popbox.style.left=MouseX+10;
            popbox.style.top=MouseY+10;
            popbox.style.visibility = "visible";
        } else popbox.style.visibility = "hidden";
    }
}

function SetCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function GetCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function DelCookie(name) {
	SetCookie(name,"",-1);
}

function AggCarrello(CodArt) {
    //Verifico se l'articolo presenta delle varianti
    var Salta=false;
    var CodVar1=document.getElementById("txtVar1_"+CodArt)
    var ImgVar1=document.getElementById("imgVar1_"+CodArt)
    if (CodVar1!=null&&CodVar1.value=="") Salta=true;
    var CodVar2=document.getElementById("txtVar2_"+CodArt)
    var ImgVar2=document.getElementById("imgVar2_"+CodArt)
    if (CodVar2!=null&&CodVar2.value=="") Salta=true;
    var FlNascondi=document.forms["articoli"].elements["txtNascondi_"+CodArt].value;
    //Se sto acquistando dal dettaglio leggo la quantità
    //if (document.forms[0].txtQta) var Qta=document.forms[0].txtQta.value;
    //else var Qta=1;
    var Qta=document.forms["articoli"].elements["txtQta_"+CodArt].value;
    if (Qta=="") Qta=1;
    else Qta=parseFloat(Qta);
    if (Qta==0) Qta=1;
    if (!Salta) {
        //Aggiungo riga articolo selezionato
        SavCookie=GetCookie("LinxCookie");
        if (CodVar1!=null) CodArt+="÷"+CodVar1.value;
        if (CodVar2!=null) CodArt+="÷"+CodVar2.value;
        if (SavCookie==null) {
            if (FlNascondi==0) SavCookie=CodArt+"_"+Qta+"_O|";
            else SavCookie=CodArt+"_"+Qta+"_P|";
        } else {
            //Cerco l'articolo
            if (SavCookie.indexOf(CodArt+"_")==-1) {
                //Se non lo trovo lo aggiungo
                if (FlNascondi==0) SavCookie+=CodArt+"_"+Qta+"_O|";
                else SavCookie+=CodArt+"_"+Qta+"_P|";
            } else {
                //Altrimenti incremento il campo qta
                var auxCookie=new Array();
                auxCookie=SavCookie.split("|");
                SavCookie="";
                for (i=0;i<auxCookie.length-1;i++) {
                    if (auxCookie[i].indexOf(CodArt)!=-1) {
                        qta=parseInt(auxCookie[i].substr(auxCookie[i].indexOf("_")+1,auxCookie[i].lastIndexOf("_")));
                        qta+=Qta;
                        SavCookie+=auxCookie[i].substr(0,auxCookie[i].indexOf("_")+1)+qta+auxCookie[i].substr(auxCookie[i].lastIndexOf("_"))+"|";
                    } else SavCookie+=auxCookie[i]+"|";
                }
            }
        }
        SetCookie("LinxCookie",SavCookie,1);
        PHPCheck('TrolleyAdd','');
        alert("L'articolo è stato aggiunto al carrello");
        //Pulisco eventuali campi varianti e quantità
        if (CodVar1!=null) {
            CodVar1.value="";
            ImgVar1.src="images/spacer.gif";
        }
        if (CodVar2!=null) {
            CodVar2.value="";
            ImgVar2.src="images/spacer.gif";
        }
        if (document.forms["articoli"].elements["txtQta_"+CodArt]) document.forms["articoli"].elements["txtQta_"+CodArt].value="";
    } else alert("Per poter acquistare l'articolo è necessario prina specificare tutte le sue varianti");
}
function EliminaRigaCarrello(CodArt) {
    if (confirm("Confermi la cancellazione della riga ?")) {
        SavCookie=GetCookie("LinxCookie");
        var auxCookie=new Array();
        auxCookie=SavCookie.split("|");
        SavCookie="";
        for (i=0;i<auxCookie.length-1;i++) {
            if (auxCookie[i].indexOf(CodArt)==-1) SavCookie+=auxCookie[i]+"|";
        }
        SetCookie("LinxCookie",SavCookie,1);
        self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;
    }
}
/*function RicalcolaCarrello() {
    var TotRighe=document.forms[0].HidTotRighe.value;
    SavCookie="";
    for (i=1;i<=TotRighe;i++) {
        //Verifico versione carrello (b2c o b2b)
        var Tipo=document.getElementsByName("radTipo"+i)(0);
        if (Tipo==null) SavCookie+=document.forms[0].elements["txtCodCarrello"+i].value+"_"+document.forms[0].elements["txtQta"+i].value+"_O|";
        else {
            if (Tipo.checked) SavCookie+=document.forms[0].elements["txtCodCarrello"+i].value+"_"+document.forms[0].elements["txtQta"+i].value+"_O|";
            else SavCookie+=document.forms[0].elements["txtCodCarrello"+i].value+"_"+document.forms[0].elements["txtQta"+i].value+"_P|";
        }
    }
    SetCookie("LinxCookie",SavCookie,1);
    self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;

}*/
function RicalcolaCarrello() {
    var TotRighe=document.forms["main"].HidTotRighe.value;
    var OldCookie=GetCookie("LinxCookie");
    OldCookie=OldCookie.substr(0,OldCookie.length-1);
    var aOldCookie=OldCookie.split("|");
    SavCookie="";
    for (i=1;i<=TotRighe;i++) {
        if (document.forms["carrello1"].elements["txtCodCarrello"+i].value.indexOf("÷")<0) {
            //Verifico versione carrello (b2c o b2b)
            var Tipo=document.getElementsByName("radTipo"+i)(0);
            if (Tipo==null) {
                SavCookie+=document.forms["carrello1"].elements["txtCodCarrello"+i].value+"_"+document.forms["carrello1"].elements["txtQta"+i].value+"_O|";
            } else {
                if (Tipo.checked) SavCookie+=document.forms["carrello1"].elements["txtCodCarrello"+i].value+"_"+document.forms["carrello1"].elements["txtQta"+i].value+"_O|";
                else SavCookie+=document.forms["carrello1"].elements["txtCodCarrello"+i].value+"_"+document.forms["carrello1"].elements["txtQta"+i].value+"_P|";
            }
        } else {
            //Se l'articolo presenta varianti reperisco le quantità dal vecchio cookie
            var DaCe=document.forms[carrello1].elements["txtCodCarrello"+i].value;
            Dace=DaCe.substr(0,DaCe.indexOf("÷")+1);
            Trovato=false;
            for (j=0;j<aOldCookie.length;j++) {
                if (aOldCookie[j].substr(0,DaCe.length)==DaCe) {
                    Trovato=true;
                    SavCookie+=aOldCookie[j]+"|";
                } else {
                    if (Trovato) j=aOldCookie.length;
                }
            }
        }
    }
    SetCookie("LinxCookie",SavCookie,1);
    self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;

}
function SvuotaCarrello(SaltaConferma,CodOrd) {
    if (document.forms["main"].HidTotRighe.value!=0) {
        if (CodOrd===undefined) CodOrd=0;
        var Prosegui=false;
        if (SaltaConferma) Prosegui=true;
        else {
            if (confirm("Confermi lo svuotamento del carrello ?")) Prosegui=true;
            else Prosegui=false;
        }
        if (Prosegui) {
            DelCookie("LinxCookie");
            if (Loggato) {
                if (!SaltaConferma) {
                    //if (confirm("Desideri svuotare anche il carrello salvato in precedenza ?")) PHPCheck("SvuotaCarrello","");
                    //else self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;
                    self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag+"&Obj=SvuotaCarrello";
                } else PHPCheck("SvuotaCarrello",CodOrd);
            } else self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;
        }
    }
}
function SalvaCarrello() {
    var TotRighe=document.forms["main"].HidTotRighe.value;
    //Elaboro stringa articoli
    var strCarrello="";
    var OldCookie=GetCookie("LinxCookie");
    OldCookie=OldCookie.substr(0,OldCookie.length-1);
    var aOldCookie=OldCookie.split("|");
    for (i=1;i<=TotRighe;i++) {
        if (document.forms["carrello1"].elements["txtCodCarrello"+i].value.indexOf("÷")<0) {
            if (document.forms["carrello1"].elements["radTipo"+i]) {
                auxTipo=(document.forms["carrello1"].elements["radTipo"+i][0].checked?"O":"P");
                strCarrello+=document.forms["carrello1"].elements["txtCod"+i].value+"÷"+document.forms["carrello1"].elements["txtQta"+i].value+"÷"+auxTipo+"|";
            } else strCarrello+=document.forms["carrello1"].elements["txtCod"+i].value+"÷"+document.forms["carrello1"].elements["txtQta"+i].value+"÷O|";
        } else {
            //Se l'articolo presenta varianti reperisco le quantità dal vecchio cookie
            var DaCe=document.forms["carrello1"].elements["txtCodCarrello"+i].value;
            DaCe=DaCe.substr(0,DaCe.indexOf("÷"));
            Trovato=false;
            for (j=0;j<aOldCookie.length;j++) {
                if (aOldCookie[j].substr(0,DaCe.length)==DaCe) {
                    Trovato=true;
                    auxCod=aOldCookie[j].substr(0,aOldCookie[j].indexOf("_"));
                    auxCod=auxCod.replace(/÷/g,".")+"÷";
                    auxQta=aOldCookie[j].substr(aOldCookie[j].indexOf("_")+1,aOldCookie[j].lastIndexOf("_")-aOldCookie[j].indexOf("_")-1)+"÷";
                    auxTipo=aOldCookie[j].substr(aOldCookie[j].lastIndexOf("_")+1)+"|";
                    strCarrello+=auxCod+auxQta+auxTipo;
                } else {
                    if (Trovato) j=aOldCookie.length;
                }
            }
        }
    }
    if (strCarrello!="") strCarrello=strCarrello.substr(0,strCarrello.length-1);
    PHPCheck("SalvaCarrello",strCarrello,"");
}
function ApriCarrello() {
    if (document.forms["naviga1"]) self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+document.forms["naviga1"].cmbArtPerPag.value;
    else self.location='index.php?PaginaCorrente=Carrello&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;
} 
function TornaCatalogo() {
    if (CodMerc=="") self.location='index.php?PaginaCorrente=Catalogo';
    else {
        if (ConFigli) self.location='index.php?PaginaCorrente=Catalogo&CodMerc='+CodMerc; 
        else self.location='index.php?PaginaCorrente=Articoli&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;
    }        
}
function Registrazione() {
    self.location="index.php?PaginaCorrente=Registrazione";
}
function PrivacyUtente(form) {
    document.forms[form].chkPrivacy.checked=false;
    if (navigator.appName=='Netscape') window.open("privacy.html","privacy","ocation=no,directories=no,scrollbars=yes,menubar=no,statusbar=no,resizable=no,width=630,height=450");
    else window.open("privacy.html","privacy","location=no,directories=no,scrollbars=yes,menubar=no,statusbar=no,resizable=no,width=630,height=450");
}
function SalvaUtente(CodUtente) {
    //Verifica campi obbligatori
    var strDaCompilare="";
    if (document.forms["registrazione"].radTipo[0].checked) {
        var campo=document.forms["registrazione"].txtCognome.value;
        if (campo.replace(/ /g, '')=="") {
            alert("ATTENZIONE! Compila il campo COGNOME");
            document.forms["registrazione"].txtCognome.focus();
            return;
        }
        var campo=document.forms["registrazione"].txtNome.value;
        if (campo.replace(/ /g, '')=="") {
            alert("ATTENZIONE! Compila il campo NOME");
            document.forms["registrazione"].txtNome.focus();
            return;
        }
    } else {
        var campo=document.forms["registrazione"].txtNome.value;
        if (campo.replace(/ /g, '')=="") {
            alert("ATTENZIONE! Compila il campo RAGIONE SOCIALE");
            document.forms["registrazione"].txtNome.focus();
            return;
        }
    }
    var campo=document.forms["registrazione"].txtIndirizzo.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo INDIRIZZO");
        document.forms["registrazione"].txtIndirizzo.focus();
        return;
    }
    var campo=document.forms["registrazione"].txtCap.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo CAP");
        document.forms["registrazione"].txtCap.focus();
        return;
    }
    var campo=document.forms["registrazione"].txtCitta.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo CITTA'");
        document.forms["registrazione"].txtCitta.focus();
        return;
    }
    var campo=document.forms["registrazione"].txtProv.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo PROVINCIA");
        document.forms["registrazione"].txtProv.focus();
        return;
    }
    if (document.forms["registrazione"].radTipo[1].checked) {
        //Azienda
        var campo=document.forms["registrazione"].txtPiCf.value;
        if (campo.replace(/ /g, '')=="") {
            alert("ATTENZIONE! Compila il campo PARTITA IVA");
            document.forms["registrazione"].txtPiCf.focus();
            return;
        }
    } else {
        //Privato
        var campo=document.forms["registrazione"].txtPiCf.value;
        if (campo.replace(/ /g, '')=="") {
            alert("ATTENZIONE! Compila il campo CODICE FISCALE");
            document.forms["registrazione"].txtPiCf.focus();
            return;
        }
    }
    var campo=document.forms["registrazione"].txtEMail.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo EMAIL");
        document.forms["registrazione"].txtEMail.focus();
        return;
    } else {
        EmailAddr = document.forms["registrazione"].txtEMail.value;
        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;    // controllo dell'email
        if (!Filtro.test(EmailAddr)) {
            alert("Controlla l'indirizzo e-mail");
            document.forms["registrazione"].txtEMail.focus();
            return;
        }
    }
    var campo=document.forms["registrazione"].selNazionalita.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo NAZIONALITA'");
        document.forms["registrazione"].selNazionalita.focus();
        return;
    }
    var campo=document.forms["registrazione"].selDivisa.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo VALUTA");
        document.forms["registrazione"].selDivisa.focus();
        return;
    }
    var campo=document.forms["registrazione"].selLingua.value;
    if (campo.replace(/ /g, '')=="") {
        alert("ATTENZIONE! Compila il campo LINGUA");
        document.forms["registrazione"].selLingua.focus();
        return;
    }

    if (CodUtente>0) {
      if (!document.forms["registrazione"].txtPassword.readOnly) {
          if (document.forms["registrazione"].txtConfPassword.value!=document.forms["registrazione"].txtPassword.value) {
              alert("ATTENZIONE! Il campo CONFERMA PASSWORD\nnon coincide con il campo PASSWORD");
              document.forms["registrazione"].txtConfPassword.focus();
              return;
          }
      }
		}
    
    if (!document.forms["registrazione"].chkPrivacy.checked) {
        alert("ATTENZIONE! Devi accettare il documento sulla PRIVACY");
        document.forms["registrazione"].chkPrivacy.focus();
        return;
    }
    //Per ultimo verifico il PIN
    //PHPCheck("VerificaPIN",document.forms["registrazione"].txtOldPin.value);
    PHPCheck("VerificaEmailDoppia",document.forms["registrazione"].txtEMail.value);
}
function Aiuto() {
    var wAiuto=window.open('guida/help-on-line.html#'+document.forms["main"].HidHelp.value,'Help','location=no, directories=no, scrollbars=yes, menubar=no, status=no, resizable=no, width=750, height=550');
}
function TipoUtente(Tipo) {
    if (Tipo=="A") {
        document.getElementById("labelNome").innerHTML="RAG.SOC.";
        document.getElementById("labelCognome").innerHTML="RAG.SOC.2";
        document.getElementById("campoCognome").innerHTML="<input name='txtCognome' type='text' size='30' maxlength='40' onfocus='select()'><font color='#FFFFFF'>*</font>";
        document.getElementById("labelCodFisc").innerHTML="PARTITA IVA";
        if (document.getElementById("labelPresentato")!=null) {
            document.getElementById("labelPresentato").innerHTML="REFERENTE";
        }
    } else {
        document.getElementById("labelNome").innerHTML="NOME";
        document.getElementById("labelCognome").innerHTML="COGNOME";
        document.getElementById("campoCognome").innerHTML="<input name='txtCognome' type='text' size='30' maxlength='40' onfocus='select()'>*";
        document.getElementById("labelCodFisc").innerHTML="CODICE FISCALE";
        if (document.getElementById("labelPresentato")!=null) {
            document.getElementById("labelPresentato").innerHTML="PRESENTATO DA";
        }
    }
}
function Logout() {
    //Uso AJAX per resettare variabili di sessione
    PHPCheck('Logout');
    //if (document.forms[0].cmbArtPerPag) self.location='index.php?PaginaCorrente='+PaginaCorrente+'&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+document.forms[0].cmbArtPerPag.value;
    //else self.location='index.php?PaginaCorrente='+PaginaCorrente+'&CodMerc='+CodMerc+'&PagCorrente='+PagCorrente+'&PagTotali='+PagTotali+'&ArtPerPag='+ArtPerPag;
}
function Login() {
    self.location='index.php?PaginaCorrente=Login';
}
function getKeyCode(e,Oggetto) {
    if (window.event) {
        var keyCode=window.event.keyCode;
        if (keyCode==13) window.event.keyCode=0;
    } else if (e) var keyCode=e.which;
    else var keyCode=0;
    switch (Oggetto) {
        case "txtPassword":
            if (keyCode==13) PHPCheck("Login",document.forms["login"].txtUtente.value,document.forms["login"].txtPassword.value);
            break;
    }
}
function ConfermaOrdine(PayPal) {
    if (PayPal===undefined) PayPal=false;
    if (PayPal) var sNomeForm="paypal";
    else var sNomeForm="carrello2";
    var Errore=false;
    //Verifico compilazione campi
    if (Loggato) {
        if (document.forms[sNomeForm].selSpedizione.value!="0"&&document.forms[sNomeForm].selSpedizione.value!="NEW") {
            var campo=document.forms[sNomeForm].txtRagSocSped.value;
            if (campo.replace(/ /g, '')=="") {
                alert("Compila il campo NOMINATIVO della sezione DATI SPEDIZIONE");
                document.forms[sNomeForm].txtRagSocSped.focus();
                return;
            } else {
                var campo=document.forms[sNomeForm].txtIndirSped.value;
                if (campo.replace(/ /g, '')=="") {
                    alert("Compila il campo INDIRIZZO della sezione DATI SPEDIZIONE");
                    document.forms[sNomeForm].txtIndirSped.focus();
                    return;
                } else {
                    var campo=document.forms[sNomeForm].txtCapSped.value;
                    if (campo.replace(/ /g, '')=="") {
                        alert("Compila il campo CAP della sezione DATI SPEDIZIONE");
                        document.forms[sNomeForm].txtCapSped.focus();
                        return;
                    } else {
                        var campo=document.forms[sNomeForm].txtCittaSped.value;
                        if (campo.replace(/ /g, '')=="") {
                            alert("Compila il campo CITTA' della sezione DATI SPEDIZIONE");
                            document.forms[sNomeForm].txtCittaSped.focus();
                            return;
                        } else {
                            var campo=document.forms[sNomeForm].txtProvSped.value;
                            if (campo.replace(/ /g, '')=="") {
                                alert("Compila il campo PROVINCIA della sezione DATI SPEDIZIONE");
                                document.forms[sNomeForm].txtProvSped.focus();
                                return;
                            }
                        }
                    }
                }
            }
        }
    } else {
//        if (document.forms[sNomeForm].txtNome.value=="") {
        var campo=document.forms[sNomeForm].txtNome.value;
        if (campo.replace(/ /g, '')=="") {
            if (document.forms[sNomeForm].radTipo[0].checked) alert("Compila il campo NOME");
            else alert("Compila il campo RAG.SOC.");
            document.forms[sNomeForm].txtNome.focus();
            return;
        } else {
            var campo=document.forms[sNomeForm].txtCognome.value;
            if (campo.replace(/ /g, '')==""&&document.forms[sNomeForm].radTipo[0].checked) {
                alert("Compila il campo COGNOME");
                document.forms[sNomeForm].txtCognome.focus();
                return;
            } else {
                var campo=document.forms[sNomeForm].txtIndir.value;
                if (campo.replace(/ /g, '')=="") {
                    alert("Compila il campo INDIRIZZO");
                    document.forms[sNomeForm].txtIndir.focus();
                    return;
                } else {
                    var campo=document.forms[sNomeForm].txtCap.value;
                    if (campo.replace(/ /g, '')=="") {
                        alert("Compila il campo CAP della sezione DATI FATTURAZIONE");
                        document.forms[sNomeForm].txtCap.focus();
                        return;
                    } else {
                        var campo=document.forms[sNomeForm].txtCitta.value;
                        if (campo.replace(/ /g, '')=="") {
                            alert("Compila il campo CITTA' della sezione DATI FATTURAZIONE");
                            document.forms[sNomeForm].txtCitta.focus();
                            return;
                        } else {
                            var campo=document.forms[sNomeForm].txtProv.value;
                            if (campo.replace(/ /g, '')=="") {
                                alert("Compila il campo PROVINCIA della sezione DATI FATTURAZIONE");
                                document.forms[sNomeForm].txtProv.focus();
                                return;
                            } else {
                                var campo=document.forms[sNomeForm].txtTel.value;
                                if (campo.replace(/ /g, '')=="") {
                                    alert("Compila il campo TELEFONO");
                                    document.forms[sNomeForm].txtTel.focus();
                                    return;
                                } else {
                                    var campo=document.forms[sNomeForm].txtPiCf.value;
                                    if (campo.replace(/ /g, '')=="") {
                                        if (document.forms[sNomeForm].radTipo[0].checked) alert("Compila il campo CODICE FISCALE");
                                        else alert("Compila il campo PARTITA IVA");
                                        document.forms[sNomeForm].txtPiCf.focus();
                                        return;
                                    } else {
                                        if (!document.forms[sNomeForm].chkPrivacy.checked) {
                                            alert("Accetta il trattamento dei dati personali");
                                            document.forms[sNomeForm].chkPrivacy.focus();
                                            return;
                                        } else {
                                            if (document.forms[sNomeForm].txtRagSocSped.value!="") {
                                                var campo=document.forms[sNomeForm].txtIndirSped.value;
                                                if (campo.replace(/ /g, '')=="") {
                                                    alert("Compila il campo INDIRIZZO della sezione DATI SPEDIZIONE");
                                                    document.forms[sNomeForm].txtIndirSped.focus();
                                                    return;
                                                } else {
                                                    var campo=document.forms[sNomeForm].txtCapSped.value;
                                                    if (campo.replace(/ /g, '')=="") {
                                                        alert("Compila il campo CAP della sezione DATI SPEDIZIONE");
                                                        document.forms[sNomeForm].txtCapSped.focus();
                                                        return;
                                                    } else {
                                                        var campo=document.forms[sNomeForm].txtCittaSped.value;
                                                        if (campo.replace(/ /g, '')=="") {
                                                            alert("Compila il campo CITTA' della sezione DATI SPEDIZIONE");
                                                            document.forms[sNomeForm].txtCittaSped.focus();
                                                            return;
                                                        } else {
                                                            var campo=document.forms[sNomeForm].txtProvSped.value;
                                                            if (campo.replace(/ /g, '')=="") {
                                                                alert("Compila il campo PROVINCIA della sezione DATI SPEDIZIONE");
                                                                document.forms[sNomeForm].txtProvSped.focus();
                                                                return;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /*if (document.forms[sNomeForm].txtPinCode) {
        if (document.forms[sNomeForm].txtPinCode.value=="") {
            alert("Compila il campo PIN CODE");
            document.forms[sNomeForm].txtPinCode.focus();
            return;
        } else PHPCheck("VerificaPinCode",document.forms[sNomeForm].txtPinCode.value,PayPal);
    } else {*/
        if (PayPal) {
            var strPar="";
            if (Loggato) {
                strPar+=document.forms["paypal"].HidConsegna.value+"÷";
                strPar+=document.forms["paypal"].HidPagamento.value+"÷";
                strPar+=document.forms["paypal"].selFatturazione.value+"÷";
                strPar+=document.forms["paypal"].selSpedizione.value+"÷";
                strPar+=document.forms["paypal"].txtRagSocSped.value+"÷";
                strPar+=document.forms["paypal"].txtIndirSped.value+"÷";
                strPar+=document.forms["paypal"].txtCapSped.value+"÷";
                strPar+=document.forms["paypal"].txtCittaSped.value+"÷";
                strPar+=document.forms["paypal"].txtProvSped.value+"÷";
                //strPar+=document.forms["paypal"].txtPinCode.value+"÷";
                strPar+="÷";
                strPar+=document.forms["paypal"].HidTotaleCarrello.value;
            } else {
                strPar+=document.forms["paypal"].HidConsegna.value+"÷";
                strPar+=document.forms["paypal"].HidPagamento.value+"÷";
                if (document.forms["paypal"].radTipo[0].checked) strPar+="P÷";
                else strPar+="A÷";
                strPar+=document.forms["paypal"].txtNome.value+"÷";
                strPar+=document.forms["paypal"].txtCognome.value+"÷";
                strPar+=document.forms["paypal"].txtIndir.value+"÷";
                strPar+=document.forms["paypal"].txtCap.value+"÷";
                strPar+=document.forms["paypal"].txtCitta.value+"÷";
                strPar+=document.forms["paypal"].txtProv.value+"÷";
                strPar+=document.forms["paypal"].txtTel.value+"÷";
                strPar+=document.forms["paypal"].txtPiCf.value+"÷";
                strPar+=document.forms["paypal"].txtEMail.value+"÷";
                strPar+=document.forms["paypal"].txtRagSocSped.value+"÷";
                strPar+=document.forms["paypal"].txtIndirSped.value+"÷";
                strPar+=document.forms["paypal"].txtCapSped.value+"÷";
                strPar+=document.forms["paypal"].txtCittaSped.value+"÷";
                strPar+=document.forms["paypal"].txtProvSped.value+"÷";
                strPar+=document.forms["paypal"].HidTotaleCarrello.value+"÷";
                strPar+="XSALE";
            }
            PHPCheck("SalvaOrdinePayPal",strPar);
        } else document.forms["carrello2"].submit();
    //}
}
function CheckEMail(EmailAddr)
{
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;    // controllo dell'email
   if (Filtro.test(EmailAddr)) return true;
   else return false;
}
