var XMLHTTP;
var stringaTemp
var idSelezionato;
var tipo_global;
var tipo_global_a;

tipo_global_a = "";
tipo_global = "";

var idSottoCategoriaGlobal; 
idSottoCategoriaGlobal = 0; 

function Richiesta(Stringa, tipo, lingua, paginaRicevuta)
{
    var randomnumber=Math.floor(Math.random()*11)
	

	/*if(document.getElementById(tipo + "_" + Stringa).innerHTML  != "" && tipo !="div_carrello" ){
		document.getElementById(tipo + "_" + Stringa).innerHTML = "";
		tipo_global = Stringa; 
		return false;
	}else{
	*/
		document.getElementById("div_tot").innerHTML = "<img src='../images/loading.gif'>";
/*
		if (tipo_global_a != "" && tipo !="div_carrello"){
			document.getElementById(tipo_global_a + "_" + tipo_global).innerHTML = "";
		}
	}

*/
	tipo_global = Stringa; 
	tipo_global_a = tipo;
	
	StringaGlobal =Stringa.toUpperCase();
	
		

	
	if (Stringa.length > 0)
    {
		stringaTemp = Stringa
		
		
		
        var url = paginaRicevuta+ "?" + randomnumber + "&scarica=true&id=" + Stringa.toUpperCase() + "&lingua=" + lingua + "&tipo=" + tipo; 
		
		/*
		if (document.getElementById("cartqty_" + Stringa) != null) {
			url = url + "&cartqty=" + document.getElementById("cartqty_" + Stringa).value
		}
		
		if (document.getElementById("tipo_prezzo_" + Stringa) != null) {
			url = url + "&tipo_prezzo=" + document.getElementById("tipo_prezzo_" + Stringa).value
		}
		*/
		
		XMLHTTP = RicavaBrowser(CambioStato, tipo);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
    else
    {
        //document.getElementById(tipo_global_a + "_" + Stringa).innerHTML = "";
        document.getElementById("div_tot").innerHTML = "";

} 
	return false;
}


function Chiudi(Stringa, tipo){
	document.getElementById("div_tot").innerHTML = "";	
	return false;
	
}
/*
function CambiaValore(obj){
	idSelezionato = obj.value; 
}

function CambiaPrezzo(conf, id){
	document.getElementById("tipo_prezzo_" + id).value = conf; 
}
*/


function CambioStato()
{
    if (XMLHTTP.readyState == 4)
    {
        var R = document.getElementById("div_tot");
        R.innerHTML = XMLHTTP.responseText; 
    }
}

function RicavaBrowser(QualeBrowser, tipo)
{
	
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
        var Classe = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
        {
            Classe = "Microsoft.XMLHTTP";
        } 
        try
        {
            OggettoXMLHTTP = new ActiveXObject(Classe);
            OggettoXMLHTTP.onreadystatechange = QualeBrowser;
            return OggettoXMLHTTP;
        }
        catch(e)
        {
            alert("Errore: l'ActiveX non verrą eseguito!");
        }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
    else
    {
        alert("L'esempio non funziona con altri browser!");
    }
}
