//Copyright (c) 2007-2020 BASSETTO NESA SRL.  //
//          All rights reserved.			  //
//       Created 11.01. 2008 by NESA 		  //
//      (Web: http://www.nesasrl.it )		  //
//Non è concessa nessuna autorizzazione per   //
//l'utilizzo anche solo parziale del presente //
//software è permessa previo accordo scritto  // 
//               con NESA srl				  //

var len_br=0;
var brs="IE"; //IE,OP,FX,CR,SF,NS
if(navigator.userAgent.indexOf("MSIE")>-1){len_br=0;brs="IE";}else{if(navigator.userAgent.indexOf("Opera")>-1) {len_br=3;brs="OP";}else {if((navigator.userAgent.indexOf("Firefox")>-1)&&(navigator.userAgent.indexOf("Navigator")<1)) {len_br=1;brs="FX";}else {if(navigator.userAgent.indexOf("Chrome")>-1) {len_br=0;brs="CR";}else {if(navigator.userAgent.indexOf("Safari")>-1) {len_br=3;brs="SF";}else {if(navigator.userAgent.indexOf("Navigator")>-1) {len_br=1;brs="NS";}}}}}}
var X0 = centro; 	//pos x dell'oggetto in index
var Y0 = 0;	//pos y dell'oggetto in index
var D0 = Math.floor(2*h_centro/7);	//delta tra oggetti
var lang = navigator.browserLanguage;
var ms1="Nome alfanumerico associato al Terminale inserito senza SPAZI";
//livelli
var jp0 = new jsGraphics("gp0");
var jp1 = new jsGraphics("gp1");
var jp2 = new jsGraphics("gp2");
var jp3 = new jsGraphics("gp3");
var jp4 = new jsGraphics("gp4");
var path = new Array ();
var utente = new Array ();
var psw = new Array ();
var n_utenti= id_utenti.length;

// Funzione per leggere lo specifico File dal percorso indicato
function estrai_utenti(percorso)
{	var str, a1, b1;
	// Attraversa il VETTORE utenti per caricare gli utenti
	var k = 0;	
	while (k < n_utenti) 
	{  str = id_utenti[k]; //caricata intera stringa prima elemento array
	   path[k] = estrai_ognistringa(str, 0, ";");  // path dei dati
	  	 a1 = path[k].length +1;
	   utente[k] =estrai_ognistringa(str, a1, ";"); // username utente
		 b1 = utente[k].length +a1 +1;
	   psw[k] = estrai_ognistringa(str, b1, ""); // password utente
	   k++;
	};  
}	

// Funzione per estrarre una sottostringa da una stringa con separatore "separatore"
function estrai_ognistringa(str, i, separatore)
{	var s1 = "";
	var k = i;
	  while (charAtTest(k, str)!= separatore)
	  {	  s1 = s1 + charAtTest(k, str);
		  k++;
	  }
	  return (s1);
}

// Funzione per estrarre un carattere da una stringa alla posizione (n)
function charAtTest(n, stringa)
{ 	var str= stringa;
    return(str.charAt(parseInt(n)));
}


//Funzione pressione tasto "Accedi"
function Enter_Click()
{	var trovato =0;
	//controlla se password ed usn ci sono	
	if((document.getElementById("Usn").value == "")||(document.getElementById("Psw").value == ""))
	{	alert("Inserire Username e Password");
		document.getElementById("Usn").focus();
		trovato =1;
	}
	else // confronta tutti gli utenti
	{	for(i = 0; i<n_utenti; i++)
		{	if((document.getElementById("Usn").value == "NESA-DATI") && (document.getElementById("Psw").value == "NESA500"))
			{	//passa alla pagina di Nesa
				trovato = 1;	//individuato un utente abilitato
				window.location.href = "\\DATI_UTENTI\\NESA\\index.php";
			}
			else
			{	if((document.getElementById("Usn").value == utente[i]) && (document.getElementById("Psw").value == psw[i]))
				{	//passa alla pagina dell'utente
					trovato = 1;	//individuato un utente abilitato
					window.location.href = "\\DATI_UTENTI\\" + path[i] + "\\httpfolder\\data_pag.php";
				}
			}
		}
	}
	// in caso di utente non abilitato
	if (trovato==0)
	{	document.getElementById("Usn").value =""; //cancella il campo
		document.getElementById("Psw").value =""; //cancella il campo
		document.getElementById("Usn").focus();
		alert("Inserire una Username e/o Password corretti");
	}
}

//Funzione verifica la pressione del tasto invio
function EseguiInvio(ev) {if ((ev.which && ev.which == 13) || (ev.keyCode && ev.keyCode == 13)){ Enter_Click();}}
