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

// 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)

// 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 per la gestione delle nazioni
arraycountry  = new Array(); //Nomi delle nazioni
//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_1_991";
  arraycategory2[i]="Vitto/Alloggio";
  arraycategory3[i]="Search_Form.Cat_NAV_1_991"; 
  
  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_1_992";
  arraycategory2[i]="Trasporti";
  arraycategory3[i]="Search_Form.Cat_NAV_1_992"; 
  
  arraycategory0[++i]="UBIEST";
  arraycategory1[i]="NAV_1_993";
  arraycategory2[i]="ServiziPubblici";
  arraycategory3[i]="Search_Form.Cat_NAV_1_993"; 
  
  arraycategory0[++i]="UBIEST" ;
  arraycategory1[i]="NAV_1_994" ;
  arraycategory2[i]="TempoLibero";
  arraycategory3[i]="Search_Form.Cat_NAV_1_994"; 
  
  arraycategory0[++i]="UBIEST" ;
  arraycategory1[i]="NAV_1_995" ;
  arraycategory2[i]="Soldi";
  arraycategory3[i]="Search_Form.Cat_NAV_1_995"; 
 
} //categoriepoi

/**
Inizizializzazione dell'array per le nazioni bisogna inserire
le nazioni che si vogliono utilizzare
*/
function categorycountry()  {
  var i=0;
  
  arraycountry[i++]="ITALIA";      
  arraycountry[i++]="FRANCIA";
  arraycountry[i++]="AUSTRIA";
  arraycountry[i++]="SVIZZERA";
  arraycountry[i++]="MONACO"; 
  arraycountry[i++]="ANDORRA"; 
  arraycountry[i++]="BELGIO";
  arraycountry[i++]="LUSSEMBURGO";
  arraycountry[i++]="OLANDA";
  arraycountry[i++]="GERMANIA";
  arraycountry[i++]="SPAGNA";
  arraycountry[i++]="INGHILTERRA";
  arraycountry[i++]="GALLES";
  arraycountry[i++]="SCOZIA";    
}//categorycountry

/**
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]="RegistrationForm.Stato";      
   acity[i]="RegistrationForm.citta";
   aaddress[i]="RegistrationForm.indirizzo";
	anumber[i]="RegistrationForm.numero"; 			

	}


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

// History delle mappe generate
/**
Funzione per la cronologia delle mappe visualizzate
@param type  
*/
function DoAction(type){
	switch(type){
		case 1:
		   // first
			document.uemapvw.DoAction(1);
			break;
		case 2:
		   // previous
			document.uemapvw.DoAction(2);
			break;			
		case 3:
		   // next
			document.uemapvw.DoAction(3);
			break;			
		case 4:
		   // last
			document.uemapvw.DoAction(4);
			break;			
		}
   // Gestione Poi
	PoiCategoryStatus();
	cancella();
	}


/**
Funzione di stampa della mappa visualizzata dall'applet
*/
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='RouteGPS/JGate/PrintMap.asp' 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; //document.forms[0].stamp.value
	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]+"\");");
  }
}


/**
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';
	if (tipo==1) force="\" FORCE=\"1";
	
	//alert(city.toUpperCase());
	//alert(AMD4);
	if ((city.toUpperCase()!=AMD4 && ADDR!=address.toUpperCase()) || ADDR!=address.toUpperCase() ) {
		if (city.toUpperCase()!=AMD4) {AMC = "";}
		if (AMC == ""){
		   //alert('Richiedo Città+Indirizzo');			
   		AddrLookup=1;
			document.uemapvw.SearchLocation( country,'', '','', city+force,'','','','',address, numero);
			}
		else{
		   //alert('Richiedo Indirizzo');			
			AddrLookup=0;
			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 della mappa contenente un percorso calcolato
*/

function SearchGetPath(){

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

	// controllo esistenza percorso
   if (document.uemapvw.GetPathID()!=null && document.uemapvw.GetPathID()!="") document.uemapvw.DeletePath();
		
	var country = '1'; //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;
	
	/* Versione originale
	if (puntox!=0 && puntoy!=0){
		document.uemapvw.AddStopSt(parseInt(puntox),parseInt(puntoy),0);
	   }
 	*/
 	// JFlat
 	if (puntox!=0 && puntoy!=0){
   	
		// alert (document.RegistrationForm.Xp[0].checked)
   		if (document.RegistrationForm.Xp[0].checked){
			document.uemapvw.AddStopSt(x,y,0);
			document.uemapvw.AddStopSt(puntox,puntoy,0); 
			}
		else{  
  			document.uemapvw.AddStopSt(puntox,puntoy,0);
			document.uemapvw.AddStopSt(x,y,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(){
	
    if (document.RegistrationForm.PathType!= null && document.RegistrationForm.PathDetail!=null){
		 if (document.RegistrationForm.PathType[0].checked)
		    algo = parseInt(document.RegistrationForm.PathType[0].value);
		 else
		    algo = parseInt(document.RegistrationForm.PathType[1].value);
		 if (document.RegistrationForm.Highway.checked)
		    algo +=parseInt(document.RegistrationForm.Highway.value);
	 	
		 document.uemapvw.GetPath(algo,parseInt(document.RegistrationForm.PathDetail[document.RegistrationForm.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('ITA');

// impostazione broker
document.uemapvw.AddPoiBrokerData('UBIEST','','NAV_1_991/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,10000,1,true); 
document.uemapvw.SetPoiCategoryRenderRatio('UBIEST','',10001,20000,0.75,true); 
document.uemapvw.SetPoiCategoryRenderRatio('UBIEST','',20001,50000,0.5,true); 

// imposta Poi
categoriepoi();
// sicronizzazione Poi
PoiCategoryStatus();
// imposta le form per le ricerche
categoryform();

document.uemapvw.SetAdditionalLayer('<RGB R="0" G="0" B="0"/><AL><EL ID="UbiLogo" X="35" Y="12" TY="V"/></AL>');

document.uemapvw.SetScaleSt(25000);
document.uemapvw.SetPoint(2068843,1436602,0);
document.uemapvw.GetMapSt();
document.uemapvw.SetLocalLayer(100, 0, 2068843, 1436602, 'gr_pin', '', 20, 20);

}// 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();
	  
  csCity = new String(document.uemapvw.GetCity());
  csRightess = new String(document.uemapvw.GetAddress());
  
  document.Search_Form.City.value= csCity.toLowerCase();
  document.Search_Form.Address.value= csRightess.toLowerCase();	

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

function CurrentScale(){
  var CurScale;
  CurScale  = document.uemapvw.GetScale();
  MMS_swapImgRestore();
  if (CurScale <= 2000) 
  	MMS_swapImage('triangolo_r1_c101','','RouteGPS/JMap/livelli1/images/triangolo_r1_c10_f2.jpg',1);
  else if (CurScale <= 10000)
  	MMS_swapImage('triangolo_r1_c91','','RouteGPS/JMap/livelli1/images/triangolo_r1_c9_f2.jpg',1);
  else if (CurScale <= 25000)
  	MMS_swapImage('triangolo_r1_c81','','RouteGPS/JMap/livelli1/images/triangolo_r1_c8_f2.jpg',1);
  else if (CurScale <= 50000)
	MMS_swapImage('triangolo_r1_c71','','RouteGPS/JMap/livelli1/images/triangolo_r1_c7_f2.jpg',1);
  else if (CurScale <= 250000)
	MMS_swapImage('triangolo_r1_c61','','RouteGPS/JMap/livelli1/images/triangolo_r1_c6_f2.jpg',1);
  else if (CurScale <= 500000)
	MMS_swapImage('triangolo_r1_c51','','RouteGPS/JMap/livelli1/images/triangolo_r1_c5_f2.jpg',1);
  else if (CurScale <= 1000000)
	MMS_swapImage('triangolo_r1_c41','','RouteGPS/JMap/livelli1/images/triangolo_r1_c4_f2.jpg',1);
  else if (CurScale <= 2000000)
	MMS_swapImage('triangolo_r1_c31','','RouteGPS/JMap/livelli1/images/triangolo_r1_c3_f2.jpg',1);
  else if (CurScale <= 5000000)
	MMS_swapImage('triangolo_r1_c21','','RouteGPS/JMap/livelli1/images/triangolo_r1_c2_f2.jpg',1);
  else if (CurScale <= 10000000)
	MMS_swapImage('triangolo_r1_c11','','RouteGPS/JMap/livelli1/images/triangolo_r1_c1_f2.jpg',1);   
}

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

     	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());
}// 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,' '));					
   	}
  	
  	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://maps2.ubiest.com/Test/JGate1.2/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");
  		}
}// UMJA_PoiMouseClicked


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


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

	}

/*
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à
    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>UbiEst: risultato ricerca</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("<BODY>");
  	op.document.write("<FONT FACE='Verdana' SIZE='2'><B>Risultato ricerca</B></font><BR>");
  	op.document.write('<FONT FACE="Verdana" SIZE="1" color="#000000"><UL>');
	for(aba=1;aba<halter;aba++){
  	   if(findtaga(aba,'AMD4')!="-1"){amd4t = findtaga(aba,'AMD4');}else{amd4t=""; }
  	     op.document.write("<LI><A 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></FONT>");
  	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:
			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)) {
	//alert(arrayelem);
	//actuawin=window.open("XmlPathTemplate.html","","width=650,height=400,scrollbars=yes"); 
	actuawin=window.open("RouteGPS/JMap/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();}
}

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><HEAD><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;\"><TITLE>Ubiest - List POI result -</title></HEAD><BODY onunload=\"opener.chiusuraopc()\"><TD WIDTH=\"100%\" VALIGN=\"top\" ALIGN=\"left\"> <DIV ALIGN=\"left\"> ");
   opc.document.write("<TABLE cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=600 Bgcolor=#DADCDE>");
   opc.document.write("<TR><TD ALIGN=right valign=top WIDTH=10 bgcolor=eeeef5 class=micro><font FACE=\"Verdana\" SIZE=\"2\"><b>No.</b></FONT></TD>");
   opc.document.write("<TD ALIGN=center valign=top WIDTH=200 bgcolor=eeeef5 class=micro><font FACE=\"Verdana\" SIZE=\"2\"><b>Description</b></FONT></TD>");
   opc.document.write("<TD ALIGN=center valign=top WIDTH=290 bgcolor=eeeef5 class=micro><font FACE=\"Verdana\" SIZE=\"2\"><b>Address</b></FONT></TD>");
   opc.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(aba=1;aba<halter;aba++){
		if ((mass=findtagc(aba,'ADDR'))!="-1") {addr=", "+mass;}else{addr="";}
		if (findtagc(aba,'NUM')!="-1") { num="N° "+findtagc(aba,'NUM'); } else {num=""; }
	   if((aba % 2)==0) {colore='#FFFFFF';}else(colore='#CACACA');
    	if (findtagc(aba,'TY')!="-1") { desc= findtagc(aba,'NAME'); }else{desc= findtagc(aba,'DESC');}
    	if ((icon=findtagc(aba,'ICON'))!="-1") {geticon="<img src=\""+"../NewLayout/PoiIcons/"+icon+".gif\" width=\"16\" height=\"16\">";}else{geticon="";}  //inserimento dell'icona
		if (findtagc(aba,'X')=="-1"){break}
		if (desc=="-1"){desc="Centra"; desc=desc.italics(); desc=desc.big();}
	   opc.document.write("<TR><TD WIDTH=10 valign=top align=right bgcolor="+colore+"><font FACE=\"Verdana\" SIZE=\"1\">"+aba+".</font></td>");
      opc.document.write("<TD id=\"T$Ucount\" NAME=\"T$Ucount\" WIDTH=150 valign=top bgcolor="+colore+" nowrap><font FACE=\"Verdana\" SIZE=\"1\">");
	   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("</FONT>");
      opc.document.write("</TD><TD WIDTH=240 valign=top align=left bgcolor="+colore+"><font FACE=\"Verdana\" SIZE=\"1\">"+ findtagc(aba,'AMD4') + addr +" " +num+"</font></td>");	    
      opc.document.write("<TD WIDTH=100 valign=top align=left bgcolor="+colore+"><font FACE=\"Verdana\" SIZE=\"1\"><center>"+geticon+"</center></FONT></td></TR>");
   } // End for 

	opc.document.write("</TABLE></DIV></TD>"); //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);
}


//--------------------------Funzioni JFlat------------------------------------------------
//var x=2398679;
//var y=1489412;

var x=2068843
var y=1436602

function ChangeCoord(varx,vary){
	x=varx;
	y=vary;
}

