﻿/* INIZIO FUNZIONE CHE CREA LE FORM HTM DINAMICAMENTE */
function PostData(to, p) {
    var myForm = document.createElement("form");
    myForm.method = "post";
    myForm.action = to;
    for (var k in p) {
        var myInput = document.createElement("input");
        myInput.setAttribute("name", k);
        myInput.setAttribute("value", p[k]);
        myForm.appendChild(myInput);
    }
    document.body.appendChild(myForm);
    myForm.submit();
    document.body.removeChild(myForm);
}
/* FINE FUNZIONE CHE CREA LE FORM HTM DINAMICAMENTE */

/* INIZIO FUNZIONE CHE GESTISCE L'AGGIUNTA AL CARRELLO */
function AggiungiProdotto(NomeIframe, NomeInput, UrlPagina, IDProdotto, CodiceProdotto, QuantitaRichiesta, QuantitaTotaleDisponibile) {
    var Valore = document.all[NomeInput].value
    var Errore = 0;
    
    if (isNaN(Valore) || Valore == "" || Valore == 0) {
        document.all[NomeInput].value = "";
        document.all[NomeInput].className = "InputCarrelloErrore";
        setTimeout("ReimpostaCarrello('" + NomeIframe + "', '" + NomeInput + "')", 2000)
        Errore = 1
    } else {
        document.all[NomeInput].className = "InputCarrello";
    }
    var d = new Date();
    if (Errore == 0) {
        document.getElementById(NomeIframe).src = "iframe_aggiungi.aspx?NomeIframe=" + NomeIframe + "&NomeInput=" + NomeInput + "&URLPagina=" + UrlPagina + "&IDProdotto=" + IDProdotto + "&CodiceProdotto=" + CodiceProdotto + "&QuantitaRichiesta=" + QuantitaRichiesta + "&QuantitaTotaleDisponibile=" + QuantitaTotaleDisponibile + "&Sgamo=" + d.getTime()
    }
}

function ReimpostaCarrello(NomeIframe, NomeInput) {
    document.all[NomeInput].value = "1";
    document.all[NomeInput].className = "InputCarrello";
    document.getElementById(NomeIframe).src = "about:blank";
}
/* FINE FUNZIONE CHE GESTISCE L'AGGIUNTA AL CARRELLO */

function ReindirizzaSuLingua(IDLinguaFiltroSito) {
    if (window.location.hash == recentHash) {
        return; // Nothing's changed since last polled.
    }
    var UrlPagina = String(window.location);
    var recentHash = window.location.hash;
    if (recentHash != ""){
        UrlPagina = UrlPagina.replace(recentHash, "")
        recentHash = recentHash.replace("#idlfs=", "")
        if (UrlPagina.indexOf("?") != -1){
            location.href = UrlPagina + "&idlfs=" + recentHash
        }else{
            location.href = UrlPagina + "?idlfs=" + recentHash
        }
    }else{
        location.hash = "idlfs=" + IDLinguaFiltroSito;
    }
}

/* INIZIO DELLA FUNZIONE CHE APRE E CHIUDE IL DIV DELLE VARIANTI */
var AppenaAperto = false;
function ApriChiudiDivVariante(Div){
    var ElencoDiv = document.getElementsByTagName("div");
    var EraAperto = false;
	for (var i=0; i<ElencoDiv.length; i++){
	    if (ElencoDiv[i].id == Div){
	        if (document.getElementById(Div).style.display == 'inline'){
	            EraAperto = true;
	        }
	    }
		if (ElencoDiv[i].id.indexOf("divVariante") != -1){
		    ElencoDiv[i].style.display = 'none';
		}
	}
	
    if (document.getElementById(Div).style.display == 'none' && EraAperto == false){
        document.getElementById(Div).style.display = 'inline';
        AppenaAperto = true;
    }else{
        document.getElementById(Div).style.display = 'none';
    }
}  

function ChiudiTuttiDivVarianti(){
    if (AppenaAperto == false){
        var ElencoDiv = document.getElementsByTagName("div");
	    for (var i=0; i<ElencoDiv.length; i++){
		    if (ElencoDiv[i].id.indexOf("divVariante") != -1){
		        ElencoDiv[i].style.display = 'none';
		    }
	    }
    }
    AppenaAperto = false;
}
/* FINE DELLA FUNZIONE CHE APRE E CHIUDE IL DIV DELLE VARIANTI */

function NascondiLivelli(){
    document.getElementById('divIngrandimento').style.visibility = "hidden"
    document.getElementById('divSfondo').style.visibility = "hidden"
}

function MostraLivelli(Foto, IconaChiudi){
    document.getElementById("divSfondo").style.height = document.body.scrollHeight;
    document.getElementById("divIngrandimento").style.top = (document.all)?document.body.scrollTop:window.pageYOffset; 
    document.getElementById('divIngrandimento').innerHTML = '<table class=\"cursore\" onclick=\"javascript:NascondiLivelli();\" width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td align=\"center\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" class=\"sfondoloading\"><a href=\"javascript:void(0)\" onclick=\"javascript:NascondiLivelli();\"><img src=\"' + Foto + '\" alt=\"Chiudi\" hspace=\"0\" vspace=\"0\" border=\"0\" class=\"bordoimmagine\"></a></td></tr></table></td></tr></table>'
    document.getElementById('divIngrandimento').style.visibility = "visible"
    document.getElementById('divSfondo').style.visibility = "visible"
}
