﻿function OpenAdmin(pag){
    switch(pag){
        case 1:
            window.location="Admin/Admin.aspx";
            break;
        case 2:
            window.location="Admin/News.aspx";
            break;    
    }
}
function OpenNews(ID) {
    window.location = "News.aspx?ID=" + ID;
}

function LoginHome(msg){
    if(document.form1.panLogin_UserName.value=="" || document.form1.panLogin_Password.value==""){
        alert(msg);
        return;
    }
    document.form1.Comando.value="01 usr="+document.form1.panLogin_UserName.value+"; pwd="+document.form1.panLogin_Password.value+";" 
    document.form1.action="Default.aspx";
    document.form1.submit();
}
function Login(msg){
    if(document.form1.panLogin_UserName.value=="" || document.form1.panLogin_Password.value==""){
        alert(msg);
        return;
    }
    document.form1.Comando.value="01 usr="+document.form1.panLogin_UserName.value+"; pwd="+document.form1.panLogin_Password.value+";" 
    document.form1.submit();
}

function Logout(){
    document.form1.Comando.value="02";
    document.form1.submit();
}

/* Selezione lingua */
function SetIta(){  
    document.form1.Comando.value="03 IT";
    document.form1.submit();
}
function SetEng(){  
    document.form1.Comando.value="03 EN";
    document.form1.submit();
}
function SetEsp(){  
    document.form1.Comando.value="03 ES";
    document.form1.submit();
}

function PopUpProdotti(foto){
    var w = 700;
    var h = 550;
    var l = Math.floor((screen.width-w)/2);
    var t = Math.floor((screen.height-h)/2);
    window.open("PopUpProdotti.aspx?ID="+foto,"","top="+t+",left="+l+",width="+w+",height="+h+",status=no,scroolbar=no,menubar=no,toolbar=no,resizable=no,location=no");
}
/*-----------------------------------------*/

function OnCart(){
    window.location="Carrello.aspx";
}
function OpenInfo(item,src){
    if(item=="?"){
        return;
    }
    if(src=="EE"){
        document.form1.Comando.value=src+" itm="+item+";";
    }
    if(src=="FF"){
        comd=src+" itm="+item+";";
        comd+="pag="+document.form1.CurrPage.value+";";
        comd+="cat="+document.form1.Categoria.value+";";
        comd+="ord="+document.form1.OrdinaPer.value+";";
        comd+="oin="+document.form1.OnlyIn.checked+";";
        comd+="src="+document.form1.txtFind.value+";";
        comd+="cod="+document.form1.chkCodice.checked+";";
        comd+="art="+document.form1.chkArticolo.checked+";";
        document.form1.Comando.value=comd;
    }
    document.form1.action="InfoProdotto.aspx";
    document.form1.__VIEWSTATE.disabled = true;
    document.form1.submit();
}

function ImgLarge(img){
    window.open("PopUp.aspx?Img="+img,"Agrioil","width=700,height=750,scrollbars=yes,resizable=yes");
}
function Resize(){
    chgt=document.getElementById("Central").offsetHeight;
    rhgt=document.getElementById("RightForm").offsetHeight;
    lhgt=document.getElementById("LeftForm").offsetHeight;
    chgt+=34;
    rhgt+=34;
    
    if (lhgt>rhgt && lhgt>chgt){
        document.getElementById("RightForm").style.height=(lhgt-40)+"px";        
        document.getElementById("Central").style.height=(lhgt-40)+"px";        
        return;
    }
    if (chgt<lhgt && rhgt<lhgt){
        document.getElementById("RightForm").style.height=(lhgt-40)+"px";
        return;
    } 
    if (rhgt>lhgt && rhgt>chgt){
        document.getElementById("LeftForm").style.height=(rhgt+5)+"px";
        return;
    }
    if (chgt>lhgt){
        document.getElementById("LeftForm").style.height=(chgt+34)+"px";
    }
    if (chgt>rhgt){
        document.getElementById("RightForm").style.height=(chgt-6)+"px";
    }
}

function ResizePage(){
    chgt=document.getElementById("frCentral").offsetHeight; 
    lhgt=document.getElementById("frLeft").offsetHeight; 
    if(chgt<lhgt){
        chgt=(lhgt-5);
        document.getElementById("frCentral").style.height=chgt+"px";
        return;
    } 
    if (lhgt<chgt){
        lhgt=chgt;
        document.getElementById("frLeft").style.height=lhgt+"px";
    }
}
function ResizeHome(){
    chgt=document.getElementById("frCentral").offsetHeight; 
    lhgt=document.getElementById("frLeft").offsetHeight; 
    
    if (lhgt<chgt){
        lhgt=chgt;
        document.getElementById("frLeft").style.height=lhgt+"px";
    }
}

function Back(src){
    switch (src){
        case 1:
            window.location="Default.aspx";
            break;
        case 2:      
            document.form1.action="Prodotti.aspx";
            document.form1.__VIEWSTATE.disabled = true;
            document.form1.submit();
            break;
    }
}

/*Catalogo*/
function Aggiorna(){
    document.form1.submit();
}
function Reset(){
    document.form1.OnlyIn.checked=false;
    document.form1.chkCodice.checked=false;
    document.form1.chkArticolo.checked=true;
    document.form1.txtFind.value="";
    document.form1.submit();
}
function SelCategoria(cat){
    document.form1.Comando.value="";
    document.form1.Categoria.value=cat;
    document.form1.submit();
}
function ChangePag(pag){
    document.form1.CurrPage.value=pag;
    document.form1.submit();
}

/* Registrazione */
function InviaReg(){
    var chkInvio=true;
    
    if(document.form1.txtAzienda.value=="") chkInvio=false;
    if(document.form1.txtIndirizzo.value=="") chkInvio=false;
    if(document.form1.txtCitta.value=="") chkInvio=false;
    if(document.form1.txtCap.value=="") chkInvio=false;
    if(document.form1.txtNazione.value=="") chkInvio=false;
    if(document.form1.txtTelefono.value=="") chkInvio=false;
    //if(document.form1.txtPIva.value=="") chkInvio=false;
    if(document.form1.txtCodFiscale.value=="") chkInvio=false;
    if(document.form1.txtMail.value=="") chkInvio=false;
    if(document.form1.txtPass.value=="") chkInvio=false;
    if(document.form1.chkPrivacy.checked==false){
        alert("Per effettuare la registrazione è necessario accettare la clausola relativa al trattamento dei dati personali.");
        return;
    }        
    
    if (chkInvio){
        if(document.form1.txtMail.value!=document.form1.txtMailConf.value){
            alert("La mail inserita e la mail di conferma non coincidono.")
            return;
        } 
        if(document.form1.txtPassConf.value!=document.form1.txtPass.value){
            alert("La password inserita e la password di conferma non coincidono.")
            return;
        } 
        if (isEmail(document.form1.txtMail.value)==0){
            alert("Attenzione, l'indirizzo email indicato non è valido.");
            return;
        }
        document.form1.Comando.value="99";
        document.form1.submit();
    }
    else{
        alert("Compilare tutti i campi contrassegnati con l'asterisco (*)")
    }
}
function Annulla(msg){
    if(confirm(msg)){
        document.form1.reset();
    }
}
function SelezionaNews(){
    window.location="News.aspx?ID="+document.form1.ComboNews.value;
}

/* Recupera password */
function Recupera(){
    if (document.form1.txtMail.value==""){
        alert("Specificare l'indirizzo email da utilizzare per il recupero della password.");
        return;
    }
    document.form1.Comando.value=1;
    document.form1.submit();
}

/* Check mail */
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
        return 1;
    else
        return 0;
}

/* Ordine */
function InviaOrdine(){
    if (document.getElementById("TipoPagamento_2").checked==true){
         /*document.form1.action="https://www.sandbox.paypal.com/cgi-bin/webscr";*/
        document.form1.action="PayPalSend.aspx";
        document.form1.submit();    
    }
    else{
        document.form1.Comando.value="O1";
        document.form1.submit();    
    }
}    
//function CambiaPagamento(){
//    if (document.getElementById("TipoPagamento_0").checked==true){
//        document.getElementById("HidBox").style.display="inherit";
//        document.getElementById("HidPayPal").style.display="none";
//        return;
//    }
//    if (document.getElementById("TipoPagamento_1").checked==true){
//        document.getElementById("HidBox").style.display="none";
//        document.getElementById("HidPayPal").style.display="none";
//        return;
//    }
//    if (document.getElementById("TipoPagamento_2").checked==true){
//        document.getElementById("HidBox").style.display="none";
//        document.getElementById("HidPayPal").style.display="inherit";
//        return;
//    }
//}

function Cerca() {
    src = document.form1.txtSearch.value;
    if (src == "") return;
    document.form1.Comando.value = "30 src="+src+";";
    document.form1.submit();
}
function OpenMail() {
    window.location = "HtmlStatiche/WebMail.htm.htm";
}