var time_variable;
 
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // per vecchi browser
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  //  Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false  serve un browsere più recente..
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 
var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object
var xmlhttp2 = new getXMLObject();
var xmlhttp3 = new getXMLObject();
var xmlhttp4 = new getXMLObject();
var xmlhttp5 = new getXMLObject();
var xmlhttp6 = new getXMLObject();
var xmlhttp7 = new getXMLObject();

function ajaxFunction(pagina,pagina_corrente) {
  var getdate = new Date();  //evito il precaching dei dati
  if(xmlhttp) { 

var tipologiaclassica = document.getElementById("tipologiaclassica").value;	   
var marcaclassica = document.getElementById("marcaclassica").value;
var modelloclassica= document.getElementById("modelloclassica").value;	
var alimentazioneclassica = document.getElementById("alimentazioneclassica").value;
var fascia = document.getElementById("fascia").value;	
//marca
inputArray = document.getElementsByName('marcaavanzata');	  
var marcaavanzata=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
marcaavanzata+=inputArray[i].value+"#";
}
//alimentazione
 
inputArray = document.getElementsByName('alimentazioneavanzata');	  
var alimentazioneavanzata=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
alimentazioneavanzata+=inputArray[i].value+"#";
}

//modelloavanzato
inputArray = document.getElementsByName('modelloavanzato');	  
var modelloavanzato=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
modelloavanzato+=inputArray[i].value+"#";
}

    xmlhttp.open("POST","risultati.php",true); //calling testing.php using POST method
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   // xmlhttp.send("marca=" + marca +"&alimentazione=" + alimentazione + "&modello=" + modello); //Posting txtname to PHP File
 xmlhttp.send("pagina=" +pagina+ "&pagina_corrente=" +pagina_corrente+"&marcaclassica=" + marcaclassica+"&tipologiaclassica=" + tipologiaclassica+"&modelloclassica=" + modelloclassica+"&alimentazioneclassica=" + alimentazioneclassica+"&fascia=" + fascia +"&marcaavanzata="+marcaavanzata+"&alimentazioneavanzata="+alimentazioneavanzata+"&modelloavanzato="+modelloavanzato); //Posting txtname to PHP File
  }
}
 
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       setTimeout('document.getElementById("risultato").innerHTML=xmlhttp.responseText;', 500); //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
   //document.getElementById("risultato").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}

// per cercare modelli, colori, ecc

function SelectRicercaClassica() {
  var getdate = new Date();  //evito il precaching dei dati
  if(xmlhttp2) { 
//var txtname = document.getElementById("txtname");
//marca
var tipologiaclassica = document.getElementById("tipologiaclassica").value;	  
var marcaclassica = document.getElementById("marcaclassica").value;
var modelloclassica = document.getElementById("modelloclassica").value;
var alimentazioneclassica = document.getElementById("alimentazioneclassica").value;
var fascia = document.getElementById("fascia").value;	  
	  
    xmlhttp2.open("POST","classica.php",true); //calling testing.php using POST method
    xmlhttp2.onreadystatechange  = handleServerResponse2;
    xmlhttp2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp2.send("marcaclassica=" + marcaclassica+"&tipologiaclassica=" + tipologiaclassica+"&modelloclassica=" + modelloclassica+"&alimentazioneclassica=" + alimentazioneclassica+"&fascia=" + fascia); //Posting txtname to PHP File
  }
}
 
function handleServerResponse2() {
   if (xmlhttp2.readyState == 4) {
     if(xmlhttp2.status == 200) {

        setTimeout('document.getElementById("selectclassica").innerHTML=xmlhttp2.responseText;',500); //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
   //document.getElementById("selectclassica").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}



function ricercaavanzata() {
  var getdate = new Date();  //evito il precaching dei dati
  if(xmlhttp4) { 
//alimentazione	  
inputArray = document.getElementsByName('alimentazioneavanzata');	  
var alimentazioneavanzata=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
alimentazioneavanzata+=inputArray[i].value+"#";
}
//marca
inputArray = document.getElementsByName('marcaavanzata');	  
var marcaavanzata=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
marcaavanzata+=inputArray[i].value+"#";
}
//modello
inputArray = document.getElementsByName('modelloavanzato');	  
var modelloavanzato=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
modelloavanzato+=inputArray[i].value+"#";
}

	  
    xmlhttp4.open("POST","risultati.php",true); //calling testing.php using POST method
    xmlhttp4.onreadystatechange  = handleServerResponse4;
    xmlhttp4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp4.send("alimentazioneavanzata=" + alimentazioneavanzata + "&marcaavanzata=" +marcaavanzata+"&modelloavanzato=" +modelloavanzato); //Posting txtname to PHP File
  }
}
 
function handleServerResponse4() {
   if (xmlhttp4.readyState == 4) {
     if(xmlhttp4.status == 200) {
        setTimeout('document.getElementById("risultato").innerHTML=xmlhttp4.responseText;',500); //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
   //document.getElementById("selectclassica").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}

//modello avanzato

function modelloavanzato() {
  var getdate = new Date();  //evito il precaching dei dati
  if(xmlhttp5) { 
//alimentazione	  
inputArray = document.getElementsByName('alimentazioneavanzata');	  
var alimentazioneavanzata=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
alimentazioneavanzata+=inputArray[i].value+"#";
}
//marca
inputArray = document.getElementsByName('marcaavanzata');	  
var marcaavanzata=""	  
for(i=0;i<inputArray.length;i++) {
//if(inputArray[i].className=='checkboxClassName') {
marcaavanzata+=inputArray[i].value+"#";
}

	  
    xmlhttp5.open("POST","modelloavanzato.php",true); //calling testing.php using POST method
    xmlhttp5.onreadystatechange  = handleServerResponse5;
    xmlhttp5.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp5.send("alimentazioneavanzata=" + alimentazioneavanzata + "&marcaavanzata=" +marcaavanzata); //Posting txtname to PHP File
  }
}
 
function handleServerResponse5() {
   if (xmlhttp5.readyState == 4) {
     if(xmlhttp5.status == 200) {
        setTimeout('document.getElementById("modelloavanzatoric").innerHTML=xmlhttp5.responseText;',500); //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
   //document.getElementById("modelloavanzatoric").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}


function salvaricerca() {
  var getdate = new Date();  //evito il precaching dei dati
  if(xmlhttp6) { 
var ricerca = document.getElementById("ricerca").value;	  	  


	  
    xmlhttp6.open("POST","salvaricerca.php",true); //calling testing.php using POST method
    xmlhttp6.onreadystatechange  = handleServerResponse6;
    xmlhttp6.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp6.send("ricerca=" + ricerca); //Posting txtname to PHP File
  }
}
 
function handleServerResponse6() {
   if (xmlhttp6.readyState == 4) {
     if(xmlhttp6.status == 200) {
        setTimeout('document.getElementById("modelloavanzatoric").innerHTML=xmlhttp6.responseText;',500); //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
   //document.getElementById("modelloavanzatoric").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}

function logincommerciante() {
  var getdate = new Date();  //evito il precaching dei dati
if(xmlhttp3) { 
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var check = document.getElementById("check").checked;
	  
    xmlhttp3.open("POST","login_commerciante.php",true); //calling testing.php using POST method
    xmlhttp3.onreadystatechange  = handleServerResponse3;
    xmlhttp3.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp3.send("username="+username+"&password=" + password+"&check=" + check); //Posting txtname to PHP File
  }
}
 
function handleServerResponse3() {
   if (xmlhttp3.readyState == 4) {
var varredirect=xmlhttp3.responseText.indexOf('accesso in corso...');
if (varredirect!= -1 ) {
  setTimeout(function(){window.location = "auto.php"}, 1500);
} 

     if(xmlhttp3.status == 200) {

       document.getElementById("logincomm").innerHTML=xmlhttp3.responseText; //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
  // document.getElementById("risultatodettaglio").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}

//salva ricerca
function salvaricerca(ricerca) {
  var getdate = new Date();  //evito il precaching dei dati
  if(xmlhttp7) { 
//var ricerca = document.getElementById("ricerca").value;	  	  
	  
    xmlhttp7.open("POST","salvaricerca.php",true); //calling testing.php using POST method
    xmlhttp7.onreadystatechange  = handleServerResponse7;
    xmlhttp7.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp7.send("ricerca=" + ricerca); //Posting txtname to PHP File
  }
}
 
function handleServerResponse7() {
   if (xmlhttp7.readyState == 4) {
     if(xmlhttp7.status == 200) {
        setTimeout('document.getElementById("modelloavanzatoric").innerHTML=xmlhttp7.responseText;',500); //Update the HTML Form element 
     }
     else {
        alert("Errore chiamata pagina dati, riprovare fra pochi secondi");
     }
   }else{
   //document.getElementById("modelloavanzatoric").innerHTML = '<div align="center"><img src="images/loader.gif"></div>'; //fino a che è 4 mostro loading
} 
}








