// array regioni 
var regionesVal = new Array(104);
var regionesTxt = new Array(104);
var countries = new Array(100);

var xcountries = new Array(10);
var xcities = new Array(10);
var xaddresses = new Array(10);
var xnumbers = new Array(10);

var xtappe = new Array(10);
var ytappe = new Array(10);
var descrtappe = new Array(10);

countries["1"] = "Italia";
countries["2"] = "Francia";
countries["3"] = "Germania";
countries["S"] = "Inghilterra";
countries["8"] = "Austria";
countries["9"] = "Svizzera";
countries["5"] = "Belgio";
countries["6"] = "Lussemburgo";
countries["7"] = "Olanda";
countries["M"] = "Spagna";
countries["T"] = "Galles";
countries["V"] = "Scozia";
countries["B"] = "Monaco";
countries["E"] = "Andorra";
countries["C"] = "Liechtenstein";

regionesVal[0] = "Tutte"; regionesTxt[0] = "Tutte";

regionesVal[1] = "NAV_3_2084"; regionesTxt[1] = 	"Cantina                     ";                             
regionesVal[2] = "NAV_3_5800"; regionesTxt[2] = 	"Ristorante                  ";                         

regionesVal[3] = "NAV_3_4013"; regionesTxt[3] = 	"Stazione Ferroviaria        ";                            
regionesVal[4] = "NAV_3_4170"; regionesTxt[4] = 	"Terminal Corriere           ";                             
regionesVal[5] = "NAV_3_4482"; regionesTxt[5] = 	"Imbarco Traghetti           ";                         
regionesVal[6] = "NAV_3_4580"; regionesTxt[6] = 	"Aeroclub                    ";
regionesVal[7] = "NAV_3_4581"; regionesTxt[7] = 	"Aeroporto                   ";                                     
regionesVal[8] = "NAV_3_9999"; regionesTxt[8] = 	"Valico Di Frontiera         ";                                 
regionesVal[9] = "NAV_3_5540"; regionesTxt[9] = 	"Distributore Di Carburante  ";                                    
regionesVal[10] ="NAV_3_7520"; regionesTxt[10] =	"Parcheggio Scoperto         ";                     
regionesVal[11] ="NAV_3_7521"; regionesTxt[11] =	"Parcheggio Coperto          ";                            
regionesVal[12] ="NAV_3_7522"; regionesTxt[12] =	"Parcheggio Di Scambio       ";                                   
regionesVal[13] ="NAV_3_5511"; regionesTxt[13] =	"Concessionario Auto         ";                          
regionesVal[14] ="NAV_3_7510"; regionesTxt[14] =	"Autonoleggio                ";                               
regionesVal[15] ="NAV_3_7897"; regionesTxt[15] =	"Area Di Servizio            ";                                          

regionesVal[16] ="TEL_801";    regionesTxt[16] =  "Farmacie                    ";
regionesVal[17] ="NAV_3_8060"; regionesTxt[17] =	"Ospedale                    ";                      
regionesVal[18] ="NAV_3_7994"; regionesTxt[18] =	"Centro Civico               ";               
regionesVal[19] ="NAV_3_9121"; regionesTxt[19] =	"Municipio                   ";                                    
regionesVal[20] ="NAV_3_8200"; regionesTxt[20] =	"Università                  ";                           
regionesVal[21] ="NAV_3_6512"; regionesTxt[21] =	"Centro Commerciale          ";                                      

regionesVal[22] ="NAV_3_5813"; regionesTxt[22] =	"Locali Notturni             ";                       
regionesVal[23] ="TEL_517";    regionesTxt[23] =  "Cinema                      ";
regionesVal[24] ="NAV_3_7929"; regionesTxt[24] =	"Teatro                      ";                             
regionesVal[25] ="NAV_3_7933"; regionesTxt[25] =	"Bowling                     ";                        
regionesVal[26] ="NAV_3_7947"; regionesTxt[26] =	"Impianto Ricreativo         ";                                 
regionesVal[27] ="NAV_3_7985"; regionesTxt[27] =	"Casinò                      ";                        
regionesVal[28] ="NAV_3_7996"; regionesTxt[28] =	"Parco Divertimenti          ";                                           
regionesVal[29] ="NAV_3_7012"; regionesTxt[29] =	"Impianto Sciistico          ";                                           
regionesVal[30] ="NAV_3_7940"; regionesTxt[30] =	"Complesso Sportivo          ";                                        
regionesVal[31] ="NAV_3_7992"; regionesTxt[31] =	"Campi Da Golf               ";                                               
regionesVal[32] ="NAV_3_7997"; regionesTxt[32] =	"Centro Sportivo             ";                                            
regionesVal[33] ="NAV_3_7998"; regionesTxt[33] =	"Pista Di Pattinaggio        ";                                       

regionesVal[34] ="NAV_3_4493"; regionesTxt[34] =	"Porto Turistico             ";                      
regionesVal[35] ="NAV_3_5999"; regionesTxt[35] =	"Monumento Storico           ";                                     
regionesVal[36] ="NAV_3_7389"; regionesTxt[36] =	"Informazione Turistica      ";                                       
regionesVal[37] ="NAV_3_7990"; regionesTxt[37] =	"Centro Congressi/Esposizioni";                                                 
regionesVal[38] ="NAV_3_7999"; regionesTxt[38] =	"Attrazione Turistica        ";                                          
regionesVal[39] ="NAV_3_8410"; regionesTxt[39] =	"Museo                       ";                                        
regionesVal[40] ="NAV_3_7011"; regionesTxt[40] =	"Albergo                     ";


function Carica() {
  document.global_form.prov.length=41;
  
  document.global_form.prov[1].text="Aeroclub";
  document.global_form.prov[1].value="NAV_3_4580";
  document.global_form.prov[2].text="Aeroporto";
  document.global_form.prov[2].value="NAV_3_4581";
  document.global_form.prov[3].text="Albergo";
  document.global_form.prov[3].value="NAV_3_7011";
  document.global_form.prov[4].text="Area di servizio";
  document.global_form.prov[4].value="NAV_3_7897";
  document.global_form.prov[5].text="Attrazione turistica";
  document.global_form.prov[5].value="NAV_3_7999";
  document.global_form.prov[6].text="Autonoleggio";
  document.global_form.prov[6].value="NAV_3_7510";
  document.global_form.prov[7].text="Bowling";
  document.global_form.prov[7].value="NAV_3_7933";
  document.global_form.prov[8].text="Campi da golf";
  document.global_form.prov[8].value="NAV_3_7992";
  document.global_form.prov[9].text="Cantina";
  document.global_form.prov[9].value="NAV_3_2084";
  document.global_form.prov[10].text="Casinò";
  document.global_form.prov[10].value="NAV_3_7985";
  document.global_form.prov[11].text="Centro civico";
  document.global_form.prov[11].value="NAV_3_7994";
  document.global_form.prov[12].text="Centro commerciale";
  document.global_form.prov[12].value="NAV_3_6512";
  document.global_form.prov[13].text="Centro congressi/esposizioni";
  document.global_form.prov[13].value="NAV_3_7990";
  document.global_form.prov[14].text="Centro sportivo";
  document.global_form.prov[14].value="NAV_3_7997";
  document.global_form.prov[15].text="Cinema";
  document.global_form.prov[15].value="TEL_517";
  document.global_form.prov[16].text="Complesso sportivo";
  document.global_form.prov[16].value="NAV_3_7940";
  document.global_form.prov[17].text="Concessionario auto";
  document.global_form.prov[17].value="NAV_3_5511";
  document.global_form.prov[18].text="Distributore di carburante";
  document.global_form.prov[18].value="NAV_3_5540";
  document.global_form.prov[19].text="Farmacie";
  document.global_form.prov[19].value="TEL_801";
  document.global_form.prov[20].text="Imbarco traghetti";
  document.global_form.prov[20].value="NAV_3_4482";
  document.global_form.prov[21].text="Impianto ricreativo";
  document.global_form.prov[21].value="NAV_3_7947";
  document.global_form.prov[22].text="Impianto sciistico";
  document.global_form.prov[22].value="NAV_3_7012";
  document.global_form.prov[23].text="Informazione turistica";
  document.global_form.prov[23].value="NAV_3_7389";
  document.global_form.prov[24].text="Lolcali notturni";
  document.global_form.prov[24].value="NAV_3_5813";
  document.global_form.prov[25].text="Monumento storico";
  document.global_form.prov[25].value="NAV_3_5999";
  document.global_form.prov[26].text="Municipio";
  document.global_form.prov[26].value="NAV_3_9121";
  document.global_form.prov[27].text="Museo";
  document.global_form.prov[27].value="NAV_3_8410";
  document.global_form.prov[28].text="Ospedale";
  document.global_form.prov[28].value="NAV_3_8060";
  document.global_form.prov[29].text="Parcheggio coperto";
  document.global_form.prov[29].value="NAV_3_7521";
  document.global_form.prov[30].text="Parcheggio di scambio";
  document.global_form.prov[30].value="NAV_3_7522";
  document.global_form.prov[31].text="Parcheggio scoperto";
  document.global_form.prov[31].value="NAV_3_7520";
  document.global_form.prov[32].text="Parco divertimenti";
  document.global_form.prov[32].value="NAV_3_7996";
  document.global_form.prov[33].text="Pista di pattinaggio";
  document.global_form.prov[33].value="NAV_3_7998";
  document.global_form.prov[34].text="Porto turistico";
  document.global_form.prov[34].value="NAV_3_4493";
  document.global_form.prov[35].text="Ristorante";
  document.global_form.prov[35].value="NAV_3_5800";
  document.global_form.prov[36].text="Stazione ferroviaria";
  document.global_form.prov[36].value="NAV_3_4013";
  document.global_form.prov[37].text="Teatro";
  document.global_form.prov[37].value="NAV_3_7929";
  document.global_form.prov[38].text="Terminal Corriere";
  document.global_form.prov[38].value="NAV_3_4482";
  document.global_form.prov[39].text="Università";
  document.global_form.prov[39].value="NAV_3_8200";
  document.global_form.prov[40].text="Valico di frontiera";
  document.global_form.prov[40].value="NAV_3_9999";
  
  document.global_form.prov[0].selected ='true' ;
}

function RiduciProv() {

  for (var i=0; i<document.global_form.re_gi.length; i++) {
    if (document.global_form.re_gi[i].selected) {
      switch(document.global_form.re_gi[i].text){
        case "Tutte":
          Carica();
          break;
        case "Cibo":
          document.global_form.prov.length=3;
          for (var j=1; j<=2; j++) {
            document.global_form.prov[j].text=regionesTxt[j];
            document.global_form.prov[j].value=regionesVal[j];
          }
          break;
        case "Trasporti":
          document.global_form.prov.length=14;
          for (var j=1; j<=12; j++) {
            document.global_form.prov[j].text=regionesTxt[j+2];
            document.global_form.prov[j].value=regionesVal[j+2];
          }
          break;
        case "Servizi pubblici":
          document.global_form.prov.length=6;
          for (var j=1; j<=5; j++) {
            document.global_form.prov[j].text=regionesTxt[j+15];
            document.global_form.prov[j].value=regionesVal[j+15];
          }
          break;
        case "Sport e tempo libero":
          document.global_form.prov.length=13;
          for (var j=1; j<=12; j++) {
            document.global_form.prov[j].text=regionesTxt[j+21];
            document.global_form.prov[j].value=regionesVal[j+21];
          }
          break;
        case "Viaggi":
          document.global_form.prov.length=8;
          for (var j=1; j<=7; j++) {
            document.global_form.prov[j].text=regionesTxt[j+33];
            document.global_form.prov[j].value=regionesVal[j+33];
          }
          
      }
      document.global_form.prov[0].selected = 'true';
    }
  }
}

// questa funzione aggiunge un item sulla select multiple settando valore e testo
//function addItemItalia () {
//	alert("Primo addItemItalia");
//	separatore = ">";
//	selectReg= document.global_form["re_gi"]; 
//	selectProv= document.global_form.prov;	
//	if ((selectReg.selectedIndex>0) && (selectProv.selectedIndex>0)) {
//		document.global_form.Xcat.options[document.global_form.Xcat.length] = new Option ("testo","valore");
//		document.global_form.Xcat.options[document.global_form.Xcat.length-1].value=selectProv.options[selectProv.selectedIndex].value;
//		document.global_form.Xcat.options[document.global_form.Xcat.length-1].text=selectProv.options[selectProv.selectedIndex].text;
//	}
//	else alert ("Attenzione! Fare prima una selezione");
//}//addItemItalia


//function checkDouble (sCheck) {
//	var linear=new Array();
//	selRef= document.global_form.Xcat;
//	selectReg= document.global_form["re_gi"]; 
//	selectProv= document.global_form.prov;	
//	linear[selRef.length]= sCheck;
//	for (i=0;i< selRef.length;i++) {
//		linear[i]	= selRef.options[i].value;
//	}
//	linear[selRef.length]= sCheck;
//	linear.sort();
//	for (i=0;i< linear.length;i++) {
//		if (linear[i] == linear[i-1])
//			return (true);
//	}
//	return (false)
//}//checkDouble


// questa funzione aggiunge un item sulla select multiple settando valore e testo
function addItemItalia () {
	selectReg=document.global_form["re_gi"]; 
	selectProv=document.global_form.prov;	
	if (selectReg.selectedIndex>0) {
		if (selectProv.selectedIndex == 0) {
				//hValue= selectReg.options[selectReg.selectedIndex].value;
				//hText=  selectReg.options[selectReg.selectedIndex].text;
	  }
		else {
				//alert ("primo")
				hValue= selectProv.options[selectProv.selectedIndex].value;
				hText=  selectProv.options[selectProv.selectedIndex].text;
		}
		//ret = checkDouble(hValue);
		//alert (ret);
    //if (ret) {
		if (document.global_form.prov.selectedIndex=="Seleziona"){
			//alert ("secondo");
			return false;
		}
		else {
			//alert ("terzo");
			//prselez= selectProv.options[selectProv.selectedIndex].text;
			//alert (selectProv.options[selectProv.selectedIndex].text);
			//alert (document.global_form.Xcat.options[0].text);
	   	var esiste=false;
	   	for (var j=0; j< document.global_form.Xcat.length; j++)  {
	     	if (document.global_form.Xcat.options[j].text==hText) {
		   		esiste=true;
				}
			}
		
			if (esiste==false) {
  			document.global_form.Xcat.options[document.global_form.Xcat.length] = new Option ("testo","valore");
				document.global_form.Xcat.options[document.global_form.Xcat.length-1].value= hValue;
				document.global_form.Xcat.options[document.global_form.Xcat.length-1].text= hText;
				document.global_form.Xcat.options[document.global_form.Xcat.length-1].selected = true;
			}
		}
		//}
	}
	else {
		alert ("Attenzione! Fare prima una selezione");	
	}
}//addItemItalia


function deleteItem () {
	document.global_form.Xcat.length=0;
}

function addItemByValue (itemValue) {
	var len = regionesVal.length;
	
  document.global_form.Xcat.options[document.global_form.Xcat.length] = new Option ("testo","valore");
	document.global_form.Xcat.options[document.global_form.Xcat.length-1].value= itemValue;
	
	for (var i = 0; i < len; i++) {
		if (itemValue == regionesVal[i]) {
				document.global_form.Xcat.options[document.global_form.Xcat.length-1].text = regionesTxt[i];
				break;
		}
	}
	
	document.global_form.Xcat.options[document.global_form.Xcat.length-1].selected = true;
}



function reselect() {
	for (var j=0; j< document.global_form.Xcat.length; j++)  {
		document.global_form.Xcat.options[j].selected = true;
	}
}

//RIMUOVERE
function addSelectedTappaByValues(id, country, city, address, num) {
	
	var countryLabel = countries[country];
	// alert("Country ["+country+"] - ["+countryLabel+"].");
	
	document.global_form.listaTappe.options[document.global_form.listaTappe.length] = new Option ("testo","valore");
	document.global_form.listaTappe.options[document.global_form.listaTappe.length-1].value = id;
	document.global_form.listaTappe.options[document.global_form.listaTappe.length-1].text = countryLabel + ' ' + city + ' ' + address + ' ' + num;
	
	document.global_form.tempListaTappe.options[document.global_form.tempListaTappe.length] = new Option ("testo","valore");
	document.global_form.tempListaTappe.options[document.global_form.tempListaTappe.length-1].value = id;
	document.global_form.tempListaTappe.options[document.global_form.tempListaTappe.length-1].text = countryLabel + ' ' + city + ' ' + address + ' ' + num;

	var countrytmp = xcountries[id];
	if (!countrytmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xcountry" + id;
		oInput.value = country;
		oInput.type = "hidden";
		xcountries[id] = document.global_form.appendChild(oInput);
	}
	else {
		countrytmp.value = country; 
	}
	
	var citytmp = xcities[id];
	if (!citytmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xcity" + id;
		oInput.value = city;
		oInput.type = "hidden";
		xcities[id] = document.global_form.appendChild(oInput);
	}
	else {
		citytmp.value = city; 
	}
	
	var addresstmp = xaddresses[id];
	if (!addresstmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xaddress" + id;
		oInput.value = address;
		oInput.type = "hidden";
		xaddresses[id] = document.global_form.appendChild(oInput);
	}
	else {
		addresstmp.value = address; 
	}
	
	var numbertmp = xnumbers[id];
	if (!numbertmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xnumber" + id;
		oInput.value = num;
		oInput.type = "hidden";
		xnumbers[id] = document.global_form.appendChild(oInput);
	}
	else {
		numbertmp.value = num; 
	}
}

function addTappaToList(id, x, y, descr) {
	
	document.global_form.listaTappe.options[document.global_form.listaTappe.length] = new Option ("testo","valore");
	document.global_form.listaTappe.options[document.global_form.listaTappe.length-1].value = id;
	document.global_form.listaTappe.options[document.global_form.listaTappe.length-1].text = descr;
	
	document.global_form.tempListaTappe.options[document.global_form.tempListaTappe.length] = new Option ("testo","valore");
	document.global_form.tempListaTappe.options[document.global_form.tempListaTappe.length-1].value = id;
	document.global_form.tempListaTappe.options[document.global_form.tempListaTappe.length-1].text = descr;

	var xtmp = xtappe[id];
	if (!xtmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xx" + id;
		oInput.value = x;
		oInput.type = "hidden";
		xtappe[id] = document.global_form.appendChild(oInput);
	}
	else {
		xtmp.value = x; 
	}
	
	var ytmp = ytappe[id];
	if (!ytmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xy" + id;
		oInput.value = y;
		oInput.type = "hidden";
		ytappe[id] = document.global_form.appendChild(oInput);
	}
	else {
		ytmp.value = y; 
	}
	
	var descrtmp = descrtappe[id];
	if (!descrtmp)
	{
		var oInput = document.createElement("INPUT");	
		oInput.name = "Xtappa" + id;
		oInput.value = descr;
		oInput.type = "hidden";
		descrtappe[id] = document.global_form.appendChild(oInput);
	}
	else {
		descrtmp.value = descr; 
	}
}

//RIMUOVERE
function aggiungiNuovaTappa() {
	lenTappe = document.global_form.listaTappe.length;
	addSelectedTappaByValues(lenTappe, document.global_form.Xcountry.value, document.global_form.Xcity.value, document.global_form.Xaddress.value, document.global_form.Xnumber.value);
}

function spostaTappa(Tmove){
	obj = document.global_form.listaTappe;
	obj1 = document.global_form.tempListaTappe;
	index = obj.selectedIndex;
	downlen = obj.length - 1;
	//alert('spostaTappa [Tmove=' + Tmove + ',index=' + index + ']');
	if (index > -1) {
		value = obj.options[index].value;
		//alert('spostaTappa [Tmove=' + Tmove + ',value=' + value + ']');
		if (value > -1) {
			spostaOggettoListaByIndex(Tmove, obj, index);
			spostaOggettoListaByIndex(Tmove, obj1, index);
			//spostaInputFieldByIndex(Tmove, value, downlen);
			spostaDynamicInputField(Tmove, value, downlen);
		}
	}
}

function cancellaTappa(){
	obj = document.global_form.listaTappe;
	obj1 = document.global_form.tempListaTappe;
	index = obj.selectedIndex;
	//alert('cancellaTappa [index=' + index + ']');
	if (index > -1) {
		value = obj.options[index].value;
		//alert('cancellaTappa [value=' + value + ']');
		if (value > -1) {
			cancellaOggettoListaByIndex(obj, index);
			cancellaOggettoListaByIndex(obj1, index);
			//cancellaInputFieldByIndex(value);
			cancellaDynamicInputField(value);
		}
	}
}

function spostaOggettoListaByIndex(Tmove, obj, index) {
	var texttmp;
	if(index>0 && Tmove=='up'){//solo se è selezionato l'indice e se l'indice non è zero
		texttmp=obj.options[index].text;
		obj.options[index].text=obj.options[index-1].text;
		obj.options[index-1].text=texttmp;
		obj.options[index-1].selected=true;
	}
	else{
		if(index>-1	&& index < obj.length-1	&& Tmove=='down'){//solo se è selezionato l'indice e se l'indice è compreso tra 0 e la lunghezza meno uno...
			texttmp=obj.options[index].text;
			obj.options[index].text=obj.options[index+1].text;
			obj.options[index+1].text=texttmp;
			obj.options[index+1].selected=true;
			
		}
	}	
}

//RIMUOVERE
function spostaInputFieldByIndex(Tmove, ind, downlen) {
	var index = Number(ind);
	if(index > 0 && Tmove=='up'){//solo se è selezionato l'indice e se l'indice non è zero
		countrytmp = xcountries[index].value;
		xcountries[index].value=xcountries[index - 1].value;
		xcountries[index - 1].value=countrytmp;
		citytmp = xcities[index].value;
		xcities[index].value=xcities[index - 1].value;
		xcities[index - 1].value=citytmp;
		addresstmp = xaddresses[index].value;
		xaddresses[index].value=xaddresses[index - 1].value;
		xaddresses[index - 1].value=addresstmp;
		numbertmp = xnumbers[index].value;
		xnumbers[index].value=xnumbers[index - 1].value;
		xnumbers[index - 1].value=numbertmp;
	}
	else{
		if(index > -1	&& index < downlen && Tmove=='down'){//solo se è selezionato l'indice e se l'indice è compreso tra 0 e la lunghezza meno uno...
			countrytmp = xcountries[index].value;
			xcountries[index].value=xcountries[index + 1].value;
			xcountries[index + 1].value=countrytmp;
			citytmp = xcities[index].value;
			xcities[index].value=xcities[index + 1].value;
			xcities[index + 1].value=citytmp;
			addresstmp = xaddresses[index].value;
			xaddresses[index].value=xaddresses[index + 1].value;
			xaddresses[index + 1].value=addresstmp;
			numbertmp = xnumbers[index].value;
			xnumbers[index].value=xnumbers[index + 1].value;
			xnumbers[index + 1].value=numbertmp;
			
		}
	}	
}

function spostaDynamicInputField(Tmove, ind, downlen) {
	var index = Number(ind);
	if(index > 0 && Tmove=='up'){//solo se è selezionato l'indice e se l'indice non è zero
		xtmp = xtappe[index].value;
		//alert('xtappe[' + index + ']' + xtappe[index].value);
		xtappe[index].value=xtappe[index - 1].value;
		//alert('xtappe[' + index + ']' + xtappe[index].value);
		xtappe[index - 1].value=xtmp;
		ytmp = ytappe[index].value;
		//alert('ytappe[' + index + ']' + ytappe[index].value);
		ytappe[index].value=ytappe[index - 1].value;
		//alert('ytappe[' + index + ']' + ytappe[index].value);
		ytappe[index - 1].value=ytmp;
		descrtmp = descrtappe[index].value;
		//alert('descrtappe[' + index + ']' + descrtappe[index].value);
		descrtappe[index].value=descrtappe[index - 1].value;
		//alert('descrtappe[' + index + ']' + descrtappe[index].value);
		descrtappe[index - 1].value=descrtmp;
	}
	else{
		if(index > -1	&& index < downlen && Tmove=='down'){//solo se è selezionato l'indice e se l'indice è compreso tra 0 e la lunghezza meno uno...
			xtmp = xtappe[index].value;
			//alert('xtappe[' + index + ']' + xtappe[index].value);
			xtappe[index].value=xtappe[index + 1].value;
			//alert('xtappe[' + index + ']' + xtappe[index].value);
			xtappe[index + 1].value=xtmp;
			ytmp = ytappe[index].value;
			//alert('ytappe[' + index + ']' + ytappe[index].value);
			ytappe[index].value=ytappe[index + 1].value;
			//alert('ytappe[' + index + ']' + ytappe[index].value);
			ytappe[index + 1].value=ytmp;
			descrtmp = descrtappe[index].value;
			//alert('descrtappe[' + index + ']' + descrtappe[index].value);
			descrtappe[index].value=descrtappe[index + 1].value;
			//alert('descrtappe[' + index + ']' + descrtappe[index].value);
			descrtappe[index + 1].value=descrtmp;
		}
	}	
}


function cancellaOggettoListaByIndex(obj, ind) {
	var index = Number(ind);
	if(index!=-1){
	  for(i=index;i<obj.length-1;i++){
			obj.options[i].text=obj.options[i+1].text;
		}
		obj.length=obj.length-1;
	}	
}

//RIMUOVERE
function cancellaInputFieldByIndex(index) {
	if(index != -1){
	  xcountries[index].value = "";
	  xcities[index].value = "";
	  xaddresses[index].value = "";
	  xnumbers[index].value = "";
	}	
}

function cancellaDynamicInputField(index) {
	/*if(index != -1){
	  xtappe[index].value = "";
	  ytappe[index].value = "";
	  descrtappe[index].value = "";
	}	*/
	
	var ind = Number(index);
	
	//alert('ind=' + ind);
	
	if (ind < 0) {
		return;
	}
	
	var i = ind + 1;
	
	//alert('i=' + i);
	
	while(true) {
		
		if (!xtappe[i] || xtappe[i].value == '') {
			break;
		}
		
		xtmp = xtappe[i].value;
		//alert('xtappe[' + i + ']' + xtappe[i].value);
		xtappe[i].value=xtappe[i - 1].value;
		//alert('xtappe[' + i + ']' + xtappe[i].value);
		xtappe[i - 1].value=xtmp;
		
		ytmp = ytappe[i].value;
		//alert('ytappe[' + i + ']' + ytappe[i].value);
		ytappe[i].value=ytappe[i - 1].value;
		//alert('ytappe[' + i + ']' + ytappe[i].value);
		ytappe[i - 1].value=ytmp;
		
		descrtmp = descrtappe[i].value;
		//alert('descrtappe[' + i + ']' + descrtappe[i].value);
		descrtappe[i].value=descrtappe[i - 1].value;
		//alert('descrtappe[' + i + ']' + descrtappe[i].value);
		descrtappe[i - 1].value=descrtmp;
		i++;
	}
	xtappe[i - 1].value = '';
	ytappe[i - 1].value = '';
	descrtappe[i - 1].value = '';
}

function printNazioneById(id) {
	var country = countries[id];
	if (country) {
		document.write(country.toUpperCase());
	}
	else {
		document.write('Nessuna');
	}
}

function checkMandatoryField(field, name) {
	if (!field || field.value == '') {
		alert("Il campo \'" + name + "\' è obbligatorio.");
		return false;
	}
	else {
		return true;
	}
}

// Setta nel campo XambiguousElement il valore dell'indice selezionato nella print_ambiguous.jhtml
// in caso di ambiguita' di indirizzi
function setAmbiguousAddress(index) {
	//alert("Indice selezionato ["+index+"]");
	document.ambiguous_form.XambiguousElement.value=index;
	document.ambiguous_form.submit();
}
// Setta nel campo XambiguousElement il valore dell'indice selezionato nella print_ambiguous.jhtml
// in caso di ambiguita' di citta'
function setAmbiguousCitta(index) {
	//alert("Indice selezionato ["+index+"]");
	document.ambiguous_form.XambiguousElement.value=index;
	document.ambiguous_form.submit();
}
