var zone_selected=new Array();
var zone_selected_TI=new Array();
var localita_selected=new Array();

function _fnShSbTim() {
	setTimeout('show_search_box()',5000);
}

function force_search_box_show(){
	//assicura la visualizzazione del form anche in presenza di errori javascript nella pagina
	addEvent(window,'load',_fnShSbTim);
}

function getScrollPosition(name){
	scrolly = (document.all)?document.documentElement.scrollTop:window.pageYOffset;
	scrollx = (document.all)?document.documentElement.scrollLeft:window.pageXOffset;
	createCookie(name+'_yPos',scrolly,0,0,5);
	createCookie(name+'_yPos',scrolly,0,0,5);
}

function resetCookies(){
 createCookie('ricerca_immobili_yPos',0,0,0,5);
 createCookie('ricerca_agenzie_yPos',0,0,0,5);
 createCookie('nuove_costruzioni_yPos',0,0,0,5);
 
}

function setScrollPosition(name){
    var yPos = readCookie(name+'_yPos');
    var xPos = readCookie(name+'_xPos');
   
    if (yPos || xPos){
	window.scrollTo(xPos,yPos);
	setTimeout("resetCookies()",1000);
    }
	
}

function setHomeSection(cat){
	createCookie('home_section',cat);
}

function getHomeSection(){
	var sec = readCookie('home_section');
	var obj = document.getElementById("idCategoria"+sec);
	if (obj){
		cambia_categoria(obj);
		xajax_getAjaxTipologiaPagIndex(sec);
	}
}

function cambia_categoria_nc(obj){
	var id=obj.id;
	var menus = document.getElementsByClassName("nc_tab");
	for (var i=0; i<menus.length; i++){
		menus[i].setAttribute('class',"nc_tab"); 
	}
	var menu = document.getElementById(obj.id);
	menu.setAttribute('class','nc_tab selected');
	
	
	
	var subid;
	subid = "sub_"+obj.id;
	var submenus = document.getElementsByClassName("sub_idCategoria");
	for (var i=0; i<submenus.length; i++){
		submenus[i].style.visibility='hidden'; 
	}
	var submenu = document.getElementById(subid);
	submenu.style.visibility='visible';
	
}


function cambia_categoria(obj){
	var subid = "sub_"+obj.id;
	if (subid){
		var submenus = document.getElementsByClassName("sub_idCategoria");
		for (var i=0; i<submenus.length; i++){
			submenus[i].style.visibility='hidden'; 
		}
		var submenu = document.getElementById(subid);
		submenu.style.visibility='visible';
		
		
		var id = obj.id.substr(11);
		with (window.document) {
			$('divLocalita').style.display='none';

			// 5 = ESTERO
			if (id == 5){
				$('CartinaGrande').style.display = 'none'
				if ($('CartinaGrandeEstero'))
					if ($('CartinaGrandeEstero').style.display == 'none')
						$('CartinaGrandeEstero').style.display = 'block';
				if ($('idCategoriaEstero'))
					$('idCategoriaEstero').value = 5;

				OnPageload();
				
				if ($('international'))
					$('international').style.display='none';

				$('divN').style.display='block';

				$('divCittaDirette').style.display = 'none';
				$('linkDirettiCitta').style.display = 'none';
				$('showLinkDirettiCitta').style.display = 'none';

				$('divEsteroCittaDirette').style.display = 'block';
				$('linkEsteroDirettiCitta').style.display = 'block';
				$('showLinkEsteroDirettiCitta').style.display = 'block';


				xajax_getAjaxNazionePagIndex("");
				  
//				$('box_ricerca_home').setStyle({height : '337px'}) ;
				hideRicercaAvanzata('ricercaAvanzata','textRicercaA');
	
				if (!$('selectBox').hasClassName('resizeEstero')){
					$('selectBox').addClassName('resizeEstero');

					if (!window.XMLHttpRequest) {
						$('selectBox').style.marginRight = '-38px';
					}
					$('selectBox').setStyle({width : '325px'});
				}

				if ($('div_back').style.display)
					$('div_back').setStyle({display : 'none'}) ;

				if ( $('MimMax'))
 					$('MimMax').setStyle({width:'240px'});


				if ($('bottoneInvia'))
					$('bottoneInvia').setStyle({width : '311px'});
				
				if ($('idTipologia').hasClassName('selFormGeo')){
					$('idTipologia').removeClassName('selFormGeo');
					$('idTipologia').addClassName('selFormGeoEstero');
				}

 				if ($('prezzoMinimo'))
					$('prezzoMinimo').style.width = '98px';

 				if ($('prezzoMassimo'))
					$('prezzoMassimo').style.width = '98px';

				//xajax_getAjaxRegioniPagIndex('window.document.dati.idNazione.value')

				$('divR').style.display='none';
			}else {
				if ($('CartinaGrandeEstero'))
					$('CartinaGrandeEstero').style.display = 'none'
				if ($('CartinaGrande').style.display == 'none')
					$('CartinaGrande').style.display = 'block'
				if ($('idCategoriaEstero'))
					$('idCategoriaEstero').value = "";

			
				if ($('international'))
					$('international').style.display='block';
				$('divN').style.display='none';
				$('divR').style.display='block';
				$('showLinkEsteroDirettiCitta').style.display = 'none';
				$('divEsteroCittaDirette').style.display = 'none';
				$('linkEsteroDirettiCitta').style.display = 'none';

//				$('box_ricerca_home').setStyle({height : '337px'}) ;

				if ($('selectBox').hasClassName('resizeEstero')){
					$('selectBox').removeClassName('resizeEstero');

					if (!window.XMLHttpRequest) {
						$('selectBox').style.marginRight = '0px';
					}

					$('selectBox').setStyle({width : '380px'});
				}

				if ($('div_back').style.display)
					$('div_back').setStyle({display : 'block'}) ;

				if ($('MimMax'))
					$('MimMax').setStyle({width:'294px'});

				if ($('bottoneInvia'))
					$('bottoneInvia').setStyle({width:'372px'});

				if ($('idTipologia').hasClassName('selFormGeoEstero')){
					$('idTipologia').removeClassName('selFormGeoEstero');
					$('idTipologia').addClassName('selFormGeo');
				}

				if ($('prezzoMinimo'))
					$('prezzoMinimo').style.width = '125px';

				if ($('prezzoMassimo'))
					$('prezzoMassimo').style.width = '125px';


				xajax_getAjaxRegioniPagIndex("IT");
				xajax_getAjaxProvincePagIndex("");

			}
			//3 = CATEGORIA_VACANZE , 4 = CATEGORIA_STANZE
			if (id==3 || id==4){
//				$('box_ricerca_home').setStyle({height : '337px'}) ;
				hideRicercaAvanzata('','textRicercaA');

				$('idContratto1').style.display='none';
				$('divZ').style.display='none';
				$('divContratto').style.display='none';
				$('divC').style.display='none';
				
				dati.idContratto[1].checked=true;
//				dati.selectPrezzoMinimo.selectedIndex=0;
//				dati.selectPrezzoMassimo.selectedIndex=0;
				xajax_getAjaxFascePrezzoPagIndex(dati.idContratto[1].value);
				$('divPrezzo').style.display='none';
				$('divCittaDirette').style.display = 'none';
				$('linkDirettiCitta').style.display = 'none';
				$('divEsteroCittaDirette').style.display = 'none';
				$('linkEsteroDirettiCitta').style.display = 'none';
			}
			else{
				$('divC').style.display='block';
				$('divZ').style.display='block';
				$('divContratto').style.display='block';
				$('idContratto1').style.display='block';
				$('divPrezzo').style.display='block';

				if (id != 5){
					showRicercaAvanzata('ricercaAvanzata','textRicercaA','ricercaAvanzata','divPrezzo','box_ricerca_home');
					if ($('ricercaAvanzata').style.display=='none'){
						$('divCittaDirette').style.display = 'block';	
						$('linkDirettiCitta').style.display = 'block';
					}else{
						$('divCittaDirette').style.display = 'none';	
						$('linkDirettiCitta').style.display = 'none';
					 }
					
/*					getElementById("divEsteroCittaDirette").style.display = 'block';
					getElementById("linkEsteroDirettiCitta").style.display = 'block';
*/
				}
			}
	
			var tabId = document.getElementById("dati").idCategoria;
			for (var ix=0;ix<=maxCategoria;ix++){
				if (getElementById("idCategoria"+ix)){
					getElementById("idCategoria"+ix).className='';
				}
			}
			getElementById("idCategoria"+id).className='selected';
			tabId.value=id;
			dati.idRegione.selectedIndex=0;
	
	//		xajax_getAjaxProvincePagIndex("");
	
			if(dati.idNazione)
				dati.idNazione.selectedIndex=0;
			if (dati.idRegione) 
				dati.idRegione.selectedIndex=0;
			if (dati.idProvincia) 
				dati.idProvincia.selectedIndex=0;
			if (dati.idTipologia)
				dati.idTipologia.selectedIndex=0;
		}
	}
}

function resettaEstero(valore){	
	
		if ((valore == 0)&&(window.document.dati.idNazione.value!='')) {

			window.document.getElementById("divEsteroCittaDirette").style.display = 'none';
			window.document.getElementById("linkEsteroDirettiCitta").style.display = 'none';
	
	
		}else{
			window.document.getElementById("divEsteroCittaDirette").style.display = 'none';
			if (!window.document.dati.idNazione.value){
			/*	window.document.getElementById("linkEsteroDirettiCitta").style.display = 'block';
				window.document.getElementById("showLinkEsteroDirettiCitta").style.display = 'block';
*/
			}
			
		}	
	
}

function getProvLink(id){
	var provId = id.replace("_citta","");
	if (provId){
		var provTxt = document.getElementById(provId).alt;
		var provLink = createPathLink("Provincia di "+provTxt,null,{id:"path_provincia"});
		return provLink;
	}
}
__dontChangeSearchPath = false;
function enableTooltip(id_zona,clearPath){
	
	if (__dontChangeSearchPath == true){
		__dontChangeSearchPath = false;
		return;
	}
	if (document.getElementById('tooltip_map')){
		var oArea=document.getElementById(id_zona);
		titolo=oArea.getAttribute("alt");
		var pathDiv = document.getElementById("tooltip_map");
		pos = titolo.search("-");
		tit = titolo.substr(pos+1);
		var zone = createPathLink(tit,function(){return false});
		pathDiv.appendChild(zone);
		return;
	}
		
	var pathDiv = document.getElementById("searchPath");
	if (typeof clearPath != "undefined" && clearPath == true){
		if (pathDiv){
			pathDiv.innerHTML = "";
			
		}
	}
	


	var oArea=document.getElementById(id_zona);
	titolo=oArea.getAttribute("alt");
	var _lastMouseOver = createPathLink(titolo,null,{id:"path_regione"});	
	if(window.document.dati.idRegione && window.document.dati.idRegione.value && !(window.document.dati.idComune && window.document.dati.idComune.value)){
		if (document.getElementById('path_provincia')){
			pathDiv.removeChild(document.getElementById('path_provincia'));
		}
		if (document.getElementById('path_comune')){
			pathDiv.removeChild(document.getElementById('path_comune'));
		}	
		if (typeof sitemap !="undefined" && sitemap=="on"){
		    _lastMouseOver = createPathLink(Provincia+" - "+titolo,null,{id:"path_provincia"});
		}else{
		    if (oArea.id.search("citta") > 0){
				var provLink = getProvLink(oArea.id);
	//			pathDiv.appendChild(provLink);
				_lastMouseOver = createPathLink(titolo,null,{id:"path_comune"});
				
		    }
			else{
				_lastMouseOver = createPathLink("Provincia di "+titolo,null,{id:"path_provincia"});
			}
		}
	}else{
		if (window.document.dati.idComune && window.document.dati.idComune.value){
		if (isNaN(oArea.id)){
			if (document.getElementById('path_provincia')){
			pathDiv.removeChild(document.getElementById('path_provincia'));
		    }
		    if (document.getElementById('path_comune')){
			pathDiv.removeChild(document.getElementById('path_comune'));
		    }
		    if (oArea.id.search("citta") > 0){
			var provLink = getProvLink(oArea.id);
			pathDiv.appendChild(provLink);
			_lastMouseOver = createPathLink(titolo,null,{id:"path_comune"});
		    }else{
			if (typeof sitemap !="undefined" && sitemap=="on"){
				_lastMouseOver = createPathLink(Provincia+" - "+titolo,null,{id:"path_provincia"});
			}else{
				_lastMouseOver = createPathLink("Provincia di "+titolo,null,{id:"path_provincia"});
			}
		    }
		}else{
		    pos = titolo.search("-");
		    tit = titolo.substr(pos+1);
		    _lastMouseOver = createPathLink(tit,null);
		}
	    }
	}
	//pathDiv.appendChild(_lastMouseOver);
}
	
function disableTooltip(e){
	__dontChangeSearchPath = false;
	if (document.getElementById('tooltip_map')){
		var pathDiv = document.getElementById("tooltip_map");
		pathDiv.innerHTML = "";
		var comune = createPathLink(window.document.dati.idComune.options[window.document.dati.idComune.selectedIndex].innerHTML,function(){return false});
		pathDiv.appendChild(comune);
		return;
	}
	
	if (document.getElementById("searchPath"))
		writePath();
	
}

function writePath(){
	try{	
	var pathDiv = document.getElementById("searchPath");
	pathDiv.innerHTML = "";
	for (var i=0;i<path.length;i++){
	    var oa = document.createElement("a");
		oa.innerHTML = path[i].innerHTML;
		if (path[i].onclick){
			oa.onclick = path[i].onclick;
		}
		oa.id = path[i].id;
		oa.className = path[i].className;
		pathDiv.appendChild(oa);
	}
	}catch(e){
		
	}
}

function createPathLink(label,action,pars){
	if (typeof action=="undefined")
		action=null;
	var a = document.createElement("a");
	a.innerHTML = label;
	a.onclick = action;
	
	if (typeof pars=="object"){
		if (pars.className)
			a.className = pars.className;
		if (pars.id)
			a.id = pars.id;
	}
	return a;
}

function enableBack(ricerca){
	
	ricerca = null;
	path = new Array();
	
	if (typeof nazione == "undefined"){
	    if (typeof sitemap !="undefined" && sitemap=="on"){
		nazione = multiItalia;
	    }else{
		nazione = "Italia";
	    }
	}

       	gestioneCitta();

	//path.push(createPathLink(Italia,function(){xajax_getAjaxProvincePagIndex('','IT');},{className:"first"}));
	path.push(createPathLink(nazione,function(){xajax_getAjaxProvincePagIndex('','IT');},{className:""}));
	var oDiv = document.getElementById("div_back");
	
	if (window.document.dati.idRegione && window.document.dati.idRegione.value!=""){
		path.push(createPathLink(window.document.dati.idRegione.options[window.document.dati.idRegione.selectedIndex].innerHTML,function(){ xajax_getAjaxProvincePagIndex(window.document.dati.idRegione.value,"IT");document.getElementById('linkcitta').style.display = '';},{id:"path_regione"}));
		
		if(window.document.dati.idProvincia && window.document.dati.idProvincia.value!=""){
		        if (typeof sitemap !="undefined" && sitemap=="on"){
			    path.push(createPathLink(Provincia+" - "+window.document.dati.idProvincia.options[window.document.dati.idProvincia.selectedIndex].innerHTML,function(){return xajax_getAjaxComuniPagIndex(window.document.dati.idProvincia.value, window.document.dati.idRegione.value);},{id:"path_provincia"}));
		        }else{
			    path.push(createPathLink("Provincia di "+window.document.dati.idProvincia.options[window.document.dati.idProvincia.selectedIndex].innerHTML,function(){return xajax_getAjaxComuniPagIndex(window.document.dati.idProvincia.value, window.document.dati.idRegione.value);},{id:"path_provincia"}));
		        }

			if (window.document.dati.idComune && window.document.dati.idComune.value!=""){
				path.push(createPathLink(window.document.dati.idComune.options[window.document.dati.idComune.selectedIndex].innerHTML,function(){return false},{id:"path_comune"}));
				
			}
		}
	}

	writePath();
}

function gestioneCitta() {
	if( document.getElementById("divCittaDirette") != null) {
		var oDivCitta = document.getElementById("divCittaDirette");
		var oLinkCitta = document.getElementById("linkDirettiCitta");
		var oShowLinkCitta = document.getElementById("showLinkDirettiCitta");
		var olinksContainer = document.getElementById("linkcitta");

		if (window.document.dati.idRegione && window.document.dati.idRegione.value){
			if(window.document.dati.idProvincia && window.document.dati.idProvincia.value){
			    if (oLinkCitta) oLinkCitta.style.display = "none";
			    if (oDivCitta) oDivCitta.style.display = "none";
			    if (oShowLinkCitta) oShowLinkCitta.style.display="none";
			    if (olinksContainer) olinksContainer.style.display="none";
			}
		}else {
		    if (oShowLinkCitta) oShowLinkCitta.style.display = "none";
		    if (oLinkCitta) oLinkCitta.style.display = "block";
		    if (oDivCitta) oDivCitta.style.display = "block";
		    if (olinksContainer) olinksContainer.style.display="block";
		}
	}
}

function enableBack_NC(ricerca){
	ricerca = null;
	path = new Array();
	
	if (typeof nazione == "undefined"){
		nazione = "Ricerca Internazionale";
	}
		
	//path.push(createPathLink(Italia,function(){xajax_getAjaxProvincePagIndex('','IT');},{className:"first"}));
	path.push(createPathLink(nazione,function(){},{className:""}))
	writePath();
}




function hideShowLinkCitta(){
	if(window.document.dati.idRegione.value){
		var newDiv = document.getElementById("showLinkDirettiCitta");
		var oDiv = document.getElementById("linkDirettiCitta");
		var childDiv = oDiv.childNodes;
		var numShowCitta = 0;
		svuota_cointainer(newDiv);
		for (var i=0; i< childDiv.length ; i++){
			if(childDiv[i].id && childDiv[i].id.indexOf("link_" + window.document.dati.idRegione.value) > -1 ){
				if(numShowCitta){
					var oSpan = document.createElement("span");
					oSpan.innerHTML +=", ";
					newDiv.appendChild(oSpan);
				}		
				var oHref = document.createElement("a");
				oHref.setAttribute("href","#");
				oHref.className="linkHome";
				oHref.setAttribute("id","show_"+ childDiv[i].id);
				oHref.innerHTML += childDiv[i].innerHTML;
				oHref.setAttribute("onclick",childDiv[i].getAttribute("onclick"));
				newDiv.appendChild(oHref);
				numShowCitta++;
			}
		}
		document.getElementById("linkDirettiCitta").style.display = "none";
		if(!numShowCitta){
			document.getElementById("divCittaDirette").style.display = "none";
			document.getElementById("showLinkDirettiCitta").style.display = "none";
			document.getElementById("linkcitta").style.display = "none";
		}else{
			if (document.getElementById('ricercaAvanzata') && document.getElementById('ricercaAvanzata').style.display=='none'){
			document.getElementById("linkcitta").style.display = "block";
				document.getElementById("divCittaDirette").style.display = "block";
				document.getElementById("showLinkDirettiCitta").style.display = "block";		
			}
		}
	}
}


function hideShowLinkEsteroCitta(){

        if (window.document.dati.idNazione.value || window.document.dati.idProvincia ) {
		
		var newDiv = document.getElementById("showLinkEsteroDirettiCitta");
		var oDiv = document.getElementById("linkEsteroDirettiCitta");
		
		var childDiv = oDiv.childNodes;
		var numShowCitta = 0;
		svuota_cointainer(newDiv);

		for (var i=0; i< childDiv.length ; i++){
			if(childDiv[i].id && childDiv[i].id.indexOf("link_" + window.document.dati.idNazione.value) > -1 ){
				if(numShowCitta){
					var oSpan = document.createElement("span");
					oSpan.innerHTML +=", ";
					newDiv.appendChild(oSpan);
				}		
				var oHref = document.createElement("a");
				oHref.setAttribute("href","#");
				oHref.setAttribute("id","show_"+ childDiv[i].id);
				oHref.innerHTML += childDiv[i].innerHTML;
				
				oHref.setAttribute("onclick",childDiv[i].getAttribute("onclick"));
				newDiv.appendChild(oHref);
				numShowCitta++;
			}
		}

		//document.getElementById("linkEsteroDirettiCitta").style.display = "none";

		if(!numShowCitta || (window.document.dati.idRegione && window.document.dati.idRegione.value) || document.getElementById("idCategoria3").className == 'selected' || document.getElementById("idCategoria4").className == 'selected' ){
			document.getElementById("divEsteroCittaDirette").style.display = "none";
			document.getElementById("showLinkEsteroDirettiCitta").style.display = "none";
		}
	}
	else
	{
		document.getElementById("divEsteroCittaDirette").style.display = "block";
		document.getElementById("linkEsteroDirettiCitta").style.display = "block";

	}
}


function manage_new_search_button(action){
	if (!document.getElementById("new_search") || __noSearchRestored)
		return;
	var btn = document.getElementById("new_search");
	switch (action){
		case "show" :
			btn.style.display = "block";
			break;
		default : btn.style.display = "none";
	}
	
}


function changeImageNaz(nazione) {
	manage_new_search_button("hide");
	var ShowItem = document.getElementById("div_nazioni");
	ShowItem.style.backgroundImage = 'url(/imgmap/cartine/' + nazione + '_selected.gif' + getVersion() + ')';
	return true;
}

function hideImageNaz(nazione) {
	manage_new_search_button("show");
	var ShowItem = document.getElementById("div_nazioni");
	ShowItem.style.backgroundImage = 'url(/imgmap/cartine/transparent.gif)';
	return true;
}
		
function changeImage(region) {
	manage_new_search_button("hide");
	var ShowItem = document.getElementById("div_regioni");
	ShowItem.style.backgroundImage = 'url(/imgmap/cartine/' + region + '_selected.gif' + getVersion() + ')';
	return true;
}

function hideImage(region) {
	manage_new_search_button("show");
	var ShowItem = document.getElementById("div_regioni");
	ShowItem.style.backgroundImage = 'url(/imgmap/cartine/transparent.gif)';
	return true;
}

function changeImageProv(provincia) {
	manage_new_search_button("hide");
	var oDiv = document.getElementById("div_provincie");
	oDiv.style.backgroundImage = 'url(/imgmap/cartine/' + window.document.dati.idRegione.value + '/select_' + provincia + '.gif' + getVersion() + ')';		
}

function hideImageProv(provincia) {
	manage_new_search_button("show");
	var oDiv = document.getElementById("div_provincie");
	oDiv.style.backgroundImage = 'url(/imgmap/cartine/transparent.gif)';	
}

function changeImageZone(zona) {
	var suffix = "";
	if (typeof __isTrovaImmobili!="undefined" && __isTrovaImmobili)
		suffix = "_TI";
	//ie sulla onclick della zona ricaricando l'immagine della zona cliccata fa scattare anche l'evento mouseover
	//che va inibito sul click
	manage_new_search_button("hide");
	var oDiv = document.getElementById("div_zone"+suffix);
	
	if(oDiv) {
		oDiv.style.backgroundImage = 'url(/imgmap/cartine/' + window.document.dati.idRegione.value + '/' + window.document.dati.idProvincia.value +'/map_zona_' + zona + '.gif' + getVersion() + ')';
	}
	
}

function hideImageZone() {
	var suffix;
	if (typeof __isTrovaImmobili!="undefined" && __isTrovaImmobili)
		suffix = "_TI";
	else
		suffix = "";
	manage_new_search_button("show");
	var oDiv = document.getElementById("div_zone"+suffix);
	oDiv.style.backgroundImage = 'url(/imgmap/cartine/transparent.gif)';	
}

function selectLocalita(citta, zone) {
	var new_selected=new Array();
	var flag=0;

	if (zone_selected.length != 0 ){
		for (i=0,j=0; i< zone_selected.length ;i++){
			if (zone_selected[i] != zone){
				new_selected[j] = zone_selected[i];
				document.getElementById(new_selected[j]).checked = "checked";
				j++;				
			}else {
				flag=1;
			} 
		}
		if (!flag){ 
			new_selected[zone_selected.length] = zone;
		}
		zone_selected=new_selected;
	}else { 
			zone_selected[0] = zone;
	}
	return true;
}


function selectZona(citta, zone,type) {
	__dontChangeSearchPath = true; 
	var flag = 0;
	
	if (typeof __isTrovaImmobili!="undefined" && __isTrovaImmobili){
		type = "TI";
	}else
	if (typeof type=="undefined")
		type=null;
	
	
	if (typeof zone=="undefined"){
		flag = 1;
	}

	url_map = "/imgmap/cartine/" + window.document.dati.idRegione.value + "/" + citta + "/map_zona_";
	

	var oContainer = document.getElementById("zone_container"+ (type ? "_"+type : ""));
	
	var browser = getBrowser();
	if ( browser && browser[0].toLowerCase().indexOf("explorer")!=-1 && parseInt(browser[1]) < 8){
	//if ( browser && browser.indexOf("msie")!=-1){
		oContainer.style.position ="relative";
		oContainer.style.left = "-150px";
	}
	var new_selected=new Array();
	var zone_sel;
	svuota_cointainer(oContainer);
	if (type=="TI")
		zone_sel = zone_selected_TI;
	else
		zone_sel = zone_selected;
	if (zone_sel.length != 0 ){
		for (i=0,j=0; i< zone_sel.length ;i++){
			if (typeof zone_sel[i] != "undefined" && zone_sel[i] != zone){
				new_selected[j] = zone_sel[i];
				createDivMap(oContainer, new_selected[j], url_map);
				//document.getElementById(new_selected[j]).checked = "checked";
				j++;
			} else { flag=1; } 
		}
		if (!flag){ 
			new_selected[zone_sel.length] = zone;
			createDivMap(oContainer, zone, url_map);
		}
		if (!type)
			zone_selected=new_selected;
		else
		if (type=="TI")
			zone_selected_TI=new_selected;
	}else
	if (typeof zone!="undefined"){
		if (!type)
			zone_selected[0] = zone;
		else
		if (type=="TI")
			zone_selected_TI[0] = zone;
		createDivMap(oContainer, zone, url_map);
	}
	
	return true;
}

function selectProvincia(provincia) {
	var oContainer = document.getElementById("provincie_container");
	var oDivChild = document.createElement("div");
	var oImg = document.createElement("img");
	var browser = getBrowser();
	if ( browser && browser[0].toLowerCase().indexOf("explorer")!=-1 && parseInt(browser[1]) < 8){
	//if ( browser && browser.indexOf("msie")!=-1){
		oContainer.style.position ="relative";
		oContainer.style.left = "-150px";
	}

	svuota_cointainer(oContainer);
	
	oDivChild.style.position="absolute";
	oDivChild.id = provincia;
	oImg.src ="/imgmap/cartine/" + window.document.dati.idRegione.value + "/select_" + provincia + ".gif"+ getVersion();
	oImg.useMap="#Map";
	oImg.border="0";
	oDivChild.appendChild(oImg);
	oContainer.appendChild(oDivChild);
	
	var oArea = document.getElementById("_map_" + provincia);
	if (oArea)
		oArea.removeAttribute("shape");
}
function selectNazione(nazione) {
	var oContainer = document.getElementById("nazioni_container");
	var oDivChild = document.createElement("div");
	var oImg = document.createElement("img");
	var browser = getBrowser();
	if ( browser && browser[0].toLowerCase().indexOf("explorer")!=-1 && parseInt(browser[1]) < 8){
	//if ( browser && browser.indexOf("msie")!=-1){
		oContainer.style.position ="relative";
		oContainer.style.left = "-150px";
	}

	svuota_cointainer(oContainer);
	
	oDivChild.style.position="absolute";
	oDivChild.id = nazione;
	oImg.src ="/imgmap/cartine/" + window.document.dati.idNazione.value + "_selected.gif"+ getVersion();
	oImg.useMap="#nazioni";
	oImg.border="0";
	oDivChild.appendChild(oImg);
	oContainer.appendChild(oDivChild);
	
	//var oArea = document.getElementById("_map_" + nazione);
	//oArea.removeAttribute("shape");
}

function createDivMap(oContainer, id_zona, url_map){
	
	var oDiv = document.createElement("div");
	var oImg = document.createElement("img");
	
	oDiv.id = "map_zona_" + id_zona;
	oDiv.style.position = "absolute";
	oImg.src = url_map + id_zona + ".gif"+ getVersion();
	oImg.useMap = "#Map";
	oImg.border="0";
	oDiv.appendChild(oImg);
	oContainer.appendChild(oDiv);
}

function svuota_cointainer(oContainer){
	if(oContainer) {
		while (oContainer.hasChildNodes())
			oContainer.removeChild(oContainer.firstChild);
	}
	
}

function svuotaDivContainer(idDiv)
{
	oDivParent = window.document.getElementById(idDiv);
	if (oDivParent)
		svuota_cointainer(oDivParent);
}


function preloadImageEstero(){
	var oMapNazioni = document.getElementById("nazioni");
	if (oMapNazioni){
		var childDiv = oMapNazioni.childNodes;
		var version = getVersion();
		for (var i=0; i< (childDiv.length - 1) ; i++){
			var imageLoad = new Image();
			if(childDiv[i].id)
				imageLoad.src = "/imgmap/cartine/" + childDiv[i].id.substring(5) + "_selected.gif" + version;

		}
	}
}

function preloadImageNazione(){
	if (!document.getElementById("regioni"))
		return (null);

	var oMapRegioni = document.getElementById("regioni");
	var aRegioni = oMapRegioni.getElementsByTagName('area');
	var imageLoad = new Image();
	var version = getVersion();
	if (typeof __loaded_regione_index == "undefined")
		__loaded_regione_index = 0;
	else
		__loaded_regione_index++;
		
	if (__loaded_regione_index < aRegioni.length){
		var sPathImg = "/imgmap/cartine/" + aRegioni[__loaded_regione_index].id.substring(5) + "_selected.gif" + version;
		imageLoad.src = sPathImg;
		imageLoad.onload = preloadImageNazione;
	}
}




function preloadImageProvincie(regione, image){
		var imageLoad = new Image();
		imageLoad.src = "/imgmap/cartine/" + regione + "/select_prov_" + image + ".gif"+ getVersion();
}

function preloadImageZone(comune, image){
		var imageLoad = new Image();
		imageLoad.src = "/imgmap/cartine/" + window.document.dati.idRegione.value + "/" + comune + "/map_zona_" + image + ".gif"+ getVersion();
}

function abilitaCitta() {
	var oDivNewCitta = window.document.getElementById("otherLinkDirettiCitta");
	var oDivCitta = window.document.getElementById("linkDirettiCitta");
	if (oDivNewCitta && oDivCitta){
		oDivAltre = window.document.getElementById("linkAltreCitta");
		if(oDivAltre)
			oDivAltre.style.display="none";
		oDivCitta.innerHTML += oDivNewCitta.innerHTML;
	}
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function createAnimatedButton(className,divContainer,onclickEvent,name){
	
	//permitted className = bottoneCerca - bottoneTrova - bottoneInvia - bottoneAttivaServizio
	var div;
	if (typeof divContainer == "string")
		div = document.getElementById(divContainer);
	else
		div = divContainer;

	var btn = document.createElement('input');
	btn.className = className;
	if(typeof name!='undefined')
		btn.name=name;
	
	if (onclickEvent){
		addEvent(btn,"click",onclickEvent);
		btn.type="button"
	}else{
		btn.type="submit";
		
	}
	btn.value = "";

	//devo fare il bind perchè co explorer non funziona
	btn.style.position='relative';
	btn.onmousedown = function(){this.style.top='1px';this.style.left='1px';};
	btn.onmouseup = function(){this.style.top='0px';this.style.left='0px';};
	btn.onmouseout = function(){this.style.top='0px';this.style.left='0px';};
	btn.onmouseover = function(){this.style.backgroundPosition='bottom';};
	btn.onmouseout = function(){this.style.backgroundPosition='top';};
	btn.onfocus = function(){this.blur();};
	
	div.appendChild(btn);

	addEvent(window,"unload",function(){purgeDomObj(btn);})

}

function toggleDiv(idCont,el,openedText,closedText){
	if (typeof el.isShowingDiv == undefined){
		el.isShowingDiv == false;
	}
	if (el.isShowingDiv){
		MEslideDown(idCont,0)
		el.isShowingDiv = false;
		el.innerHTML = closedText;
	}else{
		MEslideUp(idCont,0);
		el.isShowingDiv = true;
		el.innerHTML = openedText;
	}
	el.blur();
}



function getVersion() {
	if(version_map) {
		return version_map;
	}
	return ""; 
}

function create_accediBox(_type){
	if (typeof _type == "undefined")
		type = "U";
	else
		type = _type;
		
	if (type!="A" && type!="U"){
		alert("wrong type for create_accedi_box");
		return;
	}
	    preloadImages(new Array("/imgmap/loader3.gif"));
		selAccediBox = new Object;
		var prefix = "";
		boxLoginPars = new Array();
		switch (type){
			case "A":
				prefix = "AG_";
				selAccediBox.form_action = "/accesso_agenzie.php";
				selAccediBox.form_onsubmit = eseguiAccessoAg;
				selAccediBox.title = "<span class=\"box_header title\" ><div id=\"icona_login_agenzia\"></div>Accesso <strong class=\"title-blue\">PROFESSIONISTI</strong></span>";
				selAccediBox.footer = "<div style=\"height:20px;margin-top:10px;width:350px;font-size:13px;\"><img src=\"/imgmap/icone/icona-privato-small.png\" style=\"margin-right:5px;vertical-align:bottom\">Sei un privato? <a class=\"link_blu\" style=\"font-weight:bold;\" href=\"/accedi.php\">Accedi</a><span style=\"margin:0px 3px;\">|</span><a href=\"/agenzia/registra-nuova-agenzia.php\" class=\"link_blu\" style=\"font-weight:bold;\">Registrati</a></div>"
				selAccediBox.registrationLink = "/agenzia/registra-nuova-agenzia.php";
				break;
			default:
				selAccediBox.form_action = "/accedi.php";
				selAccediBox.form_onsubmit = eseguiAccesso;
				selAccediBox.title = "<span class=\"box_header title\"><div id=\"icona_login_utente\"></div>Accesso <strong class=\"title-blue\">PRIVATI</strong></span>";
				selAccediBox.footer = "<div style=\"height:20px;margin-top:10px;width:350px;font-size:13px;\"><img src=\"/imgmap/icone/icona-agenzia-small.png\" style=\"margin-right:5px;vertical-align:bottom\">Agenzie e Imprese Edili: <a class=\"link_blu\" style=\"font-weight:bold;\" href=\"/accesso_agenzie.php\">Accedi</a><span style=\"margin:0px 3px;\">|</span><a href=\"/agenzia/registra-nuova-agenzia.php\" class=\"link_blu\" style=\"font-weight:bold;\">Registrati</a></div>"
				selAccediBox.registrationLink = "/casa/informazioni/registrati.php";
				break;
		}
		
		accediBoxContent = ""+
		"<div id=\""+prefix+"box_accedi\" style=\"font-size:12px;width:370px;\">"+
		"		<form action=\""+selAccediBox.form_action+"\" method=\"post\" id=\""+prefix+"box_accedi_form\" target=\"_blank\" name=\"accedi_form\" style=\"margin-top:5px;\">"+
		"			<input name=\"mode\" value=\"\" type=\"hidden\" />"+
		"			<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" style=\"text-align:right;margin-left:14px;\">"+
		"				<tr style=\"display:none\" id=\""+prefix+"accediBoxErrorTr3\">"+
		"					<td>"+
		"					</td>"+
		"					<td colspan=\"3\" style=\"text-align:left;\">"+
		"						<div id=\""+prefix+"accediBoxError\" class=\"error\"></div>"+
		"					</td>"+
		"				</tr>"+
		"				<tr style=\"display:none\" id=\""+prefix+"accediBoxErrorTr1\">"+
		"					<td>"+
		"					</td>"+
		"					<td colspan=\"2\" style=\"text-align:left;\">"+
		"						<div id=\""+prefix+"accediBoxEmailError\" class=\"error\"></div>"+
		"					</td>"+
		"				</tr>"+
		"				<tr>"+
		"					<td>"+
		"						<strong>Email</strong>"+
		"					</td>"+
		"					<td>"+
		"					</td>"+
		"					<td>"+
		"						<input name=\"email\" value=\"\" type=\"text\" maxlength=\"100\" onKeyPress=\"eventOnEnter(event,function(){selAccediBox.form_onsubmit(document.getElementById('"+prefix+"box_accedi_form'))})\"/>"+
		"					</td>"+
		"				</tr>"+
		"				<tr style=\"display:none\" id=\""+prefix+"accediBoxErrorTr2\">"+
		"					<td>"+
		"					</td>"+
		"					<td colspan=\"2\" style=\"text-align:left;\">"+
		"						<div id=\""+prefix+"accediBoxPasswordError\" class=\"error\"></div>"+
		"					</td>"+
		"				</tr>"+
		"				<tr>"+
		"					<td>"+
		"						<strong>Password</strong>"+
		"					</td>"+
		"					<td>"+
		"					</td>"+
		"					<td>"+
		"						<input name=\"password\" value=\"\" type=\"password\" maxlength=\"100\" onKeyPress=\"eventOnEnter(event,function(){selAccediBox.form_onsubmit(document.getElementById('"+prefix+"box_accedi_form'))})\" />"+
		"					</td>"+
		"				</tr>"+
		"					<tr>"+
		"						<td>"+
		"							<div style=\"line-height:10px\">"+
		"								<a href=\"/ricorda_password.php\" class=\"testo_piccolo norm link_blu\" title=\"Clicca sul collegamento per recuperare la password\">recupera password</a><br />"+
		"							</div>"+
		"						</td>"+
		"					<td>"+
		"					</td>"+
		"						<td>"+
		"							<div id=\""+prefix+"accediButton_container\">"+
		"							</div>"+
		"						</td>"+
		"					</tr>"+
		"					<tr>"+
		"						<td>"+
		"						</td>"+
		"						<td>"+
		"						</td>"+
		"						<td>"+
		"							Non sei registrato? <a href=\""+selAccediBox.registrationLink+"\" class=\"link_blu underline\" style=\"font-weight:bold;\">Registrati &egrave; gratis!</a></strong>"+
		"						</td>"+
		"					</tr>"+
		"				</table>"+
		"			</form>"+
		"			<div class=\"clear\"></div>"+
		"		</div>"+
		"</div>";
		
		selAccediBox.box = new boxOverlay(prefix+'accediBox','grey');
		selAccediBox.box.setContent(accediBoxContent);
		selAccediBox.initContent = selAccediBox.box.getContent();
		
		selAccediBox.box.setTitle("<strong>"+selAccediBox.title+" <img src=\"/imgmap/LoadingSmall.gif\" style=\"display:none;margin-left:10px\" id=\""+prefix+"accedi_box_loader\"/></strong>&nbsp;");
		selAccediBox.box.setFooter(selAccediBox.footer);
		
		createAnimatedButton("bottoneAccedi",prefix+"accediButton_container",function(){return selAccediBox.form_onsubmit(document.getElementById(prefix+'box_accedi_form'))});
		
	return selAccediBox.box;
}

function eseguiAccesso(oForm){
	
	document.getElementById("accedi_box_loader").style.display="";
	oForm.mode.value = "xml";
	var loginErr = document.getElementById("accediBoxError");
	var emailErr = document.getElementById("accediBoxEmailError");
	var passwordErr = document.getElementById("accediBoxPasswordError");
	var error = false;
	var loginTr1 = document.getElementById("accediBoxErrorTr1");
	var loginTr2 = document.getElementById("accediBoxErrorTr2");

	
	if (!oForm.email.value){
		emailErr.innerHTML = "Inserisci la tua email";
		loginTr1.style.display="";
		error = true;
	}else
	if (!checkEmail(oForm.email.value)){
		emailErr.innerHTML = "Inserisci una email valida";
		loginTr1.style.display="";
		error = true;
	}
	else{
		emailErr.innerHTML = "";
		loginTr1.style.display="none";
	}
	if (!oForm.password.value){
		passwordErr.innerHTML = "Inserisci la tua password";
		loginTr2.style.display="";
		error = true;
	}
	else{
		passwordErr.innerHTML = "";
		loginTr2.style.display="none";
	}
	if (!error){
		submitAjaxForm(oForm,doLogin);
	}else{
		document.getElementById("accedi_box_loader").style.display="none";
	}
	
}

function doLogin(response){
	if (trim(response.responseText) == ""){
		var rechargeHtml = "<div style=\"width:100%;padding:40px 0px;text-align:center\"><h3>Accesso in corso...</h3><img src=\"/imgmap/loader3.gif\" alt=\"loading\"/></div>";
		selAccediBox.box.setContent(rechargeHtml);
		window.location.reload();
	}
	else{
		var loginErr = document.getElementById("accediBoxError");
		var loginTr3 = document.getElementById("accediBoxErrorTr3");
		loginErr.innerHTML = response.responseText;
		loginTr3.style.display="";
	}
	document.getElementById("accedi_box_loader").style.display="none";
}

function eseguiAccessoAg(oForm){
	
	document.getElementById("AG_accedi_box_loader").style.display="";
	oForm.mode.value = "xml";
	var loginErr = document.getElementById("AG_accediBoxError");
	var emailErr = document.getElementById("AG_accediBoxEmailError");
	var passwordErr = document.getElementById("AG_accediBoxPasswordError");
	var error = false;
	var loginTr1 = document.getElementById("AG_accediBoxErrorTr1");
	var loginTr2 = document.getElementById("AG_accediBoxErrorTr2");
		
	if (!oForm.email.value){
		emailErr.innerHTML = "Inserisci la tua email";
		loginTr1.style.display="";
		error = true;
	}else
	if (!checkEmail(oForm.email.value)){
		emailErr.innerHTML = "Inserisci una email valida";
		loginTr1.style.display="";
		error = true;
	}
	else{
		emailErr.innerHTML = "";
		loginTr1.style.display="none";
	}
	if (!oForm.password.value){
		passwordErr.innerHTML = "Inserisci la tua password";
		loginTr2.style.display="";
		error = true;
	}
	else{
		passwordErr.innerHTML = "";
		loginTr2.style.display="none";
	}
	if (!error){
		
		submitAjaxForm(oForm,doLoginAg);	
	}else{
		document.getElementById("AG_accedi_box_loader").style.display="none";
	}
	
}

function doLoginAg(response){
	if (isNumeric(response.responseText)){
		var rechargeHtml = "<div style=\"margin:0px auto;text-align:center;width:285px;padding:40px 0px;\"><h3>Accesso in corso</h3><img src=\"/imgmap/loader3.gif\" /></div>";
		selAccediBox.box.setContent(rechargeHtml);
		switch(parseInt(response.responseText)){
			case 0 :
				break;
			case 1 :
				window.location.href="/home_gestionale.php";
				break;
			case 2 :
				window.location.href="/amministrazione.php";
				break;
			default :
				window.location.href="/index.php";
				break;
		}
	}
	else{
		var loginErr = document.getElementById("AG_accediBoxError");
		var loginTr3 = document.getElementById("AG_accediBoxErrorTr3");
		loginErr.innerHTML = response.responseText;
		loginTr3.style.display="";
	}
	document.getElementById("AG_accedi_box_loader").style.display="none";
}

function checkContratto(idContratto){
	document.getElementById('radio_idContratto'+idContratto).checked = 'checked';
	if (parseInt(idContratto) == 3){
		roomManager();
	}
}

function saveLastSearchCookie(categoria,opzioni){
	if (typeof opzioni == "undefined" || typeof categoria == "undefined"){
		_raiseError("called function with empty requested argument");		
	}
	try{
		var sCookie = readCookie('imm_lss');
		var oCookie = new Object();
		if (sCookie){
			sCookie = Base64.decode(sCookie)
			oCookie = eval( "(" + sCookie + ")" );
		}
		oCookie[categoria] = opzioni;
		sCookie = Base64.encode(stringify(oCookie));
		createCookie("imm_lss",sCookie,90,0,0);
	}catch(e){
		deleteCookie("imm_lss");
		_raiseError(e);
	}
}
function cleanLastSearch(categoria){
	if (typeof categoria == "undefined"){
		_raiseError("called function with empty requested argument");		
	}
	try{
		var sCookie = readCookie('imm_lss');
		var oCookie = new Object();
		if (sCookie){
			sCookie = Base64.decode(sCookie)
			oCookie = eval( "(" + sCookie + ")" );
		}
		oCookie[categoria] = null;
		sCookie = Base64.encode(stringify(oCookie));
		createCookie("imm_lss",sCookie,90,0,0);
		
		manage_new_search_button("hide");
		__noSearchRestored = true;
	}catch(e){
		deleteCookie("imm_lss");
		_raiseError(e);
	}
}

function getLastSearchCookie(categoria){
	oCookie = null;
	try{
		var sCookie = readCookie('imm_lss');
		var oCookie = null;
	
		if (sCookie){
			sCookie = Base64.decode(sCookie)
			oCookie = eval( "(" + sCookie + ")" );
		}
	}catch(e){
		deleteCookie("imm_lss");
		_raiseError(e);
		
	}
	return oCookie;
}

function restoreLastSearchForm(categoria){
	__noSearchRestored = true;
	try{
		var oCookie = null;
		oCookie = getLastSearchCookie(categoria);
		if (oCookie && typeof oCookie == "object" && oCookie[categoria] && typeof oCookie[categoria] == "object"){
			document.getElementById("new_search").style.display = "block";
			if (oCookie[categoria].comune != ""){			
				xajax_getAjaxProvinciaAndComuniPagIndex(oCookie[categoria].comune,oCookie[categoria].provincia, oCookie[categoria].regione, oCookie[categoria].contratto,stringify(oCookie[categoria]));
			}
			else{
				xajax_getAjaxRegioneAndProvinciaPagIndex(oCookie[categoria].provincia, oCookie[categoria].regione, oCookie[categoria].contratto);
			}
			__noSearchRestored = false;
		}else{
			show_search_box();
		}
	}catch(e){
		show_search_box();
		_raiseError(e);
	}
}

function show_search_box(){
	if (document.getElementById('box_ricerca_HP'))
		document.getElementById('box_ricerca_HP').style.display="";
	if (document.getElementById('box_ricerca_LOAD'))
		document.getElementById('box_ricerca_LOAD').style.display="none";
}


function selectZoneHome(prov,sCookie){
		oCookie = eval("(" + sCookie + ")");
		zone_selected = new Array();
		if (oCookie.zone){
			zone_selected = oCookie.zone;
			selectZona(prov);
			swapZona();
		}
		if (oCookie.localita){
			zone_selected = oCookie.localita;
			selectLocalita(prov);
			salvaZone('localita');
		}	
}


/*
questa funzione effettua il check se ci sono le condizioni per visualizzare la pagina in modalità estesa e quindi
eseguire la funzione specificata come parametro in caso positivo.
@fAction = funzione da eseguire in caso di test positivo
*/

function _ifWidePage(fAction){
	var __widepage;
	
	try{
		if (screen.width >= 1280){
			__widepage = true;
		}
	}catch(e){
		__widepage = false;
		return false;
	}

	if (__widepage == true){
		if (typeof fAction == "function")
			fAction();
		return true;
	}
	return false;
}

function setPageH(){
	var nHeightToBottom = 0;
	try
	{
		if (document.viewport && $('header_container') && $('corpo') && $('footer'))
			nHeightToBottom = ((document.viewport.getHeight()) - ($('header_container').getHeight()) - ($('corpo').getHeight()) - ($('footer').getHeight()));
		if (nHeightToBottom > 0)
			$('spacerToFooter').setStyle({'height': nHeightToBottom + 'px'});
			//$('spacerToFooter').className = 'pubblicazione_utente';
	}
	catch(error)
	{
		//alert(error);
	}
}
			
	/*		
function setPageW(){
	try{
		var cH = document.getElementById("corpo").getWidth();
		var wH = document.viewport.getWidth();
		//alert("wH:"+wH+" < cH:"+cH+" && wH:"+wH+"< 1024");
		if (wH <= cH && wH < 1000){
			document.getElementById("header_container").style.width = "1000px";
			document.getElementById("footer").style.width = "1000px";
			document.getElementById("corpo_container").style.width = "1000px";
			
		
		}else{
			document.getElementById("header_container").style.width = "auto";
			document.getElementById("footer").style.width = "auto";
			document.getElementById("corpo_container").style.width ="auto";
		
		}
	}catch(r){
	
	}
}
*/
function leoHeader()
{	var bLoadLeoHdr = false;
	if (window.location.search.match('utm_source=leonardo&utm_medium=banner')) {
		bLoadLeoHdr = true;
		var dtNow = new Date();
		var dtExpires = new Date();
		dtExpires.setTime(dtNow.getTime() + 1200000 /* 20 minuti */);
		document.cookie = "leoHdr=true;expires=" + dtExpires.toGMTString() + ";path=/";
	}
	if (!bLoadLeoHdr) {
		var asCookies = document.cookie.split("; ");
		for (var nCnt = 0; nCnt < asCookies.length; nCnt++)
		{	var asCookie = asCookies[nCnt].split("=");
			if (asCookie[0] == 'leoHdr' && unescape(asCookie[1]) == 'true') {
				bLoadLeoHdr = true;
				break;
			}
		}
	}
	if (bLoadLeoHdr) {
		document.write('<'+'script type="text/javascript" src="http://www.leonardo.it/script/Leonardo_Intruder.php?idEditore=157"'+'><'+'/script'+'>');
	}
}
			
function datiSoc(file,w,h) {
  var l = Math.floor((screen.width-w)/2);
  var t = Math.floor((screen.height-h)/2);
  window.open(file,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l +",");
}

function toggleVetrina(){
	var vetrina = document.getElementById('wrap_vetrina_ricerca_container');
	var btn = document.getElementById('toggleVetrina');
	if (vetrina.style.display == "none"){
		vetrina.style.display = "block";
		btn.innerHTML = "nascondi";
		btn.style.backgroundImage = "url(/imgmap/freccetta_up.png)";
	}else{
		btn.innerHTML = "mostra";
		vetrina.style.display = "none";
		btn.style.backgroundImage = "url(/imgmap/freccetta_down.png)";
	}
}

function signUpNews(){
	if (checkEmail(document.getElementById('newsLetter_email').value)){
		submitAjaxForm("newsletter_sign",confirmSignupNewsletter,"/signupNewsletter.php");
		document.getElementById('btn_news_letter_cont').innerHTML = "<img src=\"/imgmap/loader7.gif\" style=\"margin-top:4px\"/>";
	}else{
		alert("Digita una email valida");
	}
}


function confirmSignupNewsletter(res){
	signup_box = new boxOverlay('signupNewsLetter','grey');

	var splittedRes = res.responseText.split(",");
	
	var flag = typeof splittedRes[0] != "undefined" ? splittedRes[0] : "KO";
	var errcode = typeof splittedRes[1] != "undefined" ? splittedRes[1] : 0;
	var uemail = typeof splittedRes[2] != "undefined" ? splittedRes[2] : "";
	
	if (flag=="OK"){
		var response = "Iscrizione avvenuta con successo."
		var message = "<div>Grazie per esserti iscritto alla newsletter di immobiliare.it.<br /><strong>Abbiamo inviato una mail all'indirizzo email \""+uemail+"\" contenente il link per confermare l'iscrizione</strong>.<br /><br />Riceverai le notizie più interessanti del mercato immobiliare, tutto ciò che è casa ed abitare, e infine le novità e le curiosità scovate dal nostro team editoriale, direttamente nella tua casella di posta.</div>";
	}else{
		var response = "<span style=\"margin:5px 0px;color:red\">Non è stato possibile effettuare l'iscrizione</span>"
		switch(parseInt(errcode)){
			case 1:
				var message = "<div>L'indirizzo email <strong>"+uemail+"</strong> risulta già iscritto alla newsletter di Immobiliare.it</div>";
				break;
			case 2:
				var message = "<div>L'indirizzo email inserito non è valido.</div>";
				break;
			default:
				var message = "<div>Si sono verificati degli errori durante la fase di iscrizione.<br />La preghiamo di riprovare più tardi</div>";
				break;
		}
	}
		signup_box.setContent("<div style=\"width:450px;padding:10px 0px;\"><img style=\"float:left\" src=\"/imgmap/icone/newsImmobiliare.png\" /><div style=\"float:right;width:350px;\"><div style=\"margin-bottom:5px;font-size:14px\"><strong style=\"margin-bottom:5px;\">"+response+"</strong></div><div class=\"clear\"></div><div style=\"font-size:12px\">"+message+"</div></div>");
		signup_box.setTitle("<strong>Newsletter Immobiliare.it </strong>&nbsp;");
		signup_box.show();
		
		/* reset form*/
		//document.getElementById('newsLetter_email').value="";
		//document.getElementById('newsLetter_email').onblur();
		document.getElementById('btn_news_letter_cont').innerHTML = "";
		createAnimatedButton("puls_freccetta","btn_news_letter_cont", signUpNews);
}


/*crea il boxettino per la conferma della cancellazione annunci pubblicati/preferiti/ricerche salvate relativa agli utenti registrati*/

/*
* sDivContainer: div a cui viene appeso il box overlay
* iWidth, iHeight: dimensioni in px del box
* iIdElToRemove: id annuncio pubblicato/id ricerca da cancellare
* sBookmark: il tipo di bookmark. pubblicati, preferiti, ricerche salvate
*/

function fnConfirmAction(sDivContainer,iWidth,iHeight,iIdElToRemove,sBookmark){
	
	
	var oParentlayer = document.getElementById(sDivContainer);
	
	var oConfirmLayer = document.createElement("div");
	oConfirmLayer.id="confirm_layer_"+iIdElToRemove;
	oConfirmLayer.style.backgroundColor="#aeaeae";
	oConfirmLayer.style.position="absolute";
	oConfirmLayer.style.filter="alpha(opacity = 80)";
	oConfirmLayer.style.opacity="0.8";
	
	oConfirmLayer.style.border="1px solid";
	oConfirmLayer.style.width=iWidth+"px";
	oConfirmLayer.style.height=iHeight+"px";
	oConfirmLayer.style.zIndex="140";
	
	var oConfirmControl = document.createElement("div");
	oConfirmControl.id = "controls_confirm_container_"+iIdElToRemove;
	oConfirmControl.style.filter="alpha(opacity = 100)";
	oConfirmControl.style.opacity = "1";
	oConfirmControl.style.zIndex = "150";
	oConfirmControl.style.width = iWidth+"px";
	oConfirmControl.style.height = iHeight+"px";
	
	oConfirmControl.style.position = "absolute";
	
	//dimensioni contenitore bottoni
	var iControlsDivWidth = 240; 
	var iControlsDivHeight = 35;
	
	var iControlsMargin =  Math.floor(((iHeight/2)-(iControlsDivHeight/2)))+"px "+" auto";
	
		
	var sHTMLControlContainer = "<div class=\"confirm_control\"></div>";
	
	var sHTMLButtons = "<div style=\"position:relative;opacity:1;filter:alpha(opacity = 100);z-index:150;width:"+iControlsDivWidth+"px;height:"+iControlsDivHeight+"px;background-image:url('/imgmap/fondo-box.png');margin:"+iControlsMargin+"\">";
	
	sHTMLButtons += "<div class=\"bottoneAnnulla\" onclick=\"this.parentNode.parentNode.parentNode.className = (this.parentNode.parentNode.parentNode.className.split('_confirm_box'))[0];fnRemoveNodeById(this.parentNode.parentNode.nextSibling.id);fnRemoveNodeById(this.parentNode.parentNode.id);\"></div>";
	
	switch(sBookmark){
	    case('pubblicati'):
	   	sHTMLButtons += "<div class=\"bottoneCancella\" onclick=\"location.href='pubblicaAnnunci.php?action=delete&id="+iIdElToRemove+"';\"></div>";
		break;
	    case('ricerche'):
		sHTMLButtons += "<div class=\"bottoneCancella\" onclick=\"location.href='bookmarkricerche.php?action=delete&idRicerca="+iIdElToRemove+"';\"></div>";
		break;
	    case('preferiti'):
		sHTMLButtons += "<div class=\"bottoneCancella\" onclick=\"location.href='bookmarkannunci.php?action=delete&id="+iIdElToRemove+"';\"></div>";
		break;
	}
	
	sHTMLButtons += "<div class=\"clear\"></div>";
	
	sHTMLButtons += "</div>";
	
	oConfirmControl.innerHTML = sHTMLButtons;
	
	oConfirmLayer.innerHTML = sHTMLControlContainer;
	
	
	oParentlayer.insertBefore(oConfirmLayer,oParentlayer.firstChild);
	
	//disattivo il rollover sul div padre
	oConfirmLayer.parentNode.className += "_confirm_box";
	
	
	oParentlayer.insertBefore(oConfirmControl,oParentlayer.firstChild);
	
	return false;
}

addEvent(window,'load',setPageH);
addEvent(window,'resize',setPageH);
//addEvent(window,'load',setPageW);
//addEvent(window,'resize',setPageW);
		
 

