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 = '<img src="http://www.oltrecase.it/img/loading.gif" width="16" height="16" align="absmiddle" alt="loader" />&nbsp;Loading...';
    }else{
        document.getElementById('loader').innerHTML = '';
    }
    
}

function ForceValidate(filtro_ricerca,tipo,cambio,ricerca_lang){

    Search(filtro_ricerca,tipo,cambio,ricerca_lang);
    
}