﻿/* 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;
    }
}

