/** FUNZIONE DI INIZIALIZZAZIONE **/
var infodiv,mapframeobj,content,objframe,tp_obj,delpathlayer;
var changed_addr_from=false;//viena alzato a true se cambia il valore nella form "partenza"
var changed_addr_to=false;//viena alzato a true se cambia il valore nella form "partenza"
var onload=true;
var stopClick=false;
var DefScale;
var def_statusmsg = 'Ubiest MapBroker';
var poidetail=false;
function IniMap(){        
        window.defaultStatus=def_statusmsg;                         
        checkBroser();   
        /**CHECK BROWSER**/
        if(b_moz)
                objframe=frames[0];
        else    objframe=document.frames[0];
        /*****************/    
        if(!StaticMap) {        
        document.MapBroker.SetParamConfig("GsiScale","100000");
        // document.MapBroker.SetParamConfig("TIMEOUT",'300000');
        document.MapBroker.SetParamConfig("DEBUG","0");
        document.MapBroker.SetParamConfig("ENCODING",SetEncoding);
        document.MapBroker.SetParamConfig("DEF_SCALE",String(DefScale));

        /**INZIALIZZAZIONE VERIABILI CONFIG**/
        document.MapBroker.SetParamConfig("AL_HEADER",AL_HEADER);
        document.MapBroker.SetParamConfig("AL_BODY",AL_BODY);
        document.MapBroker.SetParamConfig("AL_FOOTER",AL_FOOTER);
        
        document.MapBroker.SetParamConfig("PL_HEADER",PL_HEADER);
        document.MapBroker.SetParamConfig("PL_BODY",PL_BODY);
        document.MapBroker.SetParamConfig("PL_FOOTER",PL_FOOTER);
        document.MapBroker.SetParamConfig("PL_HEADER_ADDSTOP",PL_HEADER_ADDSTOP);
        document.MapBroker.SetParamConfig("PL_BODY_ADDSTOP",PL_BODY_ADDSTOP);

        document.MapBroker.SetParamConfig("TP_HEADER_H",TP_HEADER_H);
        document.MapBroker.SetParamConfig("TP_HEADER_B",TP_HEADER_B);
        document.MapBroker.SetParamConfig("TP_HEADER_F",TP_HEADER_F);
        document.MapBroker.SetParamConfig("TP_BODY",TP_BODY);
        document.MapBroker.SetParamConfig("TP_FOOTER",TP_FOOTER);
        
        document.MapBroker.SetParamConfig("PD_HEADER",PD_HEADER);
        document.MapBroker.SetParamConfig("PD_BODY",PD_BODY);
        document.MapBroker.SetParamConfig("PD_FOOTER",PD_FOOTER);    
        }   
        else {
         parent.frames[1].SetParamConfig("DEFAULT_MAP",SplashUrl);
         parent.frames[1].SetParamConfig("DEF_SCALE",String(DefScale));

         parent.frames[1].SetParamConfig("AL_HEADER",AL_HEADER);
         parent.frames[1].SetParamConfig("AL_BODY",AL_BODY);
         parent.frames[1].SetParamConfig("AL_FOOTER",AL_FOOTER);

         parent.frames[1].SetParamConfig("PL_HEADER",PL_HEADER);
         parent.frames[1].SetParamConfig("PL_BODY",PL_BODY);
         parent.frames[1].SetParamConfig("PL_FOOTER",PL_FOOTER);
         parent.frames[1].SetParamConfig("PL_HEADER_ADDSTOP",PL_HEADER_ADDSTOP);
         parent.frames[1].SetParamConfig("PL_BODY_ADDSTOP",PL_BODY_ADDSTOP);
         
         parent.frames[1].SetParamConfig("TP_HEADER_H",TP_HEADER_H);
         parent.frames[1].SetParamConfig("TP_HEADER_B",TP_HEADER_B);
         parent.frames[1].SetParamConfig("TP_HEADER_F",TP_HEADER_F);
         parent.frames[1].SetParamConfig("TP_BODY",TP_BODY);
         parent.frames[1].SetParamConfig("TP_FOOTER",TP_FOOTER);

         parent.frames[1].SetParamConfig("PD_HEADER",PD_HEADER);
         parent.frames[1].SetParamConfig("PD_BODY",PD_BODY);
         parent.frames[1].SetParamConfig("PD_FOOTER",PD_FOOTER);       
        
        }
        
        /************************************/
        
                          
        /*IMPOSTAZIONI DIMENSIONI MAPPA*/
        document.getElementById("mapframe").style.width=dimx; 
        document.getElementById("mapframe").style.height=dimy; 
        /*******************************/        
        /*OGGETTI DHTML*/
        mapobj=frames[0].document.getElementById("map");//OGGETTO MAPPA
        mapobj.src=SplashUrl;
        waitobj=frames[0].document.getElementById("wait");//OGGETTO WAIT
        mapframeobj=document.getElementById("framecontent");//CONTENITORE FRAME   
        poicontobj=objframe.document.getElementById('poicont');//CONTENITORE POI    
        loclayerobj=objframe.document.getElementById('loclayercont');//CONTENITORE LOCAL LAYER           
        objonload=objframe.document.getElementById('onload');
        content=objframe.document.getElementById("content"); //OGGETTO CONTENITORE MAPPA
        infodiv=document.getElementById("getstreetinfo");//CONTENITORE STREET INFO
        tp_obj=document.getElementById("textpath");//LAYER PERCORSO TESTUALE
        delpathlayer=document.getElementById("delpathlayer");         
        stoplayerlistobj=document.getElementById("stoplayerlist");       
        addrlistlayerobj = document.getElementById('addresslistlayer');
        plcontobj=document.getElementById("poilistcont");        
        /***************/        
        /*IMPOSTAZIONI DIMENSIONE MAPPA*/
        //content.style.width=dimx;        
        //content.style.height=dimy;     
        /******************/                 
        /******************/                
        /******************/
        //non si richiede più: CustomPoiUrl=document.MapBroker.GetParamConfig("CUSTOM_POI_URL");
        
        configTemplate();       

        if(!StaticMap) {
         mapout=String(document.MapBroker.initApplet(IniFile,parseInt(dimx),parseInt(dimy),parseInt(StartScale),parseInt(StartX),parseInt(StartY),parseInt(EndX),parseInt(EndY),lang,parseInt(pthalgo),parseInt(pthdet)));                
         DefScale=parseInt(document.MapBroker.GetParamConfig("DEF_SCALE"));       
         Parse(true);        
        }
        else {
          try {
  	   parent.frames[1].SetParamConfig("INIFILE",IniFile);       
           mapout=String(parent.frames[1].initApplet(parseInt(dimx),parseInt(dimy),parseInt(StartScale),parseInt(StartX),parseInt(StartY),parseInt(EndX),parseInt(EndY),lang,parseInt(pthalgo),parseInt(pthdet)));
           DefScale=parseInt(parent.frames[1].GetParamConfig("DEF_SCALE"));       
          }
          catch (error) {}
          
        }  
        
        setBgColorModeBar(document.getElementById('modbar1'));
        
        /**VISUALIZZAZIONE LAYER**/                       
        mapframeobj.style.visibility='visible';
        //if(MapLayerView) document.getElementById("maplayer").style.visibility='visible';
        //if(PathLayerView) document.getElementById("pathlayer").style.visibility='visible';
        //if(StopLayerView) document.getElementById("stoplayer").style.visibility='visible';
        /*************************/
        //se sono in modalità store locator mappa      
        onload=false;
        //alert(onload);  
        return false;                 
}

/**********************************/


var TY;
var g_params='';
var g_maptype='';
var g_amd4='';
var g_addr='';
var funct='';
function VerifyAddress(params,maptype,amc1,amd4,addr,x,y){             
   //function --> tipo di funzione da chiamare     
   //maptype 0 ---> MAPPA 
   //maptype 1 ---> PERCORSO
   //maptype 2 ---> AGGIUNTA TAPPA   
   if(maptype==0)
             funct=getmap_function; 
   else if(maptype==1) funct=js_address_addstop_function; 
      
   g_maptype=maptype;
   g_amd4=amd4;
   g_addr=addr;
   g_params=params;
   if(wlist.length>0)
        wlist[wlist.length-1].close();
   
   var getmap,num;
   num='';                                
   ret=false;
        
   if(params.split(",")[1]=="" && params.search("AMC4")==-1){
        getErrorMsg(2);               
        return;//la condizione di seguito???
        if(maptype==1)
                AddStop(-1,1,0,0,"","","","");
        }        
   else{     
     if(StaticMap) {
        try {
         parent.frames[1].verifyAddress(params);
         //parent.frames[1].searchProx(params);
        }
        catch (error) {}
     }
     else {
      TY=String(document.MapBroker.verifyAddress(params));  
      ParseVerifyAddress(TY);
     }
   }                                                                        
  }

function ParseVerifyAddress(TY) {
   var ret=false;
   var Scale=DefScale;
   switch(TY){
        case 'CIT':
                ret=true;
                Scale=70000;
        break;
        case 'CIV':
                ret=true;
        break;
        case 'LST':                                                      
             if(StaticMap)
                BuildAddressList(String(parent.frames[1].getAddressList(0,g_maptype,g_amd4,"",funct)));
             else
                BuildAddressList(String(document.MapBroker.getAddressList(0,g_maptype,g_amd4,"",funct)));
        break;
        case 'LCI'://lista                   
                   if(g_addr != ''){//se lista città con indirizzo verifico su amc4                                                                    
                       if(StaticMap)
                          BuildAddressList(String(parent.frames[1].getAddressList(1,g_maptype,"",g_addr,verifyaddr_function)));
                       else
                          BuildAddressList(String(document.MapBroker.getAddressList(1,g_maptype,"",g_addr,verifyaddr_function)));
                        }
                   else {
                        if(StaticMap)
                          BuildAddressList(String(parent.frames[1].getAddressList(0,g_maptype,"",g_addr,funct)));     
                        else
                          BuildAddressList(String(document.MapBroker.getAddressList(0,g_maptype,"",g_addr,funct)));     
                       }
        break;                
        case 'STR':
                ret=true;
        break;
        case 'ERR':                                
                if(g_params.search('AMC4')!=-1){//ho cercato un indirizzo inesistente su ambiguita sul comune
                        //alert('ambiguita');
                        ret=true;
                }
                else {
                        //getErrorMsg(1);
                        showErrorMsg(1);
                        showWaitImg(false);
                        showWaitImg(false);
                        }
                
        
        break; 
        case 'TIMEOUT':
                        getErrorMsg(4);
                        showWaitImg(false);
                        return;
        break;
        case 'EMPTY':
                        getErrorMsg(3);
                        showWaitImg(false);
                        return;
        break;                                 
        }
        if(ret){                
                if(TY != 'ERR'){        
                     if(StaticMap) {
                        amc1=String(parent.frames[1].getAttributeValue(0,"AMC1"));
                        amd4=String(parent.frames[1].getAttributeValue(0,"AMD4"));                        
                        if((amd5=String(parent.frames[1].getAttributeValue(0,"AMD5")))!='')
                                amd4=amd5;                        
                        addr=String(parent.frames[1].getAttributeValue(0,"ADDR"));
                        num=String(parent.frames[1].getAttributeValue(0,"NUM")); 
                        x=parseInt(parent.frames[1].getAttributeValue(0,"X"));
                        y=parseInt(parent.frames[1].getAttributeValue(0,"Y"));
                      }
                      else {
                        amc1=String(document.MapBroker.getAttributeValue(0,"AMC1"));
                        amd4=String(document.MapBroker.getAttributeValue(0,"AMD4"));                        
                        if((amd5=String(document.MapBroker.getAttributeValue(0,"AMD5")))!='')
                                amd4=amd5;                        
                        addr=String(document.MapBroker.getAttributeValue(0,"ADDR"));
                        num=String(document.MapBroker.getAttributeValue(0,"NUM")); 
                        x=parseInt(document.MapBroker.getAttributeValue(0,"X"));
                        y=parseInt(document.MapBroker.getAttributeValue(0,"Y"));
                      }
                }
                switch(g_maptype){                        
                        case 0:  
                             GetMapAddressList(Scale,x,y,0,amc1,amd4,addr,num);
                        break;
                        default:                        
                             //if(pathform){
                                                         
                                AddStop(-1,g_maptype,x,y,amc1,amd4,addr,num);
                             //}                                                                
                     
                        }     
                }
        return true;  
   }                                                                        
   

function GetMap(){   
        var lsRegExp =/'/g;

        showWaitImg(true);             
        country=document.addressform.Xcountry.value;
        city=document.addressform.Xcom.value;
        address=document.addressform.Xaddr.value;        
        num=document.addressform.Xnum.value;  

        city=String(city).replace(lsRegExp,"\\'");                                         
        address=String(address).replace(lsRegExp,"\\'"); 
        
        var p=country+","+city+","+address+","+num;           
        if(StaticMap)
          VerifyAddress(p,0,country,city,address,-1,-1);
        else {
         command="VerifyAddress('"+p+"',0,'"+country+"','"+city+"','"+address+"',-1,-1);";                   
         operation(false);
        } 
            
        return false;
 }



var wlist=new Array();
//var waddress=null;
function BuildAddressList(table){  
   if(PopupAddressList) {
   	row="";
        html='<html><title>'+l_listaindirizzi+'</title>';                
        html+='<LINK rel="stylesheet" href="css/map.css">';                
        html+='<body class=address_list>'+table+'</body>';
        html+='</html>';  
        /*                   
        wlist[wlist.length]=window.open("","wlist"+wlist.length,"menu=0,width=400,height=300,scrollbars=1");
        wlist[wlist.length-1].document.write(html);        
        wlist[wlist.length-1].document.close();
        wlist[wlist.length-1].focus();  
        */
        var waddress;
        waddress=window.open("","","menu=0,width=400,height=300,scrollbars=1");
        if(waddress==null)
                return;
        waddress.document.write(html);        
        waddress.document.close();
        waddress.focus();  
   }
   else {
      if(addrlistlayerobj) {
      addrlistlayerobj.innerHTML=table;
      addrlistlayerobj.style.visibility='visible';
      if(addrlistlayerobj.offsetHeight>130)
        addrlistlayerobj.style.height=130;
      }
   }
        
        return false;          
}

var wpoilist=null;
function BuildPoiList(p_poilist){  
        if(p_poilist=='null') 
        { 
          plcontobj.innerHTML="";   
          plcontobj.style.visibility='hidden';        	
        	return;
        }
        //alert(poilist);        
        if(PopupPoiOnMap){//visualizzo in popup
                if(p_poilist != 'null'){                        
                   /*l'header tabella viene configurato qui...*/                      
                   if(wpoilist!=null){
                       wpoilist.close();
                       wpoilist=null;}    
                   wpoilist=window.open("","wpoilist","menu=0,width=400,height=300,scrollbars=yes");   
                   if(wpoilist==null)
                        return;            
                   html='<html><LINK rel="stylesheet" href="css/map.css">';
                   html+='<title>'+l_listapoi+'</title><body topmargin=0 leftmargin=0>';
                   html+=p_poilist;
                   html+='</body></html>';
                   
                   wpoilist.document.write(html);
                   
                   wpoilist.document.close();
                   wpoilist.focus();                                   
                   }    
                else{
                    //viene chiusa eventuale popup
                    if(wpoilist != null) wpoilist.close();   
                    wpoilist=null;
                    }
                }        
        else{//visualizzo poi sulla pagina principale
           if(p_poilist != 'null'){                        
                   /*l'header tabella viene configurato qui...*/        
                   plcontobj.innerHTML=p_poilist;                    
                   plcontobj.style.visibility='visible';
                   if(plcontobj.offsetHeight>130){
                        document.getElementById("poilist").style.height=130;
                       }
                        
                   }    
           else{   
                   plcontobj.innerHTML="";   
                   plcontobj.style.visibility='hidden';}
        }
}
/**********************************************/
function replaceAlgotype(str){
        var lsRegExp =/ALGO/g;        
        if((pos=str.search(lsRegExp))!=-1){
			algotype=str.substring(pos+4,pos+5);			
			obj=document.getElementById("Xpthtype");
			for(i=0;i<obj.options.length;i++){			
				if(obj.options[i].value==String(algotype)){
					eval("lsRegExp =/ALGO"+algotype+"/g;")
			        str=str.replace(lsRegExp,obj.options[i].text);
					return str;					
					}
				}
			}
        }


var wtextpath=null;
function BuildTextPath(pthtext){             
        if(pthtext != ""){ 
                pthtext=replaceAlgotype(pthtext);                                                 
                /*l'header tabella viene configurato qui...*/
                txtpathwidth=dimx;                      
                table='<TABLE cellpadding=1 cellspacing=0 WIDTH='+txtpathwidth+' class="textpath">'+pthtext+'</table>';                            
                if(PopupPathDetail){//apro il percorso in popup                        
                        if(wtextpath!=null){
                            wtextpath.close();
                            wtextpath=null;}     
                        wtextpath=window.open("","wtextpath","menu=0,width="+(txtpathwidth+50)+",height=400,scrollbars=yes");                                       
                        if(wtextpath==null)
                                return;
                        html='<html>';
                        html+='<LINK rel="stylesheet" href="css/map.css">';               
                        html+='<body>'+table+'</body>';
                        html+='</html>'; 
                        wtextpath.document.write(html);
                        wtextpath.document.close();
                        wtextpath.focus(); 
                        }    
                                  
                else {                        
                        tp_obj.innerHTML=table;                      
                        }
        }    
}
//get map name & scale val
var scale,mapsrc,mapout,infomap,cx,cy;
infomap="";
var poitext="";
var poilist="";
var mapdim="";
var pathid='null';
var poimsg="";



function Parse(drawmap){     
	stopClick=false;
        switch(mapout){
                case 'EMPTY':
                        getErrorMsg(3);
                        showWaitImg(false);
                        return;
                break ;
                case 'TIMEOUT':
                        getErrorMsg(4);
                        showWaitImg(false);
                        return;
                break;
                case 'ERR':
                        //getErrorMsg(1);
                        getErrorMsg(6);
                        showWaitImg(false);
                        return;
                break;
                case '':
                        getErrorMsg(3);
                        showWaitImg(false);
                        return;
                break;
                }
        /*
        if(mapout=="EMPTY" || mapout=="TIMEOUT" || mapout=="ERR" || mapout=""){
                
                // TODO: gestire gli errori
                alert('errore nella generazione della mappa');
                return;
        } 
        */       
        mapout=new String(mapout);//netscape vuole in casting!!!                              
        out=mapout.split("_#3_");
        mapsrc=out[0];
        arr_info_map=out[1].split("_#1_");               
        scale=parseInt(arr_info_map[0]);//scala
        if(scale==-1)
                return;
        cx=parseInt(arr_info_map[1]);//punto centrale
        cy=parseInt(arr_info_map[2]);//punto centrale
        pathid=out[2];
        infomap=out[3];        
        grplist=out[4];//lista gruppi attivi nel formato BROKER|GRUPPO...        
        mapdim=out[5];
        mapdim_arr=out[5].split("_#1_");        
        if(dimx != parseInt(mapdim_arr[0]) || dimy != parseInt(mapdim_arr[1])){//resize map area
                dimx=parseInt(mapdim_arr[0]);
                dimy=parseInt(mapdim_arr[1]);
                resizeMapArea();        
        }
        locallayer=out[6];
        
        /*HTML POI*/
        if(StaticMap)
            poiout=String(parent.frames[1].getPoi(broker_list,js_poi_infomap_function,js_poi_infotemplate_function,js_poi_hl_function,js_poi_addstop_function,js_getpath_function)).split("_#2_");
        else
            poiout=String(document.MapBroker.getHTMLPoi(broker_list,js_poi_infomap_function,js_poi_infotemplate_function,js_poi_hl_function,js_poi_addstop_function,js_getpath_function)).split("_#2_");        
        poitext=poiout[0];
        poilist=poiout[1];          
        poimsg=poiout[2];         
        
        /*tolgo i poi dalla mappa*/
        poicontobj.innerHTML='';
        loclayerobj.innerHTML='';
        //prima disegno la mappa
       
        if(drawmap){
                loadMap(); 
                //alert(pathid);               
                if(pathid != 'null' && tp_obj.innerHTML != '') {
                   var txtpath='';
                   if(StaticMap)
                        txtpath= String(parent.frames[1].getHTMLPath(false,getboundarymap_function,getpthcenterstop_function));
                   else
                        txtpath= String(document.MapBroker.getHTMLPath(false,getboundarymap_function,getpthcenterstop_function));
                   BuildTextPath(txtpath);
                }
                else tp_obj.innerHTML = '';
                setScale();
                SetInfoMap(); 
                //sincronizzo le checkbox con i gruppi solo a fronte di una mappa da hystory 
                setMapCategory();
                //valorizzo la form coordinate
                setCoordFields();
        }
        //disegno i poi sulla mappa
        if(poitext != 'null'){
                //alert("disegno i poi");//max
                poicontobj.innerHTML=poitext;                
                }      

       if(locallayer && locallayer!='null') {
          loclayerobj.innerHTML=locallayer;
       }                    
                      
        BuildPoiList(poilist);  
                
        
        //disegno eventuali tappe (perchè è lento????)
        DrawStop(); 
        window.defaultStatus=def_statusmsg;  
}

function SetInfoMap(){
        //alert("infomap");
        add_poi="";
        strinfo="";
        if(infomap != 'null'){//se ho info sulpunto centrale stampo "Dove sei..."
                info=infomap.split("_#1_");                 
                //aggiungere le coordinate               
                amc1=(info[0]== "null" ? "" : info[0])+"";
                amd2=(info[1]== "null" ? "" : info[1])+"";
                amd3=(info[2]== "null" ? "" : info[2])+"";
                amd4=(info[3]== "null" ? "" : info[3])+"";
                addr=(info[4]== "null" ? "" : info[4])+"";
                num=(info[5] == "null"  ? "" : info[5]);  
                //amd4=amd4.replace("'","\'"); 
                                                            
                x=info[6];
                y=info[7]   
                strinfo=amd4+" "+addr+" "+num; 
                /**replace**/
                var lsRegExp =/'/g;
                amd4=  String(amd4).replace(lsRegExp,"\\'");                                         
                addr=  String(addr).replace(lsRegExp,"\\'");
                ////
                                         
                if(strinfo.length>70)
                        strinfo=strinfo.substr(0,70)+"...";
                add_poi="<table cellpadding=0 cellspacing=1 border=0><tr>";
                add_poi+="<td title=\""+l_aggiungi+" "+ strinfo +" " + t_partenza + "\"><a href=\"javascript:AddStop(0,0,"+x+","+y+",'"+amc1+"','"+amd4+"','"+addr+"','"+num+"');\"><img src=\"images/start.gif\" border=0></a></td>";
                add_poi+="<td title=\""+l_aggiungi+" "+ strinfo +" " + t_destinazione + "\"><a href=\"javascript:AddStop(1,0,"+x+","+y+",'"+amc1+"','"+amd4+"','"+addr+"','"+num+"');\"><img src=\"images/end.gif\" border=0></a></td></tr></table>";      
                
                
                                  
                
                if(onload && SetStop != -1 && mapmode==0){                                               
                         onload=false;
                         AddStop(SetStop,0,StartX,StartY,amc1,amd4,addr,num);                                                  
                        }                
        }
        html_info="<table border=0 width=100% class=infomap CELLPADDING=0 CELLSPACING=0><tr><td nowrap class=title>&nbsp;"+l_dovesei+":</td><td width=80% nowrap class=address>&nbsp;"+strinfo+"</td><td align=right class=addpoi>"+add_poi+"</td></tr></table>";
        document.getElementById("streetinfo").innerHTML=html_info;
        //else document.getElementById("streetinfo").innerHTML="";//...                
}

//request center map
function GetMapAddressList(scale,x,y,type,amc1,amd4,addr,num,istat){ 
	
 SetLocalLayer('spillo', 0, x, y,'dx_gr_pin','',amd4+' '+addr+' '+num);
 
 GetCenterMap(scale,x,y,type,amc1,amd4,addr,num);

}


//request center map
function GetCenterMap(scale,x,y,type,amc1,amd4,addr,num){ 
        if(addrlistlayerobj) {
         addrlistlayerobj.innerHTML='';
         addrlistlayerobj.style.height=0;
	 addrlistlayerobj.style.visibility='hidden';
        }
        if(amc1 !="") document.getElementById("Xcountry").value=amc1;   
        if(amd4 !="") document.getElementById("Xcom").value=amd4;
        if(addr !="") document.getElementById("Xaddr").value=addr;
        if(num !="") document.getElementById("Xnum").value=num;
        showWaitImg(true);
        if(StaticMap) {
          try {
            parent.frames[1].GetCenterMap(x,y,scale,type);
          }
          catch (error) {}
        }  
        else {
          mapout=String(document.MapBroker.getCenterMap(scale,x,y,type));       
          Parse(true);
        }
}



//get map by coord
function getMapByCoord(scale,x,y){ 
        //if(amc1 !="") document.getElementById("Xcountry").value=amc1;   
        //if(amd4 !="") document.getElementById("Xcom").value=amd4;
        //if(addr !="") document.getElementById("Xaddr").value=addr;
        //if(num !="") document.getElementById("Xnum").value=num;
        showWaitImg(true);
        mapout=String(document.MapBroker.getCenterMap(parseInt(scale),parseInt(x),parseInt(y),0));       
        Parse(true);                       
}



//request boundary map
/*
ctype: coord type 0 -> UTM  1 -> VIDEO 
*/
function GetBoundaryMap(x1,y1,x2,y2,ctype){
        showWaitImg(true);
        if(StaticMap) {
          try {
           parent.frames[1].GetBoundaryMap(x1,y1,x2,y2,ctype);
          }
          catch (error) {}
        }  
        else {
         mapout=String(document.MapBroker.getBoundaryMap(x1,y1,x2,y2,ctype));
         Parse(true);
        }
}



var dimx,dimy;
//object

//browser var
var b_ns,b_ie,b_moz;
var rect;

function checkBroser(){	
	b_ns = (document.layers ? true : false);
	b_ie = (document.all ? true : false);
	var b_nav = navigator.userAgent;
	b_moz = (b_nav.indexOf("Gecko")>=0?true : false);		
}




function pan(direction){
        if(scale==-1) 
                return;
        stopClick=true;
        showWaitImg(true);
        if(StaticMap) {
          try {
           parent.frames[1].pan(direction);
          }
          catch (error) {}
        }  
        else {
         command="mapout=String(document.MapBroker.pan("+direction+"));";
         operation(true);
        }
}

function setMapScale(currscale){
        if(scale==-1) 
                return; 
        showWaitImg(true);
        if(StaticMap) {
          try {
          parent.frames[1].setScale(currscale);          
          }
          catch (error) {}
        }          
        else {
         command="mapout=String(document.MapBroker.setScale("+currscale+"))";  
         operation(true); 
        }                         
}

function zoom(type){
        if(scale==-1) 
                return;
        showWaitImg(true);
        if(StaticMap) {
          try {
           parent.frames[1].zoom(type);
          }
          catch (error) {}
        }          
        else {
         command="mapout=String(document.MapBroker.zoom("+type+"));";
         operation(true);
        }
}

function deletePathNoMap() {
         tp_obj.innerHTML = '';   
         if(StaticMap) {
          try {
           parent.frames[1].deletePathNoMap();
          }
          catch (error) {}
         }
         else 
           document.MapBroker.deletePathNoMap();                     

}

function deletePath(delflags){
         tp_obj.innerHTML = '';   
         if(StaticMap) {
          try {
           parent.frames[1].deletePath(false);
          }
          catch (error) {}
         }           
         else {
          mapout=String(document.MapBroker.deletePath(false));                     
          Parse(true);
         }
        }

function loadMap(){
        if(mapout.search("http://")!=-1){//se è un indirizzo http valido...
            /*ridimensionamento mappa*/                        
            infodiv.style.visibility='hidden';//nascondo eventuale tooltip streetinfo            
            /*************************/ 
            showWaitImg(false);
            if (document.all) mapobj.filters[0].apply();
            mapobj.src=mapsrc;            
            if (document.all) mapobj.filters[0].play();
            
            /*DRAW STOP*/
            //DrawStop();scommentare assolutamente!!!!
            /***********/
            //BuildPoiList(poilist);                
            //redraw(); 
                
            if(pathid!='null') 
                delpathlayer.innerHTML='<input type="button" class=button onclick="deletePath();" value="'+l_cancella+'">&nbsp;<input width=100 type="button" class=button onclick="BuildTextPath(String('+ (StaticMap ? 'parent.frames[1]' : 'document.MapBroker')+'.getHTMLPath(false,getboundarymap_function,getpthcenterstop_function)));" value="'+l_percorso_testuale+'">';
            else        delpathlayer.innerHTML='';
            }
            objonload.style.visibility='hidden';   
}

/******* PATH FUNCTIONS ********/

/***ARRAY DELLE TAPPE***/
PoiStopSt=[null,null];

function showStopList(){
        for(i=0;i<PoiStopSt.length;i++){
                        if(PoiStopSt[i])                        
                                alert(PoiStopSt[i]);
                                } 
        }

function reset(){
        PoiStopSt=[null,null];
        }
/*-------------------------------------*/
/*------- VISUALIZZA TAPPE ------------*/
/*-------------------------------------*/

function VisuaStopList(){
  var html='';
  stop_arr=getStopFromApplet(); 
  for(i=0;i<stop_arr.length;i++)
  {     
     html+='<tr><td class=form>'+(i+1)+'</TD><td class=form  width="100%"><a class=address_list href="javascript:GetCenterMap(DefScale,'+parseInt(stop_arr[i][0])+','+parseInt(stop_arr[i][1])+',0,\'\',\'\',\'\',\'\');">'+stop_arr[i][2].toLowerCase()+'</a></td>';
     if(i==0 && stop_arr.length==1)
       html+='<td></td>';
     else if(i==0) 
       html+='<td><a TITLE="'+t_giu_tappa+'" href="#" onClick="javascript: FlagChange('+i+',1); return false;"><IMG border="0" name="giu'+i+'" src="images/Giu_grigio.gif"></a><IMG border="0" src="images/SuGiu_blank.gif"></td>';
     else if(i==stop_arr.length-1)
        html+='<td><IMG border="0" src="images/SuGiu_blank.gif"><a TITLE="'+t_su_tappa+'" href="#" onClick="javascript: FlagChange('+i+',-1); return false;"><IMG border="0" name="su'+i+'" src="images/Su_grigio.gif"></a></td>';
     else
       html+='<td><a TITLE="'+t_giu_tappa+'" href="#" onClick="javascript: FlagChange('+i+',1); return false;"><IMG border="0" name="giu'+i+'" src="images/Giu_grigio.gif"></a><a TITLE="'+t_su_tappa+'" href="#" onClick="javascript: FlagChange('+i+',-1); return false;"><IMG border="0" name="su'+i+'" src="images/Su_grigio.gif"></a></td>';
     
     html+='<td class=form align="middle" valign="top" width="16"><a href="#" onclick="javascript: FlagCanc('+i+'); return false;" TITLE="'+t_cancella_tappa+'">X</A></td>';     
     html+='</TR>';
  }
  stoplayerlistobj.innerHTML='';  
  if(html!=''){
        if(stop_arr.length>1){
           html+='<tr><td nowrap colspan=4><input type="button" class=button onclick="GetStopPath();" value="'+l_calcola+'">';
        if(pathid!='null'){
           html+='&nbsp;&nbsp;<input type="button" class=button onclick="deletePath();" value="'+l_cancella+'">&nbsp;<input width=100 type="button" class=button onclick="BuildTextPath(String(document.MapBroker.getHTMLPath(false,getboundarymap_function,getpthcenterstop_function)));" value="'+l_percorso_testuale+'">';
           }     
        html+='</td></tr>';        
        
        }
        stoplayerlistobj.innerHTML='<TABLE border=0 width="100%" cellpadding=0 cellspacing=0><tr><td colspan=4 class=title>'+l_lista_tappe+'</td></tr><tr><td><table>'+html+'</table></td></tr></TABLE>';                        
        stoplayerlistobj.style.display='inline';
  /*if(StopLayerView){
   MM_showHideLayers('maplayer','','hide','pathlayer','','hide','stoplayer','','show');  
   setMenuStyle('m3');}*/
  }      
}
/*-------------------------------------*/
/*------------ INVERTI TAPPA ----------*/
/*-------------------------------------*/
function FlagChange(idx, add)
{
  stop_arr=getStopFromApplet();  
  if(idx==0 && add<0) return;
  if(idx==stop_arr.length && add>0) return;
  old = stop_arr[idx];
  stop_arr[idx] = stop_arr[idx+add];
  stop_arr[idx+add] = old;
  /*modifico le tappe sull'applet*/
  if(StaticMap) {
   try {
    parent.frames[1].deletePathNoMap();
   }
   catch (error) {}
  }
  else 
    document.MapBroker.deletePathNoMap();                     
  for(i=0;i<stop_arr.length;i++){
    if(stop_arr[i]){
         if(StaticMap) {
            try {
                   parent.frames[1].addStop(parseInt(stop_arr[i][0]),parseInt(stop_arr[i][1]),stop_arr[i][2]);
             }
             catch (error) {}
         }
         else 
              document.MapBroker.addStop(parseInt(stop_arr[i][0]),parseInt(stop_arr[i][1]),stop_arr[i][2]);   
    }                      
 }
  /*******************************/
  
  /*ridisegno le tappe sul template*/
  DrawStop();
  /*******************************/
  VisuaStopList();
}


/*-------------------------------------*/
/*------- CANCELLA BANDIERINA ---------*/
/*-------------------------------------*/
function FlagCanc(idx)
{ 
  stop_arr=getStopFromApplet();              
  stop_arr.splice(idx,1);  
  /*ridisegno le tappe sul template*/
  if(StaticMap) {
   try {
    parent.frames[1].deletePathNoMap();
   }
   catch (error) {}
  }
  else 
    document.MapBroker.deletePathNoMap();
  for(i=0;i<stop_arr.length;i++){
     if(stop_arr[i]){                        
          if(StaticMap) {
                         try {
                             parent.frames[1].addStop(parseInt(stop_arr[i][0]),parseInt(stop_arr[i][1]),stop_arr[i][2]);
                         }
                         catch (error) {}
                         }
         else 
                         document.MapBroker.addStop(parseInt(stop_arr[i][0]),parseInt(stop_arr[i][1]),stop_arr[i][2]);                                
     }                         
  }                         
  DrawStop();
  /*******************************/
  VisuaStopList();
}


/*funzione che ritorna le tappe richieste all'applet*/
function getStopFromApplet(){
	if(StaticMap) return; // FUNZIONE DA SVILUPPARE
        var ret,arr,elem;
        stoparr=new Array();        
        if((ret=String(document.MapBroker.getStopList()))!=""){
                //alert(ret);
                arr=ret.split("_#3_")[1].split("_#2_");//recupero gli elementi                  
                for(i=0;i<arr.length;i++){                        
                        elem=arr[i].split("_#1_");
                        stoparr.push(elem);
                        }
                }
        return stoparr;
        }
/***************************************************/


/**DISEGNA TAPPA**/
/*DRAW STOP ON MAP*/
function DrawStop(){
	if(StaticMap) return; // FUNZIONE DA SVILUPPARE
        var stoplist="";
        stoplist=String(document.MapBroker.getStopList());                
        //alert("drawstop sl="+stoplist);
        var arr_stop_list=stoplist.split("_#3_");                
        frames[0].document.getElementById("stopcont").innerHTML=arr_stop_list[0];      
        VisuaStopList();            
 }
/*****************/


/*-------------------------------------*/
/*------- VISUALIZZA TAPPA ------------*/
/*-------------------------------------*/
/***********************/
function GetPath(){
   var country=document.stopform.StopXcountry.value;
   var city=document.stopform.StopXcom.value;
   var address=document.stopform.StopXaddr.value;
   var num=document.stopform.StopXnum;
   command="VerifyAddress('"+country+","+city+","+address+","+num+"',0,'"+city+"','"+address+"',-1,-1);";                
   operation(false);
}


/*CALCOLO PERCORSO DA TAPPE*/
function GetStopPath(insert){
        if(insert){
                //se non sono stae inserite le tappe ...(percorso da form)
           if(StaticMap)
             parent.frames[1].deletePathNoMap();
           else
             document.MapBroker.deletePathNoMap();
           for(i=0;i<PoiStopSt.length;i++){
                if(PoiStopSt[i]){ 
                        //alert("tappe inserite="+PoiStopSt[i][0]+"--"+PoiStopSt[i][1]+"--"+PoiStopSt[i][2]);                                                      
                       if(StaticMap)
                         parent.frames[1].addStop(PoiStopSt[i][0],PoiStopSt[i][1],PoiStopSt[i][2]);
                       else
                       	 document.MapBroker.addStop(PoiStopSt[i][0],PoiStopSt[i][1],PoiStopSt[i][2]);
                       }
             }
        }  
        //alert(1); 
        showWaitImg(true);             
        if(StaticMap)
          mapout=String(parent.frames[1].getPath(parseInt(document.getElementById("Xpthtype").value),parseInt(document.getElementById("Xpthdetail").value),lang)); //parametrizzare la lingua!!!
        else {
          mapout=String(document.MapBroker.getPath(parseInt(document.getElementById("Xpthtype").value),parseInt(document.getElementById("Xpthdetail").value),lang)); //parametrizzare la lingua!!!
          Parse(true);
        }
        loadMap();
        setScale();
}

/*aaa*/
var delstop=true;
function GetFormPath(){  
      //se ho due tappe inserite (da form...)
      showWaitImg(true);
      if(PoiStopSt[0]!=null && PoiStopSt[1]!=null){
        GetStopPath(true);
        return;
        }  
      pos=getFormProgId();        
      country="";
      eval("country=document.pathform.Xpthcountry"+pos+".value");
      eval("city=document.pathform.Xpthcom"+pos+".value");        
      eval("address=document.pathform.Xpthaddr"+pos+".value");
      eval("num=document.pathform.Xpthnum"+pos+".value");
      country=country.replace("'","\\'");
      city=city.replace("'","\\'");
      address=address.replace("'","\\'");
      num=num.replace("'","\\'");      
      
      var p=country+","+city+","+address+","+num;     
       if(StaticMap)
           VerifyAddress(p,1,country,city,address,-1,-1);
        else {
         command="VerifyAddress('"+p+"',1,'"+country+"','"+city+"','"+address+"',-1,-1);";              
         operation(false);
        } 

}

//mi ritorna quale form da processare
function getFormProgId(){
        if(PoiStopSt[0]!=null)
                return 1;
        else return 0;    
        }




/* GESTIONE AGGIUNTA TAPPE*/
function AddStop(order,addtype,x,y,amc1,amd4,addr,num){        
       if(addrlistlayerobj) {
        addrlistlayerobj.innerHTML='';
        addrlistlayerobj.style.height=0;
	addrlistlayerobj.style.visibility='hidden';
        }
        //alert("AddStop: addtype="+addtype+" -- PathLayerView="+PathLayerView+" -- onload="+onload);               
        if(PathLayerView && addtype!=2 && onload==false){//dopo aver aggiunto la tappa visualizzo il layer Percorsi 
                MM_showHideLayers('maplayer','','hide','pathlayer','','show','stoplayer','','hide');                
                setMenuStyle('m2');                              
                }
         /*
         order  -1:inserito nell'array in coda (form tappe)
                 0:inserito in posizione 0     (tappa di partenza)
                 1:inserito in posizione 1     (tappa di arrivo)
         
          
         addtype 
                 0-->aggiunta tappa da POI (partenza/arrivo)
                 1-->aggiunta tappa da calcolo percorso indirizzi form
                 2-->aggiunta tappa da form tappe
         */              
         /**chiude eventuali finestre aperte...**/
         //return;
         if(wlist.length>0)                
                wlist[wlist.length-1].close();
                    
         var pos,stop_elem;//form da popolare con i dati testuali...              
         if(!(amd4 == "" && addr=="" && num=="")){                            
                 desc = amd4;                       
                 desc=(addr=="" ? desc : desc+" "+addr);
                 desc=(num=="" ? desc : desc+" "+num);
                 //posizione di inserimento
                 stop_elem=new Array(x,y,desc);                   
                 //se calcolo percorso da form o tappa da poi....
                 if(addtype==0 || addtype==1){
                        if(addtype==0) pos=order;
                        else pos=getFormProgId();
                        
                        //alert("inserisco nell'array in pos="+pos);
                        
                        PoiStopSt[pos]=stop_elem;
                        //alert("passo qui");
                        if(amc1!='')                                   
                                eval("document.getElementById(\"Xpthcountry" + pos + "\").value=amc1;");                          
                        eval("document.getElementById(\"Xpthcom" + pos + "\").value=amd4;");
                        eval("document.getElementById(\"Xpthaddr" + pos + "\").value=addr;");
                        eval("document.getElementById(\"Xpthnum" + pos + "\").value=num;");
                        eval("document.getElementById(\"XpthX" + pos + "\").value=x;");
                        eval("document.getElementById(\"XpthY" + pos + "\").value=y;");
                 }
                 if(addtype==2){//aggiunta tappa da form tappe          
                        document.MapBroker.addStop(x,y,desc);                         
                        GetCenterMap(DefScale,x,y,0,'','','','');   
                        //ridisegno le tappe sul template
                        DrawStop();
                        //VISUALIZZO LE TAPPE
                        VisuaStopList();
                        if(amc1!='')                      
                                document.getElementById("StopXcountry").value=amc1;
                        document.getElementById("StopXcom").value=amd4;
                        document.getElementById("StopXaddr").value=addr;
                        document.getElementById("StopXnum").value=num; 
                        ShowStopLayer();                                                                       
                 }                      
         }  
         //SE NON E' STATA AGGIUNTA LA TAPPA DA FORM TAPPE...
         if(addtype == 1){//solo tappa da calcolopercorso...                                 
                if(PoiStopSt[0]!=null && PoiStopSt[1]!=null){
                        GetStopPath(true);
                        return;
                        }
                //NORMALIZZO IL SECONDO INDIRIZZO                                                
                pos=getFormProgId();                                
                eval("VerifyAddress(document.pathform.Xpthcountry" + pos + ".value+','+document.pathform.Xpthcom" + pos + ".value+','+document.pathform.Xpthaddr" + pos + ".value+','+document.pathform.Xpthnum" + pos + ".value,1,\"\",\"\",document.pathform.Xpthaddr" + pos + ".value,-1,-1);");                        
                }
         /**chiudo eventuale finestre**/         
}


/*******************************/

/*EFFETTO CARICAMENTO IMMAGINE
var count = 0;
var step=30;
function redraw(){
        var left,top;
	if(count>=step) {
		count=0;
		frames[0].document.getElementById("bgmap").style.backgroundImage="url("+mapsrc+")";
		obj.style.border="none";
		return;
		}					
	setTimeout(redraw,20);
	count++;
	
	obj=mapobj;
	obj.style.border="solid 1px";
	mapw=Math.round(count*350/step);
	maph=Math.round(count*250/step);	
	left=Math.round(350/2-mapw/2);
	top=Math.round(250/2-maph/2);	
	obj.style.top=top;
	obj.style.left=left;
	obj.style.width=mapw;
	obj.style.height=maph;
	}
*/
function redraw(){        
        obj=mapobj;
        obj.style.top=0;
	obj.style.left=0;
	obj.style.width=dimx;
	obj.style.height=dimy;
	resizeMapArea();
        }

		
function drawPoi(){        
        //var text="";                
        if(!StaticMap)
          out=String(document.MapBroker.getPoi(broker_list,js_poi_infomap_function,js_poi_infotemplate_function,js_poi_hl_function,js_poi_addstop_function,js_getpath_function)).split("_#2_");
        else
          out=String(parent.frames[1].getPoi(broker_list,js_poi_infomap_function,js_poi_infotemplate_function,js_poi_hl_function,js_poi_addstop_function,js_getpath_function)).split("_#2_");
        poitext=out[0];
        poilist=out[1];  
        poimsg=out[2];  
        
        if(out[2] && out[2]!='null' && out[2]!='undefined') { locallayer=out[2]; }
        if(poitext != 'null'  && poitext != '')
                poicontobj.innerHTML=poitext; 
        else    poicontobj.innerHTML="";  
        if(locallayer && locallayer != 'null')
                  loclayerobj.innerHTML=locallayer; 
        else    loclayerobj.innerHTML="";  
        BuildPoiList(poilist);   
        showWaitImg(false);    
}


/**template label text**/
var t_zoom_meno='';
var t_zoom_piu='';
/***********************/

/*rollover e highlighting styles function*/
function setScaleZoomBar(id_scale){
	/**restore color**/
	//if (ns4) return;
	i=1;
	while(robj=document.getElementById("z"+i)){
		robj.className='zoombar';
		i++;
		}
	/*****************/
	document.getElementById("z"+id_scale).className='zoombar_selected';
}

function setBgColorModeBar(obj){
	/**restore color**/
	//if (ns4) return;
	i=1;
	while(robj=document.getElementById("modbar"+i)){
		robj.className='mapmode';
		i++;
		}
	/*****************/
	obj.className='mapmode_selected';
}
/*******************************************/


/*set scale zoombar color*/
function setScale(){
  var CurScale;
  var id_scale;
  CurScale  = scale;
  if (CurScale <= 2000)
  	setScaleZoomBar(1);
  else if (CurScale <= 10000)
  	setScaleZoomBar(2);
  else if (CurScale <= 25000)
    setScaleZoomBar(3);
  else if (CurScale <= 50000)
    setScaleZoomBar(4);
  else if (CurScale <= 250000)
	setScaleZoomBar(5);
  else if (CurScale <= 500000)
	setScaleZoomBar(6);
  else if (CurScale <= 1000000)
	setScaleZoomBar(7);
  else if (CurScale <= 2000000)
	setScaleZoomBar(8);
  else if (CurScale <= 5000000)
	setScaleZoomBar(9);
  else if (CurScale <= 10000000)
	setScaleZoomBar(10);
}

/*******GRUPPPI*********/
function setCheckCategory(broker,obj){
        if(scale != -1){
          if(StaticMap) {
           showWaitImg(true);    
          	
             if(!obj.checked) {        //hide category
                try {
                     parent.frames[1].SetCategory(broker,obj.id,false,true);
                    }
                    catch (error) {}
             }
             else {   //show category                
                try {
                    parent.frames[1].SetCategory(broker,obj.id,true,true);
                    }
                 catch (error) {}
             }
          }
          else  {
                if(!obj.checked)
                        //hide category
                        document.MapBroker.SetCategory(broker,obj.id,false,false);
                else    //show category                
                        document.MapBroker.SetCategory(broker,obj.id,true,false);
                drawPoi();
                }                
       }
};
        
function setCategory(broker,grp){                  
        if(StaticMap) {
          try {
           parent.frames[1].SetCategory(broker,grp,true,true);
          }
          catch (error) {}
        }          
        else
          document.MapBroker.SetCategory(broker,grp,true,false);
        
        if(document.getElementById(grp))
                document.getElementById(grp).checked=true;        
  }
        
function setHttpCategory(){            
        if(grplist!=""){
                resetCheckbox();
                grp_arr=grplist.split("_#2_");
                for(i=0;i<grp_arr.length;i++){
                        elem=grp_arr[i].split("_#1_");
                        if(document.getElementById(elem[1]))
                                document.getElementById(elem[1]).checked=true;
                         setCategory(elem[0],elem[1]);
                        }
                }
        }

function setMapCategory(){  
   if(grplist!=""){
     resetCheckbox();
     grp_arr=grplist.split("_#2_");
     for(i=0;i<grp_arr.length;i++){
        elem=grp_arr[i].split("_#1_");
        if(document.getElementById(elem[1]))
           document.getElementById(elem[1]).checked=true;
        if(!StaticMap)   
          setCategory(elem[0],elem[1]);
     }
  }
}

/**apertura pagina di dettaglio**/
var wdetail=null;
var g_broker='';
var g_idpoi='';
var g_grp=''
function getPoiInfo(idpoi,grp,broker){         
        //alert(idpoi+"--"+grp+"--"+broker);
        g_idpoi=idpoi;
        g_grp=grp;
        g_broker=broker;
        poidetail=true;            
        poidet="";
        if(StaticMap) {
          custid=parent.frames[1].GetParamConfig("CUSTID");
          poidet=parent.frames[1].buildHTMLPoiDetail(idpoi,custid,broker,"");
        }
        else {
          custid=document.MapBroker.GetParamConfig("CUSTID");
          /*
          poid 
          custid
          amc1
          deturl
          */ 
          det_url=String(document.MapBroker.getPoiBrokerUrl(broker));  
          poidet=document.MapBroker.buildHTMLPoiDetail(idpoi,custid,"",det_url);
          showPoiInfo(poidet);
        }
                                                
        return false;
}
function showPoiInfo(poidet) {
  if(poidet == "") return;
  if(PopupPoiDetail){
                if(g_broker=="UBIEST"){
                        if(wdetail!=null){
                        wdetail.close();
                        wdetail=null;
                        }
                        html='<HTML>';
                        html+='<HEAD>';
                        html+='<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">';
                        html+='<TITLE>Ubiest MapBroker</TITLE>';
                        html+='</HEAD>';
                        html+='<LINK rel="stylesheet" href="css/map.css">';
                        html+=poidet;
                        html+='</BODY>';
                        html+='</HTML>';
                        wdetail=window.open("","wdetail","menu=0,scrollbars=0,width=250,height=100");
                        if(wdetail==null)
                                return;
                        wdetail.document.write(html);
                        wdetail.document.close();
                 }
                 else{
                  window.open(CustomHtmlPoiDetail+"?idpoi="+g_idpoi+"&grp="+g_grp,"wdetail","menu=0,scrollbars=0,width=250,height=100");
                }
   }
   else{//dettaglio in pagina principale
       poidetobj=document.getElementById("poidetail");
       poidetobj.innerHTML=poidet;
       poidetobj.style.visibility="visible";    
    }
    objframe.poi_id='';                                          
    return false;
         
}

function closedetail(){
        poidetobj=document.getElementById("poidetail");
        poidetobj.innerHTML="";
        poidetobj.style.visibility="hidden";
        }
/********************************/

/**stampa le labels **/
function printText(var_txt){
  document.write(var_txt);
}

/*resize map*/
var restype=0;
old_dimx=dimx;
old_dimy=dimy;
function resizeMap(){  
        if(scale==-1) 
                return;    
        if(restype==0){
                dimx=600;
                dimy=400;
                //document.images['lente'].src="images/ico_rimpicciolisci_mappa.gif";
                txtpathwidth=dimx;                
                restype=1;
        } 
        else{   restype=0;
                dimx=old_dimx;
                dimy=old_dimy;
                //document.images['lente'].src="images/ico_ingrandisci_mappa.gif";
                txtpathwidth=dimx;                
        }
        resizeMapArea();
        if(StaticMap) {
          mapout=String(parent.frames[1].resizeMap(parseInt(dimx),parseInt(dimy)));
          tobj=document.getElementById("textpath");
          tobj.innerHTML="";
          if(pathid!='null') 
           BuildTextPath(String(parent.frames[1].getHTMLPath(false,getboundarymap_function,getpthcenterstop_function)));
        }
        else {
          mapout=String(document.MapBroker.resizeMap(parseInt(dimx),parseInt(dimy)));
          tobj=document.getElementById("textpath");
          tobj.innerHTML="";
          if(pathid!='null') BuildTextPath(String(document.MapBroker.getHTMLPath(false,getboundarymap_function,getpthcenterstop_function)));
          Parse(true);
        }
}

/*History*/
function setHistory(id){
        if(scale==-1) 
                return;
        showWaitImg(true);
        switch(id){
                case 1://first
                      if(StaticMap)  
                        mapout=String(parent.frames[1].getHistoryMap(1));
                      else
                        command="mapout=String(document.MapBroker.getHistoryMap(1));";
                break;
                case 2://prev
                      if(StaticMap)  
                        mapout=String(parent.frames[1].getHistoryMap(2));
                      else
                        command="mapout=String(document.MapBroker.getHistoryMap(2));";
                break;
                case 3://next
                      if(StaticMap)  
                        mapout=String(parent.frames[1].getHistoryMap(3));
                      else
                       command="mapout=String(document.MapBroker.getHistoryMap(3));";
                break;
                case 4://last
                      if(StaticMap)  
                        mapout=String(parent.frames[1].getHistoryMap(4));
                      else
                        command="mapout=String(document.MapBroker.getHistoryMap(4));";
                break;
                }
       if(!StaticMap)
        operation(true);
}

          
/*SET GROUPS CHECKBOX*/
function setGroups(grplist){ 
        //alert(grplist);       
        var arr_grplist;
        arr_grplist = grplist.split("_#2_");
        resetCheckbox();
        for(i=0;i<arr_grplist.length;i++){
                grp_arr=arr_grplist[i].split("'");
                grpdesc=grp_arr[0]; 
                grpid=grp_arr[1];               
                document.getElementById(grpid).checked=true;
                }        
        }  
              
//deseleziona le checkbox
function resetCheckbox(){
        //alert("reset");
        formobj=document.forms["grpform"];
        for(i=0;i<formobj.length;i++)
                if(formobj.elements[i].type=="checkbox")
                        formobj.elements[i].checked=false;
                                        
        }
/*********************/        

// Selezione della modalità di funzionamento
/** Modalità Normale - Navigazione
*/
var mode=1;
/*
mode 1: normal
mode 2: distanze
mode 3: toponimi
mode 4:GPS

*/
function SetNormalMode() {
        if(scale==-1) 
                return;
 	//document.uemapvw.SetMode(1);
	//if(ns4) return;
	infodiv.style.visibility='hidden';
	mode=1;
	setBgColorModeBar(document.getElementById('modbar1'));	
	content.style.cursor='default';	
 	}

/** Modalità FlyDistance - Distanze Aeree
*/
function SetFlyDistMode() {
        if(scale==-1) 
                return;
 	//document.uemapvw.SetMode(2);
	//if(ns4) return;
	infodiv.style.visibility='hidden';	
	mode=2;
	setBgColorModeBar(document.getElementById('modbar2'));	
	
	
}

function SetGpsMode() {
        if(scale==-1) 
                return;
 	//document.uemapvw.SetMode(2);
	//if(ns4) return;
	infodiv.style.visibility='hidden';	
	mode=4;
	setBgColorModeBar(document.getElementById('modbar2'));	
	content.style.cursor='help';	
	}

/** Modalità ToolTip - Toponomi
*/
function SetToolTipMode() {
        if(scale==-1) 
                return;
	//document.uemapvw.SetMode(4);
	//if(ns4) return;
	mode=3;
        setBgColorModeBar(document.getElementById('modbar2'));
        //document.frames[0].document.style.cursor='help';
        content.style.cursor='help';
	}

/** rollover menu  **/
/*to do: se non esiste un livello intermedio interrope il ciclo!!!*/
function setMenuStyle(id){
	if(!document.getElementById)
	return;
	/**restore color**/	
	for(i=1;i<=4;i++)
	if(robj=document.getElementById("m"+i))
		robj.className='menu';				
	/*****************/
        if(document.getElementById(id)) document.getElementById(id).className='menu_selected';
}

/**funzioni di layout**/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
   if ((obj=MM_findObj(args[i]))!=null) 
   { 
    v=args[i+2];
  
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }        
	  
	  if(v=='visible' || v=='show')
	  {	 
	   clayer=MM_findObj('contentlayer');
	   if(tobj=MM_findObj(args[i])){
	          //width=tobj.offsetWidth;
	          height=tobj.offsetHeight;
	   }
	   if (clayer.style){ 	        
	   	 clayer=clayer.style;
	    //clayer.width=width;
	}	  
	  clayer.height=height;
	}	
	obj.visibility=v; 
	obj.zindex=10;
	}
}
/**********************/

/*funzionalità di stampa*/
wreport = null;
function doReport(){
        if(scale==-1) 
                return;
        //29.7 X 21 cm 1.414
        if(wreport!=null){
                wreport.close();
                wreport=null;
        }
        /**/

        //var lsRegExp =/javascript:/g;
        
        //var lsRegExp =/\"javascript:(.*)\"/g;
        
        
        if(poitext!="null"){
         if(StaticMap)
           htmlpoi=String(parent.frames[1].getReportPoi());
         else
           htmlpoi=String(document.MapBroker.getReportPoi(broker_list));      
         }                                                 
        else htmlpoi="";
    
        html='<HTML>';
        html+='<HEAD>';
        html+='<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">';
        html+='<TITLE>Ubiest MapBroker</TITLE>';
        html+='</HEAD>';
        html+='<LINK rel="stylesheet" href="css/map.css">';
        html+='<BODY class="report" leftmargin=0 topmargin=0 bottomMargin=0 rightMargin=0>';
        html+='<div class="report" style="FONT-SIZE: 0px; Z-INDEX: 3; LEFT: 0px; width: '+(dimx+20)+'px; POSITION: absolute; TOP: 0px; height: 10px;"></div>';
        html+='<div class="report" style="FONT-SIZE: 0px; Z-INDEX: 3; LEFT: 0px; width: '+(dimx+10)+'px; POSITION: absolute; TOP: '+(dimy+10)+'px; height: 100px;"></div>';
        html+='<div class="report" style="FONT-SIZE: 0px; Z-INDEX: 3; LEFT: 0px; width: 10px; POSITION: absolute; TOP: 0px; height: '+(dimy+20)+'px;"></div>';
        html+='<div class="report" style="FONT-SIZE: 0px; Z-INDEX: 3; LEFT: '+(dimx+10)+'px; width: 10px; POSITION: absolute; TOP: 0px; height: '+(dimy+20)+'px;"></div>';
        
        /**immagini bianche**/
        html+='<div style="FONT-SIZE: 0px; Z-INDEX: 2; LEFT: 0px;POSITION: absolute; TOP: 0px; height: 10px;"><img src="images/blank.gif" width="'+(dimx+20)+'" height="10"></div>';
        html+='<div style="FONT-SIZE: 0px; Z-INDEX: 2; LEFT: 0px;POSITION: absolute; TOP: '+(dimy+10)+'px; height: 100px;"><img src="images/blank.gif" width="'+(dimx+10)+'" height="100"></div>';
        html+='<div style="FONT-SIZE: 0px; Z-INDEX: 2; LEFT: 0px; width: 10px; POSITION: absolute; TOP: 0px;"><img src="images/blank.gif" height="'+(dimy+20)+'" width="10"></div>';
        html+='<div style="FONT-SIZE: 0px; Z-INDEX: 2; LEFT: '+(dimx+10)+'px; width: 10px; POSITION: absolute; TOP: 0px;"><img src="images/blank.gif" height="'+(dimy+20)+'" width="10"></div>';
        /********************/
        
        html+='<DIV  style="LEFT: 10px; POSITION: absolute; TOP: 10px" id=content>';
        html+='<div id=content style="OVERFLOW: hidden;visibility:visible;z-Index:100">'; 
        html+='<div style="position:absolute;z-Index:1;visibility:visible;">'+htmlpoi+'</div>'; 
        html+='<div><IMG  src="'+mapsrc+'"></div>';
        html+='</div>';
        html+='</div>';
        html+='<div style="FONT-SIZE: 0px; Z-INDEX: 3; LEFT: 10px; POSITION: absolute; TOP: '+(dimy+20)+'px;">';
        html+='<table cellpadding=0 cellspacing=0><tr><td><textarea style="width:'+dimx+';height:80;scrolling:none"></textarea></td></tr>';
               
        if(tp_obj.innerHTML !=""){
                if(StaticMap)
                  pth=String(parent.frames[1].getHTMLPath(true,"",""));
                else
                  pth=String(document.MapBroker.getHTMLPath(true,"",""));
                pth=replaceAlgotype(pth);       
                html+='<tr><td align=center><TABLE cellpadding=1 cellspacing=0 WIDTH="'+txtpathwidth+'" class="textpath">'+pth+'</table></td></tr>';                
                }
        html+='<tr><td><input type=button class="button" onclick="window.print();" value="'+l_stampa+'">&nbsp;<input type=button onclick="self.close();" class="button" value="'+l_chiudi+'"></td></tr>';
        html+='</table></div>';
        html+='</BODY>';
        html+='</HTML>';
        wreport=window.open("","wreport","menu=0,scrollbars=1,width="+(dimx+50)+",height="+(dimy+100));
        if(wreport==null)
                return;
        wreport.document.write(html);
        wreport.document.close(); 
}
/************************/


/*funzionalità di stampa*/
wreport = null;
function doPDAReport(){
        if(scale==-1) 
                return;
        //29.7 X 21 cm 1.414
        if(wreport!=null){
                wreport.close();
                wreport=null;
        }
        mapout=String(document.MapBroker.getReportMap(260,200));
        Parse(false);
        /**/
        html='<HTML>';
        html+='<TITLE>Report di stampa</TITLE>';
        html+='<html>';
        html+='<LINK rel="stylesheet" href="css/map.css">';
        html+='<BODY topmargin=0 leftmargin=0><table>';        
        html+='<tr><td class=box><img src="'+mapsrc+'" border=0></td></tr>';
        if(pathid!='null'){
                pth=String(document.MapBroker.getHTMLPath(true,"return;"));                
                html+='<tr><td align=center><TABLE cellpadding=0 cellspacing=0 WIDTH=258 class=box>'+pth+'</table></td></tr>';
                }
        html+='<tr><td><textarea cols=30 rows=3></textarea></td></tr>';
        html+='<tr><td><input type=button class="button" onclick="window.print();" value="'+l_stampa+'">&nbsp;<input type=button onclick="self.close();" class="button" value="'+l_chiudi+'"></td></tr>';
        html+='</table></BODY>';
        html+='</html>';
        html+='</HTML>';
        wreport=window.open("","wreport","menu=0,scrollbars=1,width=288,height=230");
        if(wreport==null)
                return;
        wreport.document.write(html);
        wreport.document.close();    
        wreport.document.focus();    
}
/************************/

/*invio mail*/
wprint = null;
function sendMail(){
        if(scale==-1) 
                return;
        //
        if(wmail!=null){
                wmail.close();
                wmail=null;
                }
        /**/ 
        //allego eventualmente percorso testuale   
        var pth="";  
        //if(grplist!="") //richiedo la nuova mappa solo ce ci sono gruppi attivi
        if(true){//da sistemare !!!! TODO max
                //alert("grplist:--"+grplist+"--");
                mapout=String(document.MapBroker.getReportMap(parseInt(dimx),parseInt(dimy)));
                Parse(false);
        }
        
        wprint=window.open("utils/mail.php?lang="+lang+"&filename="+mapsrc+"&sender="+mail_sender+"&from="+mail_sender,"wprint","menu=0,scrolling=0,width=300,height=180");
        if(wprint==null)
                return;
        //wprint.document.write(html);
        //wprint.document.close();          
        wprint.document.focus();
    
}
/************************/
var hw = null;
function Help(param,b){
        //alert(a);
        //alert(b);
  if (hw)
    hw.close();
  hw = null;
  hw = window.open("help/help_"+(new String(lang))+".htm#"+param,"","height=400,width=600,scrollbars=yes");
        
}

function ShowStopLayer(){
        if(StopLayerView)
           MM_showHideLayers('maplayer','','hide','pathlayer','','hide','stoplayer','','show');
}


function getStreetInfo(x,y,gps){
        var lat="",lon="";
        if(StaticMap) 
         out=new String(parent.frames[1].getStreetInfo(x,y,gps));
        else {
         out=new String(document.MapBroker.getStreetInfo(x,y,gps));
         parseStreetInfo(out,x,y,gps);
        }
}
function parseStreetInfo(out,x,y,gps) {  
	var street_info = '';
        if(out=="EMPTY" || out=="TIMEOUT" || out=="ERR")
                return;
        info=out.split("_#1_");	
	street_info=(info[0]=="null" ? "" : info[0])+" "; //amc1
	street_info+=(info[1]=="null" ? "" : info[1])+" ";//amd2
	street_info+=(info[2]=="null" ? "" : info[2])+" ";//amd3
	street_info+=(info[3]=="null" ? "" : info[3])+" ";//amd4
	street_info+=(info[4]=="null" ? "" : info[4])+" ";//addr
	street_info+=(info[5]=="null" ? "" : info[5])+" ";//num
	if(gps==1){
	        street_info+="<BR> GPS: ";
	        street_info+="lat "+info[6].substr(0,5)+"°";
	        street_info+="lon "+info[7].substr(0,5)+"°";
	        }
	//alert(street_info);		
	infodiv.innerHTML="<table width=120 border=0 cellspacing=1 cellpadding=1><tr><td class=tooltips align=center>"+street_info+"</td></tr></table>";	
	offx=mapframeobj.offsetLeft;
	offy=mapframeobj.offsetTop;
	//posizionamento assoluto
	if(x > dimx*0.85){
	        infodiv.style.top=offy+y;
	        infodiv.style.left=offx+x-120;}
	else{
	        infodiv.style.top=offy+y;
	        infodiv.style.left=offx+x;}
	infodiv.style.visibility='visible';
}


//evidenzia poi sulla mappa
var curr_id="";
function poiHighLighting(id){
        //reset
        if(curr_id==id)
                set=false;
        else set=true; 
        curr_id=id;       
        i=1;
        while(div=objframe.document.getElementById("poi_"+i)){
                //reset pone a 1 gli zIndex...                
                img=objframe.document.getElementById("poiimg_"+i);                
                img.className="";
                div.style.zIndex=1;
                i++;
        }
        div=objframe.document.getElementById('poi_'+id);        
        img=objframe.document.getElementById('poiimg_'+id);   
        //alert(img.className);   
        if(set)
                img.className="poiHighLight";
        else                
                {img.className="";
                 curr_id="";
                }
        div.style.zIndex=3;   
}

function setChange(id,del_type){
        PoiStopSt[id]=null; 
        if(del_type==0)
                return;
        document.getElementById("Xpthnum"+id).value="";
        if(del_type==2)
                document.getElementById("Xpthaddr"+id).value="";
        }
        

/****************/


        
//visualizza la clessidra
/*function showWaitImg(show){
        //per ikcona 32 x 32 pixel        
        if(show){
	    if(!StaticMap) 
                objframe.document.Blinker.start();
            vis='visible';
                }
        else{
 	     if(!StaticMap) 
                objframe.document.Blinker.stop();
             vis='hidden'; 
            }       
        waitobj.style.visibility=vis;   
        if(StaticMap) {
          waitobj.style.top=dimy/2-16;
          waitobj.style.left=dimx/2-16;                
        } 
        else {
         waitobj.style.top=dimy-16;
         waitobj.style.left=dimx-94;                
        }
        }
*/        
function showWaitImg(show){
        //per ikcona 32 x 32 pixel        
        if(show){
            vis='visible';
                }
        else{
             vis='hidden'; 
            }       
        waitobj.style.visibility=vis;   
        waitobj.style.top=dimy/2-16;
        waitobj.style.left=dimx/2-16;                
}        
/****************/
/*
function showWaitImg(show){
        //sostituisco l'immagine con la splash...
        mapobj.src=splash_url;
}
*/

//gestione errori
function getErrorMsg(code){        
        text="";
        eval("text=err_msg"+code+";");   
        window.defaultStatus = text;
        if(code==2)
                alert(text);
        showWaitImg(false);                
}

var werror=null;
//gestione errori
function showErrorMsg(code){
        text="";
        wtop=window.screenLeft+200;
        wleft=window.screenTop+100;
        eval("text=err_msg"+code+";");   
        werror=window.open("","werror","menu=0,scrollbars=0,width=150,height=100,top="+wtop+",left="+wleft);        
        if(werror==null)
                return;
        html='<html><title>MapBroker</title>';                
        html+='<LINK rel="stylesheet" href="css/map.css">';                
        html+='<body class=messagge onload="setTimeout(self.close,5000);"> '+text+'</body>';
        html+='</html>';                  
        werror.document.write(html);        
        werror.document.close();        
        showWaitImg(false);                
        }

/**nuova integrazione con sincronizzazione eventi**/
var timerID;
var currentoperation;

function execoperation(p_parse){
	var result;
	clearInterval(timerID);	
	result = eval(command);
	if(p_parse) Parse(true);
	return result;
	}

function operation(p_parse){       
	timerID=setInterval("execoperation("+p_parse+")",100);
	return false;
}// operation

function LatedVerifyAddress(params,maptype,amc1,amd4,addr,x,y){   
        var lsRegExp =/'/g;
        params=String(params).replace(lsRegExp,"\\'");
        amd4=String(amd4).replace(lsRegExp,"\\'");                                         
        addr=String(addr).replace(lsRegExp,"\\'"); 
        String(addr).replace(lsRegExp,"\\'");             
        if(StaticMap)
          VerifyAddress(params,maptype,amc1,amd4,addr,x,y);
        else {
         command="VerifyAddress('"+params+"',"+maptype+",'"+amc1+"','"+amd4+"','"+addr+"',"+x+","+y+");";        
         operation(false);
        }
}

function resizeMapArea(){
        document.getElementById("mapframe").style.width=dimx; 
        document.getElementById("mapframe").style.height=dimy;
        content.style.width=dimx;        
        content.style.height=dimy;
}

/**valorizza la form di ricerca coordinate ad ogni nuova mappa**/
function setCoordFields(){        
        if(objscale=document.getElementById("Xscale"))
                objscale.value=scale;  
        if(objcx=document.getElementById("Xcoordx"))
                objcx.value=cx;
        if(objcy=document.getElementById("Xcoordy"))
                objcy.value=cy;
                
        }



/**/
function SavePoint(){
        document.getElementById("Xsave").value=cx;
        document.getElementById("Ysave").value=cy;
        };

