var Article="";
function Login()
{
if(document.getElementById("Email").value=="")
	{
	reinput(document.getElementById("Email"),"Email address is required.");
	return;
	}
if(document.getElementById("Password").value=="")
	{
	reinput(document.getElementById("Password"),"Password is required.");
	return;
	}
url="Email="+encodeURIComponent(document.getElementById("Email").value)+
"&Password="+encodeURIComponent(document.getElementById("Password").value);

year	= new Date().getFullYear();
month	= new Date().getMonth()+1;
month	= PadDigits(month,2);
day		= new Date().getDate();
day		= PadDigits(day,2);
hours	= new Date().getHours();
hours	= PadDigits(hours,2);
minutes	= new Date().getMinutes();
minutes	= PadDigits(minutes,2);
seconds	= new Date().getSeconds();
seconds	= PadDigits(seconds,2);
pctime	= year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
url=url+'&Pctime='+encodeURIComponent(pctime);
var xhr				= new ajaxRequest();
xhr.method			= "POST";
xhr.program 		= "ISQ0002D1.php";
xhr.url				= url;
xhr.type			= "N";
xhr.callback		= loginstateChanged;
xhr.canvasid		= "";
xhr.waitanimation	= false;
xhr.synchronous		= false;
xhr.fireandforget	= false;
xhr.ignoreerror		= false;
xhr.execute();
}
// Receive reply
function loginstateChanged(xmlDoc) 
{ 
if (xmlDoc.getElementsByTagName("Message")[0].hasChildNodes()) 
	{
	mess=decodeURIComponent(xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue);
	}
if (xmlDoc.getElementsByTagName("Userid")[0].hasChildNodes()) 
	{
	Userid=decodeURIComponent(xmlDoc.getElementsByTagName("Userid")[0].childNodes[0].nodeValue);
	}
if (xmlDoc.getElementsByTagName("Focus")[0].hasChildNodes()) 
	{
	f=decodeURIComponent(xmlDoc.getElementsByTagName("Focus")[0].childNodes[0].nodeValue);
	}
if (mess=="OK")
	{
	if (document.getElementById('Remember').checked)
	  	{
	  	Cookie.set("globebeatlogon",Userid,365); // logon cookie stays for a year
	  	}
	else
	  	{
	  	Cookie.set("globebeatlogon",Userid,null); // logon cookie expires at end of session
		}
    window.location='ISQ0003M1.php?Article='+Article;
    }
else
	{
	document.getElementById(f).focus();
	reinput(document.getElementById(f),mess);
	}
}
function LoginGuest()
{
url="Email="+encodeURIComponent("guest@globebeat.com")+
"&Password="+encodeURIComponent("guest");

year	= new Date().getFullYear();
month	= new Date().getMonth()+1;
month	= PadDigits(month,2);
day		= new Date().getDate();
day		= PadDigits(day,2);
hours	= new Date().getHours();
hours	= PadDigits(hours,2);
minutes	= new Date().getMinutes();
minutes	= PadDigits(minutes,2);
seconds	= new Date().getSeconds();
seconds	= PadDigits(seconds,2);
pctime	= year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
url=url+'&Pctime='+encodeURIComponent(pctime);
var xhr				= new ajaxRequest();
xhr.method			= "POST";
xhr.program 		= "ISQ0002D1.php";
xhr.url				= url;
xhr.type			= "N";
xhr.callback		= loginstateChanged;
xhr.canvasid		= "";
xhr.waitanimation	= false;
xhr.synchronous		= false;
xhr.fireandforget	= false;
xhr.ignoreerror		= false;
xhr.execute();
}

function Register()
{
if(document.getElementById("EmailReg").value=="")
	{
	reinput(document.getElementById("EmailReg"),"Email address is required.");
	return;
	}
if(document.getElementById("PasswordReg").value=="")
	{
	reinput(document.getElementById("PasswordReg"),"Password is required.");
	return;
	}
if(document.getElementById("PasswordReg2").value=="")
	{
	reinput(document.getElementById("PasswordReg2"),"Please re-enter Password.");
	return;
	}
if(document.getElementById("PasswordReg").value!=document.getElementById("PasswordReg2").value)
	{
	reinput(document.getElementById("PasswordReg2"),"Password must be same as first password.");
	return;
	}
if(document.getElementById("FirstName").value=="")
	{
	reinput(document.getElementById("FirstName"),"First name is required.");
	return;
	}
if(document.getElementById("LastName").value=="")
	{
	reinput(document.getElementById("LastName"),"Surname is required.");
	return;
	}
if(document.getElementById("DateBirth").value==""||document.getElementById("DateBirth").value=="CCYY-MM-DD")
	{
	reinput(document.getElementById("DateBirth"),"Date of birth is required.");
	return;
	}
if(!(document.getElementById("Sex1").checked||document.getElementById("Sex2").checked))
	{
	reinput(document.getElementById("Sex1"),"Gender is required.");
	return;
	}

url="Email="+encodeURIComponent(document.getElementById("EmailReg").value)+
"&FirstName="+encodeURIComponent(document.getElementById("FirstName").value)+
"&LastName="+encodeURIComponent(document.getElementById("LastName").value)+
"&DateBirth="+encodeURIComponent(document.getElementById("DateBirth").value)+
"&Sex="+encodeURIComponent(document.getElementById("Sex").value)+
"&Password="+encodeURIComponent(document.getElementById("PasswordReg").value);

year	= new Date().getFullYear();
month	= new Date().getMonth()+1;
month	= PadDigits(month,2);
day		= new Date().getDate();
day		= PadDigits(day,2);
hours	= new Date().getHours();
hours	= PadDigits(hours,2);
minutes	= new Date().getMinutes();
minutes	= PadDigits(minutes,2);
seconds	= new Date().getSeconds();
seconds	= PadDigits(seconds,2);
pctime	= year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;

url=url+'&Pctime='+encodeURIComponent(pctime);
var xhr				= new ajaxRequest();
xhr.method			= "POST";
xhr.program 		= "ISQ0002D2.php";
xhr.url				= url;
xhr.type			= "N";
xhr.callback		= registerstateChanged;
xhr.canvasid		= "";
xhr.waitanimation	= false;
xhr.synchronous		= false;
xhr.fireandforget	= false;
xhr.ignoreerror		= false;
xhr.execute();
}

// Receive reply
function registerstateChanged(xmlDoc) 
{
if (xmlDoc.getElementsByTagName("Message")[0].hasChildNodes()) 
	{
	mess=decodeURIComponent(xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue);
	}
if (xmlDoc.getElementsByTagName("Email")[0].hasChildNodes()) 
	{
	email=decodeURIComponent(xmlDoc.getElementsByTagName("Email")[0].childNodes[0].nodeValue);
	}
if (xmlDoc.getElementsByTagName("Focus")[0].hasChildNodes()) 
	{
	var f=decodeURIComponent(xmlDoc.getElementsByTagName("Focus")[0].childNodes[0].nodeValue);
	}
if (mess=="OK")
	{
	content=encodeURIComponent('<div style="width:100%;height:100%"><div class="Friendhead">Almost done !</div>'
	+'<div class="smalltext" style="margin:3px;white-space:normal"><br/>An email was sent to <span style="color:#2527cf">'+email+'</span> to verify that the address you used to register is a valid email address. Follow the link in the email to complete registration.</div>'
	+'<div style="position:absolute;bottom:10px;right:10px"><input type="button" class="widebutton" onclick="popupwindow(\'destroy\');window.location=\'http://www.globebeat.com\'" value="Close" /></div></div>');
	w=350;
	h=200;
	a="create";
	popupwindow(a,w,h,content);
    }
else
	{
	document.getElementById(f).focus();
	reinput(document.getElementById(f),encodeURIComponent(mess));
	}
}

function LoginEnterKeyUp(e) 
{
if (!e)
{
var e = window.event;
}
if (e.keyCode==13||e.which==13)
	{
	Login();
	return false;
	}
}
function RegisterEnterKeyUp(e) 
{
if (!e)
{
var e = window.event;
}
if (e.keyCode==13||e.which==13)
	{
	Register();
	return false;
	}
}
function sendpassword()
{
if (document.getElementById('Email').value=="")
	{
	reinput(document.getElementById('Email'),"Enter your email address, in order for us to send your forgotten password.");
	return;
	}
url="Email="+encodeURIComponent(document.getElementById("Email").value);
var xhr				= new ajaxRequest();
xhr.method			= "POST";
xhr.program 		= "ISQ0001D2.php";
xhr.url				= url;
xhr.type			= "N";
xhr.callback		= receivepassword;
xhr.canvasid		= "";
xhr.waitanimation	= false;
xhr.synchronous		= false;
xhr.fireandforget	= false;
xhr.ignoreerror		= false;
xhr.execute();
} 
function receivepassword(xmlDoc)
{
if (xmlDoc.getElementsByTagName("Message")[0].hasChildNodes()) 
	{
	mess=decodeURIComponent(xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue);
	}
var content=encodeURIComponent('<table><tr><td class="smalltext">'+mess+'</td></tr>'
+'</table>'
+'<div style="position:absolute;bottom:10px;right:10px">&nbsp;<input type="button" class="widebutton" onclick="popupwindow(\'destroy\')" value="Close" /></div>');
w=350;
h=150;
a="create";
popupwindow(a,w,h,content);
}
function sendregistration()
{
if (document.getElementById('EmailReg').value=="")
	{
	reinput(document.getElementById('EmailReg'),"Enter your email address, in order for us to resend your registration email.");
	return;
	}
url="Email="+encodeURIComponent(document.getElementById("EmailReg").value);
var xhr				= new ajaxRequest();
xhr.method			= "POST";
xhr.program 		= "ISQ0001D1.php";
xhr.url				= url;
xhr.type			= "N";
xhr.callback		= receivesendregistration;
xhr.canvasid		= "";
xhr.waitanimation	= false;
xhr.synchronous		= false;
xhr.fireandforget	= false;
xhr.ignoreerror		= false;
xhr.execute();
} 
function receivesendregistration(xmlDoc)
{
if (xmlDoc.getElementsByTagName("Message")[0].hasChildNodes()) 
	{
	mess=decodeURIComponent(xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue);
	}
var content=encodeURIComponent('<table><tr><td class="smalltext">'+mess+'</td></tr>'
+'</table>'
+'<div style="position:absolute;bottom:10px;right:10px">&nbsp;<input type="button" class="widebutton" onclick="popupwindow(\'destroy\')" value="Close" /></div>');
w=350;
h=150;
a="create";
popupwindow(a,w,h,content);
}

function PadDigits(n,totalDigits) 
   { 
n=n.toString(); 
var pd = ''; 
if (totalDigits > n.length) 
	{ 
	for (i=0; i < (totalDigits-n.length); i++) 
		{ 
		pd += '0'; 
		} 
	} 
return pd + n.toString(); 
}
if(!Cookie.accept())
	{
	alert('Please adjust your browser to allow cookies before using this site.');
	}
else
	{
	if(Cookie.get("globebeatlogon")!="")
		{
		window.location="ISQ0003M1.php?Article="+Article;
		}
	}

