//funzione per andare ad un altra pagina e chiudere il popup
function goToPage(url) {
    window.opener.location.reload(url);
    window.close();
}
// Parte per il controllo sulle telecamere
var tlc = new Array();
for (var i=0; i<=27; i++)	tlc[i]="";
//Profilazione Telecamere per Autostrade
tlc[1]="47|51|55|57|63|65|79";
tlc[2]="90|81|82|70|75|88|72|619|620|683|684|649|650|651|652|663|664|685|686|891";
tlc[3]="74|109";
tlc[4]="99|100|101|103|106";
tlc[5]="21|26|28|29";
tlc[6]="48|50|51|54|61";
tlc[7]="98|99|106|119|122";
tlc[8]="138|140|141|142";
tlc[9]="22|23|30|31|33|34|35|36|38|40|41|42|44";
tlc[10]="144|145|146|147|149";
tlc[11]="2|4|6|7|8|9|14|19";
tlc[12]="";
tlc[13]="108|115|124|133";
tlc[14]="";
tlc[15]="";
tlc[16]="";
tlc[17]="152|153|154|156|157|158|160|161|162|163|164|165|166|167|626|630|635|636|640|643|646|647";
tlc[18]="43";
tlc[19]="58|62|64";
tlc[20]="58|60";
tlc[21]="2|14|15";
tlc[22]="";
tlc[23]="";
tlc[24]="";
tlc[25]="149";
tlc[26]="1|3|4|12";
tlc[27]="";
//questa funzione ritorna la lista delle telecamere da mostrare
function getTlc(id_mappa) {
    return tlc[Number(id_mappa)];
}

/*var N4 = document.layers;
var IE4 = document.all;
var N6IE5 = document.getElementById;

if( N6IE5 && !N4 && !IE4) {
  if( Event.KEYUP ) {
  	document.captureEvents( Event.KEYUP );
  }
	document.onkeyup = keyhandler;
}

function keyhandler(e){
if(document.layers)
  if(N4)
   Key = e.which;
  else if (IE4)
    Key = window.event.keyCode;
  else if (N6IE5) 
  	if (e && e.target == document.login.password)
  		Key = e.keyCode;
  	else
  		return;
}
function keyhandler(e){
  if(document.layers)
   Key = e.which;
  else
    Key = window.event.keyCode;
  if(Key == 13){
    if(document.all)document.login.password.blur();
    document.login.submit();
  }
}*/


//popup news ???
function displayNews(){
    var nome_popup="popupNews";
    var jsp = "home/popupNews.jsp";
    var parametri="scrollbars=yes,resizable=yes,width=370,height=500,left="+leftPos+",top="+topPos;
    loadingPopup(jsp,nome_popup,parametri);
}

//popup on the road ???
function displayOnTheRoad(){ 
    var nome_popup="News";
    var jsp = "home/popupOnTheRoad.jsp?zona=N";
    var parametri="scrollbars=yes,resizable=yes,width=350,height=500,left="+leftPos+",top="+topPos;
    loadingPopup(jsp,nome_popup,parametri);
}
function popup(url, w, h, sc) {
	window.open(url, '', 'resizable=no,scrollbars=' + sc + ',menubar=no,width=' + w + ',height=' + h);
}


//popup help page
function PopUpEvents(url,width,height){
	parametri="width="+width+",height="+height+",status=no,toolbar=no,scrollbars=yes,menubar=no,resizable=yes,left="+leftPos+",top="+(topPos-90);
	nome_popup="helpPage";
	loadingPopup(url,nome_popup,parametri);
}

function formatGetString(s){
  var f="";
  for(i=0;i<s.length;i++){
    switch(s.charAt(i)){
      case ':':
        f+="%3A";
        break;
      case '/':
        f+="%2F";
        break;
      case '.':
        f+='$';
        break;
      default:
        f+=s.charAt(i);
    }
  }
  return f;
}

//popup punto blu
function showPB(titolo,tipo,cod){
	var path="common/popupPuntoBlu.jsp";
	loadingPopup(path+'?titolo='+titolo+'&cod='+cod+'&tipo='+tipo,'puntiblu','scrollbars=yes,width=350,height=340');
}

function openMappa(jsp){
  if(jsp!=""){
	var nome_popup="Autostrade";
	var parametri="location=no,resizable=yes,status=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,width=790,height=590,left=0,top=0";
	window.open(jsp,"Autostrade",parametri);  
  }else
	alert('mappe temporaneamente non disponibili');
}

function cercaTrafficoPercorso() {
    //alert(document.ttpp.tiporicerca.value);
    if(document.ttpp.tiporicerca.value=='trf') {
       document.ttpp.action="../Ricerca/ricerca_traffico.jsp";
       document.ttpp.submit();
    }else if(document.ttpp.tiporicerca.value=='prc') {
       document.ttpp.action="../Ricerca/ricerca_percorso.jsp";
       document.ttpp.submit();        
    }
}

//funzione che riceve l'id di una mappa e ne ritorna il nome completo
function getNomeSwf(id) {
    if(id==1) {
        return "bologna_"+id;
    }else if(id==2) {
        return "firenze_"+id;    
    }else if(id==3) {
        return "sud_firenze_"+id;    
    }else if(id==4) {
        return "nord_roma_"+id;    
    }else if(id==5) {
        return "piacenza_"+id;    
    }else if(id==6) {
        return "rimini_"+id;    
    }else if(id==7) {
        return "roma_"+id;    
    }else if(id==8) {
        return "ancona_"+id;    
    }else if(id==9) {
        return "milano_"+id;    
    }else if(id==10) {
        return "pescara_"+id;    
    }else if(id==11) {
        return "genova_"+id;    
    }else if(id==12) {
        return "novara_"+id;    
    }else if(id==13) {
        return "sud_roma_"+id;    
    }else if(id==14) {
        return "foggia_"+id;    
    }else if(id==15) {
        return "vasto_"+id;    
    }else if(id==16) {
        return "bari_"+id;    
    }else if(id==17) {
        return "napoli_"+id;    
    }else if(id==18) {
        return "verona_"+id;    
    }else if(id==19) {
        return "nord_bologna_"+id;    
    }else if(id==20) {
        return "venezia_"+id;    
    }else if(id==21) {
        return "la_spezia_"+id;    
    }else if(id==22) {
        return "torino_"+id;    
    }else if(id==23) {
        return "trieste_"+id;    
    }else if(id==24) {
        return "bolzano_"+id;    
    }else if(id==25) {
        return "est_roma_"+id;    
    }else if(id==26) {
        return "savona_"+id;    
    }else if(id==27) {
        return "aosta_"+id;    
    }else if(id==101) {
        return "nord_ovest_1";    
    }else if(id==102) {
        return "centro_nord_2";    
    }else if(id==103) {
        return "nord_est_3";    
    }else if(id==104) {
        return "centro_4";     
    }else if(id==105) {
        return "centro_sud_5";     
    }
}

/*//popup cambio email ???
function displayCambioEmail(){ 
    var nome_popup="CambioEmail";
    var jsp = "/Personalizza/cambiaEmail.jsp";
    var parametri="scrollbars=yes,width=350,height=360,left="+leftPos+",top="+topPos;
    loadingPopup(jsp,nome_popup,parametri);
}*/

/*
2: Flash installed 
1: Flash not installed 
0: Unknown if Flash is installed 
*/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var fin=window.open(theURL,winName,features);
  fin.focus();
}

function getSegnalazioni(){
    if(this.active){
        movie.TCallLabel("/","placeEvt");
    }else{
        movie.TCallLabel("/","removeEvt");
    }
}

/* funzione provvisoria per la gestione delle segnalazioni */
/* OBSOLETA. ORA LA placeEvt() LA CHIAMA DIRETTAMENTE IL FLASH */
function showSegnalazioni() {
    movie.TCallLabel("/","placeEvt");
}

function getTelecamere(){
    if(this.active){
        movie.TSetProperty("/telecamere",7,1);
    }else{
        movie.TSetProperty("/telecamere",7,0);
    }
}

/* attivazione delle telecamere */
function showTelecamere() {
    var id_map=nome_swf.substring(nome_swf.lastIndexOf('_')+1,nome_swf.length );
    //settaggio della variabile action script che contiene la lista delle tlc da visualizzare
    var lista=getTlc(id_map);
    movie.SetVariable("strTlc",lista);
    //chiamata della funzione che mostra le telecamere contenute nella lista
    movie.TCallLabel("/","mostraTlc");
}

/* nasconde le telecamere mostrate in precedenza */
function hideTelecamere() {
    movie.TCallLabel("/","hideTlc");
}

/* nasconde il livello frecce di navigazione tra mappe */
function hideNav() {
	movie.TCallLabel("/","hideNav");
}

/* comandi su mappa */
function actOnMovie(imgName){
    if(!isLoading){
        objBtn[imgName].active=(objBtn[imgName].active)?false:true;
        if(objBtn[imgName].active){
            eval("document.images."+imgName+".src='"+objBtn[imgName].on+"'");
        }else{
            eval("document.images."+imgName+".src='"+objBtn[imgName].off+"'");
        }
        objBtn[imgName].action();
    }
}


function noSegnalazioni(showHide){
}

/* restore delle immagini sull'onMouseout */
function MM_swapImgRestore(image) { //v3.0
  if(!objBtn[image].active){
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }
}

function MM_findObj(n, d) { //v4.0
}

/* cambio delle immagini sull'onMouseover */
function MM_swapImage() { //v3.0
}

// popup informazioni tratta
function displayTrt(start,end,rel,fuse){
    var jsp;
   	var nome_popup="popupTrt";
   	var nmappa=nome_swf;
   	var nmappa=nmappa.substring(nmappa.indexOf('_')+1);
   	if(fuse=="0")
   	    jsp = "popupTratta.do";
   	else
   	    jsp = "popupMultiTratta.do";
   	rel = rel?rel:'errore';
   	rel = (rel=='none')?'':rel;
   	jsp+="?start="+start+"&end="+end+"&codMap="+nmappa+"&rel="+nmappa+"_"+rel;
   	var parametri="scrollbars=yes,resizable=yes,width=340,height=340,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}

/* popup informazioni su aree di sosta */
function displayAds(ads){
   	var nome_popup="popupAds";
   	var jsp = "popupAds.do";
   	jsp+="?ads="+ads;
   	var parametri="scrollbars=yes,resizable=yes,width=342,height=480,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}

/* popup informazioni su aree di parcheggio */
function displayAdp(adp){
   	var nome_popup="popupAdp";
   	var jsp = "popupAdp.do";
   	jsp+="?adp="+adp;
   	var parametri="scrollbars=yes,resizable=yes,width=342,height=300,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}

function displayPBlu(pBlu){
   	var nome_popup="popupPBlu";
   	var jsp = "popupPuntoBlu.do";
   	jsp+="?pBlu="+pBlu;
   	var parametri="scrollbars=yes,resizable=yes,width=370,height=570,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}

/* visualizza informazioni sui punti d'interesse */
function displayPoi(poi){
   	var nome_popup="popupPoi";
   	var jsp = "popupPoi.do";
   	jsp+="?codPoI="+poi;
   	var parametri="scrollbars=yes,resizable=yes,width=342,height=340,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}

/* visualizza informazioni su stazioni(caselli) */
function displayStz(stz,joined){
    var jsp;
   	var nome_popup="popupStz";
   	joined = joined?joined:'unico';
   	if (joined == "unico"){
   	    jsp = "popupStazione.do";
   	}else{
   	    jsp = "popupMultiCasello.do";
   	}
   	jsp += "?stz="+stz  +"&casello_mappa=yes"; //casello mappa serve per la gestione del back
   	var parametri="scrollbars=yes,resizable=yes,width=340,height=400,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}

/* visualizza informazioni su eventi */
/* PARAMETRO ver OBSOLETO, IL BACKEND RESTITUISCE SEMPRE LA VERSIONE PIU'RECENTE */
function displayEvt(evt,ver){
   	var nome_popup="popupEvt";
   	var jsp = "popupEvento.do";
   	ver = ver?ver:'errore';
   	jsp+="?evt="+evt;
   	var parametri="scrollbars=yes,resizable=yes,width=342,height=300,left="+leftPos+",top="+topPos;
   	loadingPopup(jsp,nome_popup,parametri);
}
/* view situazione meteo  ('20_1','previsioni'|'attuale')*/
/* view situazione meteo  ('50_','previsioni')*/
function getSituazioneMeteo(id,tipo){
    var nome_popup="popupMeteo";
	var jsp = "popupMeteo.do";
	jsp+="?codArea="+id;
	var parametri="scrollbars=yes,resizable=yes,width=485,height=485,left="+leftPos+",top="+topPos;
	loadingPopup(jsp,nome_popup,parametri);
}

function gotoPercorso(){
    window.location=url_percorso+"?swf="+setSwf+"&da="+da+"&a="+a+"&link="+document.motoreRicerca.link.value+"&adsParam="+document.motoreRicerca.adsParam.value;
}

/* funzione che sul caricamento di una mappa resetta le immagini 'on' dello zoom
che erano state cliccate sulla mappa precedente */
function setZoomImg() {
    var nm='';
    for(var i=1; i<=4;i++) {
        if(i!=2) {
            nm=eval('"zoom"+i');
            document.images[nm].src=eval('"images/zoom"+i+".gif"');
        }
        else {
            nm=eval('"zoom"+i');
            document.images[nm].src=eval('"images/zoom"+i+"on.gif"');
        }
    }
}
//funzione per stampare il contenuto del flash
function print() {
    movie.TCallLabel("/","stampa");
}

//funzione che mostra un messaggio destinato agli utenti free
function showAlert() {
    alert("questo servizio e' riservato ai telepassisti registrati al sito www.telepass.it");
}

var ff;lPos=0;tPos=90;
var url="";var width=100;var height=30;
function pp(){
	parametri="width="+width+",height="+height+",status=no,toolbar=no,scrollbars=yes,menubar=no,resizable=yes,left="+lPos+",top="+(tPos-90);
	nome_popup="helpPage";
    ff=window.open(url,"auto",parametri);
	ff.focus();
}

//funzione per la comparsa - scomparsa delle telecamere sulla mappa flash
function attivaTelecamere() {
    if(!tlc_showed) {
        tlc_showed=true;
        showTelecamere();
    }
    else if(tlc_showed) {
    	tlc_showed=false;
        hideTelecamere();
    }
}

//funzione che in base al nome della mappa corrente ritorna un id - da settare nelle
//preferenze - che individua la mappa di default
function setIdDefaultMap() {
    var id_map=nome_swf.substring(nome_swf.lastIndexOf('_')+1,nome_swf.length );
    return id_map;
}
