// JavaScript Document
// rosalinda scarcia


//<![CDATA[
function mostraBig(img, min_id) {
    //imgGrande = document.getElementById("imgGrande");
    alt_txt = document.getElementById(min_id).alt;
    //title_txt = document.getElementById(min_id).title;
    document.getElementById("imgGrande").src = "img/gallery_negozio/" + img;
    document.getElementById("imgGrande").alt = alt_txt;
    //imgGrande.title = title_txt;
    return true;
}
function mostraBigP(img, min_id) {
    //imgGrande = document.getElementById("imgGrande");
    alt_txt = document.getElementById(min_id).alt;
    //title_txt = document.getElementById(min_id).title;
    document.getElementById("imgGrande").src = "admin/img/prodotti/big/" + img;
    document.getElementById("imgGrande").alt = alt_txt;
    //imgGrande.title = title_txt;
    return true;
}

function validateForm(frm) {
    lingua = frm.lingua.value;

    if (!isName(frm.nome.value, 'NOME', 'NAME', lingua)) return false;
    if (!isName(frm.cognome.value, 'COGNOME', 'SURNAME', lingua)) return false;
    if (!isUserid(frm.userid.value, 'USERID', lingua)) return false;
    if (!isPassword(frm.password.value, 'PASSWORD', lingua)) return false;
    if (frm.userid.value == frm.password.value) {
        if (lingua == "IT") { alert("I campi USERID e PASSWORD non possono essere uguali!"); }
        else if (lingua == "EN") { alert("The fields USERID and PASSWORD can't be the same."); }
        document.forms["form_utente"].password.focus();
        return false;
    }
    if (!isPassword(frm.password2.value, 'PASSWORD 2', lingua)) return false;
    if (frm.password.value != frm.password2.value) {
        if (lingua == "IT") { alert("I campi PASSWORD non sono uguali!"); }
        else if (lingua == "EN") { alert("The fields PASSWORD don't be the same."); }
        document.forms["form_utente"].password2.focus();
        return false;
    }
    if (!isEmail(frm.email.value, lingua)) return false;
    if (!isInd(frm.via.value, 'VIA', 'STREET ADDRESS', lingua)) return false;
    if (!isNum(frm.civico.value, lingua)) return false;
    if (!isCAP(frm.cap.value, lingua)) return false;
    if (!isInd(frm.citta.value, 'CITTÀ', 'CITY', lingua)) return false;
    if (!isProv(frm.provincia.value, 'PROVINCIA', 'PROVINCE', lingua)) return false;
    if (!isInd(frm.stato.value, 'STATO', 'STATE', lingua)) return false;
    if (!isTel(frm.tel.value, lingua)) return false;
    if (frm.eta.selectedIndex == 0) {
        if (lingua == "IT") { alert("Il campo FASCIA DI ETA' non e' valido!"); }
        else if (lingua == "EN") { alert("The field AGE is not valid."); }
        return false;
    }
    if (!frm.condizioni.checked) {
        if (lingua == "IT") { alert("Conferma di conoscere le condizioni generali di vendita!"); }
        else if (lingua == "EN") { alert("Conferma di conoscere le condizioni generali di vendita!"); }
        return false;
    }
    if (!frm.privacy.checked) {
        if (lingua == "IT") { alert("Conferma di acconsentire al trattamento dei tuoi dati personali!"); }
        else if (lingua == "EN") { alert("Conferma di acconsentire al trattamento dei tuoi dati personali!"); }
        return false;
    }
    if (lingua == "IT") { return confirm("Confermi la registrazione dei dati?"); }
    else if (lingua == "EN") { return confirm("Confirm your user registration data?"); }
}

function validateFormOrdine(frm) {
    lingua = frm.lingua.value;
    disp = frm.disponibilita.value;
    if (disp == "off") {

        if (lingua == "IT") { alert("Nel carrello sono presenti prodotti non disponibili! \nRiducili o contattaci!"); }
        else if (lingua == "EN") { alert("There are not available product in your basket!"); }
        return false;
    }
    ute_cod = frm.ute_cod.value;
    var cod = new RegExp("^[0-9]{1,}$");
    if (!ute_cod.match(cod)) {
        if (lingua == "IT") { alert("Effettuare il LOGIN o la REGISTRAZIONE prima di inoltrare l'ordine!"); }
        else if (lingua == "EN") { alert("LOGIN or REGISTER your user account before order!"); }
        return false;
    }
    var appo1 = false;
    for (i = 0; i < document.getElementsByName("spedizione").length; i++) {
        if (document.getElementsByName("spedizione").item(i).checked) {
            appo1 = true;
        }
    }
    var appo2 = false;
    for (i = 0; i < document.getElementsByName("pagamento").length; i++) {
        if (document.getElementsByName("pagamento").item(i).checked) {
            appo2 = true;
        }
    }
    if (appo1 != true) {
        if (lingua == "IT") { alert("Seleziona una modalita' di SPEDIZIONE!"); }
        else if (lingua == "EN") { alert("Select a type of DELIVERY before order!"); }
        return false;
    }
    if (appo2 != true) {
        if (lingua == "IT") { alert("Seleziona una modalita' di PAGAMENTO!"); }
        else if (lingua == "EN") { alert("Select a type of PAYMENT before order!"); }
        return false;
    }
    if (document.getElementById("regalo").checked) {
        if (!isName(frm.nome.value, 'NOME', 'NAME', lingua)) return false;
        if (!isName(frm.cognome.value, 'COGNOME', 'SURNAME', lingua)) return false;
        if (!isInd(frm.via.value, 'VIA', 'STREET ADDRESS', lingua)) return false;
        if (!isNum(frm.civico.value, lingua)) return false;
        if (!isCAP(frm.cap.value, lingua)) return false;
        if (!isInd(frm.citta.value, 'CITTÀ', 'CITY', lingua)) return false;
        if (!isProv(frm.provincia.value, 'PROVINCIA', 'PROVINCE', lingua)) return false;
        if (!isInd(frm.stato.value, 'STATO', 'STATE', lingua)) return false;
        if (document.getElementById("messaggio").textLength == 0) {
            if (lingua == "IT") { return confirm("Nessun MESSAGGIO d'AUGURI accompagnera' il regalo.\nConfermi l'ordine?"); }
            else if (lingua == "EN") { return confirm("No GHIFT message writed.\nConfirm your order?"); }
        }
    }
    if (lingua == "IT") { return confirm("Confermi l'ordine?"); }
    else if (lingua == "EN") { return confirm("Confirm your order?"); }
}
// VERIFICA NOME, COGNOME, CITTA, ...
function isName(what, fnameIt, fnameEn, lingua) {
    var i = new RegExp("([a-zA-Z\ ]{3,})");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo " + fnameIt + " non e' valido."); }
        else if (lingua == "EN") { alert("The field " + fnameEn + " is not valid."); }
        return false;
    }
    return true;
}
function isInd(what, fnameIt, fnameEn, lingua) {
    var i = new RegExp("([a-zA-Z\ ]{3,})");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo " + fnameIt + " non e' valido."); }
        else if (lingua == "EN") { alert("The field " + fnameEn + " is not valid."); }
        return false;
    }
    return true;
}
// VERIFICA PROVINCIA
function isProv(what, fnameIt, fnameEn, lingua) {
    var i = new RegExp("^[a-zA-Z]{2}$");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo " + fnameIt + " non e' valido."); }
        else if (lingua == "EN") { alert("The field " + fnameEn + " is not valid."); }
        return false;
    }
    return true;
}

// VERIFICA EMAIL
function isEmail(what, lingua) {
    var i = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo E-MAIL non e' valido."); }
        else if (lingua == "EN") { alert("The field E-MAIL is not valid."); }
        return false;
    }
    return true;
}

// VERIFICA PASSWORD
function isPassword(what, fname) {
    var i = new RegExp("^[a-zA-Z0-9]{5,11}$");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo " + fname + " non e' valido."); }
        else if (lingua == "EN") { alert("The field " + fname + " is not valid."); }
        return false;
    }
    return true;
}
// VERIFICA USERID
function isUserid(what, fname) {
    var i = new RegExp("^[a-zA-Z0-9\.]{5,21}$");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo " + fname + " non e' valido."); }
        else if (lingua == "EN") { alert("The field " + fname + " is not valid."); }
        return false;
    }
    return true;
}

// VERIFICA CAP
function isCAP(what, lingua) {
    if (lingua == "IT") { i = new RegExp("^[0-9]{5}$"); }
    else if (lingua == "EN") { i = new RegExp("^[0-9]{10}$"); }
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo CAP non e' valido."); }
        else if (lingua == "EN") { alert("The field ZIP CODE is not valid."); }
        return false;
    }
    return true;
}

// VERIFICA NUM CIVICO
function isNum(what, lingua) {
    var i = new RegExp("^[0-9]{1,4}$");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo N. CIVICO non e' valido."); }
        else if (lingua == "EN") { alert("The field STREET NUMBER is not valid."); }
        return false;
    }
    return true;
}

// VERIFICA TEL
function isTel(what, lingua) {
    var i = new RegExp("^[0-9\.\/\-]{10,15}$");
    if (!i.test(what)) {
        if (lingua == "IT") { alert("Il campo TEL./CELL. non e' valido."); }
        else if (lingua == "EN") { alert("The field PHONE/MOBILE is not valid."); }
        return false;
    }
    return true;
}


function Elimina(frm, cod) {
    document.getElementById("cod").value = cod;
    document.getElementById(frm).submit();
}

//CARRELLO
function SommaPag(pre) {
    var totale
    app1 = pre.replace(',', '.');
    app2 = document.getElementById("totale_carrello").value.replace(',', '.');
    app3 = document.getElementById("spe").value.replace(',', '.');

    pag = parseFloat(app1);
    tot_carrello = parseFloat(app2);
    spe = parseFloat(app3);

    app1 = app1.replace('.', ',');
    document.getElementById("pag").value = app1;

    var somma = 0;
    somma = tot_carrello + pag + spe;

    formato = somma.toString();

    var i = new RegExp("([.]{1})");
    if (i.test(formato)) {
        array = formato.split('.');
        if (array[1].length == 1) {
            totale = array[0] + ',' + array[1] + '0';
        } else {
            totale = array[0] + ',' + array[1];
        }
    }
    else {
        totale = formato + ',00';
    }

    document.getElementById("totale_ordine").value = totale;
}
function SommaSpe(pre) {
    var totale
    app1 = pre.replace(',', '.');
    app2 = document.getElementById("totale_carrello").value.replace(',', '.');
    app3 = document.getElementById("pag").value.replace(',', '.');

    spe = parseFloat(app1);
    tot_carrello = parseFloat(app2);
    pag = parseFloat(app3);


    app1 = app1.replace('.', ',');
    document.getElementById("spe").value = app1;

    var somma = 0;
    somma = tot_carrello + pag + spe;

    formato = somma.toString();
    array = formato.split('.');

    var i = new RegExp("([.]{1})");
    if (i.test(formato)) {
        array = formato.split('.');
        if (array[1].length == 1) {
            totale = array[0] + ',' + array[1] + '0';
        } else {
            totale = array[0] + ',' + array[1];
        }
    }
    else {
        totale = formato + ',00';
    }

    document.getElementById("totale_ordine").value = totale;

}

function mouseOver(input) {
    //classe = document.getElementById(input).className;
    //document.getElementById(input).className = classe + "_Over";
    //document.getElementById(input).style.color = "#e21738";
    document.getElementById(input).style.color = "Silver";

}

function mouseOut(input) {
    document.getElementById(input).style.color = "#fff";
}

function codificaHTML(testo) {
    //elementi = document.getElementsByTagName("textarea");
    //for (i = 0; i < elementi.length; i++) {
        //elemento = elementi.item(i);
        strHTML = testo;
        //Tratta da iso8859-1 table
        if (strHtml != null) {
            //strHtml = strHtml.replace("&","&amp;");
            //strHtml =  strHtml.replace("\"","&quot;");
            //strHtml =  strHtml.replace("<","&lt;");
            //strHtml =  strHtml.replace(">","&gt;");
            //strHtml =  strHtml.replace(" ","&nbsp;");
            //strHtml =  strHtml.replace("¡","&iexcl;");
            //strHtml =  strHtml.replace("¢","&cent;");
            //strHtml =  strHtml.replace("£","&pound;");
            //strHtml =  strHtml.replace("¤","&curren;");
            //strHtml =  strHtml.replace("¥","&yen;");
            //strHtml =  strHtml.replace("¦","&brvbar;");
            //strHtml =  strHtml.replace("§","&sect;");
            //strHtml =  strHtml.replace("¨","&uml;");
            //strHtml =  strHtml.replace("©","&copy;");
            //strHtml =  strHtml.replace("ª","&ordf;");
            //strHtml =  strHtml.replace("«","&laquo;");
            //strHtml =  strHtml.replace("¬","&not;");
            //strHtml =  strHtml.replace("­","&shy;");
            //strHtml =  strHtml.replace("®","&reg;");
            //strHtml =  strHtml.replace("¯","&macr;");
            //strHtml =  strHtml.replace("°","&deg;");
            //strHtml =  strHtml.replace("±","&plusmn;");
            //strHtml =  strHtml.replace("²","&sup2;");
            //strHtml =  strHtml.replace("³","&sup3;");
            //strHtml =  strHtml.replace("´","&acute;");
            strHtml = strHtml.replace("´", "'");
            //strHtml =  strHtml.replace("µ","&micro;");
            //strHtml =  strHtml.replace("¶","&para;");
            //strHtml =  strHtml.replace("·","&middot;");
            //strHtml =  strHtml.replace("¸","&cedil;");
            //strHtml =  strHtml.replace("¹","&sup1;");
            //strHtml =  strHtml.replace("º","&ordm;");
            //strHtml =  strHtml.replace("»","&raquo;");
            //strHtml =  strHtml.replace("¼","&frac14;");
            //strHtml =  strHtml.replace("½","&frac12;");
            //strHtml =  strHtml.replace("¾","&frac34;");
            //strHtml =  strHtml.replace("¿","&iquest;");
            //strHtml =  strHtml.replace("À","&Agrave;");
            //strHtml =  strHtml.replace("Á","&Aacute;");
            strHtml = strHtml.replace("À", "A'");
            strHtml = strHtml.replace("Á", "A'");
            //strHtml =  strHtml.replace("Â","&Acirc;");
            //strHtml =  strHtml.replace("Ã","&Atilde;");
            //strHtml =  strHtml.replace("Ä","&Auml;");
            //strHtml =  strHtml.replace("Å","&Aring;");
            //strHtml =  strHtml.replace("Æ","&AElig;");
            //strHtml =  strHtml.replace("Ç","&Ccedil;");
            //strHtml =  strHtml.replace("È","&Egrave;");
            //strHtml =  strHtml.replace("É","&Eacute;");
            strHtml = strHtml.replace("È", "E'");
            strHtml = strHtml.replace("É", "E'");
            //strHtml =  strHtml.replace("Ê","&Ecirc;");
            //strHtml =  strHtml.replace("Ë","&Euml;");
            //strHtml =  strHtml.replace("Ì","&Igrave;");
            //strHtml =  strHtml.replace("Í","&Iacute;");
            strHtml = strHtml.replace("Ì", "I'");
            strHtml = strHtml.replace("Í", "I'");
            //strHtml =  strHtml.replace("Î","&Icirc;");
            //strHtml =  strHtml.replace("Ï","&Iuml;");
            //strHtml =  strHtml.replace("Ð","&ETH;");
            //strHtml =  strHtml.replace("Ñ","&Ntilde;");
            //strHtml =  strHtml.replace("Ò","&Ograve;");
            //strHtml =  strHtml.replace("Ó","&Oacute;");
            strHtml = strHtml.replace("Ò", "O'");
            strHtml = strHtml.replace("Ó", "O'");
            //strHtml =  strHtml.replace("Ô","&Ocirc;");
            //strHtml =  strHtml.replace("Õ","&Otilde;");
            //strHtml =  strHtml.replace("Ö","&Ouml;");
            //strHtml =  strHtml.replace("×","&times;");
            //strHtml =  strHtml.replace("Ø","&Oslash;");
            //strHtml =  strHtml.replace("Ù","&Ugrave;");
            //strHtml =  strHtml.replace("Ú","&Uacute;");
            strHtml = strHtml.replace("Ù", "U'");
            strHtml = strHtml.replace("Ú", "U'");
            //strHtml =  strHtml.replace("Û","&Ucirc;");
            //strHtml =  strHtml.replace("Ü","&Uuml;");
            //strHtml =  strHtml.replace("Ý","&Yacute;");
            //strHtml =  strHtml.replace("Þ","&THORN;");
            //strHtml =  strHtml.replace("ß","&szlig;");
            //strHtml =  strHtml.replace("à","&agrave;");
            //strHtml =  strHtml.replace("á","&aacute;");
            strHtml = strHtml.replace("à", "&agrave;");
            strHtml = strHtml.replace("á", "&aacute;");
            //strHtml =  strHtml.replace("â","&acirc;");
            //strHtml =  strHtml.replace("ã","&atilde;");
            //strHtml =  strHtml.replace("ä","&auml;");
            //strHtml =  strHtml.replace("å","&aring;");
            //strHtml =  strHtml.replace("æ","&aelig;");
            //strHtml =  strHtml.replace("ç","&ccedil;");
            //strHtml =  strHtml.replace("è","&egrave;");
            //strHtml =  strHtml.replace("é","&eacute;");
            strHtml = strHtml.replace("è", "e'");
            strHtml = strHtml.replace("é", "e'");
            //strHtml =  strHtml.replace("ê","&ecirc;");
            //strHtml =  strHtml.replace("ë","&euml;");
            //strHtml =  strHtml.replace("ì","&igrave;");
            //strHtml =  strHtml.replace("í","&iacute;");
            strHtml = strHtml.replace("ì", "i'");
            strHtml = strHtml.replace("í", "i'");
            //strHtml =  strHtml.replace("î","&icirc;");
            //strHtml =  strHtml.replace("ï","&iuml;");
            //strHtml =  strHtml.replace("ð","&eth;");
            //strHtml =  strHtml.replace("ñ","&ntilde;");
            //strHtml =  strHtml.replace("ò","&ograve;");
            //strHtml =  strHtml.replace("ó","&oacute;");
            strHtml = strHtml.replace("ò", "o'");
            strHtml = strHtml.replace("ó", "o'");
            //strHtml =  strHtml.replace("ô","&ocirc;");
            //strHtml =  strHtml.replace("õ","&otilde;");
            //strHtml =  strHtml.replace("ö","&ouml;");
            //strHtml =  strHtml.replace("÷","&divide;");
            //strHtml =  strHtml.replace("ø","&oslash;");
            //strHtml =  strHtml.replace("ù","&ugrave;");
            //strHtml =  strHtml.replace("ú","&uacute;");
            strHtml = strHtml.replace("ù", "u'");
            strHtml = strHtml.replace("ú", "u'");
            //strHtml =  strHtml.replace("û","&ucirc;");
            //strHtml =  strHtml.replace("ü","&uuml;");
            //strHtml =  strHtml.replace("ý","&yacute;");
            //strHtml =  strHtml.replace("þ","&thorn;");
            //strHtml =  strHtml.replace("ÿ","&yuml;");
            strHtml = strHtml.replace("“", "'");
            strHtml = strHtml.replace("”", "'");

        }
        //elemento.value = strHTML;
    //}
    return strHTML;
}

//]]>

