// JavaScript Document

function createRequestObj(){ // creo un'istanza XMLHttpRequest
	var re;
	var browser=navigator.appName;
	if (browser=="Microsoft Internet Explorer"){ // sniff browser
		re=new ActiveXObject("Microsoft.XMLHTTP");
	} else re=new XMLHttpRequest();
	return re;
}

var http=createRequestObj();

function AjaxInnerHTML(idDiv, paginaFonteDati, metodo, parametri){ // faccio una richiesta
	//alert(parametri); // debug
	var url=paginaFonteDati+"?" + parametri
	//alert (url);
	http.open(metodo, url , true)
	document.getElementById(idDiv).innerHTML="Caricamento in corso...";
	document.getElementById('pulisci').disabled = true;
	document.getElementById('ricerca').disabled = true;
	http.onreadystatechange=function(){
		if (http.readyState==4 || http.readyState=="complete"){
			if (http.status == 200){
				appo = http.responseText.split("|");
				testo_select = appo[0];
				testo_descrizione = appo[1];
				document.getElementById(idDiv).innerHTML=testo_select;
				document.getElementById('DIDA_CAT').innerHTML = testo_descrizione;
			} else {
				document.getElementById(idDiv).innerHTML="Errore di caricamento dati";
			}
		}
		document.getElementById('pulisci').disabled = false;
		document.getElementById('ricerca').disabled = false;
	}
	http.send(null);
}
function CancellaContenuto(idDiv,contenuto) {
	document.getElementById(idDiv).innerHTML= contenuto;
}

function MakeSearch() {
	if (document.getElementById('id_categoria3').value != 'null') {
		parametri = 'id_categoria='+document.getElementById('id_categoria3').value;
	}else if (document.getElementById('id_categoria2').value != 'null') {
		parametri = 'id_categoria='+document.getElementById('id_categoria2').value;
	}else if (document.getElementById('id_categoria1').value != 'null') {
		parametri = 'id_categoria='+document.getElementById('id_categoria1').value;
	}else
		parametri = 'par=1';
	if (document.getElementById('nome_oggetto').value != '')
		parametri = parametri+"&nome_oggetto="+document.getElementById('nome_oggetto').value;
	if (document.getElementById('da_tempo').value != '' && document.getElementById('a_tempo').value != '') {
		parametri = parametri+"&da="+document.getElementById('da_tempo').value;
		parametri = parametri+"&a="+document.getElementById('a_tempo').value;
	}
	if (document.getElementById('produttore').value != '')
		parametri = parametri+"&produttore="+document.getElementById('produttore').value;
	if (document.getElementById('testo_libero').value != '')
		parametri = parametri+"&testo_libero="+document.getElementById('testo_libero').value;
	
	AjaxInnerHTML('risultati', 'ricerca.php', 'POST', parametri);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}