var MEAjax = getMEAjaxObj();
var selectedRegion;
var section;
var subsection;
var selectedProv;
var cityFlag;
var selectedCity;
var selectedProvId='';
var regioneLoaded=false;
var cityBack=false;
var provBack=false;
var regBack=false;
var zoneBack = false;
/* INIZIALIZZAZIONE  */

/* CARICAMENTO INIZIALE */
var paginaOspite = document.referrer;
var utm_source = "";
var utm_medium = "";
var utm_campaign = "";

/* Setta i parametri di tracciamento a seconda di dove il widget è ospitato */

if (paginaOspite.search(/yahoo/ig) != -1){
	utm_source = "yahoo";
	utm_medium = "finanza";
	utm_campaign = "widget";
}

if (paginaOspite.search(/virgilio/ig) != -1){
	utm_source = "virgilio";
	utm_medium = "cobrand";
	utm_campaign = "widget";
}

if (paginaOspite.search(/avvenire/ig) != -1){
	utm_source = "avvenire";
	utm_medium = "cobrand";
	utm_campaign = "widget";
}
/* FINE Setta i parametri di tracciamento a seconda di dove il widget è ospitato */


addEvent(window,'load',initImmobiliare);

function initImmobiliare(){
    
    document.getElementById('IW_header').innerHTML = 
		"<div class=\"IW_clear\"><\/div>"+
		"<div id = \"IW_tabs\">"+
		"	<a id = \"IW_cerca_annunci_btn\" onclick=\"initCercaAnnunciResidenziale();\" onmouseout=\"off(this);\" onmouseover=\"on(this);\" class=\"IW_btn_tab\"><span class=\"IW_btn_left\">&nbsp;<\/span><span class=\"IW_btn_center\">Cerca Annunci<\/span><span class=\"IW_btn_right\">&nbsp;<\/span><\/a>"+
		"	<a id = \"IW_nuove_costruzioni_btn\" onclick=\"initCercaNuoveCostruzioni();\"; onmouseout=\"off(this);\" onmouseover=\"on(this);\" class=\"IW_btn_tab\"><span class=\"IW_btn_left\">&nbsp;<\/span><span class=\"IW_btn_center\">Nuove Costruzioni<\/span><span class=\"IW_btn_right\">&nbsp;<\/span><\/a>"+
		"	<a id = \"IW_cerca_agenzie_btn\" onclick=\"initCercaAgenzie();\" onmouseout=\"off(this);\" onmouseover=\"on(this);\" class=\"IW_btn_tab\"><span class=\"IW_btn_left\">&nbsp;<\/span><span class=\"IW_btn_center\">Cerca Agenzie<\/span><span class=\"IW_btn_right\">&nbsp;<\/span><\/a>"+
		"<\/div>"+
	
		"<div class=\"IW_clear\"><\/div>"+
	    
		"<div id = \"IW_menu_cont\">"+
		"<div id = \"IW_menu_left\"><\/div>"+
		
		"<div id = \"IW_menu_center\">"+
		"   <div class=\"IW_tab_menu\" id = \"IW_cerca_annunci_menu\" onmouseover=\"\" onmouseout=\"\">"+
		"	    <a onmouseover=\"on(this)\" onmouseout=\"off(this)\" class=\"IW_submenu_btn\" id = \"IW_residenziale_btn\" onclick=\"initCercaAnnunciResidenziale();\">Residenziale<\/a>"+
		"	    <a onmouseover=\"on(this)\" onmouseout=\"off(this)\" class=\"IW_submenu_btn\" id = \"IW_commerciale_btn\" onclick=\"initCercaAnnunciCommerciale();\">Commerciale<\/a>"+
		"	    <a onmouseover=\"on(this)\" onmouseout=\"off(this)\" class=\"IW_submenu_btn\" id = \"IW_turistico_btn\" onclick=\"initCercaAnnunciTuristico()\">Turistico<\/a>"+
		"	    <a onmouseover=\"on(this)\" onmouseout=\"off(this)\" class=\"IW_submenu_btn\" id = \"IW_stanze_btn\" onclick=\"initCercaAnnunciStanze()\">Stanze<\/a>"+
		"   <\/div>"+
		"<\/div>"+
		"<div id = \"IW_menu_right\"><\/div>"+
		"<div class=\"IW_clear\"><\/div>"+
		"<div id = \"IW_arrow_tab\">"+
		"    <div class=\"IW_tab_menu\" id = \"IW_cerca_annunci_menu\" onmouseover=\"\" onmouseout=\"\">"+
		"	    <a  onmouseover=\"\" onmouseout=\"\" class=\"IW_arrow\" id = \"IW_residenziale_arw\" onclick=\"\"><span>Residenziale<\/span><\/a>"+
		"	    <a  onmouseover=\"\" onmouseout=\"\" class=\"IW_arrow\" id = \"IW_commerciale_arw\" onclick=\"\"><span>Commerciale<\/span><\/a>"+
		"	    <a  onmouseover=\"\" onmouseout=\"\" class=\"IW_arrow\" id = \"IW_turistico_arw\" onclick=\"\"><span>Turistico<\/span><\/a>"+
		"	    <a  onmouseover=\"\" onmouseout=\"\" class=\"IW_arrow\" id = \"IW_stanze_arw\" onclick=\"\"><span>Stanze<\/span><\/a>"+
		"    <\/div>"+
		"<\/div><div class=\"IW_clear\"><\/div>"+
	    "<\/div>";
	
	
	document.getElementById('IW_body').innerHTML = "<div id=\"box_ricerca\">"+
	"<div id=\"cartina\">"+
	"	<\/div>"+
	"	<div id=\"form\">"+
	"	    <form action=\"http://www.immobiliare.it\" method=\"get\" id=\"dati\" name=\"dati\" target=\"_blank\">"+
	"		<input id = \"idCategoria\" name=\"idCategoria\" value=\"1\" type=\"hidden\">"+
	"		<input id = \"idProvincia\" name=\"idProvincia\" value=\"\" type=\"hidden\">"+
	"		<input id = \"prezzoMinimo\" name=\"prezzoMinimo\" value=\"\" type=\"hidden\">"+
	"		<input id = \"start\" name=\"start\" value=\"0\" type=\"hidden\">"+
	"		<input id = \"prezzoMassimo\" name=\"prezzoMassimo\" value=\"\" type=\"hidden\">"+
	"		<input id = \"azione\" name=\"azione\" value=\"avviaricerca\" type=\"hidden\">"+
	"		<input id = \"idComune\" name=\"idComune\" value=\"\" type=\"hidden\">"+
	"		<input name=\"utm_source\" value=\""+utm_source+"\" type=\"hidden\">"+
	"		<input name=\"utm_medium\" value=\""+utm_medium+"\" type=\"hidden\">"+
	"		<input name=\"utm_campaign\" value=\""+utm_campaign+"\" type=\"hidden\">"+		
	"		<table id=\"formFields\" style=\"font-size:10px;font-family:Arial, Verdana, Helvetica, sans-serif!important;margin-top:40px;\" cellspacing=\"0\" cellpadding=\"0\">"+
	"<tr>"+
	"<td colspan=\"2\">"+
	"			    <table class=\"int\" style=\"font-size:10px;font-family:Arial, Verdana, Helvetica, sans-serif!important;\" cellspacing=\"0\" cellpadding=\"0\">"+
	"		    <tr id=\"trContratto\">"+
	"			<td class=\"IW_title\">Contratto<\/td>"+
	"			<td>"+
	"				<label for=\"radio_idContratto1\"><input class=\"IW_noborder\" name=\"idContratto\" id=\"radio_idContratto1\" value=\"1\" checked=\"checked\" type=\"radio\"><span style=\"position:relative;top:-3px;top:expression('-1px');\">Vendita<\/span>"+
	"				<label for=\"radio_idContratto2\"><input class=\"IW_noborder\" name=\"idContratto\" id=\"radio_idContratto2\" value=\"2\" type=\"radio\"><span style=\"position:relative;top:-3px;top:expression('-1px');\">Affitto<\/span>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"		    <tr id=\"trReg\">"+
	"			<td class=\"IW_title\">Regione&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/td>"+
	"			<td>"+
	"			    <select name=\"idRegione\" id=\"idRegione\" class=\"IW_inputs\" onChange=\"selectFormRegione(this.options[selectedIndex].value)\">"+
	"			    <\/select>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"		    <tr id=\"trPro\">"+
	"			<td class=\"IW_title\">Provincia<\/td>"+
	"			<td>"+
	"			    <select name=\"selIdProvincia\" id=\"selIdProvincia\" class=\"IW_inputs\" onChange=\"selectFormProvincia(this.options[selectedIndex].value)\">"+
	"			    <\/select>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"		    <tr id=\"trCit\">"+
	"			<td class=\"IW_title\">Comune<\/td>"+
	"			<td>"+
	"			    <select name=\"idCitta\" id=\"idCitta\" onChange=\"selectFormCitta(this.options[selectedIndex].value); \" class=\"IW_inputs\">"+
	"			    <\/select>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"		    <tr id=\"trNom\">"+
	"			<td class=\"IW_title\">Nome Agenzia<\/td>"+
	"			<td>"+
	"			    <input type=\"text\" value=\"\" name=\"keywords\" class=\"IW_inputs\"/>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"		    <tr id=\"trZon\">"+
	"			<td class=\"IW_title\">Zona<\/td>"+
	"			<td>"+
	"			    <input name=\"zone_descrizione\" readonly=\"true\" id=\"zone_descrizione\" class=\"IW_inputs\" onClick=\"toggleZ()\" value=\" Seleziona\" style=\"display:block\"/>"+
	"				<div id=\"zone_wrap\" style=\"position:absolute;display:none\"><a id=\"cerca_annunci_btn\" onclick=\"hideZ();\" class=\"IW_btn_tab\"><span class=\"IW_btn_left\">&nbsp;<\/span><span class=\"IW_btn_center\" style=\"color:#FFF\">Chiudi<\/span><span class=\"IW_btn_right\">&nbsp;<\/span><\/a><div id=\"zoneSelect\"><\/div><\/div>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"<\/table>"+
	"<\/td>"+
	"<\/tr>"+
	"		    <tr>"+
	"			<td colspan=\"2\">"+
	"			    <table class=\"int\" id=\"bloccoHideZone\" style=\"font-size:10px;font-family:Arial, Verdana, Helvetica, sans-serif!important;\" cellspacing=\"0\" cellpadding=\"0\">"+
	"				<tr id=\"trRag\">"+
	"				    <td class=\"IW_title\">Raggio<\/td>"+
	"				    <td>"+
	"					<select name=\"raggio\" id=\"raggio\" class=\"IW_inputs\">"+
	"					    <option value=\"\" disabled selected>Seleziona<\/option>"+
	"					    <option value=\"5\">5km<\/option>"+
	"					    <option value=\"10\">10km<\/option>"+
	"					    <option value=\"25\">25km<\/option>"+
	"					    <option value=\"50\">50km<\/option>"+
	"					<\/select>"+
	"				    <\/td>"+
	"				<\/tr>"+
	"				<tr id=\"trTip\">"+
	"				    <td class=\"IW_title\">Tipologia<\/td>"+
	"				    <td>"+
	"					<select name=\"idTipologia\" id=\"idTipologia\" class=\"IW_inputs\">"+
	"					<\/select>"+
	"				    <\/td>	"+
	"				<\/tr>"+
	"				<tr id=\"trSottoTip\">"+
	"				    <td class=\"IW_title\">Sottotipo<\/td>"+
	"				    <td>"+
	"					<select name=\"sottotipologia\" id=\"sottotipologia\" class=\"IW_inputs\">"+
	"					<\/select>"+
	"				    <\/td>	"+
	"				<\/tr>"+
	"				<tr id=\"trPrezzoMin\">"+
	"				    <td class=\"IW_title\">Prezzo min<\/td>"+
	"				    <td>"+
	"					<select name=\"prezzoMinimo\" id=\"selectPrezzoMinimo\" onChange=\"updatePrezzoMax(this.selectedIndex);return false;\" class=\"IW_inputs\">"+
	"					    <option value=\"\" disabled selected>Seleziona<\/option>"+
	"					    <option value=\"100000\">100.000 &euro;<\/option>"+
	"					    <option value=\"150000\">150.000 &euro;<\/option>"+
	"					    <option value=\"200000\">200.000 &euro;<\/option>"+
	"					    <option value=\"300000\">300.000 &euro;<\/option>"+
	"					    <option value=\"500000\">500.000 &euro;<\/option>"+
	"					<\/select>"+
	"				    <\/td>"+
	"				<\/tr>"+
	"				<tr id=\"trPrezzoMax\">"+
	"				    <td class=\"IW_title\">Prezzo max<\/td>"+
	"				    <td>"+
	"					<select name=\"prezzoMax\" id=\"selectPrezzoMassimo\" onChange=\"updatePrezzoMin(this.selectedIndex);return false;\" class=\"IW_inputs\">"+
	"					    <option value=\"\" disabled selected>Seleziona<\/option>"+
	"					    <option value=\"100000\">100.000 &euro;<\/option>"+
	"					    <option value=\"150000\">150.000 &euro;<\/option>"+
	"					    <option value=\"200000\">200.000 &euro;<\/option>"+
	"					    <option value=\"300000\">300.000 &euro;<\/option>"+
	"					    <option value=\"500000\">500.000 &euro;<\/option>"+
	"					<\/select>"+
	"				    <\/td>"+
	"				<\/tr>"+
	"			    <\/table>"+
	"			<\/td>"+
	"		    <\/tr>"+	
	"		    <tr>"+
	"			<td>&nbsp;<\/td>"+
	"			<td>"+
	"			    <a id=\"cerca\" class=\"IW_button_blue\" style=\"overflow: hidden;float:right;margin-right:10px;\" onMouseOver=\"this.className='IW_button_blue_clicked';\" onClick=\"return validateForm();\" onMouseOut=\"this.className='IW_button_blue'; this.blur();\"><span class=\"IW_sx\"><\/span><span class=\"IW_pattern\"><span id=\"\" class=\"IW_\">Cerca<\/span><\/span><span class=\"IW_dx\"><\/span><\/a>"+
	"			<\/td>"+
	"		    <\/tr>"+
	"		    <tr id=\"divCittaDirette\" style=\"font-size:11px;\">"+
	"			<td colspan=\"2\">"+
	"			    <table class=\"int\" style=\"font-size:10px;font-family:Arial, Verdana, Helvetica, sans-serif!important;\" cellspacing=\"0\" cellpadding=\"0\">"+
	"				<tr>"+
	"				    <td class=\"IW_title IW_citylink\" >Link Veloci: <\/td>"+
	"				    <td id=\"IW_QuickLink\" style=\"font-size:11px;\">"+
/*	"				      <!--  <a onClick=\"selectDirect('lom','MI',8042);\">Milano, <\/a>"+
	"				        <a onClick=\"selectDirect('laz','RM',6737);\">Roma, <\/a>"+
	"				        <a onClick=\"selectDirect('tos','FI',11609);\">Firenze, <\/a>"+
	"				        <a onClick=\"selectDirect('emi','BO',5890);\">Bologna, <\/a>"+
	"				        <a onClick=\"selectDirect('pie','TO',9987);\">Torino, <\/a>"+
	"				        <a onClick=\"selectDirect('ven','PD',12137);\">Padova, <\/a>"+
	"				        <a onClick=\"selectDirect('cam','NA',5685);\">Napoli, <\/a>"+
	"				        <a onClick=\"selectDirect('lig','GE',6846);\">Genova, <\/a>"+
	"				        <a onClick=\"selectDirect('ven','VE',12370);\">Venezia <\/a>-->"+ */				        
	"				    <\/td>"+
	"				<\/tr>"+
	"			    <\/table>	"+
	"			 <\/td>   "+
	"		    <\/tr>"+
	"		<\/table>    "+
	"	    <\/form>"+
	"	<\/div>"+
	"	<div class=\"IW_clear\"><\/div>"+
	"   <\/div>";

	initCercaAnnunciResidenziale();
	return false;
}



/* INIZIALIZZAZIONI MAPPA A SECONDA DELLA SEZIONE SCELTA */

function initCercaAnnunciResidenziale(){
    
    section = 'cerca_annunci';
    subsection = 'residenziale';
    cityFlag=1;
    selectNazione('italia');
    btn = document.getElementById('cerca_annunci_btn');
    
    if(document.getElementById('idCategoria'))    document.getElementById('idCategoria').value='1';
    if (document.getElementById('dati')) document.getElementById('dati').action="http://www.immobiliare.it/index.php";
    visMenu('show');
	
    if (document.getElementById('trPro'))	document.getElementById('trPro').style.display="none";
    if (document.getElementById('trCit'))	document.getElementById('trCit').style.display="none";
    if (document.getElementById('trZon'))	document.getElementById('trZon').style.display="none";
	if (document.getElementById('trSottoTip')) document.getElementById('trSottoTip').style.display="none";
    if (document.getElementById('trRag'))	document.getElementById('trRag').style.display="none";
    if (document.getElementById('trNom'))	document.getElementById('trNom').style.display="none";
    if (document.getElementById('trPrezzoMin'))	document.getElementById('trPrezzoMin').style.display="";
    if (document.getElementById('trTip'))	document.getElementById('trTip').style.display="";
    if (document.getElementById('trPrezzoMax'))	document.getElementById('trPrezzoMax').style.display="";
    if (document.getElementById('trContratto'))	document.getElementById('trContratto').style.display="";

	if (document.getElementById('idTipologia')) document.getElementById('idTipologia').onchange=null;

    clearSelect('idTipologia');
	clearSelect('sottotipologia');
    fillSelect("idTipologia","Altro",14);
    fillSelect("idTipologia","Appartamento",4);
    fillSelect("idTipologia","Attico / Mansarda",5);
    fillSelect("idTipologia","Box / Garage",6);
    fillSelect("idTipologia","Casa indipendente",7);
    fillSelect("idTipologia","Loft / Open Space",31);
    fillSelect("idTipologia","Multiproprietà",53);
    fillSelect("idTipologia","Palazzo / Stabile",10);
    fillSelect("idTipologia","Rustico / Casale",11);
    fillSelect("idTipologia","Terreno edificabile",42);
    fillSelect("idTipologia","Villa",12);
    fillSelect("idTipologia","Villetta a schiera",13);
    fillQuickLink(section);
    activate_section_btn(section);
    activate_subsection_btn(subsection);
}

function initCercaAnnunciCommerciale(){
    
    section = 'cerca_annunci';
    subsection = 'commerciale';
    fillQuickLink(section);
    cityFlag=1;
    selectNazione('italia');
    btn = document.getElementById('cerca_annunci_btn');
    activate_section_btn(section);
    activate_subsection_btn(subsection);
    document.getElementById('idCategoria').value='2';
    document.getElementById('dati').action="http://www.immobiliare.it/index.php";
    visMenu('show');
	document.getElementById('trPro').style.display="none";
	document.getElementById('trCit').style.display="none";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trSottoTip').style.display="none";
	document.getElementById('trNom').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trTip').style.display="";
	document.getElementById('trPrezzoMin').style.display="";
	document.getElementById('trPrezzoMax').style.display="";
	document.getElementById('trContratto').style.display="";
		
    clearSelect('idTipologia');
	clearSelect('sottotipologia');
	if (document.getElementById('idTipologia')) document.getElementById('idTipologia').onchange=getSottotipologie;
    fillSelect("idTipologia","Attività / Licenza",16);
    fillSelect("idTipologia","Terreno",28);
    fillSelect("idTipologia","Immobile",63);
}


function initCercaAnnunciTuristico(){
    
    section = 'cerca_annunci';
    subsection = 'turistico';
    cityFlag=1;
    selectNazione('italia');
    btn = document.getElementById('cerca_annunci_btn');
    activate_section_btn(section);
    activate_subsection_btn(subsection);
    document.getElementById('idCategoria').value='3';
    document.getElementById('dati').action="http://www.immobiliare.it/index.php";
    fillQuickLink(section);
    visMenu('show');
	document.getElementById('trPro').style.display="none";
	document.getElementById('trCit').style.display="none";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trSottoTip').style.display="none";
	document.getElementById('trNom').style.display="none";
	document.getElementById('trTip').style.display="";
	document.getElementById('trPrezzoMin').style.display="";
	document.getElementById('trPrezzoMax').style.display="";
	document.getElementById('trContratto').style.display="";
	document.getElementById('radio_idContratto2').checked="checked";

	if (document.getElementById('idTipologia')) document.getElementById('idTipologia').onchange=null;
	
    clearSelect('idTipologia');
    clearSelect('sottotipologia');
    fillSelect("idTipologia","Agriturismo",34);
    fillSelect("idTipologia","Altro",41);
    fillSelect("idTipologia","Appartamento",33);
    fillSelect("idTipologia","Bed & Breakfast",35);
    fillSelect("idTipologia","Camera d'albergo",52);
    fillSelect("idTipologia","Casa indipendente",37);
    fillSelect("idTipologia","Villa / Villetta",38);
}

function initCercaAnnunciStanze(){
    
    section = 'cerca_annunci';
    subsection = 'stanze';
    cityFlag=1;
    selectNazione('italia');
    document.getElementById('dati').action="http://www.immobiliare.it/index.php";
    btn = document.getElementById('cerca_annunci_btn');
    activate_section_btn(section);
    fillQuickLink(section);
      activate_subsection_btn(subsection);
    document.getElementById('idCategoria').value='4';
    visMenu('show');
	document.getElementById('trPro').style.display="none";
	document.getElementById('trCit').style.display="none";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trNom').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trSottoTip').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('radio_idContratto2').checked="checked";
    clearSelect('idTipologia');
	clearSelect('sottotipologia');

	if (document.getElementById('idTipologia')) document.getElementById('idTipologia').onchange=null;

    fillSelect("idTipologia","Altro",46);
    fillSelect("idTipologia","Appartamento",49);
    fillSelect("idTipologia","Casa indipendente",44);
    fillSelect("idTipologia","Villa o villetta",47);
    
}

function initCercaAgenzie(){
    
    section = 'cerca_agenzie';
    subsection = '';
    cityFlag=0;
    selectNazione('italia');
    btn = document.getElementById('cerca_agenzie_btn');
     document.getElementById('dati').action="http://www.immobiliare.it/agenzie_immobiliari.php";
    activate_section_btn(section);
    
    document.getElementById('trPro').style.display="none";
	document.getElementById('trCit').style.display="none";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trTip').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trSottoTip').style.display="none";
	document.getElementById('trNom').style.display="";
	document.getElementById('trPrezzoMin').style.display="none";
	document.getElementById('trPrezzoMax').style.display="none";
	document.getElementById('trContratto').style.display="none";
	
	if (document.getElementById('idTipologia')) document.getElementById('idTipologia').onchange=null;	

	visMenu('hide');
    clearSelect('idTipologia');
	clearSelect('sottotipologia');    
}
function initCercaNuoveCostruzioni(){
    
    section = 'nuove_costruzioni';
    document.getElementById('dati').action="http://www.immobiliare.it/nuove_costruzioni.php";
    subsection = '';
    cityFlag=0;
    selectNazione('italia');
    btn = document.getElementById('nuove_costruzioni_btn');
    document.getElementById('idCategoria').value='6';
    fillQuickLink(section);
    activate_section_btn(section);
    document.getElementById('trPro').style.display="none";
	document.getElementById('trCit').style.display="none";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trRag').style.display="none";
	document.getElementById('trSottoTip').style.display="none";
	document.getElementById('trTip').style.display="";
	document.getElementById('trNom').style.display="none";
	document.getElementById('trPrezzoMin').style.display="none";
	document.getElementById('trPrezzoMax').style.display="none";
	document.getElementById('trContratto').style.display="none";
	
	if (document.getElementById('idTipologia')) document.getElementById('idTipologia').onchange=null;	
	
    visMenu('hide');
    clearSelect('idTipologia');
	clearSelect('sottotipologia');
    fillSelect("idTipologia","Appartamento",54);
    fillSelect("idTipologia","Box Auto",57);
    fillSelect("idTipologia","Capannone",59);
    fillSelect("idTipologia","Negozio",55);
    fillSelect("idTipologia","Ufficio",56);
    fillSelect("idTipologia","Villa / Villetta",58);
    
}


/* GESTIONE MAPPA E FORM*/

function validateForm(){

            

    if (document.dati.selIdProvincia && document.dati.selIdProvincia.value!=''){
        
	document.dati.idProvincia.value = document.dati.selIdProvincia.value.substring(10,13);
	
	document.dati.azione.value='avviaricerca';
	document.dati.idComune.value = document.dati.idCitta.value;
	document.dati.submit();
	selectNazione();
	return true;	
	
    }else{
	alert("I campi regione e provincia sono obbligatori");
	return false;
    }
    
}


function selectNazione(nazione){
    if(document.getElementById('trPro'))
	document.getElementById('trPro').style.display="none";
    if(document.getElementById('trCit'))
	document.getElementById('trCit').style.display="none";
	clearSelect('idTipologia');
	clearSelect('sottotipologia');

    if (nazione){
	map = nazione;
    }else{
	map = 'italia';
    }
    MEAjax.Request('POST', 'maps/'+map+'.html', updateNazione);
    return false;
}


function selectRegione(){
    backMap='italia';
    var zoneDesc = document.getElementById('zone_descrizione');
    zoneDesc.value=' Seleziona';
    var zoneSelect = document.getElementById('zoneSelect');
    if (zoneSelect){
	zoneSelect.innerHTML='';
    }
    

    if (this.id){
	var idArea = this.id;
	var map = idArea.substr(5,8);
	selectedRegion=map;
    }else{
	map = selectedRegion;
    }
    MEAjax.Request('POST', 'maps/'+map+'.html', updateRegione);
    
    return false;
}

function overRegione(){
    var idArea = this.id;
    var regione = idArea.substr(5,8);
    var trans = document.getElementById('trans');
    trans.src="images/cartine/"+regione+"_selected.gif";
    var tooltip = document.getElementById("tooltip_div");
    tooltip.innerHTML = this.title;
}
function outRegione(){
    var trans = document.getElementById('trans');
    trans.src="images/cartine/transparent.gif";
    var tooltip = document.getElementById("tooltip_div");
    tooltip.innerHTML = '';
}

function selectProvinciaDir(idCittaDir){
    	
    clearSelect('idCitta');
    
    if (regioneLoaded==false){
	selectFormRegione(selectedRegion)
	setTimeout("selectProvinciaDir('"+idCittaDir+"')",0);
	return false;
    }
    
    var idArea = this.id ? this.id : selectedProv;
    var map = idArea.substr(10);
    if (map){ 
		selectedProv = map;
    }
    var idProv = map;
    var idZone;
    for (i=0;i<comuni.length;i++){
	  if (comuni[i][1]==idProv)
	  {
	    fillSelect('idCitta',comuni[i][2],comuni[i][0])
	    idZone = comuni[i][0]
	  }
    
    }
	

	
   	setProvincia(map);
	selectedProv=map;
	document.getElementById('trPro').style.display="";
	if (section == 'nuove_costruzioni') 
	    document.getElementById('trCit').style.display="none";
	else 
	    document.getElementById('trCit').style.display="";
	document.getElementById('trZon').style.display="none";
	if (cityFlag) 
	    document.getElementById('trRag').style.display="";
	document.getElementById('trRag').style.display="none";
	selectFormCitta(idCittaDir);		
	
    this.blur();
    if (section=='nuove_costruzioni') document.getElementById('trCit').style.display="none";
	
    return false;
}

function selectProvincia(){
    
    clearSelect('idCitta');
    if (regioneLoaded==false){
	selectFormRegione(selectedRegion)
	setTimeout('selectProvincia()',0);
	return false;
    }
    
    var idArea = this.id ? this.id : selectedProv;
    var map = idArea.substr(10);
    if (map){ 
		selectedProv = map;
    }
    var idProv = map;
    
    for (i=0;i<comuni.length;i++){
	  if (comuni[i][1]==idProv)
	    fillSelect('idCitta',comuni[i][2],comuni[i][0])
  
    }
	
    if (map.length==2){

   	setProvincia(map);
	selectedProv=map;
	document.getElementById('trPro').style.display="";
	if (section == 'nuove_costruzioni') 
	    document.getElementById('trCit').style.display="none";
	else 
	    document.getElementById('trCit').style.display="";
	document.getElementById('trZon').style.display="none";
	if (cityFlag) 
	    document.getElementById('trRag').style.display="";
	document.getElementById('trRag').style.display="none";
    }else{
    
	var cMap = map.substr(6);
        if (cityFlag){
	    document.getElementById('trPro').style.display="";
	    document.getElementById('trCit').style.display="";
	    document.getElementById('trZon').style.display="";
	    document.getElementById('trRag').style.display="none";
	    selectedProv=cMap; 
	    if (cityBack){
		document.getElementById('trCit').style.display="none";
		document.getElementById('trZon').style.display="none";
		document.getElementById('trRag').style.display="none";
		cityBack=false;
	    }
		
	        MEAjax.Request('POST', 'maps/'+cMap+'.html', updateProvincia);
		return false;
		}else{
		
	        map = map.substr(6,2);
	        document.getElementById('trPro').style.display="";
		    document.getElementById('trCit').style.display="none";
		    document.getElementById('trZon').style.display="none";
		    document.getElementById('trRag').style.display="none";
		    selectedProv=map;
		    setProvincia(map);
        }   
		
    }
    
    this.blur();
    
    return false;
}


function selectProvinciaBack(){
    
    clearSelect('idCitta');
    
    var idArea = this.id ? this.id : selectedProv;
    var map = idArea.substr(10);
    if (map){ 
		selectedProv = map;
    }
    var idProv = map;
    
    
    for (i=0;i<comuni.length;i++){
	  if (comuni[i][1]==idProv)
	    fillSelect('idCitta',comuni[i][2],comuni[i][0])
  
    }
	
    if (map.length==2){

   	setProvincia(map);
	selectedProv=map;
	document.getElementById('trPro').style.display="";
	if (section == 'nuove_costruzioni') 
	    document.getElementById('trCit').style.display="none";
	else 
	    document.getElementById('trCit').style.display="";
	document.getElementById('trZon').style.display="none";
	if (cityFlag) 
	    document.getElementById('trRag').style.display="";
	document.getElementById('trRag').style.display="none";
    }
    
    this.blur();
   
    return false;
   
}

function overProvincia(){
    var idArea = this.id;
    var provincia = idArea.substr(5,8);
    
    var trans = document.getElementById('trans');
    
    if (provincia.length==7){
        trans.src="images/cartine/"+selectedRegion+"/select_"+provincia+".gif";
    }else{
	if (cityFlag){
	    var citta = idArea.substr(10,15);
	    trans.src="images/cartine/"+selectedRegion+"/select_"+citta+".gif";
	}else{
	    var provincia=idArea.substr(15,3);
	    trans.src="images/cartine/"+selectedRegion+"/select_prov"+provincia+".gif";
	}
    }
    var tooltip = document.getElementById("tooltip_div");
    if (cityFlag) tooltip.innerHTML = this.title;
        else{
            tooltip.innerHTML = this.title.split(' ')[0];
            this.title = this.title.split(' ')[0];
        }
}

function outProvincia(){
    
    var trans = document.getElementById('trans');
    trans.src="images/cartine/transparent.gif";
    var tooltip = document.getElementById("tooltip_div");
    tooltip.innerHTML = '';
}

function selectCitta(){
    if (this.id){
	var idArea = this.id;
    }else{
	var idArea = this.value;
    }
    
    setCitta(idArea);
    
    this.blur();
}

function overCitta(){
    var idArea = this.id;
    var trans = document.getElementById('trans');
    trans.src="images/cartine/"+selectedRegion+"/"+selectedProv+"/map_zona_"+selectedProv+"_"+idArea+".gif";
    var tooltip = document.getElementById("tooltip_div");
    tooltip.innerHTML = this.title;
    
}

function outCitta(){
    var trans = document.getElementById('trans');
    trans.src="images/cartine/transparent.gif";
    var tooltip = document.getElementById("tooltip_div");
    tooltip.innerHTML = '';
} 
 
function updateNazione(doc){
    var aAreas = new Array();
    if (document.getElementById('cartina')){
	var div = document.getElementById('cartina');
	div.innerHTML = "<div id=\"back\" style=\"visibility:hidden;\">&nbsp;<\/div>"+doc.responseText;
	aAreas = div.getElementsByTagName('area');
    }
   
    clearSelect('idRegione');
    clearSelect('selIdProvincia');
    
    for (i=0; i<aAreas.length; i++){
	aAreas[i].onclick= selectRegione;
	aAreas[i].onmouseover= overRegione;
	aAreas[i].onmouseout= outRegione;
	
	fillSelect('idRegione',aAreas[i].title,aAreas[i].title.toLowerCase().substr(0,3));
    }
    if (document.getElementById('zone_wrap'))
	    document.getElementById('zone_wrap').style.display='none';
    if (document.getElementById('trZon'))
	    document.getElementById('trZon').style.display='none';
    if (document.getElementById('bloccoHideZone'))
	    document.getElementById('bloccoHideZone').style.visibility='visible';
    if (document.getElementById('divCittaDirette'))
	    if (section != "cerca_agenzie") document.getElementById('divCittaDirette').style.display='';
	    else document.getElementById('divCittaDirette').style.display='none';
    if (document.getElementById('trRag'))
	    document.getElementById('trRag').style.visibility='visible';
}


function updateRegione(doc){
    var div = document.getElementById('cartina');
    div.innerHTML = "<div id=\"back\"><a onclick=\"selectNazione('italia'); document.getElementById('trPro').style.display='none';\">Italia<\/a><\/div>"+doc.responseText;
    var aAreas = div.getElementsByTagName('area');
    clearSelect('selIdProvincia');
    for (i=0; i<aAreas.length; i++){
	
	    if (aAreas[i].id.search('citt')==-1) {
		aAreas[i].onclick= selectProvincia;
	    }else{
		if (section!="nuove_costruzioni"){
		    aAreas[i].onclick = selectComuneZone;
		    
		}else {
		    
		    aAreas[i].onclick = function(){
					    selectFormProvincia("_map_prov_"+this.id.substring(16,19));
					    return false;
					}
		}
		
	    }
	
		aAreas[i].onmouseover= overProvincia;
		aAreas[i].onmouseout= outProvincia;
		if (aAreas[i].id.search('citt')==-1)
		fillSelect('selIdProvincia',aAreas[i].title,aAreas[i].id);
		
    }
    selectFormFieldRegion();
    document.getElementById('bloccoHideZone').style.visibility='visible';

	if (provBack) {
		document.getElementById('trPro').style.display="none";
		selectNazione();
		
	}else document.getElementById('trPro').style.display="";
	document.getElementById('trCit').style.display="none";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trRag').style.display="none";
	
	if (provBack) document.getElementById('divCittaDirette').style.display="";
	    else document.getElementById('divCittaDirette').style.display="none";
	provBack=false;
	
}


function updateProvincia(doc){

    var noClear = false;
    var div = document.getElementById('cartina');
    
    div.innerHTML = "<div id=\"back\"><a onclick=\"selectRegione('"+selectedRegion+"');\">"+regioni[selectedRegion]+"<\/a><\/div>"+doc.responseText;
    var aAreas = div.getElementsByTagName('area');
    document.getElementById('zone_descrizione').value=" Seleziona";
    
    
    
    for (i=0; i<comuni_zona.length;i++){
		    
		    if (comuni_zona[i][1] == selectedProv){
			noClear=true;
		    	idProv = comuni_zona[i][0];

			break;
		    }
		}
    
    zone_comuni[idProv].sort();

    for (i=0; i<aAreas.length; i++){
		aAreas[i].onclick= selectCitta;
		aAreas[i].onmouseover= overCitta;
		aAreas[i].onmouseout= outCitta;		
		fillZones('zoneSelect',aAreas[i].title,zone_comuni[idProv][i]);
    }
    addCloseZones('zoneSelect');
    
    document.getElementById('bloccoHideZone').style.visibility='visible';
    showZ();    
    selectFormFieldProvincia();   

     
}

function updateProvinciaBack(doc){
    regioneLoaded=true;
    var noClear = false;
    var div = document.getElementById('cartina');
    
    div.innerHTML = "<div id=\"back\"><a onclick=\"selectRegione('"+selectedRegion+"');\">"+regioni[selectedRegion]+"<\/a><\/div>"+doc.responseText;
    var aAreas = div.getElementsByTagName('area');
    document.getElementById('zone_descrizione').value=" Seleziona";
    
    
 
           
    for (i=0; i<comuni_zona.length;i++){
		    
		    if (comuni_zona[i][1] == selectedProv){
			noClear=true;
		    	idProv = comuni_zona[i][0];

			break;
		    }
		}
		
    
    zone_comuni[idProv].sort();

    for (i=0; i<aAreas.length; i++){
    
		if (aAreas[i].id.search('citt')==-1) aAreas[i].onclick= selectProvinciaBack;
		    else aAreas[i].onclick = selectComuneZone;
		aAreas[i].onmouseover= overProvincia;
		aAreas[i].onmouseout= outProvincia;		
		fillZones('zoneSelect',aAreas[i].title,zone_comuni[idProv][i]);
    }

    var trans = document.getElementById('trans1');
    trans.src="images/cartine/"+selectedRegion+"/select_prov_"+selectedProv+".gif";
   
}

/* AZIONI CLICK PROVINCIA E ZONE CITTA' */

function setProvincia(prov){
	document.getElementById('trPro').style.display="";
	document.getElementById('trCit').style.display="";
	document.getElementById('trZon').style.display="none";
	document.getElementById('trRag').style.display="none";
	selectFormFieldProvincia(prov);
    var trans = document.getElementById('trans1');
  if (trans)  trans.src="images/cartine/"+selectedRegion+"/select_prov_"+prov+".gif";

}


function setCitta(zona){

	var zoneImg = document.getElementById('zoneImg_'+zona);
	if (zoneImg){
		regioneLoaded=false;

		if (zoneImg.style.display=='inline'){
			deSelectZona(zona);
	    }else{
			selectZona(zona);
    	}
	}
    
    
}

function selectZona(zona){
    var zone = zona.split("_")[2];
    var zoneImg = document.getElementById('zoneImg_'+zona);
    zoneImg.style.display = 'inline';
    var chkBox = document.getElementById("chkbox_zone_"+zona);
    chkBox.checked="checked";
    var zoneDesc = document.getElementById('zone_descrizione');
    
    var aZone = zoneDesc.value.split(",");
    if (aZone.length==1 && trim(aZone[0])=="Seleziona"){
	aZone[0] = parseInt(zona);
    }else{
	aZone.push(parseInt(zona));
    }
    aZone.sort();
    zoneDesc.value = aZone.join(',');
    
}

function deSelectZona(zona){
    
    var zoneImg = document.getElementById('zoneImg_'+zona);
    zoneImg.style.display = 'none';
    var trans = document.getElementById('trans');
    trans.src="images/cartine/transparent.gif";
    var chkBox = document.getElementById("chkbox_zone_"+zona);
    chkBox.checked="";
    
    var zoneDesc = document.getElementById('zone_descrizione');
    var zone = getElementsByClass('IW_zone_chkbox');
    
    var aZone = new Array();
    for (i=0; i< zone.length; i++) if (zone[i].checked) aZone.push(zone[i].id.split("_")[2]);
    if (aZone.length > 0){
	aZone.sort();
	zoneDesc.value = aZone.join(',');
    }else
	zoneDesc.value=' Seleziona';
    
}
/* EFFETTI SU MENU */


function on(btn){
    
    if (btn){
	var id = (btn.id);
	var btnClass = btn.className;
	
	clickedSection = id.substr(0,id.search('_btn'));
	if (btnClass.search("_act")<0){
	    btn.setAttribute("class",btnClass+"_act");
	    btn.setAttribute("className",btnClass+"_act");
	    if (btnClass=='IW_submenu_btn'){
		
		var arrow = document.getElementById(clickedSection+"_arw");
		
		arrowClass = arrow.className;
		var act_pos = arrowClass.search("_act");
		if (act_pos<0){	    
		    
		    var arrow = document.getElementById(clickedSection+"_arw");
		    
		    arrow.setAttribute("class",arrowClass+"_act");
		    arrow.setAttribute("className",arrowClass+"_act");
		    var aBtns = getElementsByClass('IW_arrow_act');
		    for (i=0;i<aBtns.length;i++){
			
			if (aBtns[i].id != "IW_"+subsection+"_arw"){
			    aBtns[i].setAttribute("class","IW_arrow");
			    aBtns[i].setAttribute("className","IW_arrow");
			}
		    }    
		}
		
	    }
	}
    }
  if (btn)  btn.style.color = '#FFFFFF';
    
}

function off(btn){

    var id = (btn.id);
    var btnClass = btn.className;
    
    clickedSection = id.substr(0,id.search('_btn'))
    if ((clickedSection!="IW_"+section)&&(clickedSection!="IW_"+subsection)){
    
	var act_pos = btnClass.search("_act");
	if (act_pos>0){
	    btn.setAttribute("class",btnClass.substr(0,act_pos));
	    btn.setAttribute("className",btnClass.substr(0,act_pos));
	    var btnClass = btn.className;
	    if (btnClass=='IW_submenu_btn'){
    
	        var arrow = document.getElementById(clickedSection+"_arw");
	        arrowClass = arrow.className;
		
	        var act_pos = arrowClass.search("_act");
		
		if (act_pos>0){
		    
		    arrow.setAttribute("class",arrowClass.substr(0,act_pos));
		    arrow.setAttribute("className",arrowClass.substr(0,act_pos));
		}
	    
	    }
	    
	}
    }
}

function activate_section_btn(section){
    
    active_btn = "IW_"+section+"_btn";
    var aBtns = getElementsByClass('IW_btn_tab');
    var actBtns = getElementsByClass('IW_btn_tab_act');
    for (i=0;i<actBtns.length;i++){
        aBtns.push(actBtns[i]);
    }
    
    for (i=0;i<aBtns.length;i++){
	
	aBtns[i].setAttribute("class","IW_btn_tab");
	aBtns[i].setAttribute("className","IW_btn_tab");
    }
    
    on(document.getElementById(active_btn));
    
}


function activate_subsection_btn(subsection){
    
    active_btn = "IW_"+subsection+"_btn";
    var aBtns = getElementsByClass('IW_submenu_btn_act');
    for (i=0;i<aBtns.length;i++){	
	aBtns[i].setAttribute("class","IW_submenu_btn");
	aBtns[i].setAttribute("className","IW_submenu_btn");
    }
    on(document.getElementById(active_btn));
   
}

function visMenu(prop){
    var menus = getElementsByClass('IW_tab_menu');
    if (prop == 'hide'){
	for(i=0;i<menus.length;i++) menus[i].style.visibility='hidden';
    }else for(i=0;i<menus.length;i++) menus[i].style.visibility='visible';

}



/* GESTIONE MAPPA-FORM */
    
function fillQuickLink(section){
    

    if (section=='cerca_annunci'){
	document.getElementById("IW_QuickLink").innerHTML=""+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Milano/cerco_casa-Milano.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Milano, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Roma/cerco_casa-Roma.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Roma, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Firenze/cerco_casa-Firenze.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Firenze, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Bologna/cerco_casa-Bologna.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Bologna, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Torino/cerco_casa-Torino.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Torino, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Padova/cerco_casa-Padova.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Padova, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Napoli/cerco_casa-Napoli.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Napoli, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Genova/cerco_casa-Genova.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Genova, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Venezia/cerco_casa-Venezia.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Venezia <\/a>";
    }
        if (section=='cerca_agenzie'){
	
	document.getElementById("divCittaDirette").style.display="none";
	/*document.getElementById("IW_QuickLink").innerHTML=""+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Milano/cerco_casa-Milano.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Milano, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Roma/cerco_casa-Roma.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Roma, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Firenze/cerco_casa-Firenze.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Firenze, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Bologna/cerco_casa-Bologna.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Bologna, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Torino/cerco_casa-Torino.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Torino, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Padova/cerco_casa-Padova.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Padova, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Napoli/cerco_casa-Napoli.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Napoli, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Genova/cerco_casa-Genova.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Genova, <\/a>"+
		"<a target=\"_blank\" href=\"http://www.immobiliare.it/Venezia/cerco_casa-Venezia.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Venezia <\/a>";*/
    }
        if (section=='nuove_costruzioni'){
	document.getElementById("IW_QuickLink").innerHTML=""+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Milano/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Milano, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Roma/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Roma, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Torino/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Torino, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Venezia/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Venezia, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Bergamo/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Bergamo, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Bari/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Bari, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Como/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Como, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Novara/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Novara, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Lucca/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Lucca, <\/a>"+
		    "<a target=\"_blank\" href=\"http://www.immobiliare.it/nuove_costruzioni/Pisa/immobili.html?utm_source="+utm_source+"&utm_medium="+utm_medium+"&utm_campaign="+utm_campaign+"\">Pisa <\/a>";

    }
return false;
}
    
function clearSelect(zone){
    var select=document.getElementById(zone);
    if (select){
		select.innerHTML='';
		option = document.createElement('option');
		option.setAttribute('selected','selected');
		option.value = '';
		if (zone=='idTipologia' || zone=='sottotipologia')
			option.text = ' Tutte';
		else
			option.text = ' Seleziona';
		try {
			select.add(option, null); // standards compliant; doesn't work in IE
		}	
		catch(ex) {
		  select.add(option); // IE only
		}
    }
}

function fillSelect(iSelect,text,value){
    var select;
    var option = document.createElement('option');
    select = document.getElementById(iSelect);
    if (select){
	option.value = value;
	option.text = text;
    
	try {
	    select.add(option, null); // standards compliant; doesn't work in IE
	}	
	catch(ex) {
	  select.add(option); // IE only
	}
    }
}

function addCloseZones(div){
     
    var zoneDiv = document.getElementById(div);
    var HTML = "<a onclick=\"hideZ();\" style=\"padding:2px;float:right\"><strong>Chiudi<\/strong><\/a><br />";
    zoneDiv.innerHTML+=HTML;
}

function fillZones(div,text,value){

    regioneLoaded=false;
    serialZone = trim(text.split("-")[0]);
	var zoneDiv = document.getElementById(div);
    var HTML = "<label><input id=\"chkbox_zone_"+serialZone+"\" class=\"IW_zone_chkbox\" type=\"checkbox\" value=\""+value+"\" name=\"idZona[]\" onclick=\"setCitta(this.id.split('_')[2])\"/>"+text+"<\/label><br />";
	zoneDiv.innerHTML+=HTML;
    
        var zoneCont = document.getElementById('zone_container');
    if(zoneCont){    	
	HTML = "<img src=\"images/cartine/"+selectedRegion+"/"+selectedProv+"/map_zona_"+selectedProv+"_"+serialZone+".gif\" id=\"zoneImg_"+serialZone+"\" class=\"IW_zoneImg\" />";
        zoneCont.innerHTML+=HTML;
    }
    
}


function selectFormRegione(reg){
   if (reg=='') {
	regBack = true;
	selectNazione();
	
	return;
   }
   selectedRegion = reg.toLowerCase().substr(0,3);
   
   selectRegione();
}

function selectFormProvincia(prov){
    
    if (prov=='') {
		provBack = true;
		selectRegione();
   }else{
    selectedProv = prov;
   
	    
	    selectProvincia();
   }
}

function selectFormCitta(value){
    var withZone=0;
    selectedCity=value;
    for (i=0; i<comuni_zona.length;i++){
		if (comuni_zona[i][0] == value){
			withZone = 1;
			selectedProv = "_map_prov_citta_"+comuni_zona[i][1];
		}	
    }
    if (withZone) selectComuneZone(); 
		else{

			if (!cityFlag) document.getElementById('trRag').style.display="none";
				else	document.getElementById('trRag').style.display="";
					document.getElementById('trZon').style.display="none";
					document.getElementById('bloccoHideZone').style.visibility="visible";
			if (zoneBack){
			    		    
			    MEAjax.Request('POST', 'maps/'+selectedRegion+'.html', updateProvinciaBack);
			}
		}
   if (!value){
        cityBack=true;
   }
}

function selectDirect(regione,citta,idCittaDir){
    regioneLoaded=false;
    selectedRegion = regione;
    selectedProv = "_map_prov_"+citta;
    selectRegione();
    selectProvinciaDir(idCittaDir);
}


function selectComuneZone(){
    zoneBack='true';
    clearSelect('idCitta');
    if (this.id) selectedProv = this.id;

    var idArea = selectedProv;
    var idProv;
    var map = idArea.substr(10);

    if (map) selectedProv = map;

    addCloseZones('zoneSelect');
	_selectedProv = selectedProv.substring(6,8);

    for (i=0; i<comuni_zona.length;i++){
	    if (comuni_zona[i][1] == _selectedProv){
			noClear=true;
	    	idProv = comuni_zona[i][1];
			selectedCity = comuni_zona[i][0];
			break;
		    }
		}
    
		for (i=0;i<comuni.length;i++){
				
			 if (comuni[i][1]==idProv)
		    	fillSelect('idCitta',comuni[i][2],comuni[i][0])
		    }
			
   	selectOption('idCitta',selectedCity);
	var cMap = map.substr(6);
        if (cityFlag){
		    document.getElementById('trPro').style.display="";
		    document.getElementById('trCit').style.display="";
		    document.getElementById('trZon').style.display="";
		    document.getElementById('trRag').style.display="none";
		    selectedProv=cMap; 
		    if (cityBack){
			document.getElementById('trCit').style.display="none";
			document.getElementById('trZon').style.display="none";
			document.getElementById('trRag').style.display="none";
			cityBack=false;
		    }
		    
	            MEAjax.Request('POST', 'maps/'+cMap+'.html', updateProvincia);
	}else{            
	            map = map.substr(6,2);
	            document.getElementById('trPro').style.display="";
		    document.getElementById('trCit').style.display="none";
		    document.getElementById('trZon').style.display="none";
		    document.getElementById('trRag').style.display="none";
		    selectedProv=map;
		    setProvincia(map);
        }   
		
    
    this.blur();
    
    return false;
}

function selectOption(selId,value){
    var oSelect = document.getElementById('idCitta');
    for (i=0;i<oSelect.options.length;i++){
		if(oSelect.options[i].value == value) oSelect.selectedIndex=i;
	}

	}

function selectFormFieldRegion(reg){
    var oSelect = document.getElementById('idRegione');
    for (i=0;i<oSelect.options.length;i++){
		if(oSelect.options[i].value == selectedRegion) oSelect.selectedIndex=i;
    }
    regioneLoaded=true;
}

function selectFormFieldProvincia(){

    var oSelect = document.getElementById('selIdProvincia');
    for (i=0;i<oSelect.options.length;i++){
		if(oSelect.options[i].value == "_map_prov_"+selectedProv) oSelect.selectedIndex=i;
    }
	
}

function selectFormFieldCitta(){
    
    var oSelect = document.getElementById('selIdProvincia');
    for (i=0;i<oSelect.options.length;i++){
		if(oSelect.options[i].value == selectedCity) oSelect.selectedIndex=i;
	}
}


function updatePrezzoMax(index){
	document.getElementById('prezzoMinimo').value = document.getElementById('selectPrezzoMinimo').options[index].value;
	var oSel = document.getElementById('selectPrezzoMassimo');
	for (i=0; i<oSel.options.length;i++){
		if (i<index) oSel.options[i].disabled="disabled";	
			else oSel.options[i].disabled="";	
	}
}

function updatePrezzoMin(index){
	document.getElementById('prezzoMassimo').value = document.getElementById('selectPrezzoMassimo').options[index].value;
	var oSel = document.getElementById('selectPrezzoMinimo');
	for (i=0; i<oSel.options.length;i++){
		if (i>index) oSel.options[i].disabled="disabled";	
			else oSel.options[i].disabled="";	
	}
}

function showZ(){
    var el = document.getElementById('zone_wrap');
    el.style.display='block';
    document.getElementById('bloccoHideZone').style.visibility='hidden';
}

function hideZ(){
    var el = document.getElementById('zone_wrap');
    el.style.display='none';
    document.getElementById('bloccoHideZone').style.visibility='visible';
}

function toggleZ(){
    var el = document.getElementById('zone_wrap');
    if (el.style.display=='block')
        hideZ();
    else
        showZ();
}

function getSottotipologie(){
	var selectedTipologia = document.getElementById('idTipologia').value;
	
	switch (parseInt(selectedTipologia)){
		case 16 :
			if (document.getElementById('trSottoTip')) document.getElementById('trSottoTip').style.display="";
			fillSelect("sottotipologia","Centro commerciale",1);       
			fillSelect("sottotipologia","Ristorante",3);               
			fillSelect("sottotipologia","Negozio",5);                  
			fillSelect("sottotipologia","Bar",7);                      
			fillSelect("sottotipologia","Azienda agricola",9);         
			fillSelect("sottotipologia","Hotel",11);                   
			fillSelect("sottotipologia","Discoteca",13);               
			fillSelect("sottotipologia","Pizzeria",15);                
			fillSelect("sottotipologia","Pizza al taglio",17);         
			fillSelect("sottotipologia","Pub",19);                     
			fillSelect("sottotipologia","Alimentari",21);              
			fillSelect("sottotipologia","Rosticceria",23);             
			fillSelect("sottotipologia","Pasticceria",25);             
			fillSelect("sottotipologia","Parrucchiere uomo/donna",27); 
			fillSelect("sottotipologia","Bed & Breakfast",29);         
			fillSelect("sottotipologia","Ferramenta / casalinghi",31); 
			fillSelect("sottotipologia","Palestra",33);                
			fillSelect("sottotipologia","Pensione",35);                
			fillSelect("sottotipologia","Gelateria",37);               
			fillSelect("sottotipologia","Somm. Alimenti",39);          
			fillSelect("sottotipologia","Abbigliamento",41);           
			fillSelect("sottotipologia","Estetica Solarium",43);       
			fillSelect("sottotipologia","Panetteria",45);              
			fillSelect("sottotipologia","Auto officina",49);           
			fillSelect("sottotipologia","Videonoleggio",51);           
			fillSelect("sottotipologia","Tabaccheria",53);             
			fillSelect("sottotipologia","Tintoria / Lavanderia",55);   
			fillSelect("sottotipologia","Cartoleria / libreria",57);   
			fillSelect("sottotipologia","Informatica / telefonia",59); 
			fillSelect("sottotipologia","Edicola",61);                 
			fillSelect("sottotipologia","Licenza e Tabelle",63);       
			fillSelect("sottotipologia","Esercizio",65);               		
			break;
		case 28 :
			if (document.getElementById('trSottoTip')) document.getElementById('trSottoTip').style.display="";
			fillSelect("sottotipologia","Edificabile residenziale",67);
			fillSelect("sottotipologia","Edificabile commerciale",69);
			fillSelect("sottotipologia","Edificabile industriale",70);
			fillSelect("sottotipologia","Agricolo / Coltura",71);
			break;
		case 63 :
			if (document.getElementById('trSottoTip')) document.getElementById('trSottoTip').style.display="";
			fillSelect("sottotipologia","Capannone",73);                     
			fillSelect("sottotipologia","Azienda agricola",75);              
			fillSelect("sottotipologia","Garage / Parcheggio",77);           
			fillSelect("sottotipologia","Negozio",79);                       
			fillSelect("sottotipologia","Ufficio",81);                       
			fillSelect("sottotipologia","Stabile / palazzo",85);             
			fillSelect("sottotipologia","Casa di cura",89);                  
			fillSelect("sottotipologia","Magazzino",91);                     
			fillSelect("sottotipologia","Stalle / scuderie",95);             
			fillSelect("sottotipologia","Stabilimento balneare",97);         
			fillSelect("sottotipologia","Laboratorio",99);                   
			fillSelect("sottotipologia","Albergo / struttura ricettiva",101);
			fillSelect("sottotipologia","Altro",103);                        
			fillSelect("sottotipologia","Showroom",105);                     
			break;
		default :
			if (document.getElementById('trSottoTip')) document.getElementById('trSottoTip').style.display="none";
			break;
	}
}
