
var ajax = null;





function myHandler() {

//stati del readyState
//* 0 Uninitialized l'oggetto XMLHttpRequest esiste, ma non è stato richiamato alcun metodo per inizializzare una comunicazione
//* 1 Open è stato richiamato il metodo open() ed il metodo send() non ha ancora effettuato l'invio dati
//* 2 Sent il metodo send() è stato eseguito ed ha effettuato la richiesta
//* 3 Receiving i dati in risposta cominciano ad essere letti
//* 4 Loaded l'operazione è stata completata

cc=document.formcella.cella.value
//alert(cc)

//stati della status su http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
	//alert(ajax.readyState+" "+ajax.status)
    if (ajax.readyState == 4 && ajax.status == 200) {
        e = document.getElementById(cc);
		//alert(e)
		//alert(ajax.responseText)
        //e.innerHTML = ajax.responseText;
		//alert(e.innerHTML);
        e.innerHTML = ajax.responseText;
		
//		e=document.getElementById("pagina2")
//		alert(e)
		
		//nel caso in cui si parsi un XML
		//if(ajax.responseXML)
        // visualizzazione risultato parsing
        //e.innerHTML = parseXml(ajax.responseXML); la funzione parseXML è da creare alla bisogna
     // else
        // visualizzazione contenuto letto
        // evitando di scrivere la risposta in modo
        // interpretabile dal browser
        //e.innerHTML = "L'XML restituito dalla richiesta non è valido.<br />" +

    }
	
	
}





function inserisci(da,campo,t,i,a,n) {

document.formcella.cella.value=campo+a
	//alert("risultati_ajax.php?mqmin="+escape(mqmin)+"&piano="+escape(piano)+"&altre="+escape(altre)+"&frazione="+escape(frazione)+"&provincia="+escape(provincia)+"&parola="+escape(parola)+"&categoria="+escape(categoria)+"&funzionario="+escape(funzionario)+"&incaricato="+escape(incaricato)+"&proprietario="+escape(proprietario)+"&telefono="+escape(telefono)+"&mqmax="+escape(mqmax)+"&cameremin="+escape(cameremin)+"&cameremax="+escape(cameremax)+"&nvanimin="+escape(nvanimin)+"&nvanimax="+escape(nvanimax)+"&totbagni="+escape(totbagni)+"&prezzo="+escape(prezzo)+"&prezzomin="+escape(prezzomin)+"&tipomediaz="+escape(tipomediaz)+"&datainserim="+escape(datainserim)+"&datadiagg="+escape(datadiagg))
    //alert(campo)
	//alert(document.formcella.cella.value)
	//alert("annunci_modifica.php?t="+escape(t)+"&i="+escape[i]+"&a="+escape(a)+"&da="+da+"&campo="+campo+"&rand="+escape(r)+"&n="+escape(n))
	
	var r = Math.random();
    ajax = CreateXmlHttpReq(myHandler);
    ajax.open("GET","annunci_inserisci.php?t="+escape(t)+"&i="+escape(i)+"&a="+escape(a)+"&da="+da+"&campo="+campo+"&rand="+escape(r)+"&n="+escape(n));
	ajax.setRequestHeader("connection", "close");
    ajax.send(null);
	


}


function apriricerca() {
	
	x=document.getElementById("ricerca").style.display
	
	if (x!="")
  		document.getElementById("ricerca").style.display=""
	else
  		document.getElementById("ricerca").style.display="none"
	
	
}




function check(val,status) {

    //alert(status+" "+val);
	//$colorecella="#BA591E; color:#FFFFFF; font-weight:bold ";
   //$colorecella="#FFFFCC; color:#000000";

	valore=val.replace("1","")
	v1=valore+"cella1"
	v2=valore+"cella2"
	totale=""
	
    for (i=0; i<document.form1x.elements.length; i=i+1) {
	
	//alert(document.form1x.elements[i].id+" "+valore)
	
       if (document.form1x.elements[i].id==valore) {
	      //alert(v1)
		  
		  if (status) {
		    
//			e=document.getElementById(v1)
//			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    document.form1x.elements[i].checked=true
			colore2(document.form1x.elements[i],document.form1x.elements[i].value,true)
//			e.style.backgroundColor="#BA591E";
//			e.style.color="#FFFFFF";
//			e.style.fontWeight="bold";
//			e2.style.backgroundColor="#BA591E";
//			e2.style.color="#FFFFFF";
//			e2.style.fontWeight="bold";
			//e.style.backgroundColor="#BA591E";
		  
		  }
		  
		  if (!status) {
		  
			//e=document.getElementById(v1)
			//e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    document.form1x.elements[i].checked=false
			colore2(document.form1x.elements[i],document.form1x.elements[i].value,false)
//			e.style.backgroundColor="#BA591E";
//			e.style.color="#FFFFFF";
//			e.style.fontWeight="bold";
//			e2.style.backgroundColor="#BA591E";
//			e2.style.color="#FFFFFF";
//			e2.style.fontWeight="bold";
			//e.style.backgroundColor="#BA591E";
			
		  }
		  
	   }

    }
	
	valorezone()

}


function colore2(a,z,status) {

	     v1=z+"cella1"
	     v2=z+"cella2"

		  if (status) {
		    
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=true
			e.style.backgroundColor="#D3B3AF";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="#D3B3AF";
			e2.style.color="#000000";
		  
		  }
		  
		  if (!status) {
		  
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=false
			e.style.backgroundColor="";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="";
			e2.style.color="#000000";
			
		  }


}



function colore(a,z,status) {

	     v1=z+"cella1"
	     v2=z+"cella2"
		 
		 //alert(a+z+status)

		  if (status) {
		    
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=true
			e.style.backgroundColor="#D3B3AF";
			e.style.color="";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="#D3B3AF";
			e2.style.color="";
			//e.style.backgroundColor="#BA591E";
			//valorezone();
			totale=document.getElementById("zonaval_cont").innerHTML
			//alert(totale)
			//alert("METTO "+a.value) 
          if (  (totale=="&nbsp;") || (totale=="") )
			totale=a.value
		  else
			totale=totale+", "+a.value
			//alert(totale)
		  
		  }
		  
		  if (!status) {
		  
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=false
			e.style.backgroundColor="";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="";
			e2.style.color="#000000";
			//e.style.backgroundColor="#BA591E";
			//valorezone()
			totale=document.getElementById("zonaval_cont").innerHTML
//			alert(totale)
//			alert("TOLGO "+a.value) 
			stringa=a.value+", "
			stringa2=", "+a.value
			stringa3=a.value
			//alert(totale)
          if (  (totale=="&nbsp;") || (totale=="") )
			totale=a.value
		  else
			totale=totale+", "+a.value

			totale=totale.replace(stringa,"")
			totale=totale.replace(stringa2,"")
			totale=totale.replace(stringa3,"")
			//alert(totale)
			
		  }
		  
          	document.getElementById("zonaval_cont").innerHTML=totale


}




function valorezone() {

   totale=""

    for (i=0; i<document.form1x.elements.length; i++) {
	
	//alert(document.form1.elements[i].id+" "+valore)
	   if (  (document.form1x.elements[i].checked==true) && ((document.form1x.elements[i].value).indexOf('1')==-1)  )  {
	      //alert(document.form1x.elements[i].value)
	      if (totale=="")
		     totale=document.form1x.elements[i].value
		  else
		     totale=totale+", "+document.form1x.elements[i].value
	   
	   }

    }

    //alert(totale)
	
	if (totale=="")
	  totale="&nbsp;"

	document.getElementById("zonaval_cont").innerHTML=totale

}




function tipo() {
	
	
   
 
 document.getElementById("contenutozone").style.display="none"
 document.getElementById("contenutotipologie").style.display=""

//alert(val)
//document.getElementById("bologna").style.display="none"
//document.getElementById("provincia").style.display="none"
//document.getElementById("fuori").style.display="none"



}






function zone() {
	



for (i=0; i < document.form1.zon.length; i++)   {
	
   if (document.form1.zon[i].checked)
         val = document.form1.zon[i].value
		 
   }
   
   

 
 document.getElementById("contenutozone").style.display=""
 document.getElementById("contenutotipologie").style.display="none"

//alert(val)
//document.getElementById("bologna").style.display="none"
//document.getElementById("provincia").style.display="none"
//document.getElementById("fuori").style.display="none"


if (val=="bologna") {
	
	document.getElementById("bologna").style.display=""
	document.getElementById("provincia").style.display="none"

}


if (val=="provincia") {
	
	document.getElementById("bologna").style.display="none"
	document.getElementById("provincia").style.display=""

}


if (val=="tutte") {
	
	document.getElementById("bologna").style.display=""
	document.getElementById("provincia").style.display=""

}





//switchzone(val);


}











function switchzone(val) {
	
	
    for (i=0; i<document.form1x.elements.length; i++) {
	
	document.form1x.elements[i].checked=false
	
	z=document.form1x.elements[i].value
	
	v1=z+"cella1"
	v2=z+"cella2"
	e=document.getElementById(v1)
	e2=document.getElementById(v2)
	
	if (e!=null) {
		e.style.backgroundColor="#E6E5DE";
		e.style.color="#000000";
		e.style.fontWeight="normal";
		e2.style.backgroundColor="#E6E5DE";
		e2.style.color="#000000";
	}

	
	   
	}
	
	
	
if (val=="bologna") {
	
	document.getElementById("bologna").style.display=""
	document.getElementById("provincia").style.display="none"

}


if (val=="provincia") {
	
	document.getElementById("bologna").style.display="none"
	document.getElementById("provincia").style.display=""

}


if (val=="tutte") {
	
	document.getElementById("bologna").style.display=""
	document.getElementById("provincia").style.display=""

}


document.getElementById("zonaval_cont").innerHTML=""


}














function checkt(val,status) {

    //alert(status+" "+val);
	//$colorecella="#BA591E; color:#FFFFFF; font-weight:bold ";
   //$colorecella="#FFFFCC; color:#000000";

	valore=val.replace("1","")
	v1=valore+"cella1"
	v2=valore+"cella2"
	totale=""
	
    for (i=0; i<document.form1xt.elements.length; i=i+1) {
	
	//alert(document.form1x.elements[i].id+" "+valore)
	
       if (document.form1xt.elements[i].id==valore) {
	      //alert(v1)
		  
		  if (status) {
		    
//			e=document.getElementById(v1)
//			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    document.form1xt.elements[i].checked=true
			colore2t(document.form1xt.elements[i],document.form1xt.elements[i].value,true)
//			e.style.backgroundColor="#BA591E";
//			e.style.color="#FFFFFF";
//			e.style.fontWeight="bold";
//			e2.style.backgroundColor="#BA591E";
//			e2.style.color="#FFFFFF";
//			e2.style.fontWeight="bold";
			//e.style.backgroundColor="#BA591E";
		  
		  }
		  
		  if (!status) {
		  
			//e=document.getElementById(v1)
			//e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    document.form1xt.elements[i].checked=false
			colore2t(document.form1xt.elements[i],document.form1xt.elements[i].value,false)
//			e.style.backgroundColor="#BA591E";
//			e.style.color="#FFFFFF";
//			e.style.fontWeight="bold";
//			e2.style.backgroundColor="#BA591E";
//			e2.style.color="#FFFFFF";
//			e2.style.fontWeight="bold";
			//e.style.backgroundColor="#BA591E";
			
		  }
		  
	   }

    }
	
	valoretipo()

}


function colore2t(a,z,status) {

	     v1=z+"cella1"
	     v2=z+"cella2"
		 
		 //alert("V1:"+v1)
		 //alert("V2"+v2)

		  if (status) {
		    
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=true
			e.style.backgroundColor="#D3B3AF";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="#D3B3AF";
			e2.style.color="#000000";
		  
		  }
		  
		  if (!status) {
		  
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=false
			e.style.backgroundColor="";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="";
			e2.style.color="#000000";
			
		  }
		  
          


}

function coloret(a,z,status) {

	     v1=z+"cella1"
	     v2=z+"cella2"

		  if (status) {
		    
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=true
			e.style.backgroundColor="#D3B3AF";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="#D3B3AF";
			e2.style.color="#000000";
			//e.style.backgroundColor="#BA591E";
			//valorezone();
			totale=document.getElementById("tipoval_cont").innerHTML
//			alert(totale)
//			alert("METTO "+a.value) 
          if (  (totale=="&nbsp;") || (totale=="") )
			totale=a.value
		  else
			totale=totale+", "+a.value
			//alert(totale)
		  
		  }
		  
		  if (!status) {
		  
			e=document.getElementById(v1)
			e2=document.getElementById(v2)
			//alert(e.style.backgroundColor)
		    a.checked=false
			e.style.backgroundColor="";
			e.style.color="#000000";
			e.style.fontWeight="normal";
			e2.style.backgroundColor="";
			e2.style.color="#000000";
			//e.style.backgroundColor="#BA591E";
			//valorezone()
			totale=document.getElementById("tipoval_cont").innerHTML
//			alert(totale)
//			alert("TOLGO "+a.value) 
			stringa=a.value+", "
			stringa2=", "+a.value
			stringa3=a.value
			
          if (  (totale=="&nbsp;") || (totale=="") )
			totale=a.value
		  else
			totale=totale+", "+a.value

			totale=totale.replace(stringa,"")
			totale=totale.replace(stringa2,"")
			totale=totale.replace(stringa3,"")
			//alert(totale)
			
		  }
		  
          	document.getElementById("tipoval_cont").innerHTML=totale



}




function valoretipo() {

   totale=""

    for (i=0; i<document.form1xt.elements.length; i++) {
	
	//alert(document.form1.elements[i].id+" "+valore)
	   if (  (document.form1xt.elements[i].checked==true) && ((document.form1xt.elements[i].value).indexOf('1')==-1)  )  {
	      
	      if (totale=="")
		     totale=document.form1xt.elements[i].value
		  else
		     totale=totale+", "+document.form1xt.elements[i].value
	   
	   }

    }

    //alert(totale)
	if (totale=="")
	  totale="&nbsp;"
	  
	document.getElementById("tipoval_cont").innerHTML=totale

}




function minmax(campo) {
	
	
	x=campo.value
	if ( (x=="min") || (x=="max") )
	   campo.value=""

}
	


function riordina() {

i=document.getElementById('ordinamento').selectedIndex
x=document.getElementById('ordinamento').options[i].value
document.form1.ordine.value=x
document.form1.submit()

}


function cerca() {
	
	document.form1.pag.value=""
	document.form1.ordine.value=""
	document.form1.submit()
	
	
}


function cercapreferiti() {
	
	document.form1.action="risultati.php"
	document.form1.pag.value=""
	document.form1.ordine.value=""
	document.form1.submit()
	
	
}



function pagina(val) {

document.form1.pag.value=val
document.form1.submit()

}


function cambiascheda(valore) {
	
	
	document.getElementById("dettagli").style.display="none"
	document.getElementById("informazioni").style.display="none"
	document.getElementById("appuntamento").style.display="none"
	document.getElementById("immagini").style.display="none"
	document.getElementById("planimetrie").style.display="none"
	document.getElementById("video").style.display="none"
	
	document.getElementById("Image8").src="img/scheda01.gif"
	document.getElementById("Image9").src="img/scheda02.gif"
	document.getElementById("Image10").src="img/scheda03.gif"
	document.getElementById("Image11").src="img/scheda04.gif"
	document.getElementById("Image12").src="img/scheda05.gif"
	document.getElementById("Image13").src="img/scheda06.gif"

	
	document.getElementById(valore).style.display=""
	
	if (valore=="dettagli") 
		document.getElementById("Image8").src="img/scheda01_on.gif"
		
	if (valore=="immagini") 
		document.getElementById("Image9").src="img/scheda02_on.gif"

	if (valore=="planimetrie") 
		document.getElementById("Image10").src="img/scheda03_on.gif"

	if (valore=="informazioni") 
		document.getElementById("Image11").src="img/scheda04_on.gif"

	if (valore=="appuntamento") 
		document.getElementById("Image12").src="img/scheda05_on.gif"
		
	if (valore=="video") 
		document.getElementById("Image13").src="img/scheda06_on.gif"

	
}


function fotobig(f,x) {
	
	//alert(document.getElementById("menu").style.display)
	document.getElementById("bigfoto").src=f
	document.getElementById("fotobig").style.display=""
	document.getElementById("menu").style.display="none"
	document.getElementById("immagini").style.display="none"
	
	xavanti=parseInt(x)+1
	xindietro=parseInt(x)-1
	
	
	tfoto=document.getElementById("totalefoto").value
	totfoto=parseInt(tfoto)
	
//	alert(x)
//	alert(xavanti)
//	alert(xindietro)
//	alert(totfoto)
//	alert(xavanti<=totfoto)
	
	if (xindietro>0)
  		document.getElementById("linkindietro").innerHTML="<a href=\"javascript:muovifoto("+xindietro+")\" id=\"linkindietro\"><img src=\"img/foto_prec.gif\" width=\"104\" height=\"52\" border=\"0\" /></a>"
	else
  		document.getElementById("linkindietro").innerHTML=""
	
	if (xavanti<=totfoto)
		document.getElementById("linkavanti").innerHTML="<a href=\"javascript:muovifoto("+xavanti+")\" id=\"linkindietro\"><img src=\"img/foto_succ.gif\" width=\"99\" height=\"52\" border=\"0\" /></a>"
	else
  		document.getElementById("linkavanti").innerHTML=""

}


function immagini(f) {
	
	document.getElementById("fotobig").style.display="none"
	document.getElementById("menu").style.display=""
	document.getElementById("immagini").style.display=""
	
	

}

function muovifoto(x) {
	
	
	
	f=document.getElementById(x).value
	
	xavanti=parseInt(x)+1
	xindietro=parseInt(x)-1
	
//	alert(x)
//	alert(xavanti)
//	alert(xindietro)
//	alert(totfoto)
	
	tfoto=document.getElementById("totalefoto").value
	totfoto=parseInt(tfoto)
	
	if (xindietro>0)
  		document.getElementById("linkindietro").innerHTML="<a href=\"javascript:muovifoto("+xindietro+")\" id=\"linkindietro\"><img src=\"img/foto_prec.gif\" width=\"104\" height=\"52\" border=\"0\" /></a>"
	else
  		document.getElementById("linkindietro").innerHTML=""
	
	if (xavanti<=totfoto)
		document.getElementById("linkavanti").innerHTML="<a href=\"javascript:muovifoto("+xavanti+")\" id=\"linkindietro\"><img src=\"img/foto_succ.gif\" width=\"99\" height=\"52\" border=\"0\" /></a>"
	else
  		document.getElementById("linkavanti").innerHTML=""
		
	//alert(f)
	document.getElementById("bigfoto").src=f


}



function handlerpreferiti() {


    if (ajax.readyState == 4 && ajax.status == 200) {
        //e = document.getElementById(cc);
		//alert(e)
		//alert(ajax.responseText)
        //e.innerHTML = ajax.responseText;
		//alert(e.innerHTML);
        //e.innerHTML = ajax.responseText;

    }
	
	
}



function preferiti(x) {
	
	prf="preferito"+x
	document.getElementById(prf).innerHTML="<img src=\"img/preferiti.gif\" alt=\"Cogi Group\" width=\"170\" height=\"23\" border=\"0\" />"
	var r = Math.random();
    ajax = CreateXmlHttpReq(handlerpreferiti);
    ajax.open("GET","preferiti.php?cod="+escape(x)+"&rand="+escape(r));
	ajax.setRequestHeader("connection", "close");
    ajax.send(null);
	


}






function handlerpreferiti_rimuovi() {


    if (ajax.readyState == 4 && ajax.status == 200) {
        //e = document.getElementById(cc);
		//alert(e)
		//alert(ajax.responseText)
        //e.innerHTML = ajax.responseText;
		//alert(e.innerHTML);
        //e.innerHTML = ajax.responseText;
		document.location.reload()

    }
	
	
}



function preferiti_rimuovi(x) {
	
	var r = Math.random();
    ajax = CreateXmlHttpReq(handlerpreferiti_rimuovi);
    ajax.open("GET","preferiti_rimuovi.php?cod="+escape(x)+"&rand="+escape(r));
	ajax.setRequestHeader("connection", "close");
    ajax.send(null);
	


}


function metodo(x) {
	
	
	if (x!="") {
		
	document.getElementById("dettagli").style.display="none"
	document.getElementById("informazioni").style.display="none"
	document.getElementById("appuntamento").style.display="none"
	document.getElementById("immagini").style.display="none"
	document.getElementById("planimetrie").style.display="none"
	
	document.getElementById(x).style.display=""
	
	if (x=="informazioni")  {
		document.getElementById("Image11").src="img/scheda04_on.gif"
		document.getElementById("Image8").src="img/scheda01.gif"
	}

	if (x=="appuntamento")  {
		document.getElementById("Image12").src="img/scheda05_on.gif"
		document.getElementById("Image8").src="img/scheda01.gif"
	}

	}
	

}



function chiama(x) {
	
	v1="agenzia_"+x
	v2="agenzia2_"+x
	
	if (document.getElementById(v1).style.display!="") {
	
	document.getElementById(v1).style.display=""
	document.getElementById(v2).style.display=""
	
	}
	else {
		
	document.getElementById(v1).style.display="none"
	document.getElementById(v2).style.display="none"
		
	}
	
}

