/**
 * @author De Lazzari Alberto UbiEst SPA
 *  
 * Modificato da Glamm per consentire l'interfacciamento con le mappe di Google
 * E' stato conservato solo il codice che gestisce l'interfaccia (tutto cio' che non e' mappa quindi)
 *
 * Libreria con tutte le funzioni necessarie alla comunicazione tra pagina esterna e mappa
 * Il file e' composto da vecchie funzioni risistemate per il nuovo template, alcune sono state
 * eliminate e/o completamente riviste. Alcune funzioni sono state aggiunte per permettere la 
 * comunicazione tra pagina esterna e mappa.
 * 
 * Alcune librerie presenti in precedenza (template.js, config.js) sono state completamente eliminate.
 */

var country_combo=true;
var region_combo=false;
var prov_combo=false;

var fname='';
var ftype='';
var fid='';

var areaSelezionata = '';

/**
 * Filtro per estrazione poi
 */
var poiFilter = '';

var StopLayerView=false;

var startWaypoint = null;
var endWaypoint = null;

/**
 * Codici relativi ai tab superiori
 */

var icons_code = {
    "eventi": "piu_eventi",
    "musei": "piu_musei",
    "monumenti": "piu_monumenti",
    "natura": "piu_natura",
    "itinerari": "piu_itinerari",
    "mangiarebere": "piu_mangiarebere",
    "dormire": "piu_dormire",
    "infoutili": "piu_infoutili",
    "milanomese": "piu_milanomese"
};

/**
 * Riferimento al wrapper che attiva le funzioni del Template e permette di far comunicare mappa e menu esterni.
 */

var mapWrapper = null;

//	Riferimento al pacchetto dojo caricato dal Template
var _dojo = null;

//	Riferimento alla pachetto ubiest del Template
var _ubiest = null;

/**
 * Variabile globale di comunicazione, utilizzata per passare parametri o definire estensioni per il Template
 * Nel campo func sono definite alcune funzione extra da chimare all'interno del Template;
 * nel caso specifico la funzione onLoad e' richiamata alla fine del caricamento del Template.
 *
 * Ad es. In questo caso all'onload del Template e' passato come parametro la variabile che punterÃ  all'ubiListener
 * (il modulo di comunicazione tra Template ed ambiente esterno). All'interno della funzione sarÃ  inizializzata
 * questa variabile e volendo si potrebbero aggiungere chiamate alle funzioni dell'ubiListener.
 */
var ubiMapSharedVar = {
    func: {}
};

initialize = function() {
    ubiMapSharedVar.func.onLoad = function(){
        //	Se non e' gia' stata definita una variabile globale, allora la definisco.
        //	Questa funzione e' chiamata dentro al frame percio' devo accedere al parent.
        /*if (!parent.mapWrapper) {
            parent.mapWrapper = {};
        }*/
        
	var _parent;
        try {
            for (var i = 0; i < frames.length; i++) {
                if (frames[i].mainMap) {
                    _parent = frames[i];
					_parent.mapWrapper = frames[i].ubiListener;
					_parent._dojo = frames[i].dojo;
					_parent._ubiest = frames[i].ubiest;
                }
            }
        } 
        catch (e) {
            alert("Security Error")
        }
        
        if (!_parent.mapWrapper) {
            return;
        }
		    	
        if (!_parent.changeLang) {
			_parent.parent.mapWrapper = _parent.mapWrapper;
			_parent.parent._dojo = _parent._dojo;
			_parent.parent._ubiest = _parent.ubiest;
			
			_parent.parent.changeLang(lang);
			_parent.parent.GetIt('data/dynamic.jsp', parent.lang);
			_parent.parent.caricaMilanoMese();
			_parent.parent.setHttpCategoryPVMI();
						
			_parent.parent.loadResources();
		}
		else {
			_parent.changeLang(lang);
			_parent.GetIt('data/dynamic.jsp', parent.lang);
			_parent.caricaMilanoMese();
			_parent.setHttpCategoryPVMI();
			
			_parent.loadResources();
		}
	}
}

function loadResources(){
	var doc = document;
	var script = doc.createElement("SCRIPT");
	script.src = "1.2.3/js/glamm/listaPOI.js";
	var head = doc.getElementsByTagName("HEAD")[0];
	head.appendChild(script);
}

/**
 * Funzione che controlla i parametri passati da URL.
 * Gestisce il passaggio da URL di POI o percorsi che devono essere attivi dall'inizio.
 * 1 - Chiamata di esempio per un percorso: additionalPathLayer=0999033995;2157682;1457538;2165808;1478751
 * 2 - Chiamata di esempio per dei POI: filter=114,116:piu_eventi
 */

//	Con le modifiche fatte per il caricamento, 
//	questa funzione puo' essere chiamata due volte e invece deve essere chiamata una volta sola.

var paramsChecked = false;

function checkParameters(){
    if (paramsChecked) {
        return;
    }
		
	var querystring = location.search;
    if (querystring) {
		params = querystring.split("?");
		params = params[1].split("&");
		
		var default_load = true;
		for (var k in params) {
			var arr_var = params[k].split("=");
			if (arr_var[0] == "additionalPathLayer") {
				var args = arr_var[1].split(";");
				var additionalLayer = "";
				/**
				 * Imposto l'additional layer relativo al percorso che ho passato come parametro
				 */
				additionalLayer += "<PATH ID=\"" + "0.9603." + args[0] + "\"/>";
				mapWrapper.addAdditionalLayer(additionalLayer);
				
                GetIt2('data/combo.jsp', 'itinerari', lang);
                changearea('itinerari');
                var el = document.getElementById(arr_var[1]);
				if (el) {
					el.checked = true;
				}
				//setPoiCategory('mostrapercorsi', 'ITINERARI', 'itinerari');
                /**
                 * Imposto i bound della mappa.
                 */
                setTimeout(function(){
                    mapWrapper.setBoundaryMap(args[1], args[2], args[3], args[4]);
                }, 1);
                default_load = false;
			}
            if (arr_var[0] == "guide") {
                setTimeout("visible_help()", 200);
            }
			
			if (arr_var[0] == "filter") {
				var pois = arr_var[1].split(";");
				var extra = "";
				for(var p in pois){
					var els = pois[p].split(":");
					if (els.length == 4) {
						extra += "<EXTRA " + els[3] + "=\"";
						var keywords = els[0];
						var multi = els[1];
						keywords = keywords.split(",")
												
						for (var k in keywords) {
							if (k == keywords.length - 1) 
								extra += keywords[k] + "\" MULTY=";
							else 
								extra += keywords[k] + ",";
						}
						extra += "\"" + multi + "\">";
						
						GetIt2('data/combo.jsp',els[2],lang);
						changearea(els[2]);
                        var checkbox = document.getElementById(keywords);
                        if (checkBox) {
                            checkbox.checked = true;
                        }
					}
				}
				default_load = false;
				/**
				 * Imposto il filter per la richiesta POI
				 */
				mapWrapper.setPOIFilter({
                    broker: '3145.1.Tt4jZa',
                    filter: extra
                });
                mapWrapper.setPOI({
                    value: true,
                    broker: '3145.1.Tt4jZa',
                    groups: ["GRP1"],
		    force: true
                });
			}
			
			if(arr_var[0] == "itinerary")	{
				var args = arr_var[1].split(";");
				GetIt2('data/combo.jsp', 'itinerari', lang);
                changearea('itinerari');
                var el = document.getElementById(arr_var[1]);
				if (el) {
					el.checked = true;
				}
				
				var pathid = args[0].substring(5);
				mapWrapper.getItinerary(pathid);
				
				default_load = false;
			}
		}
		
		if( default_load ){
			GetIt2('data/combo.jsp','eventi',lang);
			changearea('eventi');
		}
	}
}

function setPoiFromCheck(fname, stype, datafrom, datato, periodoSt) {

    if (fobj = document.forms[fname]) {

        category = '';

        // analizziamo tutti i checkbox contenuti sulla form 
        // dobbiamo stabilire quelli attivi e capire come comporre
        // la richiesta da inviare 
        for (var i = 0; i < fobj.elements.length; i++) {
            chkb = fobj[i];
            if (chkb.type == "checkbox" && chkb.checked) {                 
                // Prendiamo in esame solo i checkbox padre: li possiamo riconoscere in quanto hanno un value (coincide con l'id per altro).
                // se non hanno figli allora va preso il loro id
                // se hanno figli e questi sono tutti selezionati allora va preso l'id del padre (che puo' contenere qualche elemento in piu')
                // se hanno figli e solo alcuni selezionati allora va preso il concatenamento dei corrispondenti id
                if (chkb.value != '') {
                   // stabiliamo il numero sotto ckbox di quello in esame
                   figliCheck = chkb.parentNode.getElementsByTagName('input');
                   if (figliCheck.length == 1) {
                       // se stesso, quindi prendiamo il suo id
                       category += chkb.id + ",";
                   } else {
                       // verifichiamo i figli selezionati e recuperiamo i loro id
                       almenoUnoNonSelezionato = false;
                       subCategory = '';
                       for (j = 1; j < figliCheck.length; j++) {
                          if (!figliCheck[j].checked)
                              almenoUnoNonSelezionato = true;    
                          if (figliCheck[j].checked) 
                              subCategory += figliCheck[j].id + ",";
                       }
                       // usiamo i dati recuperato
                       if (almenoUnoNonSelezionato)
                           category += subCategory;
                       else
                           category += chkb.id + ",";
                   }
                   
                } 

            }
        }                
        
        var params = '<EXTRA ' + stype + '="' + category.substring(0, category.length - 1) + '"';
        var iconname = icons_code[currentarea];
        
        if (iconname != undefined) 
            params += ' MULTY="' + iconname + '"';
        
        if (datafrom && datafrom != "") 
            params += datafrom;
        
        if (datato && datato != "") 
            params += datato;
        
        if (periodoSt && periodoSt != "") 
            params += periodoSt;

        if (currentarea  &&  currentarea != "")
            params += " area=\"" + currentarea + "\" ";
        
        params += '/>';
        
	poiFilter = params;

        //alert(poiFilter);
        

        if (!datafrom) datafrom = "";
        if (!datato) datato = "";
        if (!periodoSt) periodoSt = "";

        var comune = "";
        if (document.getElementById("dove") != null) {
            var arr_comune = document.getElementById("dove").value.split(",");
            comune = arr_comune[0];
        }

        // stabiliamo se passare anche i parametri del vicino a
        var nearlat = 0.0;
        var nearlon = 0.0;
        var neardistance = 0.0;  
        var arr_dove = document.getElementById("dove").value.split(",");
        if ( (arr_dove[0] == 'Milano') && (document.getElementById("near2").value!='Vicino a...') ) {
           arr_values = document.getElementById("near2").value.split(",");
           nearlat = arr_values[1];  
           nearlon = arr_values[2];		 
            // dovrebbe essere entro 1 km dal punto indicato
	    if (stype=="ALBERGHI") neardistance = 1500; else neardistance = 1000;
            //alert(nearlat+','+nearlon+','+stype+','+category+','+neardistance);
        }
	
        // invochiamo il metodo della mappa che visualizza i poi richiesti
        if (document.getElementById('mapBrokerFrame').contentWindow.showPoisOnInteractiveMap) {
            //alert(stype+','+category+','+iconname+','+datafrom+','+datato+','+periodoSt+','+currentarea+','+comune+','+nearlat+','+nearlon+','+neardistance);
            document.getElementById('mapBrokerFrame').contentWindow.showPoisOnInteractiveMap(stype,category,iconname,datafrom,datato,periodoSt,currentarea,comune,nearlat,nearlon,neardistance);
        } else
            alert('manca showPoisOnInteractiveMap');
    }
}


/**
 * Refresh delle categorie POI al cambiamento dei Tab superiori
 */

var currentarea = '';

function setPoiCategory(fname, stype, newarea)
{
    var params = "";
	if (newarea == currentarea) 
        return;
    else 
        currentarea = newarea;
    
    setPoiFromCheck(fname,stype);
}

var curr_fname = "";
var curr_stype = "";

/**
 * Funzione attivata al check/uncheck di una qualsiasi categoria sulla spalla di destra
 * @param {Object} fname
 * @param {Object} stype
 */

function setPoiCategoryCk(fname, stype) {

    if (fname == "" || stype == "") 
        return;
    
    var params = "";
    curr_fname = fname;
    curr_stype = stype;
    
    if (currentarea == "") 
        currentarea = "eventi";
    
    var datafrom = "";
    var datato = "";
    var from = false;

    /* eventuale filtro per data */
    
    periodoSt = "";
    if (document.getElementById("periodoStoricoArtistico") != null) {
        if (document.getElementById("periodoStoricoArtistico").value != "") 
            periodoSt = ' P_ST="' + document.getElementById("periodoStoricoArtistico").value + '"';
    }
    

    /*

    if (document.getElementById("isg") != null) {
    
        if ((dd = document.getElementById("isg").value) != "" &&
        (mm = document.getElementById("ism").value) != "" &&
        (yy = document.getElementById("isa").value) != "") {
            datafrom = yy + '-' + mm + '-' + dd;
            datato = yy + '-' + mm + '-' + dd;
        }
        else 
            if ((dd = document.getElementById("dag").value) != "" &&
            (mm = document.getElementById("dam").value) != "" &&
            (yy = document.getElementById("daa").value) != "") {
                datafrom = yy + '-' + mm + '-' + dd;
                from = true;
            }
        
        if ((dd = document.getElementById("ag").value) != "" &&
        (mm = document.getElementById("am").value) != "" &&
        (yy = document.getElementById("aa").value) != "" &&
        from) {
            datato = yy + '-' + mm + '-' + dd;
            
        }
        
    }

    */


     if (document.getElementById("datafrom") != null) {
           arr_values =document.getElementById("datafrom").value.split("/");
           if (arr_values.length==3) {
                datafrom = arr_values[2]+"-"+arr_values[1]+"-"+arr_values[0];
           }
     }
    

     if (document.getElementById("datato") != null) {
           arr_values =document.getElementById("datato").value.split("/");
           if (arr_values.length==3) {
                datato= arr_values[2]+"-"+arr_values[1]+"-"+arr_values[0];
           }             
     }


    setPoiFromCheck(fname,stype,datafrom,datato,periodoSt);
}

function setCheckCategory(broker, obj){
    if (!obj.checked) {
        //hide category
        mapWrapper.setPOI({
            value: false,
            broker: '3145.1.Tt4jZa',
            groups: ["GRP1"]
        });
    }
    else {//show category                
        mapWrapper.setPOI({
            value: true,
            broker: '3145.1.Tt4jZa',
            groups: ["GRP1"]
        });
    }
}

/**
 * Funzione di utilita' per MilanoMese
 */

function caricaMilanoMese(){
    if (querystring) {
        if (testParametroMilanoMese != 3) //GetIt e GetIt2 non sono state completate nell'onload
        {
            setTimeout("caricaMilanoMese()", 1000);
        }
        else {
            for (k = 0; k < params.length; k++) {
                if (params[k] == 'milanomese=1') {
                    milanomese();
                    check_key_cat_milanomese();
                    GetIt2('data/combo.jsp', 'milanomese', lang);
                    
                    break;
                }
            }
        }
    }
}

/**
 * Funzione di utilita' per MilanoMese
 */

function check_key_cat_milanomese(){
    var myparameter = document.getElementById("milanomese");
    
    if (!myparameter) {
        return;
    }
	
    var listCkeck = myparameter.getElementsByTagName("input");
    
    for (i = 0; i < listCkeck.length; i++) {
        if (listCkeck.item(i).type == 'checkbox') 
            listCkeck.item(i).checked = true;
    }
    
    setTimeout("setPoiCategory('formmilanomese','CATEGORIE','milanomese')", 1000);
}


/**
 * Funzione di switch per i tab superiori, determina il nodo in base ad un parametro numerico
 * @param {Object} parameter
 */

function check_key_cat(parameter) {

    var myparameter;

    switch (parameter) {
        case 1:
            myparameter = document.getElementById("eventi");
            break;
        case 2:
            myparameter = document.getElementById("musei");
            break;
        case 3:
            myparameter = document.getElementById("monumenti");
            break;
        case 4:
            myparameter = document.getElementById("natura");
            break;
        case 5:
            myparameter = document.getElementById("dormire");
            break;
        case 6:
            myparameter = document.getElementById("itinerari");
            break;
        case 7:
            myparameter = document.getElementById("infoutili");
            break;
        case 8:
            myparameter = document.getElementById("milanomese");
            break;
        case 9:
            myparameter = document.getElementById("mangiarebere");
            break;
        case 10:
            myparameter = document.getElementById("comuni");
            break;
        default:
            myparameter = document.getElementById("eventi");
            break;
    }
    
    var listCheck = myparameter.getElementsByTagName("input");
    
    for (i = 0; i < listCheck.length; i++) 
        if (listCheck.item(i).type == 'checkbox' && listCheck.item(i).checked) 
            return true;

    alert(l_warn_cat);	
    return false;	
}


// 04.05.2010 Mark 
// ho commentato il codice in modo da capire come si comporta il sistema

function menu(x) {
    // Seleziona i tag ul del nodo padre. Nel caso di ckbox del primo livello questo 
    // e' vuoto, mentre nel caso di ckbox del secondo livello contiene tutti i fratelli 
    // dell'elemento in esame
    objUL = x.parentNode.getElementsByTagName('ul');
    
    if (x.checked) {
        // il nodo è stato attivato (e' stato apposto il segno di spunta)
        // se si tratta di un nodo padre vanno visualizzati tutti i figli e attivati

        // il nodo è padre, quindi visualizziamo i figli
        if (objUL.length != 0) 
            objUL[0].style.display = 'block';

        // prendiamo tutte le checkbox contenute
        mycheck = x.parentNode.getElementsByTagName('input');
        
        // attiviamole
        for (i = 0; i < mycheck.length; i++) {
            mycheck[i].checked = true;
        }
    }
    else 
    {
        // il nodo e' stato disattivato (e' stato eliminato il segno di spunta)
        // se si tratta di un nodo padre vanno nascosti tutti i figli e disattivati

        // il nodo è padre, per cui nascondiamo i figli
        if (objUL.length != 0) 
            objUL[0].style.display = 'none';
        
        // recuperiamo tutte le checkbox contenute
        mycheck = x.parentNode.getElementsByTagName('input');
        
        // disattiviamo le checkbox
        for (i = 0; i < mycheck.length; i++) {
            mycheck[i].checked = false;
        }
    }
}

/**
 * Modifica la lingua della pagina
 * @param {Object} lang
 */
function changeLang(lang){

    if (lang == 'ENG') {

        document.getElementsByTagName("link")[2].href = "./style/lang_en.css";
        
         /*
        var Xpthtype = document.getElementById('Xpthtype');

        if (Xpthtype != null) {
            Xpthtype.options[0].text = 'Fastest without highway';
            Xpthtype.options[1].text = 'Shortest without highway';
            Xpthtype.options[2].text = 'Fastest with highway';
            Xpthtype.options[3].text = 'Shortest with highway';
            Xpthtype.options[4].text = 'Pedestrian';
        }
        */
        
        selectComuni = document.getElementById('dove');
        
        if (selectComuni != null) 
            selectComuni.options[0].text = 'Municipality';
    }
    else {
        document.getElementsByTagName("link")[2].href = "style/lang.css";
        document.getElementById('subtestalino').background = "../img/visita_milano.gif";
    }
}

function GetIt2(url, param, lang){
    try {
    
        if (lang == 'ENG') {
            document.getElementById('lang').value = "ENG";
            mylang = 'ENG';
        }
        else 
            if (lang == 'ITA') {
                document.getElementById('lang').value = "ITA";
                mylang = 'ITA';
            }
            else {
            
                mylang = document.getElementById('lang').value;
            }
        
        var xmlhttp = FactoryXMLHttpRequest();
        
        if (xmlhttp) {
            xmlhttp.open('GET', url + "?param=" + param + "&lang=" + mylang, true);
            xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("avanzata").innerHTML = xmlhttp.responseText;

  	            $('.date-pick').datePicker({startDate:'01/01/1990',clickInput:true}).val(new Date().asString()).trigger('change');                             

                    testParametroMilanoMese |= 2;
                }
            }
            
            xmlhttp.send(null);
        }
        
    } 
    catch (e) {
    }
}

function GetIt(url, lang){
    try {
        var xmlhttp = FactoryXMLHttpRequest();
        
        if (xmlhttp) {
            xmlhttp.open('GET', url + "?lang=" + lang, true);
            xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("me").innerHTML = xmlhttp.responseText;
                    changearea('eventi');
                                        
                    testParametroMilanoMese |= 1;
					
                    /**
                     * Il controllo per determinare se ci sono itinerari attivi all'inizio oppure categorie di POI attive
                     * e' meglio che sia effettuato qui piuttosto che a livello di parsing di parametri nel template, poiche'
                     * c'e' la necessita' di attivare determinati checkbox che sono esterni al template stesso.
                     */
                    //setTimeout(checkParameters, 1500);
					checkParameters();
                }
                setHttpCategoryPVMI();
            }
            
            xmlhttp.send(null);
        }
        
    } 
    catch (e) {
    }
}

function selectall(valore_id){
    input_ = document.getElementById(valore_id).getElementsByTagName('input');
    for (y = 0; y < input_.length; y++) {
        input_[y].checked = true;
    }
}

function deselectall(valore_id){
    input_ = document.getElementById(valore_id).getElementsByTagName('input');
    for (y = 0; y < input_.length; y++) {
        input_[y].checked = false;
    }
}

function visible_cerca() {
     /*
    document.getElementById("rightcol").style.display = "none";
    document.getElementById("container_cerca").style.display = "block";
    document.getElementById("container_mappa").style.display = "none";
    document.getElementById("container_help").style.display = "none";
    document.getElementById("rightcol_risultati").style.display = "block";
    document.getElementById("container_invita_").style.display = "none";
    document.getElementById("percorso_testuale").style.display = "none";
    */
    if (document.getElementById('mapBrokerFrame').contentWindow.flickPercorsoIndirizzoControl) 
        document.getElementById('mapBrokerFrame').contentWindow.flickPercorsoIndirizzoControl(); 
    else 
       alert('no function');      
}

function visible_invita(){
    document.getElementById("rightcol").style.display = "none";
    document.getElementById("container_cerca").style.display = "none";
    document.getElementById("container_mappa").style.display = "none";
    document.getElementById("container_help").style.display = "none";
    document.getElementById("rightcol_risultati").style.display = "none";
    document.getElementById("percorso_testuale").style.display = "none";
    document.getElementById("container_invita_").style.display = "block";
}

function visible_help(){
    document.getElementById("rightcol").style.display = "none";
    document.getElementById("container_cerca").style.display = "none";
    document.getElementById("container_mappa").style.display = "none";
    document.getElementById("container_help").style.display = "block";
    document.getElementById("extrainfo").style.margin = "0 10px 0 0";
    document.getElementById("container_invita_").style.display = "none";
	document.getElementById("percorso_testuale").style.display = "none";
}

function hide_help(){
    document.getElementById("rightcol").style.display = "";
    document.getElementById("container_cerca").style.display = "none";
    document.getElementById("container_mappa").style.display = "";
    document.getElementById("container_help").style.display = "none";
    document.getElementById("extrainfo").style.margin = "0 10px 0 0";
    document.getElementById("container_invita_").style.display = "none";
	document.getElementById("percorso_testuale").style.display = "";
}

function buildCustGroups(){
    var arr_idcustkey = IdCustKey.split(".");
    var IdCust = arr_idcustkey[0];
    var Key = arr_idcustkey[1];
    var ncols = 2;
    var html = [''];
    var grp = [''];
    var label = '';
    html.push('<div style="position:relative;width:' + boxwidth + ';" class=layerbody>');
    html.push('<table width=100% cellpadding=0 cellspacing=0 border=0 class=poigroups>');
    html.push('<form name="grpform" id="grpform">');
    for (i = 0; i < CustGroups.length; i++) {
        if (i == 0) 
            grp.push('<tr>');
        else 
            if ((i % ncols) == 0) 
                grp.push('</tr><tr>');
        grp.push('<td><table cellpadding=0 cellspacing=0><tr><td><input type="checkbox" id="');
        grp.push(CustGroups[i][0] + '" onclick="setCheckCategory(\'' + IdCust + '.' + Key + '\',this);">');
        grp.push('</td><td nowrap class=poigroups>' + CustGroups[i][1] + '</td></tr></table></td>');
    }
    html.push(grp.join('') + '</tr>');
    html.push('</form>');
    html.push('</table>');
    html.push('</div>');
    document.getElementById("layergroups").innerHTML = html.join('');
}

function vicidove() {
    
    var arr_value = document.getElementById("dove").value.split(",");
    if (arr_value[0] == 'Milano') {
           document.getElementById("vicinoa").style.display = "inline"
    } else {
           document.getElementById("vicinoa").style.display = "none"
    }    

    var arr_value = document.getElementById("dove").value.split(",");


    if (areaSelezionata!='comuni') {

       if (document.getElementById('mapBrokerFrame').contentWindow.vicidove) {
            document.getElementById('mapBrokerFrame').contentWindow.vicidove(arr_value[0],12);
       } else {
           alert('Manca ViciDove');
       }
    
    } else {
        // siamo nella sezione "Comuni" delle mappe interattive, quindi dobbiamo far vedere il comune, spostare la mappa
        // e visualizzare il perimetro


        // facciamo un reset dei checkbox soggetti vicini... dovrebbero essere spenti dopo ogni cambio
        if (document.getElementById('mappaShowEventi')) 
               document.getElementById('mappaShowEventi').checked = false;
        if (document.getElementById('mappaShowDormire')) 
               document.getElementById('mappaShowDormire').checked = false;
        if (document.getElementById('mappaShowNatura')) 
               document.getElementById('mappaShowNatura').checked = false;
        if (document.getElementById('mappaShowMusei')) 
               document.getElementById('mappaShowMusei').checked = false;
        if (document.getElementById('mappaShowArte')) 
               document.getElementById('mappaShowArte').checked = false;
     
        // attiviamo il cambio di comune
        if (document.getElementById('mapBrokerFrame').contentWindow.showComune) {
            document.getElementById('mapBrokerFrame').contentWindow.showComune(arr_value[0],12); 
        } else {
            alert('Manca showComune');
        }
        
    }
}

/**
 * Ridimensionamento automatico della pagina al window.resize
 */

function resize() {

	var container = document.getElementById("container");
	var leftContainer = document.getElementById("leftcol");
	var frameContainer = document.getElementById("framecontent");
        var rightContainer = document.getElementById("rightcol");

        leftContainer.style.width = ( container.offsetWidth - 310 ) + "px";
	frameContainer.style.width = ( container.offsetWidth - 310 ) + "px";
}

function resetRicercaPerDate(nomeLista) {

    if (nomeLista == "" || nomeLista == null) 
        return;
    
    var isg = document.getElementById("isg");
    
    if (isg != null) {
        if (nomeLista == 'Is')// Cambiato valori in DATA SINGOLA
        {
            var dag = document.getElementById("dag");
            var dam = document.getElementById("dam");
            var daa = document.getElementById("daa");
            
            var ag = document.getElementById("ag");
            var am = document.getElementById("am");
            var aa = document.getElementById("aa");
            
            dag.selectedIndex = 0;
            dam.selectedIndex = 0;
            daa.selectedIndex = 0;
            ag.selectedIndex = 0;
            am.selectedIndex = 0;
            aa.selectedIndex = 0;
        }
        else 
            if (nomeLista == 'DaA') // Cambiato valori in DATA DA o DATA A
            {
                var ism = document.getElementById("ism");
                var isa = document.getElementById("isa");
                
                isg.selectedIndex = 0;
                ism.selectedIndex = 0;
                isa.selectedIndex = 0;
            }
        
    }
}

function showItinerary(fname, fcheck, checkbox) {
  
   var arr_params = checkbox.id.split(":");
   var pathid = arr_params[0];
   var pathcolor = arr_params[1];


   if (document.getElementById('mapBrokerFrame').contentWindow.showItinerarioByCodice) {
         document.getElementById('mapBrokerFrame').contentWindow.showItinerarioByCodice(pathid,pathcolor,fcheck);   
   } else {
       alert('Manca showItinerarioByCodice');
   }  
}

/**
 * Funzione che visualizza i percorsi prefissati della Provincia di Milano
 * @param {Object} fname
 * @param {Object} fcheck
 */

function showPath(fname, fcheck){
    //se fcheck ricentro per estremi....
    if (fobj = document.forms[fname]) {
        var pathid, x1, y1, x2, y2;
        var str_itinerari = '';
        var path_val = '<PATH ID="0.9603.0900015000"/>';//contorno provincia Milano
        for (i = 0; i < fobj.elements.length; i++) 
            if (fobj[i].type == "checkbox" && fobj[i].checked) {
                var arr_params = fobj[i].id.split(";");
                pathid = arr_params[0];
                x1 = parseInt(arr_params[1]);
                y1 = parseInt(arr_params[2]);
                x2 = parseInt(arr_params[3]);
                y2 = parseInt(arr_params[4]);
                path_val += '<PATH ID="0.9603.' + pathid + '"/>';
                
                str_itinerari += pathid + ","  
            }
        
        var params = '<EXTRA ITINERARI="' + str_itinerari + '"/>';
        
        //addExtraField(params);
        //hideframe.SetCategory("CUSTOM","GRP1",true,true);
        //hideframe.SetParamConfig("PATH_EXTRA_TAG",path_val);
        
		mapWrapper.setPOIFilter({
            broker: '3145.1.Tt4jZa',
            filter: params
        });
        mapWrapper.setPOI({
            value: true,
            broker: '3145.1.Tt4jZa',
            groups: ["GRP1"],
			force: true
        });
		mapWrapper.setAdditionalLayer(path_val);
		
		if (fcheck) {
            //GetBoundaryMap(x1, y1, x2, y2, 0);
            mapWrapper.setBoundaryMap(x1, y1, x2, y2);
        }
        else {
			mapWrapper.refreshMap();
            //hideframe.GetCenterMap(cx,cy,cScale,0);
        }
    }
}

var firstTime = true;
function setHttpCategoryPVMI(){
    if (fname != "" && ftype != "" && fid != "")//passate via http....
    {
        var cobj = document.getElementById(fid);
        if (!cobj || !firstTime) 
            return;
        firstTime == false
        cobj.checked = true;
        menu(cobj);
        setTimeout("setPoiCategoryCk('" + fname + "','" + ftype + "')", 2000);
    }
}

/**
 * Funzione ricentramento per "Vicino a"
 */

recenter2Point = function(){
    if (document.getElementById("near2").value!='Vicino a...') {
       var arr_values = document.getElementById("near2").value.split(",");
       var lat = arr_values[1];  
       var lon = arr_values[2];  
       //alert(lat+","+lon)
       if (document.getElementById('mapBrokerFrame').contentWindow.recenter2Point) {
            document.getElementById('mapBrokerFrame').contentWindow.recenter2Point(lat,lon,16);   
       } else {
            alert('Manca recenter2Point');
       }
    }
}

/**
 * Ricerca indirizzo con risoluzione ambiguita' e relativo ricentramento
 */
function GetMap(){
    //showWaitImg(true);
    var country = "";
    var region = "";
    var prov = "";
    
    if (country_combo) 
        country = document.addressform.Xcountry.value.replace("'", "\\'");
    if (region_combo) 
        region = document.addressform.Xregion.value.replace("'", "\\'");
    if (prov_combo) 
        prov = document.addressform.Xprov.value.replace("'", "\\'");
    city = document.addressform.Xcom.value.replace("'", "\\'");
    address = document.addressform.Xaddr.value.replace("'", "\\'");
    num = document.addressform.Xnum.value.replace("'", "\\'");
    
	/**
	 * Georeferenziazione indirizzo
	 */
	mapWrapper.geoRef({
        addr: address,
        amc1: country,
        amd2: region,
        amd3: prov,
        amd4: city,
        num: num,
        callback: handleResult
    });
    return false;
}

/**
 * Handle che si occupa di ricentrare la mappa per risultato senza ambiguita' oppure
 * mostra la lista di ambiguta' da risolvere di fianco al form di ricerca
 * @param {Object} data
 */

function handleResult(data){
    var elem = data.data.elem;
	if (elem) {
		if (elem[1]) {
            if (elem[0].addr) {
                var container = document.getElementById("addresslistlayer");
                var content = ['<strong class="titolo_pagina">' + l_ambiguita];
                content.push(l_ambiguita_indirizzo + '</strong><br><br/>');
                content.push('<strong>' + l_nazione + ':</strong> ' + elem[0].amc1 + ' <strong><br />');
                content.push(l_citta + ':</strong> ' + elem[0].amd4 + ' <br />');
                content.push('<strong>' + l_indirizzo + ':</strong>  <br /><br />');
                content.push('<table class="dettaglioTestuale" border="0" cellpadding="0" cellspacing="0" width="100%">');
                for (var e in elem) {
                    content.push('<tr><td>');
                    content.push('<a onclick="recenterMapByAddress(' + elem[e].x + ',' + elem[e].y + ',' + elem[e].sc + '); document.getElementById(\'addresslistlayer\').innerHTML = \'\';">' + elem[e].addr + '</a>');
                    content.push('</tr></td>');
                }
                content.push('</table>');
                container.innerHTML = content.join('');
            }
            if (elem[0].amd4 && !elem[0].addr) {
            	var container = document.getElementById("addresslistlayer");
                var content = ['<strong class="titolo_pagina">' + l_ambiguita];
                content.push(l_ambiguita_citta + '</strong><br><br/>');
                content.push('<strong>' + l_nazione +':</strong> ' + elem[0].amc1 + ' <strong><br />');
                content.push('<table class="dettaglioTestuale" border="0" cellpadding="0" cellspacing="0" width="100%">');
                for (var e in elem) {
                    content.push('<tr><td>');
                    content.push('<a onclick="document.addressform.Xcom.value=\'' + elem[e].amd4 + '\'; document.getElementById(\'addresslistlayer\').innerHTML = \'\'; GetMap();">' + elem[e].amd4 + '</a>');
                    content.push('</tr></td>');
                }
                content.push('</table>');
                container.innerHTML = content.join('');
            }
		}
		else {
            if (elem.x) 
                recenterMapByAddress(elem.x, elem.y, elem.sc);
            else {
            	var container = document.getElementById("addresslistlayer");
				container.innerHTML = '<br><br><br><strong class="titolo_pagina">' + l_nessunindirizzo + '</strong>';
			}
		}
	}
}

/**
 * Ricentra la mappa e si posiziona sul primo tab in alto
 * @param {Object} _x
 * @param {Object} _y
 * @param {Object} _sc
 */

function recenterMapByAddress(_x, _y, _sc){
	mapWrapper.setMapByCoords(_x, _y, _sc);
    GetIt2('data/combo.jsp', 'eventi', lang);
    changearea('eventi');
    setPoiCategory('mostraeventi', 'KEYWORDS', 'eventi');
	document.getElementById("addresslistlayer").innerHTML = "";
}

/**
 * Calcolo percorso con relativa risoluzione di ambiguita' e successivo disegno e ricentramento di mappa
 */

var step = 0;

function GetFormPath(){
    var country = "";
    var region = "";
    var prov = "";
	
	if (step < 2) {
		if (country_combo) 
			country = document.pathform["Xpthcountry" + step].value;
		if (region_combo) 
			region = document.pathform["Xpthregion" + step].value;
		if (prov_combo) 
			prov = document.pathform["Xpthprov" + step].value;
		var city = document.pathform["Xpthcom" + step].value;
		var address = document.pathform["Xpthaddr" + step].value;
		var num = document.pathform["Xpthnum" + step].value;
		
		country = country.replace("'", "\\'");
		region = region.replace("'", "\\'");
		prov = prov.replace("'", "\\'");
		city = city.replace("'", "\\'");
		address = address.replace("'", "\\'");
		num = num.replace("'", "\\'");
	
        /**
         * Georeferenziazione indirizzo
         */
        mapWrapper.geoRef({
            addr: address,
            amc1: country,
            amd2: region,
            amd3: prov,
            amd4: city,
            num: num,
            callback: handlePathResult
        });
	}
	else {
		step = 0;
		var params = {};
        params.data = [{
            src: {
                x: startWaypoint.x,
				y: startWaypoint.y,
				id: "1.1"
            },
			broker: "GSI",
			group: "GSI",
			position: "start",
			id: "1"
        },
		{
            src: {
                x: endWaypoint.x,
				y: endWaypoint.y,
				id: "2.1"
            },
			broker: "GSI",
			group: "GSI",
			position: "end",
			id: "2"
        }];
		params.idPath = "percorso1";
		params.operation = "add";
		var pthType = document.pathform.Xpthtype;
		params.algoType = pthType.options[pthType.selectedIndex].value;
		params.reqPathShape = true;
		mapWrapper.setPath(params, handleWaypointList);
		GetIt2('data/combo.jsp', 'eventi', lang);
    	changearea('eventi');
    	setPoiCategory('mostraeventi', 'KEYWORDS', 'eventi');
	}
}

/**
 * Imposta un oggetto tappa
 * @param {Object} x
 * @param {Object} y
 */
function setWaypoint(x,y){
    if (step == 0) {
        startWaypoint = {
            x: x,
            y: y
        };
    }
    else {
        endWaypoint = {
            x: x,
            y: y
        };
    }
}

/**
 * Se non devo controllare anche l'indirizzo posso passare allo step successivo
 */
function checkStep(x,y){
	if (document.pathform["Xpthaddr" + step].value == "") {
		setWaypoint(x,y);
		step++;
	}
}

/**
 * Funzione che si occupa di gestire le ambiguita' per il calcolo percorso
 * @param {Object} data
 */ 
function handlePathResult(data){
    var elem = data.data.elem;
    if (elem) {
        if (elem[1]) {
			if (elem[0].addr) {
				var container = document.getElementById("addresslistlayer");
				var content = ['<strong class="titolo_pagina">' + l_ambiguita];
				content.push(l_ambiguita_indirizzo + '</strong><br><br/>');
				content.push('<strong>' + l_nazione + ':</strong> ' + elem[0].amc1 + ' <strong><br />');
				content.push(l_citta + ':</strong> ' + elem[0].amd4 + ' <br />');
				content.push('<strong>' + l_indirizzo +  ':</strong>  <br /><br />');
				content.push('<table class="dettaglioTestuale" border="0" cellpadding="0" cellspacing="0" width="100%">');
				for (var e in elem) {
					content.push('<tr><td>');
					content.push('<a onclick="setWaypoint(' + elem[0].x + ',' + elem[0].y + '); step++; GetFormPath(); document.getElementById(\'addresslistlayer\').innerHTML = \'\';">' + elem[e].addr + '</a>');
					content.push('</tr></td>');
				}
				content.push('</table>');
				container.innerHTML = content.join('');
			}
			if (elem[0].amd4 && !elem[0].addr) {
            	var container = document.getElementById("addresslistlayer");
                var content = ['<strong class="titolo_pagina">' + l_ambiguita];
                content.push(l_ambiguita_citta + '</strong><br><br/>');
                content.push('<strong>' + l_nazione + ':</strong> ' + elem[0].amc1 + ' <strong><br />');
                content.push('<table class="dettaglioTestuale" border="0" cellpadding="0" cellspacing="0" width="100%">');
                for (var e in elem) {
                    content.push('<tr><td>');
                    content.push('<a onclick="document.pathform[\'Xpthcom' + step + '\'].value=\'' + elem[e].amd4 + '\'; document.getElementById(\'addresslistlayer\').innerHTML = \'\'; checkStep(' + elem[0].x + ',' + elem[0].y + '); GetFormPath();">' + elem[e].amd4 + '</a>');
                    content.push('</tr></td>');
                }
                content.push('</table>');
                container.innerHTML = content.join('');
            }
        }
        else {
            if (elem.x) {
				setWaypoint(elem.x,elem.y);
				step++;
				GetFormPath();
			}
			else {
				var container = document.getElementById("addresslistlayer");
				container.innerHTML = '<br><br><br><strong class="titolo_pagina">' + l_nessunindirizzo + '</strong>';
			}
        }
    }
}

/**
 * Funzione che si occupa di gestire la stampa delle manovre per il calcolo del percorso
 * @param {Object} arg
 */
function handleWaypointList(arg){
	var container = document.getElementById("percorso_testuale");
	container.innerHTML = "";
	
	var waypointList = arg.pitem;
	/**
	 * Intestazione Partenza / Arrivo
	 */
	var content = [''];
	var f = waypointList[0].pnt[0];
	var t = waypointList[waypointList.length - 1].pnt[0];
    content.push('<strong>' + l_partenza + ' <a onclick="mapWrapper.setMapByCoords(' + f.x + ', ' + f.y + ',10000);">');
	content.push(waypointList[0].from.amd4 + ' ' + waypointList[0].from.addr + '</a></strong><br>');
    content.push('<strong>' + l_arrivo + ' <a onclick="mapWrapper.setMapByCoords(' + t.x + ', ' + t.y + ',10000);">')
	content.push(waypointList[waypointList.length - 1].from.amd4 + ' ' + waypointList[waypointList.length - 1].from.addr + '</a></strong><br>');
	
	/**
	 * Tabella manovre
	 */
	var sumLen = 0;
	var sumTime = 0;
	content.push('<table width="100%"><tbody>');
	content.push('<tr><th rowspan="2">NÂ°</th>');
	content.push('<th rowspan="2" colspan="2">' + l_indicazione + '</th>');
	content.push('<th colspan="2"><div align="center">' + l_distanza + '</div></th>');
	content.push('<th rowspan="2"><div align="center">' + l_tempototale + '</div></th></tr><tr>');
	content.push('<th><div align="center">' + l_parziale + '</div></th>');
	content.push('<th><div align="center">' + l_distanzatotale + '</div></th></tr>');
	
	for(var w in waypointList){
		content.push('<tr><td><div align="center">' + (w * 1 + 1) + '</div></td>');
		content.push('<td width="25"><img width="25" height="25" src="ManeuverIcons/turn' + waypointList[w].typ.v + '.gif"></td>');
		var st = waypointList[w].pnt[0];
		var en = waypointList[w].pnt[1];
		content.push('<td><a onclick="mapWrapper.setBoundaryMap(' + st.x + ',' + st.y + ',' + en.x + ',' + en.y + ');">');
		content.push(waypointList[w].typ.strc + '<br></a>' + waypointList[w].from.amd4 + ' ' + waypointList[w].from.addr + '</td>');
		content.push('<td> ' + formatDistance(waypointList[w].len) + ' </td>');
		sumLen += waypointList[w].len * 1;
		content.push('<td> ' + formatDistance(sumLen) + ' </td>');
		sumTime += waypointList[w].time * 1;
		content.push('<td>' + formatTime(sumTime) + '</td>');
		content.push('</tr>');
	}
	content.push('</tbody></table>');
	
	container.innerHTML = content.join('');
}

/**
 * Funzione di formattazione delle distanze
 * @param {Object} dist
 */
function formatDistance(dist){
	var val = dist / 10;
	if( val < 1000 ){
		return val + " m";
	}
	else
		return (val / 1000).toFixed(1) + " km";
}

/**
 * Funzione della formattazione del tempo
 * @param {Object} tempo
 */
function formatTime(tempo){
    var ore, minuti, secondi;
    if ((tempo / 3600) >= 1) {
        ore = parseInt((tempo / 3600));
    }
    else {
        ore = 0;
    }
    if ((tempo % 3600) != 0) {
        minuti = (tempo - ore * 3600);
        minuti = parseInt(minuti / 60);
    }
    else {
        minuti = 0;
    }
    if ((tempo % 60) != 0) {
        secondi = (tempo - ore * 3600 - minuti * 60);// minuti*60
    }
    else {
        secondi = 0;
    }
    if (ore == 0 && minuti == 0 && secondi == 0) 
        return "";
    
    if (ore < 10) {
        ore = "0" + parseInt(ore, 10);
    }
    if (minuti < 10) {
        minuti = "0" + parseInt(minuti, 10);
    }
    if (secondi < 10) {
        secondi = "0" + parseInt(secondi, 10);
    }
    
    return ore + ":" + minuti + ":" + secondi;
}

/**
 * Funzione che restituisce il Filter utilizzato per disegnare in mappa, le categorie POI attivate
 */
function getFilterPOI(){
	//alert("Stringa di esportazione POI:\n" + poiFilter + "\n" + mapWrapper.mapInfo());
	var filter = mapWrapper.getPoiFilter({
		broker: '3145.1.Tt4jZa',
		group: 'GRP1'
	});
	
	alert("Stringa di esportazione POI:\n" + filter + "\n" + mapWrapper.getMapInfo())
}

/**
 * ****************************************************
 * Funzioni tolte da script/javascript.js e messe in lib.js
 * ****************************************************
 */

/**
 * 
 * @param {Object} area
 */
function changearea(area) {

   // conserviamo il riferimento dell'area selezionata
   areaSelezionata = area; 

   // ad ogni cambio deve essere eseguito un reset della mappa... deve tornare alla posizione originale
   if (document.getElementById('mapBrokerFrame').contentWindow.resetMap)
          document.getElementById('mapBrokerFrame').contentWindow.resetMap();

   // inoltre facciamo un reset dei dati
   if (document.getElementById('mapBrokerFrame').contentWindow.clearDati)
          document.getElementById('mapBrokerFrame').contentWindow.clearDati();

   //
   if (area == 'itinerari') {
       document.getElementById("visualizzaStampa" + lang).style.display = "none"
   } else {
       document.getElementById("visualizzaStampa" + lang).style.display = "inline"
   }

   document.getElementById("rightcol").getElementsByTagName("table")[0].style.display=""

   // 21.05.10 non serve + cambiare colore a seconda dell'area, ma accendere la classe
   //document.getElementsByTagName('body')[0].className = area;


   if (area=='eventi') {
       document.getElementById("linkeventi").className = "on";
   } else {
       document.getElementById("linkeventi").className = "off";
   }
   if (area=='comuni') {
       document.getElementById("linkcomuni").className = "on";
   } else {
       document.getElementById("linkcomuni").className = "off";
   }
   if (area=='musei') {
       document.getElementById("linkmusei").className = "on";
   } else {
       document.getElementById("linkmusei").className = "off";
   }
   if (area=='monumenti') {
       document.getElementById("linkmonumenti").className = "on";
   } else {
       document.getElementById("linkmonumenti").className = "off";
   }
   if (area=='natura') {
       document.getElementById("linknatura").className = "on";
   } else {
       document.getElementById("linknatura").className = "off";
   }
   if (area=='itinerari') {
       document.getElementById("linkitinerari").className = "on";
   } else {
       document.getElementById("linkitinerari").className = "off";
   }
   if (area=='dormire') {
       document.getElementById("linkdormire").className = "on";
   } else {
       document.getElementById("linkdormire").className = "off";
   }
   if (area=='infoutili') {
       document.getElementById("linkinfo").className = "on";
   } else {
       document.getElementById("linkinfo").className = "off";
   }


   liste=document.getElementById('me').getElementsByTagName('ul');
   for (i=0; i<liste.length; i++){
	   liste[i].style.display="none";
   }
   
   if(area=="infoutili") {
      document.getElementById("extrainfo").style.display="block"
   } else {
      document.getElementById("extrainfo").style.display="none"
   }
   
   document.getElementById("rightcol").style.display ="block";
   document.getElementById("container_cerca").style.display ="none";
   document.getElementById("container_mappa").style.display ="block";
   document.getElementById("container_help").style.display ="none";
   document.getElementById("container_invita_").style.display ="none";
   document.getElementById("rightcol_risultati").style.display ="none";
   document.getElementById("percorso_testuale").style.display ="block";
   document.getElementById("mostramilanomese").style.display="none";
   document.getElementById("h3_cercaavanzata").style.display="block";	

   if(elem=document.getElementById(area))
		  elem.style.display="block";
}


function milanomese(){
   liste=document.getElementById('me').getElementsByTagName('ul');
   
	for (i=0; i<liste.length; i++){
	 liste[i].style.display="none";
	}

	document.getElementById("rightcol").getElementsByTagName("table")[0].style.display="none";
	document.getElementById("h3_cercaavanzata").style.display="none";	
	
	document.getElementById("mostramilanomese").style.display="block";
	document.getElementsByTagName('body')[0].className = "milanomese";
}

function inviaEmailAmico() {

    if (document.getElementById('mapBrokerFrame').contentWindow.flickSendFriendMailControl) 
        document.getElementById('mapBrokerFrame').contentWindow.flickSendFriendMailControl('http://www.visitamilano.it/turismo/mappeinterattive/index.html'); 
    else 
       alert('no function');    

}

function printMappa() {
    if (document.getElementById('mapBrokerFrame'))
          document.getElementById('mapBrokerFrame').contentWindow.print();
}



 
function showNearPois() {

          var elenco = ""; 
          // 
          if (document.getElementById('mappaShowEventi')) {
              if (document.getElementById('mappaShowEventi').checked)
                     elenco += "eventi:149,97,132,152,112,147,151,148,145,117,150,135,156,146;";
          }
          if (document.getElementById('mappaShowDormire')) { 
              if (document.getElementById('mappaShowDormire').checked)
                     elenco += "dormire:208;";
          }
          if (document.getElementById('mappaShowNatura')) {
              if (document.getElementById('mappaShowNatura').checked)
                     elenco += "natura:41,198,199,197,190,191,48,47,49,50,46,45,44,43,42,231,176;";
          }
          if (document.getElementById('mappaShowMusei')) {
              if (document.getElementById('mappaShowMusei').checked)
                     elenco += "musei:26,2;";
          }  
          if (document.getElementById('mappaShowArte')) {
              if (document.getElementById('mappaShowArte').checked)
                     elenco += "monumenti:7,14,13,12,11,10,9,8,15,196,24,23,22,21,20,19,18,17,16;";
          } 
          if (document.getElementById('mappaShowInfoUtili')) {
              if (document.getElementById('mappaShowInfoUtili').checked)
                     elenco += "infoutili:96,170,248,247,25,166,173,88,27,84,85,86,68,67,77,76,200,79,54,55,65,78,244,80,82,81,4,89,69,73,72,71,74,70,168,75;";
          } 
          //
          if (document.getElementById('mapBrokerFrame').contentWindow.elencoPoiPerMappaNuovoSito)                   
             document.getElementById('mapBrokerFrame').contentWindow.elencoPoiVicinoComune(elenco,3000);
          else
             alert('Manca la funziona elencoPoiPerMappaNuovoSito');

          // attiviamo la visualizzazione degli itinerari
          if (document.getElementById('mappaShowItinerari').checked)
              document.getElementById('mapBrokerFrame').contentWindow.elencoItinerariVicinoComune(3000,2);
          else               
              document.getElementById('mapBrokerFrame').contentWindow.pulisciItinerariNuovoSito();   
}



