/* Copyright(C) 2006 Antonio Trigiani * All Rights Reserved. */ 

function showhideLogin() {
  var elem = document.getElementById("xlogin");
    if (elem.style.visibility == 'hidden') {
        elem.style.visibility = 'visible';
        elem.style.display = 'block';
        elem.style.position = 'relative';
        elem.style.left = '600px';


    } else {
        elem.style.visibility = 'hidden';
        elem.style.display = 'none';
    }
}

var req = null; 

function tryLogin() { 

clearFields(new Array("login","pass")); 
if (!validate(document.miaform.login.value,"^[A-z0-9]+$", "Spiacente Username non valido :P","login"))
{ return false; } 
if (!validate(document.miaform.pass.value, "^[A-z0-9_.,\\-!;:?=]{4,}$", "Sorry Password non valida :P","pass"))
{ return false; } 
// Use AJAX to check if the user/password are valid. 

req = CreateXmlHttpReq(loginHandler);
req.open("GET","/log-in?login="+document.miaform.login.value+"&pass="+document.miaform.pass.value+"&rand="+escape(Math.random()));
req.send(null); 
}


function tryLogin2() { 

clearAllFields(new Array("login2","pass2"), null); 
if (!validate(document.miaform2.login2.value,"^[A-z0-9]+$", "Spiacente Username non valido :P","login2"))
{ return false; } 
if (!validate(document.miaform2.pass2.value, "^[A-z0-9_.,\\-!;:?=]{4,}$", "Sorry Password non valida :P","pass2"))
{ return false; } 
// Use AJAX to check if the user/password are valid. 

req = CreateXmlHttpReq(loginHandler);
req.open("GET","/log-in?login="+document.miaform2.login2.value+"&pass="+document.miaform2.pass2.value+"&rememberme="+document.miaform2.rememberme.checked+"&rand="+escape(Math.random()));
req.send(null); 
} 

 

function loginHandler() { 
if (req.readyState == 4 && req.status == 200) //tutto ok

{ 
var res = req.responseText; 
if (res.indexOf("OK:")!= -1) {
// Login success. Get the cookie from the HTTP reply and set it. 

secret = res.substring(3, res.length+1); 
if (document.miaform2.rememberme.checked == false) { 
//Just for this session.
setCookie("secret",secret);
setCookie("secret",secret,false,"/","diggitsport.com");
setCookie("secret",secret,false,"/",".diggitsport.com");
} 
else 
{ 
//Set a cookie valid for the next 60 days. 
var now = new Date; 
t = now.getTime(); 
now.setTime(t+(3600*24*1000*60));
setCookie("secret",secret,now);
setCookie("secret",secret,now,"/","diggitsport.com");
setCookie("secret",secret,now,"/",".diggitsport.com"); 
} 
var l = window.location.toString(); 
var i = l.indexOf("?uri="); 
if (i == -1) {
	if(document.miaform2.login_type.value=='header') { 
	//window.location = 'al0_index.php';
	window.location.reload();
	return true; 
	} 
	//window.location = '/';
	window.location = '/last';
} 
else { 
	i+=5; 
	l = unescape(l.substring(i,l.length+1)); 
//	window.location = l; 
	} 

} 


else { //Login failed. Show an error. 
warnField2("login2"); 
warnField2("pass2");
alert('Username e password digitata non coincidono con alcun utente registrato. Ti preghiamo di controllare che i dati inseriti siano corretti e riprovare.'); 
} } } 
focusTarget = "document.miaform2.login2";
