// ******************************************************************************
// *************************      SEZIONE VARIABILI      ************************
// ******************************************************************************

// Variabile che testa se il browser in uso è o meno Nescape
var	IE = (document.all) ? true : false;
var	NS6 = (!IE && document.getElementById) ? true : false;
var	NS4 = (document.layers) ? true : false;
// Secondi in cui deve rimanere visibile il layer del profilo prima di chiudersi automaticamente
var tempoApertProf = 3;
// ID del timeout per ottimizzare l'occupazione della memoria
var idTimeout = null;
var aumentoDimensioneTesto = location.search.substring(location.search.indexOf("STB=")+4, (location.search.substr(location.search.indexOf("STB=")+4).indexOf(";"))+(location.search.indexOf("STB=")+4));

// ******************************************************************************
// *************************      SEZIONE FUNZIONI      *************************
// ******************************************************************************

function writeDate(){  
// Funzione che scrive la data odierna in formato: giorno per esteso, data, mese per esteso, anno

  var data = new Date();
  var yr = data.getFullYear();
  var mName = data.getMonth();
  var dName = data.getDay();
  var dayNr = ((data.getDate()<10) ? "0" : "")+ data.getDate();
  var days = new Array ('Domenica','Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato');
  var mesi = new Array ('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');
  var Day = days[dName];
  var Month = mesi[mName];
  
  document.write(Day+", "+dayNr+" "+Month+" "+yr);
}

function validateSelectValue(obj){
// Funzione che consente di testare il valore selezionato su una select passata.
// Se il valore è nullo viene presa come selezione valida la prima delle opzioni possibili
	var i
	var href
	i = obj.options.selectedIndex;
	href = obj.options[i].value
  if((href=="")||(href=="#")){
	//obj.options[0].selected = true;
  }
  else{
    // QUI DEVE ESSERE GESTITA L'APERTURA DEL POP-UP PER I VARI E-TOOLS
    window.open(href,"_blank");
  }
  obj.options[0].selected = true;
}

function visualizzaProfilo(homeFlag){
// Funzione che mi consente di rendere visibile un layer sulla pagina. 
// Viene poi chiamata la funzione di scomparsa dello stesso con un ritardo impostabile dalla variabile tempoApertProf
  
  var scostamentoTop = 0;
  if(homeFlag!="null"){
    scostamentoTop = 25;
  }
  if(NS4){
	for (i=0; i<document.layers.length; i++){
		whichEl=document.layers[i];
		if (whichEl.id == "idProfile"){
			if(homeFlag!=null){
      			  whichEl.top = '113';
    			}else{
    			  whichEl.top = '88';
    			}
			whichEl.visibility = "visible";
  			idTimeout = setTimeout("nascondiProfilo(i)",tempoApertProf * 1000);
			break;
		}
	}
  }
  if(NS6){
    if(homeFlag=="home"){
      document.getElementById('idProfile').style.top = '113';
	}
	else{
      document.getElementById('idProfile').style.top = '88';
	}
    document.getElementById('idProfile').style.visibility = "visible";
	idTimeout = setTimeout("nascondiProfilo()",tempoApertProf * 1000);
  }
  if(IE){
    if(homeFlag=="home"){
      idProfile.style.top = '113px';
    }else{
      idProfile.style.top = '88px';
    }
    idProfile.style.visibility = "visible";
    idTimeout = setTimeout("nascondiProfilo()",tempoApertProf * 1000);
  }
}

function nascondiProfilo(contatore){
// Funzione che nasconde il layer precedentemente visualizzato

  clearTimeout(idTimeout);
  if(NS4){
    whichEl=document.layers[contatore].visibility = 'hidden';
  }
  if(NS6){
    document.getElementById('idProfile').style.visibility = "hidden";
  }
  if(IE){
    idProfile.style.visibility = "hidden";
  }
}

function openPopup(url, wName, w, h, t, l, normalMode){
// Funzione parametrica che consente l'apertura di un pop-up.
// Prende in ingresso l'url della pagina, il nome della finestra, la larghezze e l'altezza della finestra, 
// il numero di pixel della finestra dal bordo alto e sinistro dello schermo e la possibilità di decidere se
// la pop-up deve avere le caratteristiche di una finestra normale o senza tool di navigazione

  var wOptions = "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l
  if(normalMode){
    wOptions += ",status=yes,toolbar=yes,resizable=yes,scrollbars=yes,history=no,location=yes" 
  }
  window.open(url,wName,wOptions);
}

function writeIcoText(){
  if(aumentoDimensioneTesto!="BIG"){
    document.write('<a href="javascript:manualTextResize()"><img src="'+sourcePath+'images/ico_txt_big.gif" width="20" height="15" border="0" alt="Ingrandisci il testo" name="icoTextResize" hspace="1" vspace="1"></a>');
  }
  else{
    document.write('<a href="javascript:manualTextResize()"><img src="'+sourcePath+'images/ico_txt_small.gif" width="20" height="15" border="0" alt="Riduci il testo" name="icoTextResize" hspace="1" vspace="1"></a>');
  }
}

function manualTextResize(){
  if(document.all){
    if(aumentoDimensioneTesto!="BIG"){
      aumentoDimensioneTesto = 'BIG';
      styleFile.href=sourcePath+"css/StyleBig.css";
	  document.images['icoTextResize'].src = sourcePath+"images/ico_txt_small.gif";
	  document.images['icoTextResize'].alt = "Riduci il testo";
    }
    else{
      aumentoDimensioneTesto = '';
      styleFile.href=sourcePath+"css/StyleSmall.css";
	  document.images['icoTextResize'].src = sourcePath+"images/ico_txt_big.gif"
	  document.images['icoTextResize'].alt = "Ingrandisci il testo";
    }
  }
  else{
    if(aumentoDimensioneTesto!="BIG"){
      location.href = location.href + "?STB=BIG;";
    }
    else{
	  location.href = location.href.substr(0, location.href.indexOf(location.search));
    }
  }
}

function dimensionamentoTesto(){
  if(aumentoDimensioneTesto=="BIG"){
    if(document.all){
      document.write('<link id="styleFile" rel="stylesheet" href="'+sourcePath+'css/StyleBig.css">');
    }
	else{
      document.write('<link rel="stylesheet" href="'+sourcePath+'css/StyleBig.css">');
    }
  }
  else{
    if(document.all){
      document.write('<link id="styleFile" rel="stylesheet" href="'+sourcePath+'css/StyleSmall.css">');
    }
	else{
      document.write('<link rel="stylesheet" href="'+sourcePath+'css/StyleSmall.css">');
    }
  }
}


function hideShowLayer(elem,visib,myForm){
  if(NS4){
    var myObj = eval("document.ids."+elem);
	myObj.visibility = visib;
  }
  if(NS6){
    document.getElementById(elem).style.visibility = visib;
  }
  if(IE){
    if(myForm!=null){
      var myObj = eval("document.forms['"+myForm+"']."+elem);
    }
    else{
      var myObj = eval(elem);
    }
	var myObj = eval("try {myObj.style.visibility = visib;} catch (e) {}");
  }
}

var wPopup = null;

function openLoginDialog(nextUrl){
	var wOptions = "width=250,height=380,top=100,left=100";
	//var wOptions = "width=315,height=350,top=200,left=200";
	wOptions += ",status=yes,toolbar=no,resizable=yes,scrollbars=no,history=no,location=no";
    wPopup = window.open('../NR/System/Access/ManualLoginPopup527a.html?NEXTURL='+nextUrl,'_NEW',wOptions);
}

function openOtherDialog(url, nexturl){
	var wOptions = "width=250,height=380,top=100,left=100";
	//var wOptions = "width=315,height=350,top=200,left=200";
	wOptions += ",status=yes,toolbar=no,resizable=yes,scrollbars=no,history=no,location=no";
    wPopup = window.open(url+'?NEXTURL='+nexturl,'_NEW',wOptions);
}

function closeCloseLogin(){
  wPopup = null;
  window.location.reload();
}


// ******************************************************************************
// ****************      ESECUZIONE IN APERTURA DI PAGINA      ******************
// ******************************************************************************

dimensionamentoTesto();
document.write('<STYLE>');
document.write('.divProfilo{position:absolute; left:0px; visibility:hidden;');
/*
if(NS4){
  document.write(' top:88px;}');
}else{
*/
  document.write(' top:88px;}');
//}
document.write('</STYLE>')

