///////////////////////////////////////
// UbiEst Java Applet Methods support
///////////////////////////////////////
// variabil per la risoluzione dell' indirizzo , per il percorso testuale e per i pop-up



var AMC1 ="";  // codice della nazione
var AMC2 ="";  // codice della regione;
var AMC3 ="";  // codice della provincia;
var AMC4 ="";  // codice del comune
var AMC5 ="";  // codice di zona di un comune

var AMD4 ="";  // descrizione del comune (nome)
var ADDR ="";  // descrizione indirizzo
var AMC  ="";  // insieme dei codici descritti sopra


var normcounter=0;

// Abilita i pop-up prima di chiudersi a richiamare una funzione di ricerca
var search = 0;
// Se vale 1 indica che sto ricercando solo un comune senza indirizzo
var searchcity = 0;
// Cambia la descrizione a seconda si ricerchi un indirizzo(0) o un comune e un indirizzo(1)
var AddrLookup = 0;
// Abilita(1)/Disabilita(0) l'apertura del pop-up per le ricerche dei comuni
var CityPopup = 0;
// Individua il tipo ricerca che si sta effettuando
/*
1 --> ricerca mappa da un indirizzo
2 --> calcolo percorso (prima tappa)
3 --> calcolo percorso (seconda tappa)
4 --> aggiungi tappa
5 --> calcolo percorso
*/
var searchtype=0;

var scala = 0;   // scala da richiedere
var puntox = 0;  // coord X (UTM)
var puntoy = 0;  // coord Y (UTM)

var ScaleMaxPoi=1000000; // scala massima per richiedere i Poi
var StatusCheck=true;  // variabile stato checkbox poi   true(attivati)\false(disattivati)

// Array per la gestione dei P.O.I
arraycategory0= new Array(); //Nome del broker
arraycategory1= new Array(); //Identificativo del gruppo
arraycategory2= new Array(); //Descrizione del gruppo
arraycategory3= new Array(); //nome checkbox nella pagina html (form+campo)

//Array gestione Form di ricerca
acountry = new Array();
acity    = new Array();
aaddress = new Array();
anumber  = new Array();

//Array gestione Salvataggio poligoni
var puntiPoligono="";
var numverticipoligono=0;
var arrayelemp;
var xp=0;
var yp=0;

var opc = null; // variabile finestra poi

function categoriepoi()  {
  var i=0;

  arraycategory0[i]="";
  arraycategory1[i]="";
  arraycategory2[i]="";
  arraycategory3[i]="";

  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_2_1001";
  arraycategory2[i]="Vitto";
  arraycategory3[i]="Category_Form.Cat_NAV_2_1001";

  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_1_992";
  arraycategory2[i]="Trazporti";
  arraycategory3[i]="Category_Form.NAV_1_992";

  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_2_1012";
  arraycategory2[i]="Turismo";
  arraycategory3[i]="Category_Form.NAV_2_1012";

  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_3_7510";
  arraycategory2[i]="Autonoleggio";
  arraycategory3[i]="Category_Form.NAV_3_7510";

  arraycategory0[++i]="UBIEST" ;
  arraycategory1[i]="NAV_2_1010" ;
  arraycategory2[i]="TempoLibero";
  arraycategory3[i]="Category_Form.NAV_2_1010";

  arraycategory0[++i]="UBIEST" ;
  arraycategory1[i]="NAV_2_1011" ;
  arraycategory2[i]="Sport";
  arraycategory3[i]="Category_Form.NAV_2_1011";

  /**CATEGORIE CUSTOM SECTION START**/  
  arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="CUST1" ;
  arraycategory2[i]="CUST1";
  arraycategory3[i]="Category_Form.Cat_CUST1";

  arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="CUST2" ;
  arraycategory2[i]="CUST2";
  arraycategory3[i]="Category_Form.Cat_CUST2";

  arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="CUST3" ;
  arraycategory2[i]="CUST3";
  arraycategory3[i]="Category_Form.Cat_CUST3";
  
} //categoriepoi


/**
Inizilaizzazione dei quattro array per la gestione delle form di ricerca
all'interno della pagina principale a seconda delle ricerche che si
intendono utilizzare
*/
function categoryform(){
var i=0;

   acountry[i]="";
   acity[i]   ="";
   aaddress[i]="";
   anumber[i] ="";
   // 1 campi ricerca indirizzo
   acountry[++i]="ricerca.Country";
   acity[i]="ricerca.City";
   aaddress[i]="ricerca.Address";
   anumber[i]="ricerca.Number";
   // 2 campi calcolo percorso(1)
   acountry[++i]="percorsi.Country";
   acity[i]="percorsi.City";
   aaddress[i]="percorsi.Address";
   anumber[i]="percorsi.Number";
   // 3 campi calcolo percorso(2)
   acountry[++i]="percorsi.Country2";
   acity[i]="percorsi.City2";
   aaddress[i]="percorsi.Address2";
   anumber[i]="percorsi.Number2";
   // 4 campi aggiungi tappa
   acountry[++i]="percorsi2.Country";
   acity[i]="percorsi2.City";
   aaddress[i]="percorsi2.Address";
   anumber[i]="percorsi2.Number";
   // 5 campi calcolo percorso
   acountry[++i]="percorsi2.Country";
   acity[i]="percorsi2.City";
   aaddress[i]="percorsi2.Address";
   anumber[i]="percorsi2.Number";
   }


//------------------------------------------------------mappa-------------------------------------------------------

// Selezione della modalità di funzionamento
/** Modalità Normale - Navigazione
*/
function SetNormalMode() {
 	document.uemapvw.SetMode(1);
	if(ns4) return;
	setBgColorModeBar(document.getElementById('modbar1'));		
 	}

/** Modalità FlyDistance - Distanze Aeree
*/
function SetFlyDistMode() {
 	document.uemapvw.SetMode(2);
	if(ns4) return;	
	setBgColorModeBar(document.getElementById('modbar2'));	
	}

/** Modalità MultiPath - Percorsi
*/
function SetMultiPathMode() {
	document.uemapvw.SetMode(3);
	if(ns4) return;
	setBgColorModeBar(document.getElementById('modbar3'));
	}

/** Modalità ToolTip - Toponomi
*/
function SetToolTipMode() {
	document.uemapvw.SetMode(4);
	if(ns4) return;
        setBgColorModeBar(document.getElementById('modbar3'));
	}

// History delle mappe generate
/**
Funzione per la cronologia delle mappe visualizzate
@param type
*/
function DoAction(type){
	//	case 1:first
	//	case 2:previous
	//	case 3:next
	//	case 4:last

	document.uemapvw.DoAction(parseInt(type));
        // Gestione Poi
	PoiCategoryStatus();
	cancella();
	}


/**
Funzione di stampa della pagina contenente la mappa
*/
function PrintPage() {
  window.print();
}

/**
Funzione di stampa della mappa visualizzata dall'applet
Questa non deve essere utilizzata con php 4.2 usare PrintPage();
*/
function PrintMap() {
  var lsRegExp = /\+/g;
  var scrip1= "<SCRIPT LANGUAGE='JavaScript'>function printit(){ if (window.print) { window.print() ;} else {";
  var scrip2= "var WebBrowser = '<OBJECT ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>';";
  var scrip3= "document.body.insertAdjacentHTML('beforeEnd', WebBrowser); webBrowser1.ExecWB(6, 2);}}" ;
  var scrip4= "<SCRIPT LANGUAGE='JavaScript'>function c(){document.forms[0].submit();}<\/SCRIPT>";
  var html = "<html><body bgcolor='#ffffff'  leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><form action='/JMB1.3.0/JGate/PrintMap.php' method='POST'><input type='hidden' name='datagif' Value='"+document.uemapvw.GetMap2Print()+"'></form></body></html>";
  var dim = "height=490,width=470,resizable=no,scrollbars=0";
  o = window.open( "","",dim);
  o.document.write(scrip4+html); //scrip
  o.c();
  o.document.close();
}

/**
Visualizza il dettagio dei Poi contenuti nella mappa (non è un evento applet)
*/
function POIOnMap(){
	var lsRegExp =/\+/g;
	var x;
	testx=document.uemapvw.DisplayPoi();
	if(opc!=null){opc.close(); opc=null;}
	if (testx==""){ return;}
	x=  unescape(String(testx).replace(lsRegExp,' '));
	setxmlc(x);
	if (arrayelemc.length > 1  )	{visuac();}
}

//------------------------------------------------------mappa-------------------------------------------------------

//------------------------------------------------------ricerca-----------------------------------------------------

/**
Sincronizza lo stato dei Poi (accesi\spenti) tra l'applet e la pagina principale (checkbox)
*/
function PoiCategoryStatus(){
  for(i=1; i<arraycategory0.length; i++){
  	 eval("document."+arraycategory3[i]+ ".checked=document.uemapvw.GetPoiCategoryStatus(\""+arraycategory0[i] +"\",\""+arraycategory1[i]+"\");");
  }
}

/**
Attiva disattiva i checkbox dei Poi
*/
function CheckStatus(status){
  for(i=1; i<arraycategory0.length; i++){
  	 eval("document."+arraycategory3[i]+ ".disabled="+status+";");
  }
}

function StoreLocatorCalcPath(X,Y)
{
DeletePathNoMap(); 
document.uemapvw.AddStopSt(StartPathX,StartPathY,0);
document.uemapvw.AddStopSt(X,Y,0);
GetPath();
}
/**
Cancella il percorso senza generare nuova mappa e chiude pop-up
*/
function DeletePathNoMap(){

 if(document.uemapvw.GetPathID()!=null && document.uemapvw.GetPathID()!="")
   document.uemapvw.DeletePathNoMap();
	startaddress=0;
	stopaddress=0;
	cancella();
}

/**
Cancella il percorso sia nella mappa che nel pop-up
*/
function DeletePath(){
	document.uemapvw.DeletePath();
	startaddress=0;
	stopaddress=0;
	cancella();
	}

/**
Visualizza il percorso testuale se non già visualizzato
*/
function DisplayDetailPath() {
    if (actuawin==null)
    	ubitag();
	 else
	actuawin.focus();
}

/**
Risoluzione dell'indirizzo per ottenere le sue coordinate
@param country codice della nazione
@param city nome del comune
@param address nome dell'indirzzo
@param numero numero civico
@param tipo intero per forzare la ricerca a un solo risultato
*/
function Search(country,city,address,numero,tipo){
	// varibile per il force dell'indirizzo
	var force="";
	  if (tipo==1) force="\" FORCE=\"1";  // non usare apice singolo --> if (tipo==1) force='\" FORCE=\"1';

	if ((city.toUpperCase()!=AMD4 && ADDR!=address.toUpperCase()) || ADDR!=address.toUpperCase() ) {
	  if (city.toUpperCase()!=AMD4) {AMC = "";}
	  if (AMC == ""){
   	    AddrLookup=1;
   	    if (address.toUpperCase()=="") address=" ";
	    document.uemapvw.SearchLocation( country,'', '','', city+force,'','','','',address, numero);
	  }
	  else{
	    AddrLookup=0;
   	    if (address.toUpperCase()=="") address=" ";
	    document.uemapvw.SearchLocation( AMC+force,'', '','', city,'','','','',address, numero);
	  }			
	  return false;
	}
	else if (AMD4!=city.toUpperCase()){
	  searchcity = 1;
	  document.uemapvw.SearchLocation( country, '', '', '', '', '','','', city, '', '');
	  return false;
	}
	return true;
}// Search


/**
Risoluzione dell'indirizzo per ottenere le sue coordinate anche se trova nomi uguali
@param type tipo di ricerca
@param country codice della nazione
@param city nome del comune
@param address nome dell'indirzzo
@param numero numero civico
*/
function SearchAddress(type,country,city,address,numero){
	searchtype=type;
	CityPopup = 1;
	Search(country,city,address,numero,0);
	CityPopup = 0;
	}

/**
Azzera le varibile usate per le ricerche
*/
function Reset(){        
	AMC  = "";
	AMC1 = "";
	AMC2 = "";
	AMC3 = "";
	AMC4 = "";
	AMC5 = "";
	AMD4 = "";
	ADDR = "";
	search = 0;
	scala  = 0;
	puntox = 0;
	puntoy = 0;
	}

/**
Richiesta di una mappa a partire da un indirizzo
*/
function SearchMapbyCoord() {

	search = 1;  // Parametro per l'appletwindows
	searchtype=1;

	var country = eval("document."+acountry[searchtype]+"[document."+acountry[searchtype]+".selectedIndex].value");
	var city    = eval("document."+acity[searchtype]+".value;");
	var address = eval("document."+aaddress[searchtype]+".value;");
	var numero  = eval("document."+anumber[searchtype]+".value;");

	// risoluzione dell'indirizzo
	if (!Search(country,city,address,numero,1))
		return;

	// Richiesta centratura mappa
	if (puntox!=0 && puntoy!=0){
		document.uemapvw.GetMapByCoord(parseInt(scala),parseInt(puntox),parseInt(puntoy),0);
		}

	// Reset parametri
	Reset();

	city    = eval("document."+acity[searchtype]   +".value=\"\";");
	address = eval("document."+aaddress[searchtype]+".value=\"\";");
	numero  = eval("document."+anumber[searchtype] +".value=\"\";");
	searchtype=0;

}// SearchMapbyCoord



/** IMPOSTAZIONE POI COME PARTENZA **/
FlagStart=0;
PoiStartSt=new Array(0,0);
function SetPoiStartSt(country,city,address,number,x,y){        
   if(!city && !address)
   {
     FlagStart=1;
     document.uemapvw.GetToolTip(x,y,-1);
     return;
   }
   
   if(!city)
   {
	  aop=address.split(' - ');
	  if(aop[1])
	  {
	   city=aop[1];
	   address=aop[0];
	  }
  }
  if(country)
  {
   if(document.percorsi.Country.options[document.percorsi.Country.selectedIndex].value != country)
    document.percorsi.Country.options.value=country;
  }
  document.percorsi.City.value=city;
  document.percorsi.Address.value=address;
  document.percorsi.Number.value=number;		
  PoiStartSt[0]=x;
  PoiStartSt[1]=y;
}

/** IMPOSTAZIONE POI COME DESTINAZIONE **/
FlagStop=0;
PoiFinishSt=new Array(0,0);
function SetPoiFinishSt(country,city,address,number,x,y){
   if(!city && !address)
   {
     FlagStop=1;
     document.uemapvw.GetToolTip(x,y,-1);
     return;
   }
	if(!city)
	{
	  aop=address.split(' - ');
	  if(aop[1])
	  {
	   city=aop[1];
	   address=aop[0];
	  }
  }
  if(country)
  {
   if(document.percorsi.Country2.options[document.percorsi.Country2.selectedIndex].value != country)
    document.percorsi.Country2.options.value=country;
  }
  document.percorsi.City2.value=city;
  document.percorsi.Address2.value=address;
  document.percorsi.Number2.value=number;
  PoiFinishSt[0]=x;
  PoiFinishSt[1]=y;
}
/****/

function ResetPoiStart(type){
	PoiStartSt[0]=0;
	PoiStartSt[1]=0;
	fobj=document.percorsi;
	switch(type){
	        case 1:
	                fobj.Address.value='';
	                fobj.Number.value='';
	        break;
	        case 2:
	                fobj.Number.value='';
	        break;
	        }
}

function ResetPoiFinish(type){
	PoiFinishSt[0]=0;
	PoiFinishSt[1]=0;  
  fobj=document.percorsi;
	switch(type){
	        case 1:
	                fobj.Address2.value='';
	                fobj.Number2.value='';
	        break;
	        case 2:
	                fobj.Number2.value='';
	        break;
	        }  
}



/**nuova integrazione con sincronizzazione eventi**/
var timerID;
var currentoperation;
var skip_search=0;
var startaddress=0;
var stopaddress=0;

function execoperation(){
	var result;
	clearInterval(timerID);
	result = eval(currentoperation);
	return result;
	}

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


/**************************************************/
function CheckStopPoi(){//controlla che le coordinate non siano uguali        
        if(PoiStartSt[0]==PoiFinishSt[0] && 
           PoiStartSt[1]==PoiFinishSt[1] &&
           PoiStartSt[0]!=0)
        return true;
        else return false;
        }
/**************************************************/

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



function NormalizeAddress(type){ 
     if(type!=0){                  
         	searchtype=type;
         	country = eval("document." + acountry[searchtype]+"[document."+acountry[searchtype]+".selectedIndex].value;");
         	city    = eval("document." + acity[searchtype]+".value;");
         	address = eval("document." + aaddress[searchtype]+".value;");
         	numero  = eval("document." + anumber[searchtype]+".value;");
         	// risoluzione dell'indirizzo
		      if(skip_search==0){
            if (!Search(country,city,address,numero,1))
            		return;
          }            	                	                	                	                	
      }
  		if (puntox!=0 && puntoy!=0){  		        
			  document.uemapvw.AddStopSt(parseInt(puntox),parseInt(puntoy),0);	
		  	skip_search=0;		
			  addstop++;
			  currentoperation = "SearchGetPath2()";
			  operation();
			}
}

function CalcolaPercorso(){        
    if (document.uemapvw.GetPathID()!=null && document.uemapvw.GetPathID()!="") 
		document.uemapvw.DeletePathNoMap();

    SearchGetPath2();
}

/*****************************************/
/**     CALCOLO PERCORSO SECTION START **/
addstop=0;
function SearchGetPath2(){        
		
    if(CheckStopPoi()){
       alert('I punti di partenza e arrivo coincidono\nSelezionare tappe diverse!');
       return;
    }
		
    search=1;
    if(addstop==2 || document.uemapvw.GetMode(0)==2){//se ci sono almeno 2 tappe...
       addstop=0;
       searchtype=0;
       Reset();
    
       currentoperation = "GetPath()";
  	 	 operation();
       //GetPath(); 
       SetNormalMode();                               
       return;
     }
    if(addstop==0){  
      stype=2;  
      if(PoiStartSt[0]!=0 && PoiStartSt[1]!=0){//se eseiste una tappa poi come partenza...
         stype=0;
         puntox=PoiStartSt[0];
         puntoy=PoiStartSt[1];
      } 
      NormalizeAddress(stype);
    }
    else{
      stype=3;  
      if(PoiFinishSt[0]!=0 && PoiFinishSt[1]!=0){//se eseiste una tappa poi come destinazione...
        stype=0;
        puntox=PoiFinishSt[0];
        puntoy=PoiFinishSt[1];
     }  
     NormalizeAddress(stype);
    }
}

/*****************************************/
function SearchAddStopSt() {

	search = 1;  // Parametro per l'appletwindows
	searchtype=4;

	var country = eval("document."+acountry[searchtype]+"[document."+acountry[searchtype]+".selectedIndex].value;");
	var city    = eval("document."+acity[searchtype]+".value;");
	var address = eval("document."+aaddress[searchtype]+".value;");
	var numero  = eval("document."+anumber[searchtype]+".value;");

	// risoluzione dell'indirizzo
	if (!Search(country,city,address,numero,1))
		return;

	// Richiesta centratura mappa con aggiunta bandierina
	if (puntox!=0 && puntoy!=0){
		document.uemapvw.AddStopSt(parseInt(puntox),parseInt(puntoy),0);
		document.uemapvw.GetMapByCoord(parseInt(scala),parseInt(puntox),parseInt(puntoy),0);
		}

	// Reset parametri
	Reset();

	city    = eval("document."+acity[searchtype]   +".value=\"\";");
	address = eval("document."+aaddress[searchtype]+".value=\"\";");
	numero  = eval("document."+anumber[searchtype] +".value=\"\";");

	searchtype=0;
}// SearchAddStopSt

/**
Richiesta di una mappa a fronte di una ricerca di prossimità
di un gruppo o un singolo P.O.I
*/
function SearchPoi(){

	var a = document.poi.Xpoi_group.selectedIndex+1;   // indice gruppo P.O.I selezionato
	var SearchType;  // da gestire

  	// Controllo se il gruppo già attivo più eventuale attivazione di tale gruppo
  	if (a!= 0 && !document.uemapvw.GetPoiCategoryStatus(arraycategory0[a], arraycategory1[a])){
		document.uemapvw.ActivatePoiCategoryStatus(arraycategory0[a],arraycategory1[a], true);
		eval("document."+arraycategory3[a]+ ".checked=true;");
  	}

	//Richiesta mappa con POI
	document.uemapvw.Search("","","","", "","",arraycategory0[a],arraycategory1[a], document.poi.Xpoi_description.value, "", /*parseInt(SearchType)*/ 22222,  document.poi.Xpoi_ray.value != "" ? parseInt(document.poi.Xpoi_ray.value) : 0,"","");

	document.poi.Xpoi_description.value="";
	document.poi.Xpoi_ray.value="";

}// SearchPoi

/**
Richiesta della mappa contenente un percorso calcolato
*/
function SearchGetPath(){

	search = 1;  // Parametro per l'appletwindows
	searchtype=5;

	var country = eval("document."+acountry[searchtype]+"[document."+acountry[searchtype]+".selectedIndex].value;");
	var city    = eval("document."+acity[searchtype]+".value;");
	var address = eval("document."+aaddress[searchtype]+".value;");
	var numero  = eval("document."+anumber[searchtype]+".value;");

	var algo=0;  // Parametro per il calcolo del percorso

	// risoluzione dell'indirizzo
	if (!Search(country,city,address,numero,1))
		return;

	if (puntox!=0 && puntoy!=0)
		document.uemapvw.AddStopSt(parseInt(puntox),parseInt(puntoy),0);

 	GetPath();

	Reset(); // Reset parametri

	city    = eval("document."+acity[searchtype]   +".value=\"\";");
	address = eval("document."+aaddress[searchtype]+".value=\"\";");
	numero  = eval("document."+anumber[searchtype] +".value=\"\";");
	searchtype=0;
}// SearchGetPath

/**
Funzione di calcolo percorso
*/
function GetPath(){
        /*
        ALGO = algoritmo di calcolo
	1 = percorso più veloce senza autostrada; 		
	2 = percorso più breve senza autostrada;
	5 = percorso più veloce con autostrada;	(default)
	6 = percorso più breve con autostrada;
	8 = percorso pedonale;
        */
	 // se calcolo il percorso con Da A
   	 if (document.percorsi.Xpthtype!= null && document.percorsi.Xpthdetail!=null){	
		 document.uemapvw.GetPath(parseInt(document.percorsi.Xpthtype.value),parseInt(document.percorsi.Xpthdetail.value),'');
		 
		}
	 
  	 else{
  		document.uemapvw.GetPath(0,0,'');
  		}

	}// GetPath()
//------------------------------------------------------ricerca-----------------------------------------------------




//--------------------------------------------------------EventiApplet--------------------------------------------------------
/**
Obbligatorio per la partenza dell'Applet setta i parametri
necessari per il suo funzionamento
*/
function UMJA_AppletLoaded(){
// setto lingua
document.uemapvw.SetLanguage(lang);
// impostazione broker
document.uemapvw.AddPoiBrokerData('UBIEST','','NAV_2_1001/0,NAV_1_992/0,NAV_2_1012/0,NAV_3_7510,NAV_2_1010,NAV_2_1011');
// impostazione aspect ratio
document.uemapvw.SetPoiCategoryRenderRatio('UBIEST','',2000,5000,1,true);
document.uemapvw.SetPoiCategoryRenderRatio('UBIEST','',5001,20000,0.75,true);
document.uemapvw.SetPoiCategoryRenderRatio('UBIEST','',20001,50000,0.5,true);


//CUSTOM POI
/*document.uemapvw.AddPoiBrokerData('CUSTOM',CustomPoiUrl,'CUST1/0,CUST2/0,CUST3/0');
document.uemapvw.SetPoiCategoryRenderRatio('CUSTOM','',2000,50000,1,true);
document.uemapvw.SetPoiCategoryRenderRatio('CUSTOM','',50001,1000000,1,true);
document.uemapvw.SetPoiCategoryRenderRatio('CUSTOM','',1000001,10000000,1,true);
*/
//LOCAL LAYER
//document.uemapvw.SetLocalLayer(101,10,10,20,'UbiLogo','Ubiest',-1,-1);

document.uemapvw.SetLocalLayer(102,0,StartX,StartY, 'boscolo_32x32','',-1,-1);


// imposta Poi
//categoriepoi();

PoiCategoryStatus();
// imposta le form per le ricerche
categoryform();
// Tool-tip multipli
//document.uemapvw.SetStreetInfoFlag(1);
// Street Info flag
//document.uemapvw.SetStopInfoFlag(1);

if(MapMode=='path')
 StoreLocatorCalcPath(EndPathX,EndPathY);
else
{ 
 document.uemapvw.SetScaleSt(StartScale);
 document.uemapvw.SetPoint(StartX,StartY,0);
 document.uemapvw.GetMapSt();
} 

 SetPoiFinishSt(HotelCountry,HotelCity,HotelAddress,HotelCiv,StartX,StartY);

}// UMJA_AppletLoaded


/*
Salvataggio dei dati relativi al centro mappa coordinate e indirizzo JLOC
*/
function UMJA_ConfirmPoint(){
/*
Simile alla UMJA_StreetInfo()	in più :
// ritorna la coord X del centro mappa o dell'ultimo punto selezionato da un click
GetPosX(int PosType, int CoordSys)
// ritorna la coord Y del centro mappa o dell'ultimo punto selezionato da un click
GetPosY(int PosType, int CoordSys)
*/
/* ESEMPIO DI IMPOSTAZIONE CAMPI DI UNA FORM CHIAMANTE*/
 opener.document.result_form.Ycity.value = document.uemapvw.GetCity();
 opener.document.result_form.Yaddr.value = document.uemapvw.GetAddress();
 if (document.uemapvw.GetPosX(2,0)==0){
   	opener.document.result_form.Yx.value    = document.uemapvw.GetPosX(1,0);
   	opener.document.result_form.Yy.value    = document.uemapvw.GetPosY(1,0);
 	}
 else{
  	opener.document.result_form.Yx.value    = document.uemapvw.GetPosX(2,0);
   	opener.document.result_form.Yy.value    = document.uemapvw.GetPosY(2,0);   
 }
   
 close();
}// UMJA_ConfirmPoint


/*
Evento scatenato al click del mouse sulla mappa nella modalità
Fly distence
*/
function UMJA_FlyDistMouseClicked(){
/*
// ritorna la lunghezza totale o parziale???
GetDistance()
*/
	numverticipoligono++;
	if (numverticipoligono==1){
		xp= document.uemapvw.GetPosX(2,0);
		yp= document.uemapvw.GetPosY(2,0);
		}
	puntiPoligono+=numverticipoligono+','+document.uemapvw.GetPosX(2,0)+','+document.uemapvw.GetPosY(2,0)+';'

}// FlyDistMouseClicked


/*
Evento ottenuto dalla ricerca di un indirizzo
*/
function UMJA_LocationList(){
/*
// ritorna l'XML a fronte di una ricerca di indirizzo
GetXmlLocationList()
*/
//alert('UMJA_LocationList');
setxmla(document.uemapvw.GetXmlLocationList());
}// UMJA_LocationList


/*
Evento scateneto al caricamento di ogni mappa
*/
function UMJA_MapLoaded(){
CurrentScale();
// compatibilità Plug in 1.5 inizio
var dovesei = document.uemapvw.GetCurrentLocation(4);
var city =  document.uemapvw.GetCurrentLocation(4);;
var addr = '';
var num = '';

mystr=new String(document.uemapvw.GetCurrentLocation(5)); 

if(mystr != "" && (mystr.search('@')==-1)){
  dovesei = dovesei +' - '+document.uemapvw.GetCurrentLocation(5).toLowerCase();
  addr = document.uemapvw.GetCurrentLocation(5);
if(document.uemapvw.GetCurrentLocation(6) != "")
  dovesei = dovesei +', '+document.uemapvw.GetCurrentLocation(6).toLowerCase();
  num = document.uemapvw.GetCurrentLocation(6);
}
document.Info_Form.DoveSei.value=dovesei.toUpperCase();
// Plug in 1.5 fine

if(!PopupPoiOnMap)// || (opc!=null && !opc.closed))
  POIOnMap();
}// UMJA_MapLoaded


function MMS_swapImage() { //v3.0
  var i,j=0,x,a=MMS_swapImage.arguments; document.MM_srs=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_srs[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MMS_swapImgRestore() { //v3.0
  var i,x,a=document.MM_srs; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {x.src=x.oSrc;}
}


/*
funzione richiamata dopo un calcolo percorso
*/
function UMJA_MapPathLoaded(){        
/*
GetPathID() // ritorna il codice dell'ultimo percorso calcolato e ancora presente sulla mappa
GetXmlPath() // ritorna l'xml con il dettagli del percorso testuale appena calcolato
*/
  if (document.uemapvw.GetCustomerID() != "" && document.uemapvw.GetPathID() != "" && document.uemapvw.GetPathID() != null) {
      //alert('PathID= '+document.uemapvw.GetPathID());
      var lsRegExp =/\+/g;
      var x;
      testx=document.uemapvw.GetXmlPath();
      if (testx==" "){ return;}
      x=  unescape(String(testx).replace(lsRegExp,' '));
      setxml(x);
      ubitag();
  }
}// UMJA_MapPathLoaded


/*
Cambio modalità di funzionamento dell'applet
*/
function UMJA_ModeChanged(){
/*
GetMode(int type) // ritona la modatità di funzinamento attuale o precedente
*/
}// UMJA_ModeChanged


/*
Evento per la gestione e la segnalazione di eventuali errori o
di assenza di risultatio in caso di ricerche
*/
function UMJA_OnError(){
/*
GetErrorCode()        // ritorna il codice dell'errore
GetErrorDescription() // ritorna la descrizione dell'errore
*/
err_msg='';
err_code=document.uemapvw.GetErrorCode();
eval('err_msg=e_'+err_code);
alert(err_msg);
if(err_code==71)
        document.uemapvw.DeletePathNoMap();//cancello le tappe se fallisce il percorso
}// UMJA_OnError


/*
Evento scatenato a fronte di una ricerca di P.O.I
*/

var effectnetscape=0;
function UMJA_PoiLoadedOnMap(){
   var ns4 = (document.layers)? true:false
	var lsRegEx =/\+/g;
	var x;
  	var testx=document.uemapvw.GetXmlPoiList();

  	if (testx==" "){ return;}
   if(opc!=null){opc.close()}
	// Netscape  la seconda volta non si apre
	if (effectnetscape==0) {
		x= unescape(new String(testx).replace(lsRegEx,' '));
		effectnetscape=1;
   	}
	else {
		if (ns4)
			x= unescape(new String(testx).replace(lsRegEx,'  '));
		else
			x= unescape(new String(testx).replace(lsRegEx,' '));
   	}

  	setxmlc(x);
   if (arrayelemc.length > 1)	visuac();
}// UMJA_PoiLoadedOnMap


/*
Evento scatenato al click del mouse sopra un P.O.I
*/
var detailwin;
function UMJA_PoiMouseClicked(){
/*
GetPoiBrokerID() // ritorna il broker del Poi selezionato
GetPoiCategoryID() // ritorna la categoria del Poi selezionato
GetPoiID() // ritorna l'identificatico ID del Poi selezionato
GetPoiURL() // ritorna l'URL se specificata (link)
GetPoiToolTip() // ritorna il nome o una descrizione del Poi
*/
	var stringpoiid   = document.uemapvw.GetPoiID();
	var stringpoicust = document.uemapvw.GetPoiBrokerID();
	var stringpoiicon = document.uemapvw.GetPoiIcon();
	var stringpoiurl	= document.uemapvw.GetPoiURL();

if (PopupPoiDetail){
	// dettaglio pop-up
	if(stringpoicust=='NAV')
		detailwin=window.open(UbiPoiBrokerUrl+"?XidPOI="+stringpoiid+"&XidPoiBroker="+stringpoicust, "DettaglioPoi","height=320,width=560,scrollbars=no");
	else
		if(stringpoiurl == "" || stringpoiurl == null){
			detailwin=window.open(LocalPoiBrokerUrl, "DettaglioPoi","height=320,width=560,scrollbars=no");
			}
		else{
	   	detailwin=window.open(stringpoiurl, "DettaglioPoi","height=320,width=560,scrollbars=no");
		 }
		
		detailwin.focus();
		}
else { 
  document.getElementById("poidetaillayer").innerHTML='';
	// dettaglio nella pagina
  pagepoihtml='<TABLE cellpadding="2" cellspacing="1" border="0" WIDTH="100%">';
  pagepoihtml+='<TR>';
  pagepoihtml+='<TD COLSPAN="2" class=navbarheader>'+l_dettaglio_poi+'</TD>';
  pagepoihtml+='</TR>';
  pagepoihtml+='<TR>';
  pagepoihtml+='<TD ALIGN="right" valign="top" class=form><B>'+l_numero+' :</B></TD>';
  pagepoihtml+='<TD ALIGN=left valign=top class=form>'+stringpoiid+'</TD>';
  pagepoihtml+='</TR>';
  pagepoihtml+='<TR>';
  pagepoihtml+='<TD ALIGN=right valign=top class=form><B>'+l_descrizione+' :</B></TD>'
  pagepoihtml+='<TD ALIGN=left valign=top class=form>'+document.uemapvw.GetPoiToolTip()+'</TD>';
  pagepoihtml+='</TR>';
  pagepoihtml+='<TR>';
  pagepoihtml+='<TD ALIGN=right valign=top class=form><B>'+l_info+' :</B></TD>'
  pagepoihtml+='<TD ALIGN=left valign=top class=form>'+document.uemapvw.GetPoiInfo()+'</TD>';
  pagepoihtml+='</TR>';
  pagepoihtml+='</TABLE>';
	
	document.getElementById("poidetaillayer").innerHTML= pagepoihtml;
	pagepoihtml='';
	centermapc(document.uemapvw.GetPoiX(),document.uemapvw.GetPoiY(),stringpoiid); 
	}
}// UMJA_PoiMouseClicked

/*
Evento ottenuto alla pressione del tasto destro del mouse
*/
function UMJA_RightMouseClicked(){
/*
GetPosX(int PosType, int CoordSys) // con PosType=2 ritorna la coord. X dell'ultimo click sulla mappa
GetPosY(int PosType, int CoordSys) // con PosType=2 ritorna la coord. Y dell'ultimo click sulla mappa
*/
}// UMJA_RightMouseClicked


/*
Evento causato dal posizionamento di una bandierina sulla mappa
*/
function UMJA_StopSelected(){

/*
GetStopNumber() // ritorna il numero di tappe(bandierine) attualmente selezionate
GetFlagNumber() // ritoena il numero della tappa(bandierine) attualmente selzionata
*/
}// UMJA_StopSelected

/*
Evento di cancellazione di una bandierina
*/
function UMJA_DeleteStop(){
}

/*
Evento scatenato dalla richiesta di visualizzazione dell'intero
indirizzo al click del mouse su una determinata via o piazza
*/
function UMJA_StreetInfo(){
 if(FlagStart==1)
 {
  alert(document.uemapvw.GetCountry());
  document.percorsi.City.value=document.uemapvw.GetCity();
  document.percorsi.Address.value=document.uemapvw.GetAddress();
  document.percorsi.Number.value=document.uemapvw.GetCivicNumber();		
  PoiStartSt[0]=document.uemapvw.GetPosX(1,0);
  PoiStartSt[1]=document.uemapvw.GetPosY(1,0);
  FlagStart=0;
 }
 if(FlagStop==1)
 {
	document.percorsi.City2.value=document.uemapvw.GetCity();
	document.percorsi.Address2.value=document.uemapvw.GetAddress();
	document.percorsi.Number2.value=document.uemapvw.GetCivicNumber();	
	PoiFinishSt[0]=document.uemapvw.GetPosX(1,0);
	PoiFinishSt[1]=document.uemapvw.GetPosY(1,0);
    FlagStop=0;
 }
    
/*
metodi utilizzabili dall'applet
GetCountry()     // ritorna lo stato della mappa attuale
GetCity()        // ritorna la città della mappa attuale
GetAddress()     // ritorna l'indirizzo della mappa attuale
GetCivicNumber() // retorna il civico della mappa attuale

GetCurrentLocation(int i)
i = 1 come GetCountry()
i = 4 come GetCity()
i = 5 come GetAddress()
i = 6 come GetCivicNumber(

*/
}// UMJA_StreetInfo

//------------------------------------------------------------------Indirizzi---------------------------------------------------------
var arrayelema ; //array indirizzi

/*
Effetua il parser dell'xml passato e inserisce gli elementi
in un array divisi per Tag
*/
function setxmla(xmldatpass1){
  xmldatpass = new String(xmldatpass1);
  if (xmldatpass!=""){
    arrayelema= xmldatpass.split('<');
    i=0;
    index=0;
    // sto ricercando solo la città
    /*
    max max max*/
    if (searchcity == 1)
    	index = presencea(eval("document."+acity[searchtype]+".value;"));

    if (index!=-1 && searchcity==1 && CityPopup==0){   // se premuto ...
    	AddrLookup=0;
  	  	setarray(index);
    }else{      
	  	CityPopup=0;
  	  	visuaa();
  		}
    searchcity = 0;
  	 }
  else{
    search = 0;
  }
}

/*
Ricerca all'interno di un tag il valore di un attributo
*/
function findtaga(number,attribute1) {
	//attribute=new String(attribute1);
	attribute=attribute1;
	pass = arrayelema[number];
	pass =new String(pass);
	re= /\=+/g;
	gender = pass.replace(re,' ');
	//splitto per "
	arrayattributi = gender.split('"');
	//correggo il primo elemento
	firstelem= arrayattributi[0].split(' ');
	arrayattributi[0]=firstelem[1];
	re= /b/g;
	var testa;
	for(i=0;i<arrayattributi.length;i++){
  		testa=lTrim(arrayattributi[i].replace(re,""));
  		testa=rTrim(testa.replace(re,""));
    	if(testa==attribute){ return(arrayattributi[i+1]); }
	}
	return "-1";
	}

function lTrim(str){
  return (new String(str)).replace(/^\s*/, "")
}

function rTrim(str){
  return (new String(str)).replace(/\s+$/, "")
}

/*
Funzione di creazione e visualizzazione del pop-up in
caso di più indirizzi con possibilità di scelta
*/
var op = null;
function visuaa() {
var aba=0;
var amd4t="";
var amd5t="";
halter=arrayelema.length
if (halter > 2) {
  	op=window.open("","","width=300,height=300,scrollbars=yes,screenX=320,screenY=375,left=320,top=375") ;
  	op.document.write("<HTML>");
  	op.document.write("<HEAD>");
	op.document.write("<TITLE>"+l_address_list_title+"</TITLE>");
  	op.document.write("</HEAD>");
	op.document.write("<LINK rel=\"stylesheet\" href=\"Styles/map.css\">");
  	op.document.write("<BODY class=address_list>");
  	op.document.write(l_address_list_title);
  	op.document.write('<UL>');
	for(aba=1;aba<halter;aba++){
	   if(findtaga(aba,'AMD5')!="-1"){amd5t = findtaga(aba,'AMD5');}else{amd5t=""; } 
  	   if(findtaga(aba,'AMD4')!="-1"){amd4t = findtaga(aba,'AMD4');}else{amd4t=""; }
  	   
  	   op.document.write("<LI><A class=address_list NAME='A"+aba+"' ID='A"+aba+"' HREF='javascript:opener.setarray("+aba+");op=self;op.close();'>"+((amd5t!='') ? amd5t+' ('+amd4t+')' : amd4t));
  	   if (findtaga(aba,'ADDR')!="-1") {
  	     if (AddrLookup == 1)
  	       op.document.write(" ("+findtaga(aba,'ADDR')+")</A><br>");
  	     else
  	       op.document.write(" "+findtaga(aba,'ADDR')+"</A><br>");
  	   }
  	   else op.document.write("</A><br>");
  	   } // End for
  	op.document.write("</UL>");
  	op.document.write("</BODY>");
  	op.document.write("</HTML>");
  	op.document.close();
    }
  else{
  	setarray(1);
  }
}


/*
Ricerca se all'interno dell'xml è riporato il nome di una
particolare città
*/
function presencea(pres) {
	pres= new String(pres) ;
	pres=pres.toUpperCase();
	var xer=0;
	for(xer=1 ;xer <arrayelema.length ; xer++){
		if (findtaga(xer,'AMD4')==pres) { return xer;}
		}
	return -1;
	}


/*
Setta le variabili di ricerca indirizzo con le variabili contenute
in un tag dell'xml di risultato
*/
function setarray(numb){           
AMC1 = findtaga(numb,'AMC1');
AMC2 = findtaga(numb,'AMC2');
AMC3 = findtaga(numb,'AMC3');
AMC4 = findtaga(numb,'AMC4');
AMC5 = findtaga(numb,'AMC5');
AMC  = AMC1+','+AMC2+','+AMC3+','+AMC4+','+AMC5;
var citta = findtaga(numb,'AMD4');
var indirizzo = findtaga(numb,'ADDR');
scala  = findtaga(numb,'SC');
puntox = findtaga(numb,'X');
puntoy = findtaga(numb,'Y');


if (indirizzo==-1 && search!=1)
	eval("document."+aaddress[searchtype]+".value=ADDR=indirizzo=\"\";");

if ( indirizzo==-1 && (AddrLookup==0 || (AddrLookup==1 && citta==eval("document."+acity[searchtype]+".value")  )) )
	eval("document."+aaddress[searchtype]+".value=ADDR=indirizzo=\"\";");

if (indirizzo!="-1" && indirizzo!="" /*&& indirizzo.charAt(0)!='@'*/ && citta!="-1" && citta!=""){
	if (indirizzo.charAt(0)=='@'){indirizzo ="";}
	eval("document."+aaddress[searchtype]+".value=ADDR=indirizzo;");
	eval("document."+acity[searchtype]+".value=AMD4=citta;");
	}
else if (indirizzo!="-1" && indirizzo!=""){
	if (indirizzo.charAt(0)=='@'){indirizzo ="";}
	eval("document."+aaddress[searchtype]+".value=ADDR=indirizzo;");
	 }
else if (citta!="-1" && citta!="" ){
	eval("document."+acity[searchtype]+".value=AMD4=citta;");
	 }

if (op!=null){
	op.close();
	op = null;
	}
if(search==1){
	switch(searchtype){
		case 1:
			SearchMapbyCoord();
			break;
		case 2:
			startaddress=1;
      skip_search++;
			NormalizeAddress(2);
			break;
		case 3:
			stopaddress=1;
      skip_search++;
			currentoperation = "SearchGetPath2()";
			operation();
			break;
		case 4:
			SearchAddStopSt();
			break;
		case 5:
			SearchGetPath();
			break;
		}

	}
}// End setarray

//------------------------------------------------------------------Percorsi---------------------------------------------------------
var arrayelem =null; //array percorsi

function setxml(xmldatpass){
var mystr = new String(xmldatpass);	// plug-in 1.5
arrayelem= mystr.split('<');            // plug-in 1.5
arrayelem=arrayelem.slice(1,arrayelem.length);
halter=arrayelem.length
var aba=0;
i=0;
}

var actuawin=null;  // variabile finestra percorso
function chiusuraactuawin(){
actuawin=null;
}

// ----------------------------------Percorso Testuale dinamico------------------------------------------------
var X1arr=new Array();
var Y1arr=new Array();
var X2arr=new Array();
var Y2arr=new Array();
var Tex=new Array();
var len=1;

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

function layerwrite(id,nestref,text) {
   if (ns4) {
	       if (nestref) var lyr = eval('document.'+nestref+'.document.'+id+'.document')
		    else var lyr = document.layers[id].document
		     lyr.open()
		     lyr.write(text)
		       lyr.close()
   }
  else if(ie4) document.all[id].innerHTML= text
}


function fontscale(size,div) {

for (var i = 1; i < X1arr.length ; i++) {
	layerwrite("welcomeDiv"+i,null,'<span class="s10">'+Tex[i]+'</span>')
    }

layerwrite('welcomeDiv'+div,null,'<span class="s'+size+'"><b>'+Tex[div]+'</B></span>')
}


function setcolor(iddat) {
if (ns4) return;
for (var i = 1; i < X1arr.length ; i++) {
        if((i % 2)==0) 
        tdclass='txtpath_1';
        else tdclass='txtpath_2';
        
        document.getElementById(new String("a"+i)).className=tdclass;
        document.getElementById(new String("c"+i)).className=tdclass;
        document.getElementById(new String("d"+i)).className=tdclass;
        document.getElementById(new String("e"+i)).className=tdclass;
        document.getElementById(new String("f"+i)).className=tdclass;
}
len=iddat;
        if((iddat % 2)==0) 
        tdclass_hl='txtpath_hl_1';
        else tdclass_hl='txtpath_hl_2';
        document.getElementById(new String("a"+iddat)).className=tdclass_hl;
        document.getElementById(new String("c"+iddat)).className=tdclass_hl;
        document.getElementById(new String("d"+iddat)).className=tdclass_hl;
        document.getElementById(new String("e"+iddat)).className=tdclass_hl;
        document.getElementById(new String("f"+iddat)).className=tdclass_hl;
}

function Ins(x1,y1,x2,y2, testo) {
     var i=X1arr.length;
     
     if(i<1) i=1;
     X1arr[i]=x1;
     Y1arr[i]=y1;
     X2arr[i]=x2;
     Y2arr[i]=y2;
     Tex[i]=testo ;
}

function Prev() {
var HrefObj;	
if (len>1){
     len--;
	 //setcolor(len);
    centermap(X1arr[len],Y1arr[len],X2arr[len],Y2arr[len]);
	 }
}

function Next() {
var HrefObj;		
  if (len<(X1arr.length-1)){
     len++;
	 //setcolor(len); 
    centermap(X1arr[len],Y1arr[len],X2arr[len],Y2arr[len]);
	 }
}

function First() {
     len=1;
	 //setcolor(len);
    centermap(X1arr[len],Y1arr[len],X2arr[len],Y2arr[len]);
}

function Last() {
	len = X1arr.length-1;
	//setcolor(len);
    centermap(X1arr[len],Y1arr[len],X2arr[len],Y2arr[len]);
}


// variabile per l'html dinamico del percorso testuale
var pagehtml='';
/*END ubitag() FUNCTION*/
function ubitag(){
//visualizziamo la pagina 
if (actuawin!=null){  actuawin.close();}
if ((arrayelem!=null)) {

	if (PopupPathDetail){
		// percorso pop-up
		actuawin=window.open("XmlPathTemplate.php?lang="+lang,"","width=650,height=400,scrollbars=yes"); 
		}
	else{	
	
	        /*header section start*/
	        pagehtml+='<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">';
                pagehtml+='<TR>';
                pagehtml+='<td valign=middle align=center>';
                pagehtml+='<table WIDTH="550" BORDER="0" CELLPADDING="2" CELLSPACING="1">';
                pagehtml+='<tr>';
                pagehtml+='<td align=left width=60 CLASS=txtpath_label><font color="#C60B27">'+l_partenza+':</font></TD>';
                pagehtml+='<td WIDTH=490><a CLASS=stop_desc href="#" onClick="First()">';
                resetindex();
		start=" "+ findtag('FROM','AMD4');
		actuaindex();
		start+=" "+ findtag('FROM','AMD5');        
		resetindex();
		pagehtml+=" "+start;
                pagehtml+='</a>';					 					
                pagehtml+='</TD>';
                pagehtml+='</tr>';
                pagehtml+='<tr>';
                pagehtml+='<td align=left width=60 CLASS=txtpath_label><font color="#C60B27">'+l_arrivo+'</font></td>';
                pagehtml+='<td WIDTH=490><a CLASS=stop_desc href="#" onClick="Last()">';
                while(findtag('TO','AMD4')!="-1"){
				actuaindex();			
				stop=" "+ findtag('TO','AMD4');
				actuaindex();
				stop+=" "+ findtag('TO','AMD5');				
				}			
		resetindex();
		pagehtml+=stop;
                pagehtml+='</TD>';
                pagehtml+='</TR>';
                pagehtml+='</table>';
                pagehtml+='</td>';
                pagehtml+='<td>';
                 //<!--navigazione mappe section start-->	      
                pagehtml+='<TABLE BORDER="0" align="center"><FORM NAME="buttonbar">';
                pagehtml+='<tr>';
                pagehtml+=' <td width="40" valign="top" align=right height="25"><img name="Primo" src="images/primo.gif" width="34" height="25" BORDER="0" usemap="#primo" hspace="0"> ';
                pagehtml+=' <MAP name="primo"> ';
                pagehtml+='     <area sshape="rect" coords="0,0,30,30" href="#Primo" alt="First" onClick="First()">';
                pagehtml+=' </map>';
                pagehtml+=' </td>';
                pagehtml+=' <td width="25" valign="top" height="25"><img name="indietro" src="images/indietro.gif" width="25" height="25" BORDER="0" usemap="#indietro" hspace="0"> ';
                pagehtml+=' <MAP name="indietro"> ';
                pagehtml+='     <area sshape="rect" coords="0,0,30,30" href="#Prev" alt="Previuos" onClick="Prev()">';
                pagehtml+=' </map>';
                pagehtml+=' </td>';
                pagehtml+=' <td width="25" valign="top" height="25"><img name="avanti" src="images/avanti.gif" width="25" height="25" BORDER="0" usemap="#avanti" hspace="0"> ';
                pagehtml+=' <MAP name="avanti"> ';
                pagehtml+='     <area sshape="rect" coords="0,0,30,30" href="#Next" alt="Next" onClick="Next()">';
                pagehtml+=' </map>';
                pagehtml+=' </td>';
                pagehtml+=' <td width="40" valign="top" height="25"><img name="Ultimo" src="images/ultimo.gif" width="34" height="25" BORDER="0" usemap="#ultimo" hspace="0"> ';
                pagehtml+=' <MAP name="ultimo"> ';
                pagehtml+='     <area sshape="rect" coords="0,0,30,30" href="#Ultimo" alt="Last" onClick="Last()">';
                pagehtml+=' </map>';
                pagehtml+=' </td>';
                pagehtml+=' </tr></FORM>';
                pagehtml+='</TABLE>';                
                //<!--navigazione mappe section end-->                
                pagehtml+='</td>';
                pagehtml+='<td><A HREF="#" ONCLICK="window.print();"><img src="images/printerlogo.gif" border=0></a></td>';
                pagehtml+='</tr>';
                pagehtml+='</table>';                
	        /*header section end*/	
		pagehtml+='<table width ="100%" class=txtpath CELLPADDING="0" CELLSPACING="1">';                          																			
		//azzero l'indice 
	  	resetindex();
	  	var leng=0;
	  	var globaltime=0 ;
	  	var indexarray= new Array();
	  	resetindex();
	  	var incrementa=0;
	            
	  	while (findtag('PINFO','LEN')!='-1'){  			
	  			indexarray[incrementa++]= getindex(); //prelevo l'indice del PINFO
				actuaindex();
	  			globaltime += parseInt(findtag('PINFO','TIME'));  		      								
	  			}
		resetindex();
	  	while (findtag('PITEM','LEN')!='-1') {
	  			indexarray[incrementa++]= getindex(); //prelevo l'indice del PINFO
	  			actuaindex();
				leng += (parseInt(findtag('PITEM','LEN'))/10);
	  			} 			

		     
		pagehtml+='<TR>';                      
                pagehtml+='<TD ROWSPAN="2" ALIGN=right valign=top    CLASS=txtpath_label>N.</TD>';
                pagehtml+='<TD ROWSPAN="2" ALIGN=center valign=top   CLASS=txtpath_label>'+l_descrizione_tappe+'</script></TD>';
                pagehtml+='<TD COLSPAN="2" align=center valign=top   CLASS=txtpath_label>'+l_distanza+'</TD>',
                pagehtml+='<TD ALIGN=center valign=top HEIGHT="20"   CLASS=txtpath_label>'+l_tempo+'</TD>';
                pagehtml+='</TR>';
                pagehtml+='<TR>';
                pagehtml+='<TD ALIGN=center valign=center   CLASS=txtpath_label>'+l_step+'</TD>';
                pagehtml+='<TD ALIGN=center valign=center   CLASS=txtpath_label>'+l_totale+'</TD>';
                pagehtml+='<TD ALIGN=center valign=center   CLASS=txtpath_label>'+l_totale+'</TD>';
                pagehtml+='</TR>';
	
		resetindex();
		var count=1;
		var scanarray =0 ;
		var endscanarray= true;
		// attenzione il pitem viene prelevato pro
		var stepa=0;
		var stepatotal=0;
		uptime =0;
		while(findtag('PITEM','LEN') !="-1"){
				actuaindex();
				stepa=parseInt(findtag('PITEM','LEN'))/10;
				stepatotal+=stepa;
				actuaindex();
				wgha=parseInt(findtag('PITEM','WGH'));
				//tempi parziali
				pass = parseInt(stepa);
				wgha= parseInt(wgha);
				if (pass!=0){
						utime=parseInt((pass/10)/((wgha/1.8)*1000/3600)*10); 
					   uptime+=utime;
					   }
				else{
						utime=0 ; 
						uptime+=utime;
						}	                
				X1= parseInt(findtag('PNT','X'));   ;
				actuaindex();
				X1arr[count]=X1;
				Y1= parseInt(findtag('PNT','Y'));  ;
	         Y1arr[count]=Y1
				X2= parseInt(findtag('PNT','X'));  ;
				X2arr[count]=X2
				actuaindex();
				Y2= parseInt(findtag('PNT','Y'));   ;
				Y2arr[count]=Y2
				UText=findtag('TYP','STRC');
				CityFrom="";
				if (endscanarray && (indexarray[scanarray]<getindex())){ 
						actuaindex();
						CityFrom=findtag('FROM','AMD4');
						actuaindex();
						CityFrom+="-"+ findtag('FROM','AMD5');
						UText+=" "+ findtag('TO','AMD4');
						actuaindex();
						UText+=" "+ findtag('TO','AMD5');
						scanarray++;
						if(scanarray == indexarray.length){
								endscanarray= false;												
								} //verifica una delle principali caratteristiche
						}
				else{
						actuaindex();
						testfromamd4=findtag('FROM','AMD4');
						actuaindex();
						testfromamd5=findtag('FROM','AMD5');
						testtoamd4=findtag('TO','AMD4');
						actuaindex();
						testtoamd5=findtag('TO','AMD5');
						if(testfromamd4 != testtoamd4) {
								UText+=testtoamd4//+"-"+testtoamd5
								if(testfromamd5 != testtoamd5) { 
	                     		UText+=" - "+testtoamd5      
							 			} 						
								}
						else {
								if(testfromamd5 != testtoamd5) { 
	                          	UText+=" - "+testtoamd5      
										}   
								}						
						}
				//inserisci le date 		
				if((count % 2)==0) 
                                        tdclass='txtpath_1';
                                else    tdclass='txtpath_2';   		
												
				pagehtml+='<TR>';
				pagehtml+='<TD nowrap WIDTH=10 valign=top ID=\"a'+count+'\" align=left  class='+tdclass+'><ILAYER><LAYER ID=\"NA$Ucount\">'+count+'.'+'</LAYER></ILAYER></td>';
				if (ns4)
					pagehtml+='<TD class='+tdclass+'   valign=top><ILAYER><LAYER ID=\"N$Ucount\"  width=\"100%\"><a ID=\"c'+count+'\" class=\"'+tdclass+'\" href=\"javascript:centermap('+X1+','+Y1+','+X2+','+Y2+');setcolor('+count+');\">'+UText+'</a></LAYER></ILAYER></td>';
				else
					pagehtml+='<TD class='+tdclass+' valign=top><ILAYER><LAYER ID=\"N$Ucount\"   width=\"100%\"><a ID=\"c'+count+'\" class=\"'+tdclass+'\" name=\"$ref\" href=\"javascript:centermap('+X1+','+Y1+','+X2+','+Y2+');setcolor('+count+');\">'+UText+'</a></LAYER></ILAYER></td>';			  
				// attributi campo step
				pagehtml+='<TD class='+tdclass+' ALIGN=right valign=top ID=\"d'+count+'\"    nowrap>'+visualength(stepa)+'</td>' ;
				// attributi campo 
				pagehtml+='</td><TD class='+tdclass+'  ALIGN=right valign=top ID=\"e'+count+'\"  nowrap>'+visualength(stepatotal)+'</td>';
				// attributi campo step
				pagehtml+='</td><TD class='+tdclass+'  ALIGN=right valign=top ID=\"f'+count+'\"   nowrap>'+visuatime(uptime)+'</td>';		
				pagehtml+='</TR>';
				
				count++;
			}
		
		pagehtml+='<tr>';
		pagehtml+='<td class=txtpath_label COLSPAN="2" VALIGN="top" align="right">'+l_totale+' :</td>';	
		pagehtml+='<td class=txtpath_label COLSPAN="2" align="center" VALIGN="top" nowrap>'+visualength(leng)+'</td>';
		pagehtml+='<td class=txtpath_label COLSPAN="2" align="right" VALIGN="top" nowrap>'+visuatime(globaltime)+'</td>';	
		pagehtml+='</tr>';	
		
		pagehtml+='</table>';
		pagehtml+='</table>';

		if (ns4){		
			var pathlayer_obj=document.layers['txtpathlayer'];		
			pathlayer_obj.document.write(pagehtml);		
			pathlayer_obj.document.close();	
		   }
		else{
	    document.getElementById("txtpathlayer").innerHTML=pagehtml;
	    pagehtml='';
		  setcolor(1);
		  }   					
	
	}
	
}
else{
	UMJA_MapPathLoaded();
	}
}
/*END ubitag() FUNCTION*/


var xs=0; //indice di partenza ricerca

function resetindex() {
xs=0;
}

function actuaindex() {
xs--;
}

function getindex() {
return xs;
}

function centermap(centrax1,centray1,centrax2,centray2) {
  document.uemapvw.CenterTextPath(centrax1,centray1,centrax2,centray2,0,'');
}

function cancella() {
arrayelem=null;
if (actuawin!=null){actuawin.close();}
/*cancello gli elementi della form*/
for(i=2;i<=3;i++){
        eval("document."+acity[i]   +".value=\"\";");
        eval("document."+aaddress[i]+".value=\"\";");
        eval("document."+anumber[i] +".value=\"\";");
      }

//document.getElementById("txtpathlayer").innerHTML='';      
PoiStartSt=new Array(0,0);
PoiFinishSt=new Array(0,0);
}

function findtag(tag,attribute2) {
attribute=attribute2;
re= /\=+/g;
gender=new Array() ;
arrayattributi=new Array() ;
for(tas =xs ; tas<arrayelem.length ;tas++) {
  	xs++;
  	pass = arrayelem[tas]; //"becco" l'elemento
  	//tolgo uguale
  	gender = pass.replace(re,'');
  	arrayattributi=gender.split('"');
	firstelem= arrayattributi[0].split(' ');
  	pass =new Array() ;
  	//rappresenta l'attributo
  	pass[0]=firstelem[0]
  	arrayattributi[0]=firstelem[1];
  	pass=pass.concat(arrayattributi);
  	testtag = lTrim(pass[0]);
  	testtag = rTrim(pass[0]);
  	if (testtag==tag) {break;}
}
arrayattributi=pass;
if (arrayattributi[0]=="/PINFO>") { return "-1"; }
re= /b/g;
for(i=0;i<arrayattributi.length;i++){
  	testa=lTrim(arrayattributi[i].replace(re,""));
  	testa=rTrim(testa.replace(re,""));
  	//alert('testa'+testa+'!');
  	//alert('att'+attribute+'!');
    if(testa==attribute){ return(arrayattributi[i+1]); }
    }
return "-1";
}

function visua() {
op=window.open("","","width=100,heigth=199") ;
halter=arrayelem.length
var aba=0;
for(aba=1;aba<halter;aba++){
     op.document.write(findtag(aba,'AMD4')+"<p>");
     }
}

function visualength(lung) {
var st ;
var unit ;
if(lung>1000 ) {lung= lung/1000; unit="km";}
          else {lung/=1; unit="m" ;}

pass=parseInt(lung);
st= new String(pass+" "+unit);
return st;
}

function visuatime(tempo) {
var st ;
var ore;
var minuti;
var secondi;
var ns4 = (document.layers)? true:false
if (ns4 && parseInt(tempo)<60)
	return "00:00:"+tempo
if ((tempo/3600)>1){ore = parseInt(tempo/3600);}
  		else{ore=0;}
if ((tempo%3600)!=0) {
		   minuti =(tempo-ore*3600);
  		   minuti/=60;
  		   minuti=parseInt(minuti);
  		}else{
            minuti=0;
  	    }
if ((tempo%60)!=0) {
			secondi=(tempo-ore*3600-minuti*60);       // minuti*60
  		}else{
		    secondi=0 ;
  		}
ores=new String(ore);
minutis=new String(minuti);
secondis=new String(secondi);
if (ores.length<2) {   ores="0"+ores;}
if (minutis.length<2) { minutis="0"+ minutis; }
if (secondis.length<2) { secondis="0"+secondis ;}
return ores+":"+minutis+":"+secondis
}

//--------------------------------------------------------Ricerca dei POI--------------------------------------------------------------
<!--
var arrayelemc ; //array ricerca Poi

function setxmlc(xmldatpass2){
arrayelemc=new Array();
arrayelemc= xmldatpass2.split('<');
i=0;
}

function findtagc(number,attribute3) {
attribute=attribute3;
pass = arrayelemc[number];
pass=new String(pass);
//tolgo gli uguale
re= /\=+/g;
gender = pass.replace(re,'');
//splitto per "
arrayattributi = gender.split('"');
//correggo il primo elemento
firstelem= arrayattributi[0].split(' ');
arrayattributi[0]=firstelem[1];
re= /b/g;
for(i=0;i<arrayattributi.length;i++){
  	 testa=lTrim(arrayattributi[i].replace(re,""));
  	 testa=rTrim(testa.replace(re,""));
     if(testa==attribute){ return(arrayattributi[i+1]); }
}
return "-1";
}

function chiusuraopc() {
opc=null;
}

function visuac() {
var aba=0;
halter=arrayelemc.length;

if(opc!=null){opc.close(); opc=null;}

if (halter > 1){
   var parent;
   
   if(PopupPoiOnMap)
 	  parent = 'opener.';
 	 else
 	  parent = '';

    pagepoihtml='<TABLE CELLPADDING="0" cellspacing="0" border="0" width=100% class=poilist>';
    //pagepoihtml+='<td width="1%" align="center" class=navbarheader><a href="javascript:Help(\'PercorsoPOI\',lang);" class=questionmark>&nbsp;&#63;&nbsp;</a></td>';
    pagepoihtml+='<TR><TD ALIGN=right valign=top WIDTH=5%  class=poilist_header>' + l_numero + '</TD>';
    pagepoihtml+='<TD ALIGN=left valign=top WIDTH=20% class=poilist_header>&nbsp;' + l_descrizione + '</TD>'
    pagepoihtml+='<TD ALIGN=center valign=top WIDTH=40% class=poilist_header>' + l_indirizzo + '</TD>';
    pagepoihtml+='<TD ALIGN=center valign=top WIDTH=5% class=poilist_header>' + l_icona + '</TD>';
	  if(PathLayerView)
	    pagepoihtml+='<TD ALIGN=center valign=top WIDTH=10% class=poilist_header colspan=2>' + l_aggiungi + '</TD>';
		if(StoreLocatorMode)
		   pagepoihtml+='<TD ALIGN=center valign=top WIDTH=5% class=poilist_header>&nbsp;'+l_tipopercorso+'</TD>';
	  pagepoihtml+='</TR>';
 	  pagepoihtml+='</TABLE>'; //inseriamo

    pagepoihtml+='<TABLE cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=100% class=poilist>';
  	for(aba=1;aba<halter;aba++){
      if((aba%10)==0)
		  	pagepoihtml+='</table><TABLE cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=100% class=poilist>';
	    Xcoordx=findtagc(aba,'X');
		  Xcoordy=findtagc(aba,'Y');
		  Xamd4=findtagc(aba,'AMD4')
		  if ((Xaddr=findtagc(aba,'ADDR'))!="-1") {addr=", "+Xaddr;}else{addr="";Xaddr=""}
		  if ((Xnum=findtagc(aba,'NUM'))!="-1") { num="N° "+Xnum; } else {num=""; Xnum="";}
	    if((aba % 2)==0) {tdclass='poilist1';}else(tdclass='poilist2');
    	if (findtagc(aba,'TY')!="-1") { desc= findtagc(aba,'NAME'); }else{desc= findtagc(aba,'DESC');}
    	if ((icon=findtagc(aba,'ICON'))!="-1") {geticon="<img src=\""+DirPoiIcons+icon+".gif\" width=\"16\" height=\"16\">";}else{geticon="";}  //inserimento dell'icona		
		  if (findtagc(aba,'X')=="-1"){break}
		  if (desc=="-1"){desc=l_centra;}
	    pagepoihtml+='<TR>'
	    pagepoihtml+='<TD WIDTH=5% valign=top align=right class=' + tdclass + '>'+aba+'</td>';
      pagepoihtml+='<TD id="T$Ucount" NAME="T$Ucount" WIDTH=20% valign=top class=' + tdclass + '>';
	    pagepoihtml+='<a name="c'+aba+'" id="c'+aba+'" href="javascript:'+parent+'centermapc('+findtagc(aba,'X')+','+findtagc(aba,'Y')+',\''+findtagc(aba,'ID')+'\');\">'+desc+'</a>';
      pagepoihtml+='</TD><TD WIDTH=40% valign=top align=left class=' + tdclass + '>'+ Xamd4 + addr +' ' +num+'</td>';
      pagepoihtml+='<TD valign=top align=left WIDTH=5% class=' + tdclass + '><center>'+geticon+'</center></td>';
	    if(PathLayerView){
	   	 pagepoihtml+='<TD valign=top align=left WIDTH=5% class=' + tdclass + '><center><a href="javascript:'+parent+'SetPoiStartSt(\'\',\'' + Xamd4 + '\',\'' + Xaddr + '\',\'' + Xnum + '\',' + Xcoordx + ',' + Xcoordy + ');'+parent+'MM_showHideLayers(\'maplayer\',\'\',\'hide\',\'pathlayer\',\'\',\'show\',\'poilayer\',\'\',\'hide\');'+parent+'setMenuStyle(\'m2\');" title="' + l_imposta_partenza + '"><img src="images/stop2.gif" border="0"></a></center></td>';
		  pagepoihtml+='<TD valign=top align=left WIDTH=5% class=' + tdclass + '><center><a href="javascript:'+parent+'SetPoiFinishSt(\'\',\'' + Xamd4 + '\',\'' + Xaddr + '\',\'' + Xnum + '\',' + Xcoordx + ',' + Xcoordy + ');'+parent+'MM_showHideLayers(\'maplayer\',\'\',\'hide\',\'pathlayer\',\'\',\'show\',\'poilayer\',\'\',\'hide\');'+parent+'setMenuStyle(\'m2\');" title="' + l_imposta_destinazione + '"><img src="images/stop1.gif" border="0"></a></center></td>';	
	   }
 	    if(StoreLocatorMode)
    	  pagepoihtml+='<TD valign=top align=left WIDTH=5% class=' + tdclass + '><center><a class=poi_list name="p'+aba+'" href="javascript:'+parent+'StoreLocatorCalcPath(' + Xcoordx + ',' + Xcoordy + ')" TITLE="'+t_calcola+'"><IMG border=0 src="images/stop1.gif"></A></center></td>';   	
	   pagepoihtml+='</TR>';
   } // End for
 	 pagepoihtml+='</TABLE>'; //inseriamo
 	 
 	 if(PopupPoiOnMap)
 	 {
  	opc=window.open("","","width=540,height=300,scrollbars=yes,screenX=250,screenY=375,left=250,top=375");
  	opc.document.write("<HTML><HEADgeticon><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;\"><TITLE>" + l_poilist_list_title + "</title></HEAD>");
	  opc.document.write("<LINK rel=\"stylesheet\" href=\"Styles/map.css\">");
	  opc.document.write("<BODY onUnload=\""+parent+"chiusuraopc()\">");
    opc.document.write(pagepoihtml);
  	opc.document.write("</BODY>");
  	opc.document.write("</HTML>");
  	opc.document.close();
   }
   else
   {
   	document.getElementById("poidetaillayer").innerHTML=pagepoihtml;
   	pagepoihtml='';
   }
  }
else{
  	setarray(1);
	}

}

function centermapc(a,b,c){
  document.uemapvw.CenterTextPath(a,b,0,0,0,c);
}

/*
Funzione di visualizzazione del pop-up
*/
var visuaop = null;
function SavePoly(){
	puntiPoligono+=(++numverticipoligono)+','+xp+','+yp+';'
	IdUff=prompt("Codice Poligono", "");
	arrayelemp=puntiPoligono.split(';');
	var aba=0;
	halter=arrayelemp.length
	if (halter>2){
	  	visuaop=window.open("","","width=300,height=300,scrollbars=yes") ;
	  	visuaop.document.write("<HTML>");
	  	visuaop.document.write("<HEAD>");
		visuaop.document.write("<TITLE>Salvataggio Punti Ufficio " + IdUff + "</TITLE>");
	  	visuaop.document.write("<LINK REL='stylesheet' type='text/css' href='Styles.css'>");
	  	visuaop.document.write("</HEAD>");
	  	visuaop.document.write("<BODY>");
	  	visuaop.document.write("<FORM NAME=POLY ACTION=JGate/SavePoly.php METHOD=POST>");
	  	visuaop.document.write("<FONT FACE='Verdana' SIZE='2'><B>Salvataggio Poligono Codice " + IdUff+ "</B></font><BR>");
	  	visuaop.document.write('<FONT FACE="Verdana" SIZE="1" color="#000000"><UL>');
		visuaop.document.write("Coordinate " + halter + " punti : <INPUT NAME=IDUFF VALUE=" + IdUff+ ">");
	  	visuaop.document.write("<INPUT NAME=LISTA VALUE=" + puntiPoligono + ">");
		visuaop.document.write("<INPUT TYPE=submit VALUE=CONFERMA>");
	  	visuaop.document.write("<FORM>");
	  	visuaop.document.write("</UL></FONT>");
	  	visuaop.document.write("</BODY>");
	  	visuaop.document.write("</HTML>");
	  	visuaop.document.close();
	  	}// end if
	ResetPolygon();
	document.uemapvw.SetMode(1);	
	// close();
	}// End VisuaP

/*
Svuota i parametri (punti) del poligono
*/
function ResetPolygon(){
	puntiPoligono="";
	numverticipoligono=0;
	arrayelemp=null;
	xp=0;
	yp=0;
	}

function ChangeOption()
{
 var obj = document.percorsi.HPoiList;	
 var strVal = obj.options[obj.selectedIndex].value;
 
 if(!strVal)
 {
   PoiStartSt[0]=0;
   PoiStartSt[1]=0;
   fobj=document.percorsi;
   document.percorsi.City.value='';
   document.percorsi.Address.value='';
   document.percorsi.Number.value='';
 }

 var arrayVal= strVal.split(';');
 var i=0; 

 SetPoiStartSt(arrayVal[i++],arrayVal[i++],arrayVal[i++],'',arrayVal[i++],arrayVal[i++]);

} 

