///////////////////////////////////////
// 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=0; // 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();

/**
Inizilaizzazione dei quattro array per la gestione dei P.O.I devono
essere definite a seconda dei P.O.I da visualizzare
*/
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_2_1002";
  arraycategory2[i]="Alloggio";
  arraycategory3[i]="Category_Form.Cat_NAV_2_1002";

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

  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_1_993";
  arraycategory2[i]="ServiziPubblici";
  arraycategory3[i]="Category_Form.Cat_NAV_1_993";

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

  arraycategory0[++i]="UBIEST" ;
  arraycategory1[i]="NAV_1_995" ;
  arraycategory2[i]="Soldi";
  arraycategory3[i]="Category_Form.Cat_NAV_1_995";
  
  /**CATEGORIE CUSTOM SECTION START**/  
  arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="1" ;
  arraycategory2[i]="1";
  arraycategory3[i]="Category_Form.Cat_1";

    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="2" ;
  arraycategory2[i]="2";
  arraycategory3[i]="Category_Form.Cat_2";
  
    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="3" ;
  arraycategory2[i]="3";
  arraycategory3[i]="Category_Form.Cat_3";
  
    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="4" ;
  arraycategory2[i]="4";
  arraycategory3[i]="Category_Form.Cat_4";
  
    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="5" ;
  arraycategory2[i]="5";
  arraycategory3[i]="Category_Form.Cat_5";
  
    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="6" ;
  arraycategory2[i]="6";
  arraycategory3[i]="Category_Form.Cat_6";
  
    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="7" ;
  arraycategory2[i]="7";
  arraycategory3[i]="Category_Form.Cat_7";
  
  
    arraycategory0[++i]="CUSTOM" ;
  arraycategory1[i]="99" ;
  arraycategory2[i]="99";
  arraycategory3[i]="Category_Form.Cat_99";
  
  /**CATEGORIE CUSTOM SECTION END**/  

} //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();
	/*
	if (actuawin!=null){
		cancella();
		ubitag();
		}
	else
		{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++){
  	 //alert("document."+arraycategory3[i]+ ".disabled="+status+";");
  	 eval("document."+arraycategory3[i]+ ".disabled="+status+";");
  }
}


/*
Cancella il percorso sia nella mappa che nel pop-up
*/
function DeletePath(){
	document.uemapvw.DeletePath();
	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){
	//	alert(country+' '+city+' '+address+' '+numero);
	// 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 == ""){
		   //alert('Richiedo Città+Indirizzo');
   		AddrLookup=1;
   		//if (address.toUpperCase()=="") address="@"+city;
   		if (address.toUpperCase()=="") address=" ";
			document.uemapvw.SearchLocation( country,'', '','', city+force,'','','','',address, numero);
			}
		else{
		   //alert('Richiedo Indirizzo');
			AddrLookup=0;
   		//if (address.toUpperCase()=="") address="@"+city;
   		if (address.toUpperCase()=="") address=" ";
			document.uemapvw.SearchLocation( AMC+force,'', '','', city,'','','','',address, numero);
		}			
		return false;
		}
	else if (AMD4!=city.toUpperCase()){
		//alert('Richiedo Città');
		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){
	//alert(type);
	searchtype=type;
	CityPopup = 1;
	Search(country,city,address,numero,0);
	CityPopup = 0;
	//alert(type);
	}

/**
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 **/
PoiStartSt=new Array(0,0);
function SetPoiStartSt(city,address,number,x,y){        
	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 **/
PoiFinishSt=new Array(0,0);
function SetPoiFinishSt(city,address,number,x,y){
	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();
			}
}

/**     CALCOLO PERCORSO SECTION START **/
addstop=0;
function SearchGetPath2(){
        if (document.uemapvw.GetPathID()!=null && document.uemapvw.GetPathID()!="") 
		//document.uemapvw.DeletePath();
		document.uemapvw.DeletePathNoMap();
		
        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();
                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);
	   }

 	//document.uemapvw.GetPath(0,0,'');
 	GetPath();

	// Reset parametri
	Reset();

	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()
/*
function GetPath(){

	 // se calcolo il percorso con Da A
    if (searchtype==3 && document.percorsi.PathType!= null && document.percorsi.PathDetail!=null){
		 if (document.percorsi.PathType[0].checked)
		    algo = parseInt(document.percorsi.PathType[0].value);
		 else
		    algo = parseInt(document.percorsi.PathType[1].value);

		 if (document.percorsi.Highway.checked)
		    algo +=parseInt(document.percorsi.Highway.value);

		 if (document.percorsi.Path[1].checked)
		    algo = parseInt(document.percorsi.Path[1].value);

		 document.uemapvw.GetPath(algo,parseInt(document.percorsi.PathDetail[document.percorsi.PathDetail.selectedIndex].value),'');
	 	 algo=0;
		}
	 // se calcolo il percorso con aggiungi tappa
    else if (searchtype==5 && document.percorsi2.PathType!= null && document.percorsi2.PathDetail!=null){
		 if (document.percorsi2.PathType[0].checked)
		    algo = parseInt(document.percorsi2.PathType[0].value);
		 else
		    algo = parseInt(document.percorsi2.PathType[1].value);

		 if (document.percorsi2.Highway.checked)
		    algo +=parseInt(document.percorsi2.Highway.value);

		 if (document.percorsi2.Path[1].checked)
		    algo = parseInt(document.percorsi2.Path[1].value);

		 document.uemapvw.GetPath(algo,parseInt(document.percorsi2.PathDetail[document.percorsi2.PathDetail.selectedIndex].value),'');
	 	 algo=0;
		}
  	 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_2_1002/0,NAV_1_992/0,NAV_1_993/0,NAV_1_994/0,NAV_1_995/0');
// 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,'1/0,2/0,3/0,4/0,5/0,6/0,7/0,99/0,100/1');
document.uemapvw.SetPoiCategoryRenderRatio('CUSTOM','',2000,50000,1,true);
document.uemapvw.SetPoiCategoryRenderRatio('CUSTOM','',50001,1000000,0.75,true);
document.uemapvw.SetPoiCategoryRenderRatio('CUSTOM','',1000001,10000000,0.5,true);

//LOCAL LAYER
document.uemapvw.SetLocalLayer(101,10,10,20,'RemaxLogoMap','Remax',-1,-1);

ScaleMaxPoi = 10000000;
StatusCheck = true;

AddStopPoi=true;//consente di aggiugere poi come punti del percorso

// imposta Poi
categoriepoi();
// sicronizzazione Poi

//text info
document.uemapvw.SetPoiText('CUSTOM','',extra0);

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

document.uemapvw.SetScaleSt(StartScale);
document.uemapvw.SetPoint(StartX,StartY,0);
document.uemapvw.GetMapSt();

}// UMJA_AppletLoaded


/*
Salvataggio dei dati relativi al centro mappa coordinate e indirizzo
*/
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)

*/
}// UMJA_ConfirmPoint


/*
Evento scatenato al click del mouse sulla mappa nella modalità
Fly distence
*/
function UMJA_FlyDistMouseClicked(){
/*

// ritorna la lunghezza totale o parziale???
GetDistance()

*/
}// FlyDistMouseClicked


/*
Evento ottenuto dalla ricerca di un indirizzo
*/
function UMJA_LocationList(){
/*

// ritorna l'XML a fronte di una ricerca di indirizzo
GetXmlLocationList()

*/
setxmla(document.uemapvw.GetXmlLocationList());
}// UMJA_LocationList


/*
Evento scateneto al caricamento di ogni mappa
*/
function UMJA_MapLoaded(){
CurrentScale();
var dovesei = document.uemapvw.GetCurrentLocation(4);
if(document.uemapvw.GetCurrentLocation(5) != "" &&(document.uemapvw.GetCurrentLocation(5).search('@')==-1)){
  dovesei = dovesei +' - '+document.uemapvw.GetCurrentLocation(5).toLowerCase();
if(document.uemapvw.GetCurrentLocation(6) != "")
  dovesei = dovesei +','+document.uemapvw.GetCurrentLocation(6).toLowerCase();
}
document.Info_Form.DoveSei.value=dovesei;

}// 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;}
}


/*
Evento ottenuto dopo un calcolo percorso
*/
function UMJA_MapPathLoaded(){
/*
// ritorna il codice dell'ultimo percorso calcolato e ancora presente sulla mappa
GetPathID()
// ritorna l'xml con il dettagli del percorso testuale appena calcolato
GetXmlPath()

*/
  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;}
/*
     	if(effectnetscape==0) {
     			x=  unescape(String(testx).replace(lsRegExp,' '));
     			//effectnetscape2=1;
     		}
     	else {
     			x=  unescape(String(testx).replace(lsRegExp,'  '));
     		}
*/
     	x=  unescape(String(testx).replace(lsRegExp,' '));
      setxml(x);
  		ubitag();
  }
}// UMJA_MapPathLoaded


/*
Cambio modalità di funzionamento dell'applet
*/
function UMJA_ModeChanged(){
/*

// ritona la modatità di funzinamento attuale o precedente
GetMode(int type)

*/
}// 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
*/
//alert('Codice Errore :'+document.uemapvw.GetErrorCode()+'\n Errore : '+document.uemapvw.GetErrorDescription());
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(){
/*

// ritorna l'xml contenente i dati dei P.O.I effettuando una ricerca
GetXmlPoiList()
*/
   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,' '));
   	}

  	//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
*/
function UMJA_PoiMouseClicked(){
/*

// ritorna il broker del Poi selezionato
GetPoiBrokerID()
// ritorna la categoria del Poi selezionato
GetPoiCategoryID()
// ritorna l'identificatico ID del Poi selezionato
GetPoiID()
// ritorna l'URL se specificata (link)
GetPoiURL()
// ritorna il nome o una descrizione del Poi
GetPoiToolTip()


  if(document.uemapvw.GetPoiURL() == "" || document.uemapvw.GetPoiURL() == null){
    	window.open("http://maps.ubiest.com/Product/JGate/Ext/GetPoiDetail.php?XidPOI="+document.uemapvw.GetPoiID()+"&XidPoiBroker="+document.uemapvw.GetPoiBrokerID(), "Percorso","height=320,width=560,scrollbars=no");
     	}
  else{

   	window.open(document.uemapvw.GetPoiURL(), "Percorso","height=320,width=560,scrollbars=no");
  	}
*/
	var stringpoiid   = document.uemapvw.GetPoiID();
	var stringpoicust = document.uemapvw.GetPoiBrokerID();
	var stringpoiicon = document.uemapvw.GetPoiIcon();
	var stringpoiurl	= document.uemapvw.GetPoiURL();


	if (stringpoiid.indexOf(',')==-1){
          if(document.uemapvw.GetPoiBrokerID() == "NAV") {
	    	window.open("http://maps.ubiest.com/Product/JGate/Ext/GetPoiDetail.php?XidPOI="+document.uemapvw.GetPoiID()+"&XidPoiBroker="+document.uemapvw.GetPoiBrokerID(), "Percorso","height=320,width=560,scrollbars=no");
                }
	  else {
             if(document.uemapvw.GetPoiURL() == "" || document.uemapvw.GetPoiURL() == null){
	     	var poi_id,pop_up_params;
	     	poi_id=new String(document.uemapvw.GetPoiID());
	     	if(poi_id.search("-")>0){
	     	        //immobile
	     	        // window.open("http://www.remax.it/pubscripts/ListingFull.asp?AgentID="+poi_id.split("-")[0]+"&ListingId="+poi_id.split("-")[1]+"&Lang=IT");
	     	        window.open("http://www.remax.it/"+poi_id.split("-")[0]+"-"+poi_id.split("-")[1]);
	     	        
	     	}
	     	else
	     	        // window.open("http://www.remax.it/pubscripts/OfficeFull.asp?OfficeID="+poi_id+"&Lang=IT");
	     	        window.open("http://www.remax.it/OfficeProfile.aspx?OfficeId="+poi_id+"&Lang=IT");
	     	
	     	}
	  else{
	   	window.open(document.uemapvw.GetPoiURL(), "Percorso","height=320,width=560,scrollbars=no");
	  	}
          } // NON NAV

	}
	else{

	arraypoiid = stringpoiid.split(',');
	arraypoicust = stringpoicust.split(',');
	arraypoiicon = stringpoiicon.split(',');
	arraypoiurl = stringpoiurl.split(',');

	var oppoi;

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

	oppoi=window.open("","","width=400,height=300,scrollbars=yes,screenX=500,screenY=375,left=500,top=375") ;
  	oppoi.document.write("<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;\"><TITLE>Lista risultati multipli</title></HEAD><BODY><TD WIDTH=\"100%\" VALIGN=\"top\" ALIGN=\"left\"> <DIV ALIGN=\"left\"> ");
   	oppoi.document.write("<TABLE cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=340 Bgcolor=#DADCDE>");
   	oppoi.document.write("<TR><TD ALIGN=right valign=top WIDTH=20 bgcolor=eeeef5 class=micro><font FACE=\"Verdana\" SIZE=\"2\"><b>No.</b></FONT></TD>");
   	oppoi.document.write("<TD ALIGN=right valign=top WIDTH=100 bgcolor=eeeef5 class=micro><font FACE=\"Verdana\" SIZE=\"2\"><b>Impianto</b></FONT></TD>");
   	oppoi.document.write("<TD ALIGN=center valign=top WIDTH=100 bgcolor=eeeef5 class=micro><font FACE=\"Verdana\" SIZE=\"2\"><b>Icon</b></FONT></TD></TR>");
	for (var i=0 ; i<arraypoiid.length ; i++){
		if((i % 2)==0) {colore='#FFFFFF';}else(colore='#CACACA');
		if (arraypoiicon[i]) {geticon="<img src=\""+"../PoiIcons/"+arraypoiicon[i]+".gif\" width=\"16\" height=\"16\">";}else{geticon="";}  //inserimento dell'icona
		if (arraypoiurl[i] ) {geturl=arraypoiurl[i];} else {geturl="";}
		oppoi.document.write("<TR><TD WIDTH=10 valign=top align=right bgcolor="+colore+"><font FACE=\"Verdana\" SIZE=\"1\">"+(i+1)+".</font></td>");
  		oppoi.document.write("<TD id=\"T$Ucount\" NAME=\"T$Ucount\" WIDTH=150 valign=top bgcolor="+colore+" nowrap><font FACE=\"Verdana\" SIZE=\"1\">");
		oppoi.document.write('<a name=\"c'+i+'\" id=\"c'+i+'\" href=\"javascript:opener.poimouseclicked(\''+arraypoiid[i]+'\',\''+arraypoicust[i]+'\',\''+geturl+'\');\"><center>'+arraypoiid[i]+'</center></a>');
		oppoi.document.write("</FONT></TD>");
		oppoi.document.write("<TD WIDTH=100 valign=top align=left bgcolor="+colore+"><font FACE=\"Verdana\" SIZE=\"1\"><center>"+geticon+"</center></FONT></td></TR>");
	}
	oppoi.document.write("</TABLE></DIV></TD>"); //inseriamo
  	oppoi.document.write("</BODY>");
  	oppoi.document.write("</HTML>");
  	oppoi.document.close();

	}
}// UMJA_PoiMouseClicked

function poimouseclicked(id, cust, cUrl){

UbiPoiBrokerUrl=LocalPoiBrokerUrl="http://maps.ubiest.com/Product/JGate/Ext/GetPoiDetail.php";
if( cUrl)
   detailwin=window.open(cUrl, "Percorso","height=320,width=560,scrollbars=no");
else {
   if(document.uemapvw.GetPoiBrokerID()=='NAV')
	detailwin=window.open(UbiPoiBrokerUrl+"?XidPOI="+id+"&XidPoiBroker="+cust, "DettaglioPoi","height=320,width=560,scrollbars=no");
   else
   	detailwin=window.open(LocalPoiBrokerUrl+"?XidPOI="+id+"&XidPoiBroker="+cust, "DettaglioPoi","height=320,width=560,scrollbars=no");
   }
  detailwin.focus();
}

/*
Evento ottenuto alla pressione del tasto destro del mouse
*/
function UMJA_RightMouseClicked(){
/*

// con PosType=2 ritorna la coord. X dell'ultimo click sulla mappa
GetPosX(int PosType, int CoordSys)
// con PosType=2 ritorna la coord. Y dell'ultimo click sulla mappa
GetPosY(int PosType, int CoordSys)

*/
}// UMJA_RightMouseClicked


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

/*
alert(document.uemapvw.GetFlagNumber());
alert(document.uemapvw.GetCurrentLocation(5));
alert(document.uemapvw.GetModeFlag());
*/

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

*/
}// UMJA_StopSelected

/*
Evento di cancellazione di una bandierina
*/
function UMJA_DeleteStop(){
//alert("cancello = "+document.uemapvw.GetFlagNumber());
	}

/*
Evento scatenato dalla richiesta di visualizzazione dell'intero
indirizzo al click del mouse su una determinata via o piazza
*/
function UMJA_StreetInfo(){
/*

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*$/, "") Non funziona con NS
  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="";
halter=arrayelema.length
if (halter > 2) {
  	op=window.open("","","width=300,height=300,scrollbars=yes,screenX=520,screenY=375,left=520,top=375") ;
  	op.document.write("<HTML>");
  	op.document.write("<HEAD>");
	op.document.write("<TITLE>"+l_address_list_title+"</TITLE>");
//op.document.write("<LINK REL='stylesheet' type='text/css' href='Styles.css'>"); Da problemi con Nestcape se mancante Styles.css
  	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,'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();'>"+amd4t);
  	   // if (findtaga(aba,'ADDR')!="-1" && (AddrLookup != 1)) {
  	   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) {/*alert("ci sta");*/ 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;");
	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){
arrayelem= xmldatpass.split('<');
arrayelem=arrayelem.slice(1,arrayelem.length);
//alert(arrayelem);
halter=arrayelem.length
var aba=0;
i=0;
}

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

//finestra principale
function ubitag(){
//visualizziamo la pagina
if (actuawin!=null){  actuawin.close();}
if ((arrayelem!=null)) {
	actuawin=window.open("XmlPathTemplate.html","","width=650,height=400,scrollbars=yes");
}
else{
	UMJA_MapPathLoaded();
	}
}

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=\"\";");
        }
        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
  	//alert('pass='+pass);
  	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;
//try{
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]); }
    }
//}catch(er){return("-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){
//alert(xmldatpass);
arrayelemc=new Array();
//alert(xmldatpass2);
arrayelemc= xmldatpass2.split('<');
//alert(arrayelemc);
i=0;
}

function findtagc(number,attribute3) {
//alert(arrayelemc);
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";
}

var opc = null; // variabile finestra poi

function chiusuraopc() {
//alert("chiuso");
opc=null;
}

function visuac() {
var aba=0;
halter=arrayelemc.length
if(opc!=null){opc.close(); opc=null;}

if (halter > 1){
	opc=window.open("","","width=640,height=300,scrollbars=yes,screenX=500,screenY=375,left=500,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=\"opener.chiusuraopc()\">");
    opc.document.write("<TABLE cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=600 class=poilist>");
    opc.document.write("<TR><TD ALIGN=right valign=top WIDTH=10  class=poilist_header>" + l_numero + "</TD>");
    opc.document.write("<TD ALIGN=center valign=top WIDTH=200 class=poilist_header>" + l_descrizione + "</TD>");
    opc.document.write("<TD ALIGN=center valign=top WIDTH=290 class=poilist_header>" + l_indirizzo + "</TD>");
    opc.document.write("<TD ALIGN=center valign=top  class=poilist_header>" + l_icona + "</TD>");
	if(AddStopPoi)
		opc.document.write("<TD ALIGN=center valign=top class=poilist_header colspan=2>" + l_aggiungi + "</TD>");
	opc.document.write("</TR>");

  	for(aba=1;aba<halter;aba++){
	    if((aba%10)==0)
			opc.document.write("</table><TABLE cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=600 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=\""+"PoiIcons/"+icon+".gif\" width=\"16\" height=\"16\">";}else{geticon="";}  //inserimento dell'icona		
		if (findtagc(aba,'X')=="-1"){break}
		if (desc=="-1"){desc=l_centra;}
	   opc.document.write("<TR><TD WIDTH=10 valign=top align=right class=" + tdclass + ">"+aba+"</td>");
       opc.document.write("<TD id=\"T$Ucount\" NAME=\"T$Ucount\" WIDTH=200 valign=top class=" + tdclass + ">");
	   opc.document.write('<a name=\"c"+aba+"\" id=\"c"+aba+"\" href=\"javascript:opener.centermapc('+findtagc(aba,'X')+','+findtagc(aba,'Y')+',\''+findtagc(aba,'ID')+'\');\">'+desc+'</a>');
       opc.document.write("</TD><TD WIDTH=290 valign=top align=left class=" + tdclass + ">"+ Xamd4 + addr +" " +num+"</td>");
       opc.document.write("<TD valign=top align=left class=" + tdclass + "><center>"+geticon+"</center></td>");
	   if(AddStopPoi){
	   	opc.document.write("<TD valign=top align=left class=" + tdclass + "><center><a href=\"javascript:opener.SetPoiStartSt('" + Xamd4 + "','" + Xaddr + "','" + Xnum + "'," + Xcoordx + "," + Xcoordy + ");opener.MM_showHideLayers('maplayer','','hide','pathlayer','','show','poilayer','','hide');opener.setMenuStyle('m2');\" title=\"" + l_imposta_partenza + "\"><img src=\"PoiIcons/stop1.gif\" border=\"0\"></a></center></td>");
		opc.document.write("<TD valign=top align=left class=" + tdclass + "><center><a href=\"javascript:opener.SetPoiFinishSt('" + Xamd4 + "','" + Xaddr + "','" + Xnum + "'," + Xcoordx + "," + Xcoordy + ");opener.MM_showHideLayers('maplayer','','hide','pathlayer','','show','poilayer','','hide');opener.setMenuStyle('m2');\" title=\"" + l_imposta_destinazione + "\"><img src=\"PoiIcons/stop2.gif\" border=\"0\"></a></center></td>");	
	   }
	   opc.document.write("</TR>");
   } // End for

	opc.document.write("</TABLE>"); //inseriamo
  	opc.document.write("</BODY>");
  	opc.document.write("</HTML>");
  	opc.document.close();
    }
else{
  	setarray(1);
	}

}


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



