var XMLHTTP;
var stringaTemp
var idSelezionato;
var tipo_global;
var tipo_global_a;

tipo_global_a = "";
tipo_global = "";

var idSottoCategoriaGlobal; 
idSottoCategoriaGlobal = 0; 

function VerificaCodice(campo){
	Richiesta("verifica", "codice", "1", "../inc_gen/verifica-codice.asp?codice=" + campo.value + "&campo= " + campo.name + "&a=");

}
function CancellaCampo(campo){
	Richiesta("verifica", "codice", "1", "../inc_gen/no-codice.asp");
	campo.value = "";
	alert("Controllare di aver inserito il corretto COD.FISCALE/P.I./E-MAIL");          
}

function Ridireziona(){
	document.location="registrati-cartaceo.asp";       
}


function VisualizzaProdottoEccezionaleDivVis(){
	document.getElementById("prodotto-eccezionale-div-vis").className = "";      
}

function ChiudiProdottoEccezionaleDiv(){
	document.getElementById("prodotto-eccezionale-div-vis").className = "vis2";      
}

function RichiestaProdotto(Stringa, tipo, idSettorePerSottoSettore, paginaRicevuta,eccezione_spese){
	Richiesta(Stringa, tipo, idSettorePerSottoSettore, paginaRicevuta);

	if (eccezione_spese == -1){
		VisualizzaProdottoEccezionaleDivVis();
	}
}


function Richiesta(Stringa, tipo, idSettorePerSottoSettore, paginaRicevuta)
{
    var randomnumber=Math.floor(Math.random()*11)
	
		document.getElementById(tipo + "_" + Stringa).innerHTML = "<img src='../admin/images/loading.gif'>";
		if (tipo_global_a != ""){
			document.getElementById(tipo_global_a + "_" + tipo_global).innerHTML = "";
		}
	
	if(tipo =="risposta" ){
		if(document.getElementById(tipo + "_" + Stringa).innerHTML  != ""){
			document.getElementById(tipo + "_testo_" + Stringa).innerHTML = "Chiudi";
		}else{
			document.getElementById(tipo + "_testo_" + Stringa).innerHTML = "Leggi risposte";
		}
	}
	tipo_global = Stringa; 
	tipo_global_a = tipo;
	
	//alert(tipo + "_" + Stringa);
	
	StringaGlobal =Stringa.toUpperCase();
	
		

	
	if (Stringa.length > 0)
    {
		stringaTemp = Stringa
		
		
		
        var url = paginaRicevuta+ "?" + randomnumber + "&scarica=true&idSettore=" + Stringa.toUpperCase() + "&idCategoria=" + idSettorePerSottoSettore + "&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 = "";
    } 
	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(tipo_global_a + "_" + tipo_global);
        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!");
    }
}

function CambiaValore(id_div, nome_div, percorso, obj){
	idSelezionato = obj.value;
	var x = obj.selectedIndex;	
	
	document.getElementById("nomeSettore").value = obj.options[x].text;
	
	Richiesta(id_div,nome_div,idSelezionato,percorso);
	return false;
}

function ValoreSottocategoria(obj){
	idSottoCategoriaGlobal  = obj.value; 	
	var x = obj.selectedIndex;	
	document.getElementById("nomeSottoCat").value = obj.options[x].text;
	document.getElementById("idSottoCat").value = idSottoCategoriaGlobal
}


function Submit_form( obj ) {
	var submit = true;
	
	if (submit) {
		(obj.form).submit();
	}
}

function RispondiMessaggio(id, div){
	var testo;
	testo = document.getElementById("testoRisposta_" + id ).value;
	Richiesta(id, div, 'true&testo=' + testo , '../inc_gen/risposta_messaggi.asp');
}


