var xmlHttpGetMessages;

//messaggi di errore
function displayError(message){alert("Errore di accesso al server! "+ message );}

function ajaxGet(URL, vars, strResultFunc, rifImm, pagina, lac)
{
	var xmlHttpReq=false;
	if(window.XMLHttpRequest)
	{
		xmlHttpReq=new XMLHttpRequest();
		//if(xmlHttpReq.overrideMimeType){xmlHttpReq.overrideMimeType('text/xml');}
	}
	else if(window.ActiveXObject){xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP");}
	if(!xmlHttpReq){alert("Errore nella ceazione dell'oggetto XMLHttpRequest.");}
	//
	xmlHttpGetMessages=xmlHttpReq;
	//
	if(xmlHttpReq)
	{
		try
		{
			xmlHttpReq.open("POST", URL, true);
			xmlHttpReq.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			xmlHttpReq.send(vars);
			xmlHttpReq.onreadystatechange=function(){
				if(xmlHttpReq.readyState==4)
				{
					if(xmlHttpReq.status==200){
						try{
							eval(strResultFunc+'(xmlHttpReq.responseText, '+rifImm+', '+pagina+', '+lac+');');
						}catch(e){displayError(e.toString());}
					}else{displayError(xmlHttpReq.statusText);}
				}
			}
		}catch(e){displayError(e.toString());}
	}
}
function openInBox(pagina, idImm, rifImm, die, news, lac)
{
	var param = "die="+die+"&pagina="+pagina+"&idImm="+idImm+"&lac="+lac+"";
	ajaxGet("php/box_dettaglio_immobile.php", param, "openBoxDettaglio", rifImm, pagina, lac);
}
function openInBox_en(pagina, idImm, rifImm, die, news, lac)
{
	var param = "die="+die+"&pagina="+pagina+"&idImm="+idImm+"&lac="+lac+"";
	ajaxGet("php/box_dettaglio_immobile_en.php", param, "openBoxDettaglio", rifImm, pagina, lac);
}

function openBoxDettaglio(text, rifImm, pagina, lac)
{
	document.getElementById("box-dettaglio-immobile").innerHTML=text;	//dettaglio imm
	//colori bordi
	if(rifImm!=null && pagina!=null){
		var fieldsets = document.getElementsByTagName("fieldset");
		var span = document.getElementsByTagName("span");
		var div = document.getElementsByTagName("div");
		var color='';
		var fieldset = "fldst_"+rifImm;
		var nuovo = "nuovo_"+rifImm;
		//
		if(pagina==0){color='#D9D2B5';}
		if(pagina==1){color='#51b91e';}
		if(pagina==2){color='#ffbc1c';}
		//
		for(i=0;i<fieldsets.length-2;i++)
		{
			//novità
			if(fieldsets[i].lang=='1'){document.getElementById(fieldsets[i].id).style.border = '2px solid #ff0000';} 
			else{document.getElementById(fieldsets[i].id).style.border = '2px solid '+color;}//colori pagina
			//toglie lo sfondo bianco dall'imm selezionato
			document.getElementById(fieldsets[i].id).style.backgroundColor = '#F2F2E6';
			//imm selezionato
			if(fieldsets[i].id==fieldset){
				document.getElementById(fieldset).style.border = '2px solid #0066ff';
				document.getElementById(fieldset).style.backgroundColor = '#ffffff';}
		}
		//scritta novità
		if(lac==0){
			for(i=0;i<span.length-4;i++){
			if(span[i].id==nuovo){document.getElementById(nuovo).style.color = '#0066ff';} 
			else{document.getElementById(span[i].id).style.color = '#ff0000';}}
		}else{
			for(i=0;i<span.length;i++){
			if(span[i].id==nuovo){document.getElementById(nuovo).style.color = '#0066ff';} 
			else{document.getElementById(span[i].id).style.color = '#ff0000';}}
		}
	}
}
function filtro_imm(filtro, news, lac, pagina)
{
	
	//parmetri filtro
	var select1 = document.getElementById('tipo_imm');
	var tipo_imm = select1.options[select1.selectedIndex].value;
	var select2 = document.getElementById('localita');
	var localita = select2.options[select2.selectedIndex].value;
	var select3 = document.getElementById('prezzo');
	var prezzo = select3.options[select3.selectedIndex].value;
	var select4 = document.getElementById('contratto');
	var contratto = select4.options[select4.selectedIndex].value;
	var die=0;if(lac==1){die=1;}
	//
	if(tipo_imm=='Tipo immobile' && localita=="Localita' ( TUTTE )" && prezzo=='Prezzo' && contratto=='Contratto'){alert('ATTENZIONE ! INDICARE ALMENO UN CRITERIO PER LA RICERCA DEGLI IMMOBILI.');}
	else{
		//stampa imm
		var param="die="+die+"&lac="+lac+"&pagina="+pagina+"&filtro="+filtro+"&news="+news+"&tipo_imm="+tipo_imm+"&localita="+localita+"&prezzo="+prezzo+"&contratto="+contratto+"";
		ajaxGet("php/immobili.php", param, "openBoxImmobili", null, null, null);
		// stampa dettaglio
		var param1="filtro="+filtro+"&die="+die+"&lac="+lac+"&pagina="+pagina+"&tipo_imm="+tipo_imm+"&localita="+localita+"&prezzo="+prezzo+"&contratto="+contratto+"";
		ajaxGet("php/box_dettaglio_immobile_filtro.php", param1, "dettImm", null, null, null);
	}
}
function filtro_imm_en(filtro, news, lac, pagina)
{
	
	//parmetri filtro
	var select1 = document.getElementById('tipo_imm');
	var tipo_imm = select1.options[select1.selectedIndex].value;
	var select2 = document.getElementById('localita');
	var localita = select2.options[select2.selectedIndex].value;
	var select3 = document.getElementById('prezzo');
	var prezzo = select3.options[select3.selectedIndex].value;
	var select4 = document.getElementById('contratto');
	var contratto = select4.options[select4.selectedIndex].value;
	var die=0;if(lac==1){die=1;}
	//
	if(tipo_imm=='Tipo immobile' && localita=="Localita' ( TUTTE )" && prezzo=='Prezzo' && contratto=='Contratto'){alert('WARNING! SEARCH CRITERIA NOT SPECIFIED !');}
	else{
		//stampa imm
		var param="die="+die+"&lac="+lac+"&pagina="+pagina+"&filtro="+filtro+"&news="+news+"&tipo_imm="+tipo_imm+"&localita="+localita+"&prezzo="+prezzo+"&contratto="+contratto+"";
		ajaxGet("php/immobili_en.php", param, "openBoxImmobili", null, null, null);
		// stampa dettaglio
		var param1="filtro="+filtro+"&die="+die+"&lac="+lac+"&pagina="+pagina+"&tipo_imm="+tipo_imm+"&localita="+localita+"&prezzo="+prezzo+"&contratto="+contratto+"";
		ajaxGet("php/box_dettaglio_immobile_filtro_en.php", param1, "dettImm", null, null, null);
	}
}
function openBoxImmobili(text, rifImm, pagina, news)
{
	document.getElementById("box-lista-immobili").innerHTML=text;	//imm
}
function dettImm(text)
{
	document.getElementById("box-dettaglio-immobile").innerHTML=text;	//dettaglio imm
}
//cercaper hp
function check_filtro()
{
	var invio=true;
	var select1 = document.getElementById('tipo_imm');
	var tipo_imm = select1.options[select1.selectedIndex].value;
	var select2 = document.getElementById('localita');
	var localita = select2.options[select2.selectedIndex].value;
	var select3 = document.getElementById('prezzo');
	var prezzo = select3.options[select3.selectedIndex].value;
	var select4 = document.getElementById('contratto');
	var contratto = select4.options[select4.selectedIndex].value;
	//
	if(tipo_imm=='Tipo immobile' && localita=="Localita' ( TUTTE )" && prezzo=='Prezzo' && contratto=='Contratto')
		{invio=false; alert('ATTENZIONE ! INDICARE ALMENO UN CRITERIO PER LA RICERCA DEGLI IMMOBILI.');}
	return invio;
}
function check_filtro_en()
{
	var invio=true;
	var select1 = document.getElementById('tipo_imm');
	var tipo_imm = select1.options[select1.selectedIndex].value;
	var select2 = document.getElementById('localita');
	var localita = select2.options[select2.selectedIndex].value;
	var select3 = document.getElementById('prezzo');
	var prezzo = select3.options[select3.selectedIndex].value;
	var select4 = document.getElementById('contratto');
	var contratto = select4.options[select4.selectedIndex].value;
	//
	if(tipo_imm=='Tipo immobile' && localita=="Localita' ( TUTTE )" && prezzo=='Prezzo' && contratto=='Contratto')
		{invio=false; alert('WARNING! SEARCH CRITERIA NOT SPECIFIED !');}
	return invio;
}
	
//abilita campi file
function abilita_file(id) 
{ 
	if(id==2){document.getElementById('foto2').disabled = false;}	
	if(id==3){document.getElementById('foto3').disabled = false;}
	if(id==4){document.getElementById('foto4').disabled = false;}
	if(id==5){document.getElementById('foto5').disabled = false;}
	if(id==6){document.getElementById('foto6').disabled = false;}
}

function open_delete(idImm, pagina, new_)
{
	document.getElementById('box-filtro').style.display = 'none';
	document.getElementById('box-msg-delete').style.display = 'block';
	document.getElementById('box-msg-delete').innerHTML = "<b>Sei sicuro di voler cancellare questo immobile<br />insieme alle sue foto ? " + 
		"<a href='javascript:delete_imm("+idImm+", "+pagina+", "+new_+");'>SI</a> - <a href='javascript:close_delete();'>NO</a></b>";
}
function close_delete()
{
	document.getElementById('box-filtro').style.display = 'block';
	document.getElementById('box-msg-delete').style.display = 'none';
}
function delete_imm(idImm, pagina, new_)
{
	if(pagina==0){window.location.href = "lista_dettagli_immobili.php?link_aggiorna_cancella=1&dettaglio_info_email=1&cancella=1&idImm="+idImm+"&pagina="+pagina+"&new="+new_+"";}
	if(pagina==1){window.location.href = "castellaro_golf_old.php?link_aggiorna_cancella=1&dettaglio_info_email=1&cancella=1&idImm="+idImm+"&pagina="+pagina+"&new="+new_+"";}
	if(pagina==2){window.location.href = "marina_di_san_lorenzo_old.php?link_aggiorna_cancella=1&dettaglio_info_email=1&cancella=1&idImm="+idImm+"&pagina="+pagina+"&new="+new_+"";}
}






	var newX;
	var newY;
	var spaceX;
	var spaceY;
	
function get_risoluzioni() {

		if (self.innerHeight)	{
			// Gecko 										
			spaceX = parseInt(self.innerWidth);
			spaceY = parseInt(self.innerHeight);
		} else if (document.documentElement && document.documentElement.clientHeight) {
			// IExplorer 6 Strict Mode
			 document.documentElement.style.overflow="hidden";
			 spaceX = document.documentElement.clientWidth;
			 spaceY = document.documentElement.clientHeight;
		}  else if (document.body.clientHeight) {
			// IExplorer  Other
			spaceX=document.body.clientWidth;
			spaceY=document.body.clientHeight;
		}
		

		newX =(spaceX-1920)/2;
		newY= (spaceY-1200)/2;
}

function gestione_finestra() {
		get_risoluzioni();
		//
		var tab_esterna= document.getElementById("tab-esterna");
		var tab_interna = document.getElementById("tab-interna");
		//
		tab_esterna.style.width = spaceX + "px";
		tab_esterna.style.height = spaceY + "px";
		//
		tab_interna.style.width = spaceX + "px";
		tab_interna.style.height = spaceY + "px";
		tab_interna.style.verticalAlign = "middle";
		//barre
		if(spaceX < 1002){tab_esterna.style.overflow = 'auto';}
		if(spaceY < 592){tab_esterna.style.overflow = 'auto';}
		//
		if(spaceX < 1002){tab_interna.style.height = (spaceY-16) + "px";}
		if(spaceY < 592){tab_interna.style.width = (spaceX-16) + "px";}

		tab_esterna.style.visibility="visible";
}

function colorariga(idc) 
{ 
	if(document.getElementsByTagName) 
	{
		for(i=0; i<document.getElementsByTagName("input").length; i++)
		{
			if(document.getElementsByTagName("input")[i].value == "'+idc+'")
			{document.getElementById("riga_'+idc+'").style.backgroundColor = '#ffffff';}
		}
	}
}
//input ins imm
function tabindex() 
{ 
	document.getElementById('rif').focus();	
}
//input ins imm
function set_rif_imm() 
{ 
	document.getElementById('rif').select();	
}
//input ins imm
function set_utente() 
{ 
	document.getElementById('utente').select();	
}

//stampa foto immobili originali
function apri_img_originale(rif, foto, b, h, alt) 
{ 
	winName = window.open('', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
	with(winName.document)
	{
		open();
		write('<html><head><script type="text/javascript"></script><link href="css/michelini.css" rel="stylesheet" type="text/css" media="screen" />');
		write('<link href="css/michelini_stampa_foto.css" rel="stylesheet" type="text/css" media="print" />');
		write('<title>Agenzia Immobiliare Michelini</title></head>');
		write('<body id="body-stampa-foto">');
		write('<img src="../foto_immobili/'+foto+'" alt=' + alt + '><br>');
		write('<div id="nome_foto_stampa"><b>riferimento immobile #'+rif+' - ' + alt + ' </b>');
		write('&nbsp; <a id="link_stampa" href="javascript:window.print();window.close();">stampa</a> - <a id="link_stampa" href="javascript:window.close();">chiudi</a></div>');
		write('</body></html>');
		close();
	}
}
function apri_img_originale_en(rif, foto, b, h, alt) 
{ 
	winName = window.open('', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
	with(winName.document)
	{
		open();
		write('<html><head><script type="text/javascript"></script><link href="css/michelini.css" rel="stylesheet" type="text/css" media="screen" />');
		write('<link href="css/michelini_stampa_foto.css" rel="stylesheet" type="text/css" media="print" />');
		write('<title>Real estate agency  Michelini</title></head>');
		write('<body id="body-stampa-foto">');
		write('<img src="../foto_immobili/'+foto+'" alt=' + alt + '><br>');
		write('<div id="nome_foto_stampa"><b>reference  property #'+rif+' - ' + alt + ' </b>');
		write('&nbsp; <a id="link_stampa" href="javascript:window.print();window.close();">print</a> - <a id="link_stampa" href="javascript:window.close();">exit</a></div>');
		write('</body></html>');
		close();
	}
}

//form email
function form_email(id_immobile, pagina) 
{ 
	winName = window.open('invio_info_immobile.php?pagina=' + pagina + '&idImm=' + id_immobile + '', "", "scrollbars=0,status=0,width=260,height=420,left=0,top=0,resizable=0");
}
function form_email_en(id_immobile, pagina) 
{ 
	winName = window.open('invio_info_immobile_en.php?pagina=' + pagina + '&idImm=' + id_immobile + '', "", "scrollbars=0,status=0,width=260,height=420,left=0,top=0,resizable=0");
}

function input_login() 
{ 
	document.getElementById('utente').focus();
}
//stampa scheda imm
function stampa_scheda(rif_immobile, id_immobile, agenzia, pagina) 
{ 
	winName = window.open('stampa_scheda.php?rif=' + rif_immobile + '&pagina=' + pagina + '&agenzia=' + agenzia + '&idImm=' + id_immobile + '', "", "scrollbars=0,width=995,height=660,left=0,top=0,resizable=0,status=0");
}
function stampa_scheda_en(rif_immobile, id_immobile, agenzia, pagina) 
{ 
	winName = window.open('stampa_scheda_en.php?rif=' + rif_immobile + '&pagina=' + pagina + '&agenzia=' + agenzia + '&idImm=' + id_immobile + '', "", "scrollbars=0,width=995,height=660,left=0,top=0,resizable=0,status=0");
}

//colora pulsanti login
function colora_pulsante(param, pulsante) 
{ 
	if(pulsante == 0)
	{
		if(param == 0)
		{
			document.getElementById('reset').style.backgroundColor = '#ffffff';
		}
		else
		{
			document.getElementById('reset').style.backgroundColor = '#eaeaea';
		}
	}
	else
	{
		if(param == 0)
		{
			document.getElementById('submit').style.backgroundColor = '#ffffff';
		}
		else
		{
			document.getElementById('submit').style.backgroundColor = '#eaeaea';
		}
	}
}
//convalida campi frm 
function convalidaInput(convalida) 
{
	invio = true; 	
	//
	switch(convalida)
	{	
		//login
		case 0:	
			NU = document.getElementById('utente').value;
			PW = document.getElementById('pw').value;
			//
			if(NU == null || NU == '')
			{
				alert('Nome utente mancante!! Prego reinserirlo');
				invio = false; 
				document.getElementById('utente').select();
			}
			else if(PW == null || PW == '')
			{
				alert('Password mancante!!Prego reinserirla');
				invio = false; 
				document.getElementById('pw').select();
			}
		break;
		
		//ins imm
		case 1:	
			rif = trim(document.getElementById('rif').value);
			lettera = trim(document.getElementById('lettera').value);
			descrit = trim(document.getElementById('descr_it').value);
			descren = trim(document.getElementById('descr_en').value);
			pr = trim(document.getElementById('prezzo').value);
			sup = trim(document.getElementById('sup_comm').value);
			//
			//ricava gli ultimi 3 caratteri del file caricato
			foto1 = document.getElementById('foto1').value; 
			l_str1_est = foto1.length - 3;
			foto2 = document.getElementById('foto2').value; 
			l_str2_est = foto2.length - 3;
			foto3 = document.getElementById('foto3').value;
			l_str3_est = foto3.length - 3;
			foto4 = document.getElementById('foto4').value;
			l_str4_est = foto4.length - 3;
			foto5 = document.getElementById('foto5').value;
			l_str5_est = foto5.length - 3;
			foto6 = document.getElementById('foto6').value;
			l_str6_est = foto6.length - 3;
			//
			est1 = foto1.substr(l_str1_est, foto1.length);
			est2 = foto2.substr(l_str2_est, foto2.length);
			est3 = foto3.substr(l_str3_est, foto3.length);
			est4 = foto4.substr(l_str4_est, foto4.length);
			est5 = foto5.substr(l_str5_est, foto5.length);
			est6 = foto6.substr(l_str6_est, foto6.length);
			//
			if((rif == null || rif == '') || rif == 0)
			{
				alert('Numero di riferimento immobile mancante o uguale a zero !!');
				invio = false; 
				document.getElementById('rif').value='';
				document.getElementById('rif').select();
			}
			else if(isNaN(rif))
			{
				alert('Il riferimento immobile non è un numero');
				invio = false; 
				document.getElementById('rif').value='';
				document.getElementById('rif').select();
			}
			else if(lettera!='' && !isNaN(lettera))
			{
				alert('La lettera non può essere un numero !! ');
				invio = false; 
				document.getElementById('lettera').value='';
				document.getElementById('lettera').select();
			}
			else if(sup != '' && isNaN(sup))
			{
				alert('La superficie non è un numero !!');
				invio = false; 
				document.getElementById('sup_comm').value='';
				document.getElementById('sup_comm').select();
			}
			else if(descrit.length > 500)
			{
				alert('Non si possono inserire più di 500 caratteri per la descrizione dell\'immobile italiano !!');
				invio = false; 
				document.getElementById('descr_it').select();
			}
			else if(descren.length > 500)
			{
				alert('Non si possono inserire più di 500 caratteri per la descrizione dell\'immobile inglese !!');
				invio = false; 
				document.getElementById('descr_en').select();
			}

			///////
			//controlla che una o più foto non siano caricate più volte
			if((foto1 != '') && (foto2 != ''))
			{
				if(foto1 == foto2)
				{
					alert('ATTENZIONE! La foto 1 è uguale alla foto 2!!');
					invio = false; 
				}
			}
			//
			if((foto1 != '') && (foto3 != ''))
			{
				if(foto1 == foto3)
				{
					alert('ATTENZIONE! La foto 1 è uguale alla foto 3!!');
					invio = false; 
				}				
			}
			//
			if((foto1 != '') && (foto4 != ''))
			{
				if(foto1 == foto4)
				{
					alert('ATTENZIONE! La foto 1 è uguale alla foto 4!!');
					invio = false; 
				}				
			}
			//
			if((foto1 != '') && (foto5 != ''))
			{
				if(foto1 == foto5)
				{
					alert('ATTENZIONE! La foto 1 è uguale alla foto 5!!');
					invio = false; 
				}				
			}
			//
			if((foto1 != '') && (foto6 != ''))
			{
				if(foto1 == foto6)
				{
					alert('ATTENZIONE! La foto 1 è uguale alla foto 6!!');
					invio = false; 
				}				
			}
			//
			if((foto2 != '') && (foto3 != ''))
			{
				if(foto2 == foto3)
				{
					alert('ATTENZIONE! La foto 2 è uguale alla foto 3!!');
					invio = false; 
				}
			}
			//
			if((foto2 != '') && (foto4 != ''))
			{
				if(foto2 == foto4)
				{
					alert('ATTENZIONE! La foto 2 è uguale alla foto 4!!');
					invio = false; 
				}
			}
			//
			if((foto2 != '') && (foto5 != ''))
			{
				if(foto2 == foto5)
				{
					alert('ATTENZIONE! La foto 2 è uguale alla foto 5!!');
					invio = false; 
				}
			}
			//
			if((foto2 != '') && (foto6 != ''))
			{
				if(foto2 == foto6)
				{
					alert('ATTENZIONE! La foto 2 è uguale alla foto 6!!');
					invio = false; 
				}
			}
			//
			if((foto3 != '') && (foto4 != ''))
			{
				if(foto3 == foto4)
				{
					alert('ATTENZIONE! La foto 3 è uguale alla foto 4!!');
					invio = false; 
				}
			}
			//
			if((foto3 != '') && (foto5 != ''))
			{
				if(foto3 == foto5)
				{
					alert('ATTENZIONE! La foto 3 è uguale alla foto 5!!');
					invio = false; 
				}
			}
			//
			if((foto3 != '') && (foto6 != ''))
			{
				if(foto3 == foto6)
				{
					alert('ATTENZIONE! La foto 3 è uguale alla foto 6!!');
					invio = false; 
				}
			}
			//
			if((foto4 != '') && (foto5 != ''))
			{
				if(foto4 == foto5)
				{
					alert('ATTENZIONE! La foto 4 è uguale alla foto 5!!');
					invio = false; 
				}
			}
			//
			if((foto4 != '') && (foto6 != ''))
			{
				if(foto4 == foto6)
				{
					alert('ATTENZIONE! La foto 4 è uguale alla foto 6!!');
					invio = false; 
				}
			}
			//
			if((foto5 != '') && (foto6 != ''))
			{
				if(foto5 == foto6)
				{
					alert('ATTENZIONE! La foto 5 è uguale alla foto 6!!');
					invio = false; 
				}
			}
			//controlla che l'img sia del formato giusto
			if(foto1 != '')
			{
				if((est1 != 'gif') && (est1 != 'jpg') && (est1 != 'png') && (est1 != 'GIF') && (est1 != 'JPG') && (est1 != 'PNG'))
				{
					alert("Formato della foto 1 errato. Sono ammessi solo immagini di tipo: .gif / . jpg / .png");
					invio = false; 
				}
			}
			if(foto2 != '')
			{
				if((est2 != 'gif') && (est2 != 'jpg') && (est2 != 'png') && (est2 != 'GIF') && (est2 != 'JPG') && (est2 != 'PNG'))
				{
					alert("Formato della foto 2 errato. Sono ammessi solo immagini di tipo: .gif / . jpg / .png");
					invio = false; 
				}
			}
			if(foto3 != '')
			{
				if((est3 != 'gif') && (est3 != 'jpg') && (est3 != 'png') && (est3 != 'GIF') && (est3 != 'JPG') && (est3 != 'PNG'))
				{
					alert("Formato della foto 3 errato. Sono ammessi solo immagini di tipo: .gif / . jpg / .png");
					invio = false; 
				}
			}
			if(foto4 != '')
			{
				if((est4 != 'gif') && (est4 != 'jpg') && (est4 != 'png') && (est4 != 'GIF') && (est4 != 'JPG') && (est4 != 'PNG'))
				{
					alert("Formato della foto 4 errato. Sono ammessi solo immagini di tipo: .gif / . jpg / .png");
					invio = false; 
				}
			}
			if(foto5 != '')
			{
				if((est5 != 'gif') && (est5 != 'jpg') && (est5 != 'png') && (est5 != 'GIF') && (est5 != 'JPG') && (est5 != 'PNG'))
				{
					alert("Formato della foto 5 errato. Sono ammessi solo immagini di tipo: .gif / . jpg / .png");
					invio = false; 
				}
			}
			if(foto6 != '')
			{
				if((est6 != 'gif') && (est6 != 'jpg') && (est6 != 'png') && (est6 != 'GIF') && (est6 != 'JPG') && (est6 != 'PNG'))
				{
					alert("Formato della foto 6 errato. Sono ammessi solo immagini di tipo: .gif / . jpg / .png");
					invio = false; 
				}
			}
		break;
		
		//email
		case 2:	
			nome = trim(document.getElementById('nome').value);
			cognome = trim(document.getElementById('cognome').value);
			recapiti = trim(document.getElementById('recapiti').value);
			email = trim(document.getElementById('email').value);
			var email_rex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	

			if(nome == null || nome == '')
			{
				alert('Nome mancante!! Prego reinserirlo');
				invio = false; 
				document.getElementById('nome').select();
			}
			else if(cognome == null || cognome == '')
			{
				alert('Cognome mancante!!Prego reinserirlo');
				invio = false; 
				document.getElementById('cognome').select();
			}
			else if(email == null || email == '')
			{
				alert('Email mancante!!Prego reinserirla');
				invio = false; 
				document.getElementById('email').select();
			}
			else if(!email_rex.test(email))
			{
				alert('Indirizzo email non valido!!Prego reinserirlo');
				invio = false; 
				document.getElementById('email').select();
			}
			else if((recapiti == null || recapiti == '') || isNaN(recapiti))
			{
				alert('Recapiti mancanti o non validi !!Prego reinserirli');
				invio = false; 
				document.getElementById('recapiti').select();
			}
			else if(document.getElementById('privacy').checked == false)
			{
				alert('Manca l\'autorizzazione al trattamento dei dati!!');
				invio = false; 
			}
		break;
		
		case 3:	
			nome = trim(document.getElementById('nome').value);
			cognome = trim(document.getElementById('cognome').value);
			recapiti = trim(document.getElementById('recapiti').value);
			email = trim(document.getElementById('email').value);
			var email_rex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	

			if(nome == null || nome == '')
			{
				alert('Insert first name ');
				invio = false; 
				document.getElementById('nome').select();
			}
			else if(cognome == null || cognome == '')
			{
				alert('Insert last name ');
				invio = false; 
				document.getElementById('cognome').select();
			}
			else if(email == null || email == '')
			{
				alert('Insert a valid email address ');
				invio = false; 
				document.getElementById('email').select();
			}
			else if(!email_rex.test(email))
			{
				alert('insert a valid email address ');
				invio = false; 
				document.getElementById('email').select();
			}
			else if((recapiti == null || recapiti == '') || isNaN(recapiti))
			{
				alert('Insert a contact telephone number ');
				invio = false; 
				document.getElementById('recapiti').select();
			}
			else if(document.getElementById('privacy').checked == false)
			{
				alert('Missing authorisation of the personal data treatment !!');
				invio = false; 
			}
		break;
	}
	return invio;
}

function abilita_cerca_imm()
{
	if(document.getElementById('cerca_imm').checked == true)
	{
		document.getElementById('tipoimmobile').disabled=false;
		document.getElementById('tipo-immobile').disabled=false;
		document.getElementById('sl').disabled=false;
		document.getElementById('ar').disabled=false;
		document.getElementById('en').disabled=false;
		document.getElementById('al').disabled=false;
		document.getElementById('gl').disabled=false;
		document.getElementById('mar').disabled=false;
		document.getElementById('tut').disabled=false;
		document.getElementById('prezzo').disabled=false;
		document.getElementById('vani').disabled=false;
		document.getElementById('giard').disabled=false;
		document.getElementById('pa').disabled=false;
		document.getElementById('box2').disabled=false;
		document.getElementById('vista').disabled=false;
		document.getElementById('asc').disabled=false;
		document.getElementById('ter').disabled=false;
		document.getElementById('pisc').disabled=false;
		document.getElementById('termo').disabled=false;
		document.getElementById('statoimmobile').disabled=false;
		/**/
	}
	else if(document.getElementById('cerca_imm').checked == false)
	{
		document.getElementById('tipoimmobile').disabled=true;
		document.getElementById('tipo-immobile').disabled=true;
		document.getElementById('sl').disabled=true;
		document.getElementById('ar').disabled=true;
		document.getElementById('en').disabled=true;
		document.getElementById('al').disabled=true;
		document.getElementById('gl').disabled=true;
		document.getElementById('mar').disabled=true;
		document.getElementById('tut').disabled=true;
		document.getElementById('prezzo').disabled=true;
		document.getElementById('vani').disabled=true;
		document.getElementById('giard').disabled=true;
		document.getElementById('pa').disabled=true;
		document.getElementById('box2').disabled=true;
		document.getElementById('vista').disabled=true;
		document.getElementById('asc').disabled=true;
		document.getElementById('ter').disabled=true;
		document.getElementById('pisc').disabled=true;
		document.getElementById('termo').disabled=true;
		document.getElementById('statoimmobile').disabled=true;
		/**/
	}
}

function convalidaCercaImmobile()
{
	var invio = true;
	var nomecognome = trim(document.getElementById('nome_cognome').value);
	var recapito = trim(document.getElementById('recapito').value);
	var email = trim(document.getElementById('email').value);
	var email_rex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
	//
	if(nomecognome == null || nomecognome == '')
	{
		document.getElementById('loc').style.display='none';
		document.getElementById('rec').style.display='none';
		document.getElementById('nc').style.display='block';
		document.getElementById('em').style.display='none';
		document.getElementById('nome_cognome').select();
		invio = false; 
	}
	else if(email == null || email == '')
	{
		document.getElementById('loc').style.display='none';
		document.getElementById('rec').style.display='none';
		document.getElementById('nc').style.display='none';
		document.getElementById('em').style.display='block';
		document.getElementById('email').select();
		invio = false; 
	}
	else if(!email_rex.test(email))
	{
		document.getElementById('loc').style.display='none';
		document.getElementById('rec').style.display='none';
		document.getElementById('nc').style.display='none';
		document.getElementById('em').style.display='block';
		document.getElementById('email').select();
		invio = false; 
	}
	else if((recapito == null || recapito == '') || isNaN(recapito))
	{
		document.getElementById('loc').style.display='none';
		document.getElementById('nc').style.display='none';
		document.getElementById('em').style.display='none';
		document.getElementById('rec').style.display='block';
		document.getElementById('recapito').select();
		invio = false; 
	}
	if(document.getElementById('cerca_imm').checked == true)
	{
		if(document.getElementById('sl').checked == false && 
			document.getElementById('ar').checked == false && 
			document.getElementById('en').checked == false && 
			document.getElementById('al').checked == false && 
			document.getElementById('gl').checked == false && 
			document.getElementById('mar').checked == false && 
			document.getElementById('tut').checked == false)
		{
			document.getElementById('loc').style.display='block';
			document.getElementById('rec').style.display='none';
			document.getElementById('nc').style.display='none';
			document.getElementById('em').style.display='none';
			invio = false; 
		}
	}
	
	return invio;
}

//trim per le stringhe
function trim(input)
{
	var valore = input.split(' ');
	var msg = ''; 
	for (i=0; i<valore.length; i++)
	{
		msg += valore[i]; 
	} 
	return msg;	
}
//verifica se un numero è decimale o no
function isInt(myNum) 
{ 
	var myMod = myNum % 1;
 	if(myMod == 0){return true;}else{return false;}
}
//estrae la parte intera
function estrae_intero(myNum) 
{ 
	var parte_dec = myNum % 1;          
	var parte_int = myNum - parte_dec;
	return parte_int + "";
}
