var http = false;



if(navigator.appName == "Microsoft Internet Explorer"){

	http = new ActiveXObject("Microsoft.XMLHTTP");

}else{

	http = new XMLHttpRequest();

}



function validate(filtro_ricerca,tipo,cambio,ricerca_lang){



    Loading(1);

    

    setTimeout("Search('"+filtro_ricerca+"','"+tipo+"','"+cambio+"','"+ricerca_lang+"')",500);

    

}



function Search(filtro_ricerca,tipo,cambio,ricerca_lang){



    http.abort();

	http.open("GET", "search_object.php?ricerca_lang="+ricerca_lang+"&ajax_call_tipo="+tipo+"&filtro_ricerca=" + filtro_ricerca, true);

	http.onreadystatechange=function(){

		if(http.readyState == 4){

			/* Prima di ricaricare controllo la presenza dell'oggetto */

			if(document.getElementById(cambio)){

				document.getElementById(cambio).innerHTML = http.responseText;

				if(cambio == 'span_tipo' && tipo == 'cat'){

					cambio = 'span_subtipo';

					ForceValidate('','tipo',cambio);

				}else{

					Loading(0);            

				}

			}else{

				Loading(0); 

			}

          

		}

	}

	http.send(null);

	

}



function Loading(Load){



    if(Load == 1){

        document.getElementById('loader').innerHTML = 'Loading...';

    }else{

        document.getElementById('loader').innerHTML = '';

    }

    

}



function ForceValidate(filtro_ricerca,tipo,cambio,ricerca_lang){

    Search(filtro_ricerca,tipo,cambio,ricerca_lang);

}







function AzzeraParametri(){

	document.forms['frmRicerca'].contratto.selectedIndex = 0;

	document.forms['frmRicerca'].cat.selectedIndex = 0;

	document.forms['frmRicerca'].tipo.selectedIndex = 0;

	document.forms['frmRicerca'].tipo.disabled= true;

	document.forms['frmRicerca'].comune.selectedIndex = 0;

	document.forms['frmRicerca'].zona.selectedIndex = 0;

	document.forms['frmRicerca'].zona.disabled= true;

	document.forms['frmRicerca'].richiesta.value = '';
	
	document.forms['frmRicerca'].vani.value = '';
	
	document.forms['frmRicerca'].rif.value = '';

}


