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){
	$.get("ajax/search_object.php?ricerca_lang="+ricerca_lang+"&ajax_call_tipo="+tipo+"&filtro_ricerca="+filtro_ricerca, function(data){
   /* Prima di ricaricare controllo la presenza dell'oggetto */
			if(document.getElementById(cambio)){
				document.getElementById(cambio).innerHTML = data;
				if(cambio == 'span_tipo' && tipo == 'cat'){
					cambio = 'span_subtipo';
					ForceValidate('','tipo',cambio);
				}else{
					Loading(0);
				}
			}else{
				Loading(0);
			}
 });
 
	
}

function Loading(Load){

    if(Load == 1){
        document.getElementById('loader').innerHTML = '<img src="http://www.immobiliaremeneghello.com/img/ricerca_loading.gif" width="16" height="16" align="middle" alt="loader" />';
    }else{
        document.getElementById('loader').innerHTML = '';
    }
    
}

function ForceValidate(filtro_ricerca,tipo,cambio,ricerca_lang){
    Search(filtro_ricerca,tipo,cambio,ricerca_lang);
}

function validateamg(AA,MM){
	
    Loading(1);
    
    setTimeout("amg('"+AA+"','"+MM+"')",500);
    
}

function amg(AA,MM){

    http.abort();
	http.open("GET", "../ita/amg.php?AA="+AA+"&MM="+MM+"&ajax_call=1", true);
	http.onreadystatechange=function(){
		if(http.readyState == 4){
			/* Prima di ricaricare controllo la presenza dell'oggetto */
			if(document.getElementById('span_giorno')){
				document.getElementById('span_giorno').innerHTML = http.responseText;
			}else{
				Loading(0); 
			}
          
		}
	}
	http.send(null);
	
}

function PrezzoAV(){
		if(document.forms['frmRicerca'].contratto.options[document.forms['frmRicerca'].contratto.selectedIndex].value == '0'){
			document.forms['frmRicerca'].prezzomax.value = "";
			document.getElementById('prezzomax').style.display = "none";
			document.getElementById('prezzoa').style.display = "none";
			document.getElementById('prezzov').style.display = "inline";
			document.getElementById('labPrezzomax').style.display = "none";
			document.getElementById('labPrezzoa').style.display = "none";
			document.getElementById('labPrezzov').style.display = "inline";
		}else if(document.forms['frmRicerca'].contratto.options[document.forms['frmRicerca'].contratto.selectedIndex].value == '1'){
			document.forms['frmRicerca'].prezzomax.value = "";
			document.getElementById('prezzomax').style.display = "none";
			document.getElementById('prezzov').style.display = "none";
			document.getElementById('prezzoa').style.display = "inline";
			document.getElementById('labPrezzomax').style.display = "none";
			document.getElementById('labPrezzov').style.display = "none";
			document.getElementById('labPrezzoa').style.display = "inline";
		} else {
			document.forms['frmRicerca'].prezzomax.value = "";
			document.getElementById('prezzomax').style.display = "inline";
			document.getElementById('prezzov').style.display = "none";
			document.getElementById('prezzoa').style.display = "none";
			document.getElementById('labPrezzomax').style.display = "inline";
			document.getElementById('labPrezzov').style.display = "none";
			document.getElementById('labPrezzoa').style.display = "none";
		}
	}
	
function ResetPmax(){
		if (isNaN(document.forms['frmRicerca'].prezzomax.value)){
			document.forms['frmRicerca'].prezzomax.value = '';
		}
	}


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'].mq.value = '';
	document.forms['frmRicerca'].rif.value = '';
	document.forms['frmRicerca'].prezzomax.value = "";
	document.forms['frmRicerca'].prezzov.selectedIndex = 0;
	document.forms['frmRicerca'].prezzoa.selectedIndex = 0;	
	
}

