// JavaScript Document
//========================================================================0
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0
//========================================================================0
/*					JAVASCRIPT  FUNCTIONS
#02- function hidelayer(lay)
#03- function showlayer(lay)
#06- function Validate_Login(logincheck)
#07- function Validate_LoginHomepage()

*/

//========================================================================0
//#02-                function hidelayer(lay)                 xxxxxxxxxxxx0
//========================================================================0
// function used to show and hide layers passed as paramenters....
function hidelayer(lay) {
if (ie4) {document.all[lay].style.visibility = "hidden";}
if (ns4) {document.layers[lay].visibility = "hide";}
if (ns6) {document.getElementById([lay]).style.display = "none";}
if (my_bros.ie5) {document.getElementById([lay]).style.display = "none";}
if (my_bros.ie6) {document.getElementById([lay]).style.display = "none";}
}

//========================================================================0
//#03-                function showlayer(lay)                 xxxxxxxxxxxx0
//========================================================================0
function showlayer(lay) {
if (ie4) {document.all[lay].style.visibility = "visible";}
if (ns4) {document.layers[lay].visibility = "show";}
if (ns6) {document.getElementById([lay]).style.display = "block";}
if (ie5) {document.getElementById([lay]).style.display = "block";}
if (ie6) {document.getElementById([lay]).style.display = "block";}
}

//========================================================================0
//#06-                function Validate_Login()               xxxxxxxxxxxx0
//========================================================================0
// #06-
  function Validate_Login(logincheck) {
     // variables definition
	var username = document.login.username.value;
	var password = document.login.password.value;
	var tabdiag = document.getElementById("id_tabdiag");
	var cella1 = document.getElementById("id_cella1");
	var cella2 = document.getElementById("id_cella2");
	var msg = "";
	var submsg = "";
	
	var filterLogin = /^[a-zA-Z0-9]+$/; //accettati caratteri alfanumerici
	var filterLogin2 = /^[a-zA-Z0-9]+([a-zA-Z0-9\_\-]+)$/; //all'inizio una o pił lettere maiuscole o minuscole, poi sono accettati alfanumerici, trattino, undersc.
		//-------------------------------------------------------------------------
        //check the username
        if ((username == "") || (username == "undefined")) {
			//document.login.username.style.backgroundColor="#f7d05b";
			//document.login.username.className="errborder";
			document.getElementById("id_username").className="errlabel";
			if (msg == "") {
				//msg = "Attenzione, controllare i campi evidenziati in giallo:";
				document.login.username.focus();
				msg="<ul>"; //begin the Unordered List
			}
			msg = msg  + "<li>" + "<b>Username</b> is required" + "</li>";
        }
		else
		{
			//sono accettati solo caratteri alfanumerici
			if (filterLogin2.test(username) ==false) {
				document.getElementById("id_username").className="errlabel";
				if (msg == "") {
					document.login.username.focus();
					msg="<ul>"; //begin the Unordered List
				}
				msg = msg  + "<li>" + "<b>Username</b>: only letters and numbers" + "</li>";
			}
        }
		//-------------------------------------------------------------------------
        //check the password
        if ((password == "") || (password == "undefined")) {
			document.getElementById("id_password").className="errlabel";
			if (msg == "") {
				document.login.password.focus();
				msg="<ul>"; //begin the Unordered List
			}
			msg = msg  + "<li>" + "<b>Password</b> is required" + "</li>";
        }
		//------FINAL CHECK             -------------------------------------------
		if (msg == "") {
			//send data
			//document.login.action = "00-logincheck.php";
			document.login.action = logincheck;
			document.login.submit();
			}
        else { 
			// errors, back to the login page...
			//submsg = "Attenzione, controllare i campi evidenziati in giallo:";
			submsg = "Please, check the hilighted fields:" + msg + "</ul>";
			cella2.innerHTML = submsg;
			//document.getElementById("cella").style.backgroundColor="#ffffff";
			//ele.className="errtext";
			tabdiag.className="errtable";
			cella1.className="errlogo";
			cella2.className="errmsg";
			//document.getElementById("cella").style.borderWidth="thick";
			return false; 
        }
  } // end function  Validate_Login()

//========================================================================0
//#07-                function Validate_LoginHomepage()               xxxxxxxxxxxx0
//========================================================================0
// #07-
  function Validate_LoginHomepage() {
     // variables definition
	var username = document.login.username.value;
	var password = document.login.password.value;
	//var tabdiag = document.getElementById("id_tabdiag");
	//var cella1 = document.getElementById("id_cella1");
	//var cella2 = document.getElementById("id_cella2");
	var msg = "";
	var submsg = "";
	
	var filterLogin = /^[a-zA-Z0-9]+$/; //accettati caratteri alfanumerici
	var filterLogin2 = /^[a-zA-Z0-9]+([a-zA-Z0-9\_\-]+)$/; //all'inizio una o pił lettere maiuscole o minuscole, poi sono accettati alfanumerici, trattino, undersc.
		//-------------------------------------------------------------------------
        //check the username
        if ((username == "") || (username == "undefined")) {
			//document.getElementById("id_username").className="errlabel";
			if (msg == "") {
				//document.login.username.focus();
				msg="<ul>"; //begin the Unordered List
			}
			msg = msg  + "<li>" + "<b>Username</b> is required" + "</li>";
        }
		else
		{
			//sono accettati solo caratteri alfanumerici
			if (filterLogin2.test(username) ==false) {
				//document.getElementById("id_username").className="errlabel";
				if (msg == "") {
					//document.login.username.focus();
					msg="<ul>"; //begin the Unordered List
				}
				msg = msg  + "<li>" + "<b>Username</b>: only letters and numbers" + "</li>";
			}
        }
		//-------------------------------------------------------------------------
        //check the password
        if ((password == "") || (password == "undefined")) {
			//document.getElementById("id_password").className="errlabel";
			if (msg == "") {
				//document.login.password.focus();
				msg="<ul>"; //begin the Unordered List
			}
			msg = msg  + "<li>" + "<b>Password</b> is required" + "</li>";
        }
		//------FINAL CHECK             -------------------------------------------
		if (msg == "") {
			//send data
			document.login.action = "/uptest/login/10-logincheck.php";
			//document.login.action = "/uptest/login/";
			document.login.submit();
			}
        else { 
			// errors, sent to the login page...
			document.login.action = "/uptest/login/?up=err";
			document.login.submit();
			return false; 
        }
  } // end function  Validate_LoginHomepage()

//========================================================================0
