	var ns6 = (!document.all && document.getElementById);
	var ie4 = (navigator.appName.indexOf("Microsoft")!=-1) ? true : false;
	var ns4 = (document.layers);

	// visualizza la clessidra
	function visualizza_attendi(id) {
		if(typeof(id) == 'undefined')
        	document.getElementById('attendi').style.display = 'block';
        else
        	document.getElementById(id).style.display = 'block';
	}
	
	// nasconde la clessidra
	function nascondi_attendi(id) {
		if(typeof(id) == 'undefined')
		    document.getElementById('attendi').style.display = 'none';
		else
			document.getElementById(id).style.display = 'none';
	}
	
	// riempie in tempo reale un div mentre si scrive su un campo input  
	function fillTextRealTime(idsource,iddest) { 
		if(!iddest)
			iddest = idsource+'_txt';
		document.getElementById(iddest).innerHTML=document.getElementById(idsource).value;
	}
 
    function Opec() {
        this.classe; 
        this.fonte; 
        this.rank;
        this.posx="null"; 
        this.posy="null";
        this.longitudine="null";
        this.latitudine="null";
        this.distanza="null";
        this.linea_aria="null";
        this.codiceOPEC;
        this.categorie; 
        this.peso_commerciale;
        this.categoria;
        this.nome;
        this.comune;
        this.toponimo;
        this.indirizzo;
        this.cap;
        this.provincia;
    }
        
    function clickAdv(page, tipo){
        cmPHP('','','',tipo,page);
        adv = window.open(page,"adv"); 
        adv.focus();
    }
    
    function displaySelect(id) {     
        var obj = document.getElementById(id);
        obj.style.visibility = ( obj.style.visibility == 'hidden') ? 'visible' : 'hidden';
        obj.style.display    = ( obj.style.display == 'none')      ? 'block'   : 'none';
    }
    
    function getListing() {
    
    	var cosa = document.getElementById("richiesta_aziende").cosa.value;
	    cosa     = cosa.replace("&","e");
		if(cosa=='' || cosa =='undefined') { 
			alert("Vous devez préciser un nom ou une activité."); return;
			nascondi_attendi();
		} else {
        	visualizza_attendi();
        	var post =   "cosa="         + encodeURI( cosa ? cosa : "" ) +
	                     "&dove="        + encodeURI( document.getElementById("richiesta_aziende").dove.value ? document.getElementById('richiesta_aziende').dove.value : "" ) +
	                     "&page="        + encodeURI( document.getElementById("richiesta_aziende").page.value ? document.getElementById('richiesta_aziende').page.value : "" ) +
	                     "&lat="         + encodeURI( document.getElementById("lat").value ? document.getElementById('lat').value : "" ) +
	                     "&lng="         + encodeURI( document.getElementById("lng").value ? document.getElementById('lng').value : "" ) +
	                     "&lato="        + encodeURI( document.getElementById("lato").value ? document.getElementById('lato').value : "" ) +
	                     "&cat="         + encodeURI( document.getElementById("cat").value ? document.getElementById('cat').value : "" ) +
	                     "&codiceistat=" + encodeURI( document.getElementById("istat").value ? document.getElementById('istat').value : "" ) +
	                     "&usa_dove="    + encodeURI( document.getElementById("usa_dove").value ? document.getElementById('usa_dove').value : "" )+
	                     "&template="    + encodeURI( document.getElementById("template").value ? document.getElementById('template').value : "" ) +
	                     "&p="           + encodeURI( document.getElementById("richiesta_aziende").p.value ? document.getElementById('richiesta_aziende').p.value : "" )+
	                     "&rp="          + encodeURI( document.getElementById("rp").value ? document.getElementById("rp").value : "" );
			
     		var xmlhttp = newXMLHttpRequest();
			document.getElementById("istat").value = '';
	        if (xmlhttp!=null) {    
	            xmlhttp.open("POST","/getListing.php",true);
	            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	            xmlhttp.send(post);
	            xmlhttp.onreadystatechange = handleResponse(xmlhttp, manageListing, ResponseType.html);
	        } else {
	            alert("Votre navigateur ne lit pas XMLHttpRequest.");
	        	nascondi_attendi();
	        }
	    }
    }
	
	function geocodeAddress(address, method) {
	
		if (document.getElementById("richiesta_aziende").cosa.value=="") {
             alert("Vous devez préciser un nom ou une activité.");
		} else {
			
        	if (!address) {// se non c'e' ricerca di prossimita'
        		if (method == 'async') {
        			getListing("richiesta_aziende");
				} else {	
					visualizza_attendi();
					document.getElementById("richiesta_aziende").submit();
				}
				
			} else { 
			
				if (geocoder && document.getElementById("richiesta_aziende").dove.value) {
		
					visualizza_attendi();
					address += ", " + document.getElementById("richiesta_aziende").dove.value + ", fr";
                    geocoder.getLocations(address, function(response){                        
                        if (!response || response.Status.code != 200) {
                            alert(address + " not found");
                        } else {
          
                        	place = response.Placemark[0];
                            document.getElementById('lat').value = place.Point.coordinates[1];
                            document.getElementById('lng').value = place.Point.coordinates[0];
                            
                            if (method == 'async') {                               
          
                                getListing();
                                
                            }else{
          
                           		document.getElementById("richiesta_aziende").submit();
                            }    
                            window.scrollTo(0,0);
                        }
                    });
                }
            }
        }
	}

    function manageListing(HTMLResult){
		nascondi_attendi();
		var cosa = document.getElementById("richiesta_aziende").cosa.value ? document.getElementById('richiesta_aziende').cosa.value : ""; 
        var dove = document.getElementById("richiesta_aziende").dove.value ? "-"+document.getElementById('richiesta_aziende').dove.value : "";
        var page = document.getElementById("richiesta_aziende").page.value ? document.getElementById('richiesta_aziende').page.value : "" ;
       
        pageTracker._trackPageview("/listing/"+cosa.replace(/\s/i, "_")+dove.replace(/\s/i, "_")+"/index_"+page+".htm" );//tracking per analytics
        document.getElementById("colonna_cx").innerHTML = HTMLResult;
        if(document.getElementById("column_up_left_inside")!=null)
        	document.getElementById("column_up_left_inside").innerHTML = "Carte des r&eacute;sultats";
        loadMarkers();
    }
   	
	function GoToUrl(urlPage,target){
		if(urlPage.indexOf("https://") == -1){
			if(urlPage=='#') {}
	    	else{ 
	    		if(urlPage.indexOf("http://") == -1) urlPage = "http://"+urlPage;
	    	}
    	}
    	if(target!=null)
	        remote=window.open(urlPage,target);
	    else
        	remote=window.open(urlPage,"pagina", "resizable=1,menubar=1,toolbar=1,scrollbars=1,location=1");
        remote.focus();
    }
    
    function GoToPopUp(urlPage,namePage, width, height){
    	
		if(urlPage.indexOf("https://") == -1){
			if(urlPage=='#') {}
	    	else{ 
	    		if(urlPage.indexOf("http://") == -1) urlPage = "http://"+urlPage;
	    	}
    	}
    	
    	if(width==null || typeof(width)=='undefined') width=400;
    	if(height==null || typeof(height)=='undefined') height=450;
    	    	
       	remote=window.open(urlPage,'namePage', "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,titlebar=0,width="+width+",height="+height);
       	
        remote.focus();
        
    }
    
	function GoToPopUpFull(urlPage,namePage){
		GoToPopUp(urlPage,namePage, 1024, 800);
	}
    
    function TY_page(url) { 
	 	window.opener.document.location=url; 
	 	window.close(); 
	 	return false; 
	} 
    
    function lato(value) {
        if(document.getElementById('prossimita').value== '') {
            alert("Vous devez remplir les 3 champs de recherche : Quoi, Où et à côté de...");
             document.getElementById('opzioni_lato').style.visibility = ( document.getElementById('opzioni_lato').style.visibility == 'hidden') ? 'visible' : 'hidden';
             document.getElementById('opzioni_lato').style.display    = ( document.getElementById('opzioni_lato').style.display == 'none')      ? 'block'   : 'none';
        }else{
	        document.getElementById('metri_lato').innerHTML = value;
	    	document.getElementById('lato').value           = value;
	        document.getElementById('opzioni_lato').style.visibility = ( document.getElementById('opzioni_lato').style.visibility == 'hidden') ? 'visible' : 'hidden';
            document.getElementById('opzioni_lato').style.display    = ( document.getElementById('opzioni_lato').style.display == 'none')      ? 'block'   : 'none';
 	    	getListing('richiesta_aziende');
	    }	
    }
    
    function manageGeocodeInversa(XMLResult) {
        if( XMLResult ) {
            var address = XMLResult.getElementsByTagName('ADDRESS')[0];
            if(address) {
                document.getElementById('prossimita').value = address.getAttribute("ADDR")+" "+((address.getAttribute("NUM")!=null) ? address.getAttribute("NUM") : "");        
                document.getElementById('dove').value       = ( address.getAttribute("AMD4") ) ? address.getAttribute("AMD4") : "";
                getListing('a',"undefined",'lato');
		    } else {
                if( document.getElementById('posx') ) document.getElementById('posx').value="";
                if( document.getElementById('posy') ) document.getElementById('posy').value="";
            }
        }
    }
    
    //function pageNext(page,p,x,y) {
    function pageNext(page) {
    	visualizza_attendi();
        document.getElementById('page').value = page;
        geocodeAddress(document.getElementById('prossimita').value, 'async');
    }
    
	// deprecated , viene mantenuta per compatibilita con i vecchi script
	function pulisci(str){
        //return ((str) ? str.replace(/[\s|\"*°#@]/g," ") : "");
        //return ((str) ? str.replace(/[%2c]/g,", ") : " ");
        return str;
	}
    
    function replaceAll(OldString,FindString,ReplaceString) {
        var SearchIndex = 0;
        var NewString = ""; 
        while (OldString.indexOf(FindString,SearchIndex) != -1)    {
            NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
            NewString += ReplaceString;
            SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);         
        }
        NewString += OldString.substring(SearchIndex,OldString.length);
        return NewString;
    }

    function showCat(tipo,showHide,n){
    	disp1 = 'none';
        disp2 = 'block';
    	if(showHide == "show"){
    		 disp1 = 'block';
    		 disp2 = 'none';
    	}
    	document.getElementById("altre"+tipo).style.display=disp2;
    	document.getElementById("nascondi"+tipo).style.display=disp1;
    	for(i=3;i<n;i++){
    		document.getElementById(tipo+"3"+i).style.display=disp1;
    	}
    }
    
    function showInfoWindow(codiceOPEC) {
        html = "<table cellpadding=\"0\" cellspacing=\"5\" border=\"0\"><tr><td class=\"wPadding5 bbCode11 grey001\" valign=\"top\" colspan=\"3\"><span class=\"orange002\"><strong>"+opecs[codiceOPEC].nome+"</strong></span><br/>";
        html += "</td></tr></table>";
        document.getElementById('tabber').style.visibility="visible";
    }
    
    /*function selectMarker(index) {
        if(markers && (index < markers.length) && (markers[index] != 'undefined') ) markers[index].select();
    }
    
    function deselectMarker(index) {
        if(markers && (index < markers.length) && (markers[index] != 'undefined') ) markers[index].deselect();
    }*/
    
    function checkData(nomeForm){
		var cosa = nomeForm.cosa.value;
		nomeForm.pagina.value = "";
		nomeForm.totPage.value = "";
		if(cosa == "es: ristorante" || cosa == ""){
			alert("Insérez un produit, un service ou une opération commerciale.");
			return false;
		}
		else if(cosa == "es: mario rossi" || cosa == ""){
			alert("Insérez le nom d'un professionnel ou d'une société.");
			return false;
		}
		else return true;
	}
	
	function Get_Cookie( name ) {
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) &&
		( name != document.cookie.substring( 0, name.length ) ) )
		{
		return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	}
	
	// script che visualizza un elemento nascosto
	function visualizza(id) {
        if (document.getElementById) {
            if(document.getElementById('+id+').style.display == 'none'){
               document.getElementById('+id+').style.display = 'block';
            } else {
               document.getElementById('+id+').style.display = 'none';
            }
        }
	}
    
    function zeroFields(form) {
        form.page.value = 1;
        form.lat.value="";
        form.lng.value="";
        form.cat.value="";
        form.posx.value="";
        form.posy.value="";   
    }
    
    function saveCoords(opec, lng, lat) {        
        var post = "opec="+opec+"&lat="+lat+"&lng="+lng;
        var xmlhttp = newXMLHttpRequest();

        if (xmlhttp!=null) { 
			xmlhttp.open("POST","/saveCoords.php",true); 
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");         
            xmlhttp.send(post);
        } else {
            alert("Votre navigateur ne lit pas XMLHttpRequest.");
        }    
    }    
    
// questa funzione conta il testo scritto nella textarea del commento, non deve superare i 200 caratteri
function conta(testo,val) {
       
    var x = testo.value;
	var ext = x.length;
	var ris = 200-ext;
	
	if (ris<0) {
			alert("Vous pouvez écrire 200 caractères maximum.");
			var shorter = x.slice(0,200); 
			document.getElementById(val).value = shorter;
	}
			
}

function readPost(opec, id) {

    var post = "opec="+opec;
   
    var xmlhttp = newXMLHttpRequest();

    if (xmlhttp!=null) {            
        xmlhttp.open("POST","/readPost.php",true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");         
        xmlhttp.onreadystatechange = handleResponse(xmlhttp, manageReadPost, ResponseType.html, id);
        xmlhttp.send(post);
    } else {
       alert("Votre navigateur ne lit pas XMLHttpRequest.");
    }
    
}

function manageReadPost(HTMLResult, id) {
       document.getElementById(id).innerHTML = HTMLResult;
}

/******************** voto pecorelle *****************************/
function setRate(voto,id) {
	var id		= (id==null) ? 0 : id;
	var opec 	= document.getElementById("codiceOPEC_"+id).firstChild.nodeValue;
	var numVoti = document.getElementById('num_voti_'+id).firstChild.nodeValue;
	var cookie	= getCookie("__co"+opec);
	var today	= new Date();  
	var expires	= new Date(); 
	
	if(!cookie) {
		setCookie("__co"+opec, voto, expires.setTime(today.getTime() + (1000*60*60)));
		var xmlhttp = newXMLHttpRequest();
		if (xmlhttp!=null) {
			xmlhttp.open("POST","/saveVoto.php",true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.send("opec="+opec+"&voto="+voto+"&num_voti="+numVoti);
			xmlhttp.onreadystatechange = handleResponse(xmlhttp, manageRate, ResponseType.html);            
		} 
		else {
			alert("Votre navigateur ne lit pas XMLHttpRequest.")
		}
	} 
}

function manageRate(HTMLResult) {
	document.getElementById("iakkeStarFeedBack").innerHTML = HTMLResult;
}
	
function rateItem(stars) {
	var id     = (id==null) ? 0 : id;
	var opec   = document.getElementById("codiceOPEC_"+id).firstChild.nodeValue;
	var cookie = getCookie("__co"+opec);
	if(!cookie) {
		eId = 'hidden_star_rating';
		if (stars != 0)
			document.getElementById(eId).value = stars;
		else
			document.getElementById(eId).value = '';
		showStars(stars);
	}
	else
		document.getElementById('iakkeStarBackgroundFooter').innerHTML = "Vous avez d&eacute;j&agrave; vot&eacute; !";
}

function showStars(stars, id ) {
  document.getElementById('currentStarRating').style.width= '' + (20 * stars) + '%';
}

function showStarsFromValue() {
  showStars(document.getElementById('hidden_star_rating').value);
}	
/******************* FINE voto pecorelle ***************************/


//inizializza oggetto goggle maps per calcolo itinerari
function initGmapItinerary(){
	if (GBrowserIsCompatible()) {
	            map_dir  = new GMap2(document.getElementById("map_directions"));
	            map_dir.addControl(new GSmallMapControl());            
	            map_dir.setCenter(new GLatLng(46.227638, 2.213749), 5);
	            
	            gdir     = new GDirections(map_dir, document.getElementById("directions"));
	            GEvent.addListener(gdir, "load", onGDirectionsLoad);
	            GEvent.addListener(gdir, "error", handleErrors);
	}
}

//menu area amministrazione
function mmenu(mID) {
	var menu = document.getElementById(mID);
	var display = menu.style.display;
	menu.style.display = (display == "block") ? "none" : "block";
	menu.parentNode.style.listStyleImage = (display == "block") ? "url(http://css.iakke.com/default/images/account/cartellachiusa.gif)" : "url(http://css.iakke.com/default/images/account/cartellaaperta.png)";
}

window.onload = function() {
	var uls = document.getElementsByTagName("ul");
	for (i=0;i< uls.length;i++) {
		if(uls[i].className=="submenu")uls[i].style.display = "none";
	}
}

function convertText(stringa) {
	if (stringa.lenght==0 )
		return '';         
	        
	char_err	= new Array("%2c",    "%2C",    "%27",    "%26",     "\"",   "\'",    "&nbsp;|",    "|",    "&nbsp;",        "+",         "&amp;",         "&gt;",      "&lt;",      "_"   , "#*#"       );
	char_exat	= new Array(", ",     ", ",    	"'",      "&amp;",	 "" , 	 "'",     " ", 	        " ", 	" ",             " ",         "&" 	,          " ",         " ",         " "   , ","     );
	
	stringa		= str_replace(char_err, char_exat, stringa);
	stringa 	= html_entity_decode(stringa,'ENT_QUOTES');
	
	return stringa;
}

/* Method convertTxtToUrl
     *
     * @param string str testo da convertire in url
     * @return stringa pronta per essere usata in una url
     */
    function convertTxtToUrl(string) {
    	
     	if (!(string) || string=='')
    		return '';         
    	var str			= utf8_decode(trim(string));	
		regexp			= new Array(" ", "'",	",", "(", ")", ":", ";", ".", "-", "\'", "\\"); 
		regsost 		= new Array("_", "_", 	"",	  "",  "",  "",  "",  "", "_", "_", "");
        str				= str_replace(regexp,regsost,str);
        str				= htmlentities(str);
		entities   		= new Array("&amp;", "&Agrave;", "&agrave;", "&Acirc;", "&acirc;", "&Aelig;", "&aelig;", "&Ccedil;", "&ccedil;", "&Eacute;", "&eacute;", "&Egrave;", "&egrave;", "&Ecirc;", "&ecirc;", "&Euml;", "&euml;", "&Icirc;", "&icirc;", "&Iuml;", "&iuml;", "&#140;", "&#156;", "&Ocirc;", "&ocirc;", "&Ugrave;", "&ugrave;", "&Ucirc;", "&ucirc;", "&Uuml;", "&uuml;", "&#159;", "&yuml;" );
        normal     		= new Array("e",     "A",        "a",         "A",      "a",       "A",       "a",       "C",        "c",        "E",        "e",        "E",        "e",        "E",       "e",       "E",      "e",      "I",       "i",       "I",      "i",      "O",      "o",      "O",       "o",       "U",        "u",        "U",       "u",        "U",     "u",      "Y",      "y"      );
        var string_app	= str_replace(entities, normal, str);
        string_app		= string_app.toLowerCase(); 
        string_app		= trim(string_app);
        
        string_app		= str_replace("&","e",string_app); 
        string_app		= html_entity_decode(string_app,'ENT_QUOTES');
        string_app		= string_app;
        return string_app;
    } 

function str_replace(search, replace, subject) {
    //      example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    //      returns 1: 'Kevin.van.Zonneveld'
    //      example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    //      returns 2: 'hemmo, mars'
 
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

function trim(string) {
	return string.replace(/^\s*([\S\s]*?)\s*$/,'$1');
}

// {{{ htmlentities
function htmlentities (string, quote_style) {
    // Convert all applicable characters to HTML entities
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_htmlentities/
    // +       version: 810.2018
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');
    // *     returns 1: 'Kevin &amp; van Zonneveld'

    var histogram = {}, symbol = '', tmp_str = '', i = 0;
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
    
    return tmp_str;
}// }}}

// {{{ html_entity_decode
function html_entity_decode( string, quote_style ) {
    // Convert all HTML entities to their applicable characters
    // 
    // -    depends on: get_html_translation_table
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'

    var histogram = {}, symbol = '', tmp_str = '', i = 0;
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    
    return tmp_str;
}// }}}

// {{{ get_html_translation_table
function get_html_translation_table(table, quote_style) {
    // Returns the translation table used by htmlspecialchars() and htmlentities()
    // 
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // %          note: Table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
    useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
    
    // Map numbers to strings for compatibilty with PHP constants
    if (!isNaN(useTable)) {
        useTable = constMappingTable[useTable];
    }
    if (!isNaN(useQuoteStyle)) {
        useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
    }
    
    if (useTable == 'HTML_SPECIALCHARS') {
        // ascii decimals for better compatibility
        entities['38'] = '&amp;';
        entities['60'] = '&lt;';
        entities['62'] = '&gt;';
    } else if (useTable == 'HTML_ENTITIES') {
        // ascii decimals for better compatibility
	    entities['38'] = '&amp;';
	    entities['60'] = '&lt;';
	    entities['62'] = '&gt;';
	    entities['160'] = '&nbsp;';
	    entities['161'] = '&iexcl;';
	    entities['162'] = '&cent;';
	    entities['163'] = '&pound;';
	    entities['164'] = '&curren;';
	    entities['165'] = '&yen;';
	    entities['166'] = '&brvbar;';
	    entities['167'] = '&sect;';
	    entities['168'] = '&uml;';
	    entities['169'] = '&copy;';
	    entities['170'] = '&ordf;';
	    entities['171'] = '&laquo;';
	    entities['172'] = '&not;';
	    entities['173'] = '&shy;';
	    entities['174'] = '&reg;';
	    entities['175'] = '&macr;';
	    entities['176'] = '&deg;';
	    entities['177'] = '&plusmn;';
	    entities['178'] = '&sup2;';
	    entities['179'] = '&sup3;';
	    entities['180'] = '&acute;';
	    entities['181'] = '&micro;';
	    entities['182'] = '&para;';
	    entities['183'] = '&middot;';
	    entities['184'] = '&cedil;';
	    entities['185'] = '&sup1;';
	    entities['186'] = '&ordm;';
	    entities['187'] = '&raquo;';
	    entities['188'] = '&frac14;';
	    entities['189'] = '&frac12;';
	    entities['190'] = '&frac34;';
	    entities['191'] = '&iquest;';
	    entities['192'] = '&Agrave;';
	    entities['193'] = '&Aacute;';
	    entities['194'] = '&Acirc;';
	    entities['195'] = '&Atilde;';
	    entities['196'] = '&Auml;';
	    entities['197'] = '&Aring;';
	    entities['198'] = '&AElig;';
	    entities['199'] = '&Ccedil;';
	    entities['200'] = '&Egrave;';
	    entities['201'] = '&Eacute;';
	    entities['202'] = '&Ecirc;';
	    entities['203'] = '&Euml;';
	    entities['204'] = '&Igrave;';
	    entities['205'] = '&Iacute;';
	    entities['206'] = '&Icirc;';
	    entities['207'] = '&Iuml;';
	    entities['208'] = '&ETH;';
	    entities['209'] = '&Ntilde;';
	    entities['210'] = '&Ograve;';
	    entities['211'] = '&Oacute;';
	    entities['212'] = '&Ocirc;';
	    entities['213'] = '&Otilde;';
	    entities['214'] = '&Ouml;';
	    entities['215'] = '&times;';
	    entities['216'] = '&Oslash;';
	    entities['217'] = '&Ugrave;';
	    entities['218'] = '&Uacute;';
	    entities['219'] = '&Ucirc;';
	    entities['220'] = '&Uuml;';
	    entities['221'] = '&Yacute;';
	    entities['222'] = '&THORN;';
	    entities['223'] = '&szlig;';
	    entities['224'] = '&agrave;';
	    entities['225'] = '&aacute;';
	    entities['226'] = '&acirc;';
	    entities['227'] = '&atilde;';
	    entities['228'] = '&auml;';
	    entities['229'] = '&aring;';
	    entities['230'] = '&aelig;';
	    entities['231'] = '&ccedil;';
	    entities['232'] = '&egrave;';
	    entities['233'] = '&eacute;';
	    entities['234'] = '&ecirc;';
	    entities['235'] = '&euml;';
	    entities['236'] = '&igrave;';
	    entities['237'] = '&iacute;';
	    entities['238'] = '&icirc;';
	    entities['239'] = '&iuml;';
	    entities['240'] = '&eth;';
	    entities['241'] = '&ntilde;';
	    entities['242'] = '&ograve;';
	    entities['243'] = '&oacute;';
	    entities['244'] = '&ocirc;';
	    entities['245'] = '&otilde;';
	    entities['246'] = '&ouml;';
	    entities['247'] = '&divide;';
	    entities['248'] = '&oslash;';
	    entities['249'] = '&ugrave;';
	    entities['250'] = '&uacute;';
	    entities['251'] = '&ucirc;';
	    entities['252'] = '&uuml;';
	    entities['253'] = '&yacute;';
	    entities['254'] = '&thorn;';
	    entities['255'] = '&yuml;';
    } else {
        throw Error("Table: "+useTable+' not supported');
        return false;
    }
    
    if (useQuoteStyle != 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    
    if (useQuoteStyle == 'ENT_QUOTES') {
        entities['39'] = '&#039;';
    }
    
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal)
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}// }}}

// {{{ utf8_encode
function utf8_encode ( string ) {
    // Encodes an ISO-8859-1 string to UTF-8
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_utf8_encode/
    // +       version: 811.1414
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}// }}}


// {{{ utf8_decode
function utf8_decode ( str_data ) {
    // Converts a string with ISO-8859-1 characters encoded with UTF-8   to single-byte
    // ISO-8859-1
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_utf8_decode/
    // +       version: 810.621
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = ac = c1 = c2 = c3 = 0;

    str_data += '';

    while ( i < str_data.length) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }

    return tmp_arr.join('');
}// }}}


// {{{ strpos
function strpos( haystack, needle, offset){
    // Find position of first occurrence of a string
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14

    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}// }}}

/**
 * Function  checkValidUrl
 * controlle se la url e' valida
 * 
 * @param strUrl string url da controllare
 * @param urlPrefix int se 1 la url e' del tipo http://www.miosito.it se 0 www.miosito.it 
 * 
 * return boolean true se ok false altrimenti
 */ 
function checkValidUrl(strUrl,urlPrefix) {
	if(urlPrefix==1) 
		var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	else
        var RegexUrl = /(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        
        return RegexUrl.test(strUrl);
}

function manageComment(id,az) {
	var today   = new Date();  
	var expires = new Date();
	var cookie  = getCookie("__co"+id+az);
	
	var post  = "id="+id;
    	post += "&az="+az;	
    	
	if(!cookie) {	
	 	xmlhttp = newXMLHttpRequest();
		if (xmlhttp!=null) { 
			setCookie("__co"+id+az, id+az, expires.setTime(today.getTime() + (1000*60*60))); 
			xmlhttp.open("POST","/manageComment.php",true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		    xmlhttp.setRequestHeader("Content-length",post.length);
			xmlhttp.onreadystatechange = handleResponse(xmlhttp, myComment, ResponseType.xml);
			xmlhttp.send(post);
		} else {
	        alert("Votre navigateur ne lit pas XMLHttpRequest.");
	    }	
	} else {
	      alert("Vous avez déjà voté !");
	}
}

function myComment() {
	alert("Merci pour la participation !");
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	    var html = xmlhttp.responseText;
		document.getElementById("visVoto").innerHTML = html;
	}
}

// ritorna 1 se la mail e' valida 0 altrimenti        
function isEmail(string) {
	string = trim(string);
	if(string=='') return 0
	var re = /^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|info|biz)$/;
  	if (re.test(string)) 
  		return 1;
	else 
		return 0;
}	

// ritorna 1 se la la stringa e un  num di telefono valido(es 02 22 34 55 opp 02223455) 0 altrimenti        
function isTelefono(num_tel) {
	 var regex = new RegExp(/^(01|02|03|04|05|06|07|08|09)[0-9]{8}/gi);
	 if(regex.test(num_tel))
	 	return 1
	 else
		return 0	
} 

function checkUrl404(url) {
	var post	= "server="+url;
    var async	= false; // eseguo chiamata sincrona
 	xmlhttp = newXMLHttpRequest();
	if (xmlhttp!=null) { 
		xmlhttp.open("POST","/check_url404.php",async);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    xmlhttp.setRequestHeader("Content-length",post.length);
	    if(async==true){xmlhttp.onreadystatechange = handleResponse(xmlhttp, checkUrl404Handler, ResponseType.html);}
		xmlhttp.send(post);
		if(!async){	checkUrl404Handler(xmlhttp.responseText);}
	} else {
        alert("Votre navigateur ne lit pas XMLHttpRequest.")
    }	
}

function checkUrl404Handler(HTMLResult) {
	if(HTMLResult.indexOf('ok')>-1){
		document.getElementById('urlcheck').value = 1;
	}
	else {
		document.getElementById('urlcheck').value = 0;
	}
} 

function GoToUrlByParams(url,target,opec,action,utente) {
    if(opec!=null && action!=null && utente!=null) {
		url += "?"+ "opec=" + opec + "&action=" + action + "&utente=" + utente;
	} else if(opec!=null && action!=null) {
		url += "?"+ "opec=" + opec + "&action=" + action;
	} else if(opec!=null && action==null) { 
		url += "?"+ "opec=" + opec;
	} 				
	GoToUrl(url,target);	
}

// funzione per la validazione del tag target dell'href
function externalLinks() {
	 if (!document.getElementsByTagName) return;
	 var anchors = document.getElementsByTagName("a");
	 for (var i=0; i< anchors.length; i++) {
	   var anchor = anchors[i];
	   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
	     anchor.target = "_blank";
	 }
}

window.onload = externalLinks;

function separaNumTel(str) {
	var  numero = trim(str);
	var _numero = "";
	for( var j = 0; j < numero.length ; j+=2 ) {
		_numero += numero.substr(j, 2)+" ";
	}
	return _numero;
} 
 
function removeElement(arr,elem) {
	var i = 0;
	for (i=0; i < arr.length; i++)	
		if(arr[i]==elem) {
			arr.splice(i,1);
			break;
		}
	return arr;
}

function addElement (arr,elem) {
	var i = 0;
	for (i=0; i < arr.length; i++)	if(arr[i]==elem) return arr
	arr[arr.length] = elem;
	return arr;
}

/**
redirect by form.submit
params:
	url  string 
	aInputHidden associative array for input hidden default null 
	idForm string default fredir
	method string default post
*/	
function redirectByForm(url, aInputHidden, idForm,  method) {
	var formInput 	= null;
	var form 		= document.createElement('form');
	idForm = (typeof(idForm)!='undefined') ? idForm : 'fredir';
	form.name 		= idForm; 
	form.id 		= idForm;
	form.action 	= url;
	form.method		= (method==null || method=='') ? "post" : method;
	if(typeof(aInputHidden)!='undefined') {
		for(var key in aInputHidden) {
			formInput 		= document.createElement("input");
			formInput.type 	= "hidden";
			formInput.name 	= key;
			formInput.id 	= key;
			formInput.value = aInputHidden[key];
			form.appendChild(formInput);
			formInput 	= null;
		}
	}
	document.body.appendChild(form);
	
	document.forms[idForm].submit();
}

 // {{{ in_array
function in_array(needle, haystack, strict) {
    // Checks if a value exists in an array
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true

    var found = false, key, strict = !!strict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}// }}} 	


function strToHash(str, elemSeparator, fieldSeparator) {
	if(elemSeparator==null) elemSeparator = '=';
	if(fieldSeparator==null) fieldSeparator = '&';
	var aField		= new Array();
	var aElem		= new Array();
	var aElemTemp 	= str.split(elemSeparator);
	for(i=0; i < aElemTemp.length; i++) {
		aField 			= aElemTemp[i].split(fieldSeparator);
		aElem[aField[0]]= aField[1];
	}
	return aElem;
}

function array_unique( array ) {
    // Removes duplicate values from array  
    // 
    // version: 905.3122
    // discuss at: http://phpjs.org/functions/array_unique
    // +   original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
    // +      input by: duncan
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nate
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Michael Grier
    // %          note 1: the second argument, sort_flags is not implemented
    // *     example 1: array_unique(['Kevin','Kevin','van','Zonneveld','Kevin']);
    // *     returns 1: ['Kevin','van','Zonneveld']
    // *     example 2: array_unique({'a': 'green', 0: 'red', 'b': 'green', 1: 'blue', 2: 'red'});
    // *     returns 2: {'a': 'green', 0: 'red', 1: 'blue'}
    
    var key = '', tmp_arr1 = {}, tmp_arr2 = {};
    var val = '';
    tmp_arr1 = array;
    
    var __array_search = function (needle, haystack) {
        var fkey = '';
        for (fkey in haystack) {
            if ((haystack[fkey] + '') === (needle + '')) {
                return fkey;
            }
        }
        return false;
    };

    for (key in tmp_arr1) {
        val = tmp_arr1[key];
        if (false === __array_search(val, tmp_arr2)) {
            tmp_arr2[key] = val;
        }
        
        delete tmp_arr1[key];
    }
    
    return tmp_arr2;
}



//abilita/disabilita i campi di un form
// aFields array con nomi dei campi
// type string (disable|enable)
function setField(aFields, type){
	for(i=0; i < aFields.length; i++)
 		document.getElementById(aFields[i]).disabled = (type=='disable') ? true : false;
}

//visualizza/nasconde gli elementi di una pagina
// aFields array con nomi dei campi
// type string (display|hidden)
function setHtmlElement(aFields, type){
	for(i=0; i < aFields.length; i++) {
		if(document.getElementById(aFields[i])!=null)
 			document.getElementById(aFields[i]).style.display = (type=='display') ? "" : "none";
 	}
}

function checkCampoObblig(id) {
	if(document.getElementById(id).type=='checkbox') {
		if(document.getElementById(id).checked==false)
			setImgKo(id, "Certains champs ne sont pas remplis correctement");
		else
			setImgOk(id);
	}
	else if(document.getElementById(id).type=='select-multiple') {
		if(document.getElementById('catRight').options.length == 0){
			setImgKo(id,"Certains champs ne sont pas remplis correctement");
		}
		else{
			setImgOk(id);
		}
	}
	else {
		if ((document.getElementById(id).value=='')||(document.getElementById(id).value==' ')||(document.getElementById(id).value=='0') )
			setImgKo(id, "Certains champs ne sont pas remplis correctement");
		else
			setImgOk(id);
	}
}
 
function checkSelectCombo(id) {
			
	if ((document.getElementById(id)) && document.getElementById(id).selectedIndex == "")
        setImgKo(id, "Certains champs ne sont pas remplis correctement");
	else
		setImgOk(id);
}

function custLog(x,base) {
	// Created 1997 by Brian Risk.  http://brianrisk.com
	return parseFloat(parseFloat(Math.log(x))/parseFloat(Math.log(base)));
}


function sortNumber(a,b){
	return a - b;
}

// ordina gli elementi dell'array A in maniera decrescente 
//e ritorna un array B con gli indici di A 
function sortKey(inputArr) {
	var i,j		= 0;
	var keyArr = new Array();
	var tmpArr = new Array();
	var tmpArrNoDup = new Array();
	i=0;
	while(i < inputArr.length){
		tmpArr[i] = inputArr[i];
		i++;
	}
	tmpArr.sort(sortNumber);
	h=0;
	for(var val in tmpArr){
		tmpArrNoDup[h] = tmpArr[val];
		h++;
	}
	var max = tmpArrNoDup.length;
	i= 0;
	while(i<max){
		j=0;
		while(j < max) {
			if(inputArr[j]==tmpArrNoDup[max-(i+1)]) {
				keyArr[i] = j;
			}
			j++;
		}
		i++;
	}
	return keyArr;
}

// INIZIO box di ricerca per booking
function zeroFieldsBok(form) {
        form.page_bok.value = 1;
        form.lat_bok.value="";
        form.lng_bok.value="";
        form.cat_bok.value="";
        form.posx_bok.value="";
        form.posy_bok.value="";   
}

function geocodeAddressBok(address, method) {
	if (document.getElementById("search_booking").dove_bok.value=="") {
             alert("Vous devez préciser un ville.");
	} else {
        if (method == 'async') {
			getListingBok();
		} else {
			visualizza_attendi();
			document.getElementById("search_booking").submit();
		}
    }
}


function getListingBok() {

	if (document.getElementById("search_booking").dove_bok.value=="") {
        alert("Vous devez préciser un ville.");
	} else {
    	visualizza_attendi();
        var post =   "cosa="   		 + encodeURI( document.getElementById("search_booking").cosa_bok.value ? document.getElementById('search_booking').cosa_bok.value : "" ) +
                     "&dove="        + encodeURI( document.getElementById("search_booking").dove_bok.value ? document.getElementById('search_booking').dove_bok.value : "" ) +
                     "&page="        + encodeURI( document.getElementById("search_booking").page_bok.value ? document.getElementById('search_booking').page_bok.value : "" ) +
                     "&lat="         + encodeURI( document.getElementById("search_booking").lat_bok.value ? document.getElementById("search_booking").lat_bok.value : "" ) +
                     "&lng="         + encodeURI( document.getElementById("search_booking").lng_bok.value ? document.getElementById("search_booking").lng_bok.value : "" ) +
                     "&lato="        + encodeURI( document.getElementById("search_booking").lato_bok.value ? document.getElementById("search_booking").lato_bok.value : "" ) +
                     "&cat="         + encodeURI( document.getElementById("search_booking").cat_bok.value ? document.getElementById("search_booking").cat_bok.value : "" ) +
                     "&codiceistat=" + encodeURI( document.getElementById("search_booking").istat_bok.value ? document.getElementById("search_booking").istat_bok.value : "" ) +
                     "&usa_dove="    + encodeURI( document.getElementById("search_booking").usa_dove_bok.value ? document.getElementById("search_booking").usa_dove_bok.value : "" )+
                     "&template="    + encodeURI( document.getElementById("search_booking").template_bok.value ? document.getElementById("search_booking").template_bok.value : "" ) +
                     "&p="           + encodeURI( document.getElementById("search_booking").p_bok.value ? document.getElementById('search_booking').p_bok.value : "" )+
                     "&rp="          + encodeURI( document.getElementById("search_booking").rp_bok.value ? document.getElementById("search_booking").rp_bok.value : "" );
                     
		var xmlhttp = newXMLHttpRequest();
        if (xmlhttp!=null) {    
            xmlhttp.open("POST","/getListing.php",true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send(post);
            xmlhttp.onreadystatechange = handleResponse(xmlhttp, manageListingBok, ResponseType.html);
        } else {
            alert("Votre navigateur ne lit pas XMLHttpRequest.");
        	nascondi_attendi();
        }
	}    
}

function manageListingBok(HTMLResult){

		nascondi_attendi();
		var cosa = document.getElementById("search_booking").cosa_bok.value ? document.getElementById('search_booking').cosa_bok.value : ""; 
        var dove = document.getElementById("search_booking").dove_bok.value ? "-"+document.getElementById('search_booking').dove_bok.value : "";
        var page = document.getElementById("search_booking").page_bok.value ? document.getElementById('search_booking').page_bok.value : "" ;
       
        pageTracker._trackPageview("/listing_booking/"+cosa.replace(/\s/i, "_")+dove.replace(/\s/i, "_")+"/index_"+page+".htm"); //tracking per analytics
        
        document.getElementById("colonna_cx").innerHTML = HTMLResult;
        if(document.getElementById("column_up_left_inside")!=null)
        	document.getElementById("column_up_left_inside").innerHTML = "Carte des r&eacute;sultats";
        loadMarkers();
}

// FINE box di ricerca per booking

function visScheda() {
	//non deve fare nulla
}

function vis_scheda() {
	//non deve fare nulla
}