
/* pietre */
var colore_tmp_pietre = "";
function ChangeImgPietre(colore) {
   colore_tmp = colore;
   var size1 = document.getElementById("size1");
   size1.src = '../images/formati/pietre_'+colore+'300x600.jpg';
   
   var size2 = document.getElementById("size2");
   size2.src = '../images/formati/pietre_'+colore+'150x600.jpg';
   
   var size3 = document.getElementById("size3");
   size3.src = '../images/formati/pietre_'+colore+'75x600.jpg';
   
   var size4 = document.getElementById("size4");
   size4.src = '../images/formati/pietre_'+colore+'300x300.jpg';
}

/*function OpenLightbox2(colore_sel, size, prodotto, dimensione) {
   // link della lightbox
   var link = "a" + size;
   
    // se non è selezionato alcun colore, prende il nero di default
   if (colore_sel == "") {
      colore_sel = 'nero';
   }
   
   // percorso delle immagini
   //var dim = "images/piastrelle/" + prodotto + '_'+ colore_sel +'_'+ size;
   var dim = "../images/piastrelle/provvisoria";
 
 
   // crea il riferimento dei link
   CambiaLink(link2, dim + '.jpg', colore_sel, dimensione);
   CambiaLink(link2 + 'b', dim + 'b.jpg', colore_sel, dimensione);
   CambiaLink(link2 + 'c', dim + 'c.jpg', colore_sel, dimensione);
   CambiaLink(link2 + 'd', dim + 'd.jpg', colore_sel, dimensione);
   
}*/

function OpenLightbox(colore_sel, size, prodotto, dimensione, lingua) {
   // link della lightbox
   var link = "a" + size;
   
    // se non � selezionato alcun colore, prende il nero di default
   if (colore_sel == "") {
      colore_sel = 'nero';
   }
   
   // percorso delle immagini
   var dim = "../images/piastrelle/" + prodotto + '_'+ colore_sel +'_'+ dimensione;
   //var dim = "images/piastrelle/provvisoria";
 

   // crea il riferimento dei link
   CambiaLink(link, dim + '.jpg', colore_sel, dimensione, lingua);
   CambiaLink(link + 'b', dim + 'b.jpg', colore_sel, dimensione, lingua);
   CambiaLink(link + 'c', dim + 'c.jpg', colore_sel, dimensione, lingua);
   CambiaLink(link + 'd', dim + 'd.jpg', colore_sel, dimensione, lingua);
   
}

/*function CambiaLink2 (link, dim, colore_sel, dimensione) {
   var element = document.getElementById(link);
   
   if (element != null) {
      element.href = dim;
      
      //element.title = "Colore: " + colore_sel + "<br />Dimensione: " + dimensione;
      element.title = "Foto non disponibile";
   }
}*/

function CambiaLink (link, dim, colore_sel, dimensione, lingua) {
   var element = document.getElementById(link);
   
   if (element != null) {
      element.href = dim;
      
      if (lingua == "eng") {
         element.title = "Colour: " + colore_sel + "<br />Dimension: " + dimensione;
      } else if ((lingua == "por") || (lingua == "bra")) {
         element.title = "Colour: " + colore_sel + "<br />Dimension: " + dimensione;
      } else {
         element.title = "Colore: " + colore_sel + "<br />Dimensione: " + dimensione;
      }
      //element.title = "Foto non disponibile";
   }
}

/* metalli */
var colore_tmp_metalli = "";
function ChangeImgMetalli(colore) {
   colore_tmp = colore;
   var size1 = document.getElementById("size1");
   size1.src = '../images/formati/metalli_'+colore+'600x600.jpg';
   
   var size2 = document.getElementById("size2");
   size2.src = '../images/formati/metalli_'+colore+'200x600.jpg';
}

/* rilievi */
var colore_tmp_rilievi = "";
function ChangeImgRilievi(colore) {

   colore_tmp = colore;
   
   var size1 = document.getElementById("size1");
   size1.src = '../images/formati/rilievi_'+colore+'600x600.jpg';
}

/* funzione apertura menu ita */
function ChangeBGOnIta (nome, menu) {
   nome.style.backgroundImage="url('../images/menu/menu_"+menu+"_on.jpg')";
}

function ChangeBGOffIta (nome, menu) {
   nome.style.backgroundImage="url('../images/menu/menu_"+menu+"_off.jpg')";
}

/* funzione apertura menu ita home */
function ChangeBGOnItaHome (nome, menu) {
   nome.style.backgroundImage="url('images/menu/menu_"+menu+"_on.jpg')";
}

function ChangeBGOffItaHome (nome, menu) {
   nome.style.backgroundImage="url('images/menu/menu_"+menu+"_off.jpg')";
}

/* funzione apertura menu eng */
function ChangeBGOnEng (nome, menu) {
   nome.style.backgroundImage="url('../images/menu/menu_"+menu+"_on.jpg')";
}

function ChangeBGOffEng (nome, menu) {
   nome.style.backgroundImage="url('../images/menu/menu_"+menu+"_off.jpg')";
}

/* switch immagini menu */
function switchImage(id_img, img)
{
	var id=document.getElementById(id_img);
	id.src=img;
}

function getProducts(count) {
    if (count == 0) return "";
    //var ret = "<table>\n<tr><th>"+document.getElementById("qty").value+"</th><th>Prodotti</th></tr>\n";
    var ret = "<table>";
    var STYLE = "style='font-size: 12px;color: black;font-family: Verdana, Helvetica, Arial, sans-serif; vertical-align: top;'";
    var i = 0;
    var c = 1;
    var check = true;
    for (i;c <= 100 ;i++ ) {
        var elm = document.getElementById("product_id_" + c);
        c++;
        if (elm == null) continue;
        if (elm.checked) {
            var tmp = c - 1;
            ret += "<tr>";
            ret += "<td "+STYLE+">";
            ret += "" + document.getElementById("product_qty_" + tmp).value;
            ret += " x \""+ document.getElementById("product_pkg_" + tmp).value + "\"";
            ret += "</td><td "+STYLE+">";
            ret += elm.value;
            ret += "</td>";
            ret += "</tr>";
            check = false;
        }
    }
    ret += "</table>";
    if (check) {
        ret = "";
    }
    return ret;
}

function checkQty(count) {
    if (count == 0) return true;
    //var ret = "<table>\n<tr><th>"+document.getElementById("qty").value+"</th><th>Prodotti</th></tr>\n";
    var i = 0;
    var c = 1;
    for (i;c <= 100 ;i++ ) {
        var elm = document.getElementById("product_id_" + c);
        var qty = document.getElementById("product_qty_" + c);
        c++;
        if (elm == null) continue;
        if (elm.checked) {
            if (parseInt(qty.value) < 10) {
                return true;
            }
        }
    }
    return false;
}

function checkInvia(lang, type, count) {

    if (lang=='ita') {
        var nome = document.getElementById("Nome").value;
        var cognome = document.getElementById("Cognome").value;
        var indirizzo = document.getElementById("Indirizzo").value;
        var cap = document.getElementById("CAP").value;
        var citta = document.getElementById("Citta").value;
        var provincia = document.getElementById("Provincia").value;
        var email = document.getElementById("Email").value;
        var telefono = document.getElementById("Telefono").value;
        var privacy = document.invia.Privacy;
        var check = false;
        var prodotti = getProducts(count);
        var qty = checkQty(count);

        if (type == 0) { //privato
            check = document.getElementById("CF").value == "";
        } else if (type == 1 || type == 2) { //azienda odistributori
            check = document.getElementById("PI").value == "" || document.getElementById("Azienda").value == "";
        }

        // se non stato inserito un dato obbligatorio lo notifica
        if( (nome == "") || (cognome == "") || (indirizzo == "") || (cap == "") || (provincia == "") || (citta == "") || (email == "") || (telefono == "") ||  check) {
            alert("Non hai inserito tutti i dati obbligatori");
            return;
        }

        // se l'email non contiene un punto e una chiocciola lo notifica
        if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
            alert("Mail non valida");
            return;
        }

        // se non viene accettata la privacy, lo notifica
        if (privacy[1].checked) {
            alert("Per proseguire devi accettare la privacy");
            return;
        }

        if (prodotti == "") {
            alert("Per proseguire devi selezionare almeno un prodotto");
            return;
        }

        if (qty) {
            alert("Uno o più prodotti hanno un numero di pezzi inferiore alla quantit&agrave; minima (minimo 10 pezzi)");
            return;
        }

        document.getElementById("Prodotti").value = prodotti;

        
        document.invia.submit();
    }
/*
if (lang=='esp') {
   var nome = document.getElementById("Nombre").value;
   var cognome = document.getElementById("Apellidos").value;
   var azienda = document.getElementById("Empresa").value;
   var email = document.getElementById("Email").value;
   var telefono = document.getElementById("Telefono").value;
   var privacy = document.invia.Privacy;
   
   // se non � stato inserito un dato obbligatorio lo notifica
    if((nome == "") || (cognome == "") || (azienda == "") || (email == "") || (telefono == "")) {
        alert("No ha insertado todos los datos obligatorios");
        return false;
    }
    
    // se l'email non contiene un punto e una chiocciola lo notifica
    if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
        alert("Mail no v�lido");
        return false;
    }
    
    // se non viene accettata la privacy, lo notifica
    if (privacy[1].checked) {
        alert("Para continuar debe aceptar la privacy");
        return false;
    }
    
    document.invia.submit();
}


if (lang=='eng') {
   var nome = document.getElementById("FirstName").value;
   var cognome = document.getElementById("LastName").value;
   var azienda = document.getElementById("Company").value;
   var email = document.getElementById("Email").value;
   var telefono = document.getElementById("Phone").value;
   var privacy = document.invia.Privacy;
   
   // se non � stato inserito un dato obbligatorio lo notifica
    if((nome == "") || (cognome == "") || (azienda == "") || (email == "") || (telefono == "")) {
        alert("You haven't filled all the mandatory data");
        return false;
    }
    
    // se l'email non contiene un punto e una chiocciola lo notifica
    if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
        alert("Mail not valid");
        return false;
    }
    
    // se non viene accettata la privacy, lo notifica
    if (privacy[1].checked) {
        alert("To continue you have to accept the privacy");
        return false;
    }
    
    document.invia.submit();
}

if ((lang=='por') || (lang=='bra')) {
   var nome = document.getElementById("Nome").value;
   var cognome = document.getElementById("Apelido").value;
   var azienda = document.getElementById("Empresa").value;
   var email = document.getElementById("Email").value;
   var telefono = document.getElementById("Telefone").value;
   var privacy = document.invia.Privacy;
   
   // se non � stato inserito un dato obbligatorio lo notifica
    if((nome == "") || (cognome == "") || (azienda == "") || (email == "") || (telefono == "")) {
        alert("You haven't filled all the mandatory data");
        return false;
    }
    
    // se l'email non contiene un punto e una chiocciola lo notifica
    if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
        alert("Mail not valid");
        return false;
    }
    
    // se non viene accettata la privacy, lo notifica
    if (privacy[1].checked) {
        alert("To continue you have to accept the privacy");
        return false;
    }
    
    document.invia.submit();
}
*/
}

// prelevato su: http://www.web-link.it
// preload immagini
var myimages=new Array()
function preloadImg(){
   for (i=0;i<preloadimages.arguments.length;i++){
   myimages[i]=new Image()
   myimages[i].src=preloadimages.arguments[i]
   }
}

function enableProduct(obj, id) {
    var elm = document.getElementById("product_qty_" + id);
    if (obj.checked) {
        elm.value = 10;
        elm.disabled = false;
    } else {
        elm.value = 0;
        elm.disabled = true;
    }
    //document.getElementById("product_qty_" + id);

}

function checkProduct(obj, msg) {
    var MIN_VAL = 10;
    if(isNaN(parseInt(obj.value))) {
        obj.value = MIN_VAL;
    }
    if (obj.value < MIN_VAL) {
        obj.value = MIN_VAL;
        alert(msg);
    }

}
