
  var ricerca_mar;
  
   
function AJAXDatiQrt(tipoquery) 
{
	if (tipoquery == 1)
		{
    var valorecampo = document.formdati.marca.options[document.formdati.marca.selectedIndex].value;
		document.formdati.all.options.length=0;		 
		document.formdati.all.options[0]= new Option("Seleziona l'allestimento");
		document.getElementById('all').disabled=true;
		if (valorecampo == 0)
			{
			document.getElementById('mod').disabled=true;
			}
			else
			{
			document.getElementById('mod').disabled=false;
			}
		}
	if (tipoquery == 2)
		{
    var valorecampo = document.formdati.mod.options[document.formdati.mod.selectedIndex].value;

    		if (valorecampo == 0)
			{
			document.getElementById('all').disabled=true;
			}
			else
			{
			document.getElementById('all').disabled=false;
			}
	
		}


	// branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        ricerca_mar = new XMLHttpRequest();
		if (tipoquery == 1)
			{
	    	ricerca_mar.onreadystatechange = selmodelli;
			
			ricerca_mar.open("GET", "/webservices/Query_AutoQRT.cfm?p="+valorecampo+"&tipo="+tipoquery,true);
			}
		if (tipoquery == 2)
			{
    	    ricerca_mar.onreadystatechange = selallestimenti;
			ricerca_mar.open("GET", "/webservices/Query_AutoQRT.cfm?p="+valorecampo+"&tipo="+tipoquery,true);
			}

        ricerca_mar.send(null);

    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        ricerca_mar = new ActiveXObject("Microsoft.XMLHTTP");
        if (ricerca_mar) {
			if (tipoquery == 1)
				{
		    	ricerca_mar.onreadystatechange = selmodelli;
				ricerca_mar.open("GET", "/webservices/Query_AutoQRT.cfm?p="+valorecampo+"&tipo="+tipoquery,true);
				}
			if (tipoquery == 2)
				{
            	ricerca_mar.onreadystatechange = selallestimenti;
	            ricerca_mar.open("GET", "/webservices/Query_AutoQRT.cfm?p="+valorecampo+"&tipo="+tipoquery,true);
				}
            ricerca_mar.send();
        }
    }
}

     

	 
  function selmodelli() {   
    var strRes;       
    var arrValori; 
	var arrModello;     
	  if (ricerca_mar.readyState == 4) {	    
		  strRes=ricerca_mar.responseText;
		  arrValori=strRes.split("|");
		  document.formdati.mod.options.length=0;		    
		  for(i=0;i<arrValori.length;i++)
		  {
			 arrModello= arrValori[i].split("$")
			
			document.formdati.mod.options[document.formdati.mod.options.length]= new Option(arrModello[0]) ; 
		   	document.formdati.mod.options[document.formdati.mod.options.length -1].value= arrModello[1];
			
		  }
		 
		 }
	}
	
	
  function selallestimenti() {   
    var strRes;       
    var arrValori; 
	var arrAllestimento;     
	  if (ricerca_mar.readyState == 4) {	    
		  strRes=ricerca_mar.responseText;
		  arrValori=strRes.split("|");
		  document.formdati.all.options.length=0;		    
		  for(i=0;i<arrValori.length;i++)
		  {
			 arrAllestimento= arrValori[i].split("$")
			
			document.formdati.all.options[document.formdati.all.options.length]= new Option(arrAllestimento[0]) ; 
		   	document.formdati.all.options[document.formdati.all.options.length -1].value= arrAllestimento[1];
			
		  }
		 
		 }
	}

	
function checkImm() {   
    var anno=document.formdati.anno_immatr.value;       
    var mese=document.formdati.mese_immatr.value; 
	var modello=document.formdati.all.value;     
	
	  if (anno == "" || mese == "" || modello==0) {	    
	  
	  	return true;
		
		}
		else
		{
			arrRange= modello.split("_");
			userInput=anno;
			inimm=arrRange[3];
			inimm=inimm.substring(0,4)
			finimm=arrRange[4];
			finimm=finimm.substring(0,4)
			if (finimm == 0) 
			{
				finimm=999999;
			}
			
			
			if (userInput >= inimm && userInput <= finimm)
				{
					return true;
				}
				else
				{
					alert("data di prima immatricolazione errata!");
					return false;
					
				}
		
		}
		 	  }
		 
		


		  
