// $Id: checkFormLogin.js 2943 2009-06-18 09:48:21Z Neil $

function checkFormMyAccount()
{
	email = document.getElementById("email").value;
	password = document.getElementById("password").value;
	
	if (email == "" || email == null)
	{
		hideMyAccountErrors();
		document.getElementById("emailMAError").style.display = "block";
		document.getElementById("email").select();
		return false;
	}
	/*else if (!isValidEmail(email))
	{
		hideMyAccountErrors();
		document.getElementById("emailMAInvalidError").style.display = "block";
		document.getElementById("email").select();
		return false;
	}*/
	else if (password == "" || password == null)
	{
		hideMyAccountErrors();
		document.getElementById("passwordMAError").style.display = "block";
		document.getElementById("password").select();
		return false;
	}
	return true;
}

function hideMyAccountErrors()
{
	document.getElementById("emailMAError").style.display = "none";
	document.getElementById("emailMAInvalidError").style.display = "none";
	document.getElementById("passwordMAError").style.display = "none";
}

function checkFormHosted()
{
	hsemail = document.getElementById("hs_username").value;
	hspassword = document.getElementById("hs_password").value;
	
	if (hsemail == "" || hsemail == null)
	{
		hideHostedErrors();
		document.getElementById("emailHostError").style.display = "block";
		document.getElementById("hs_username").select();
		return false;
	}
	else if (!isValidEmail(hsemail))
	{
		hideHostedErrors();
		document.getElementById("emailHostInvalidError").style.display = "block";
		document.getElementById("hs_username").select();
		return false;
	}
	else if (hspassword == "" || hspassword == null)
	{
		hideHostedErrors();
		document.getElementById("passwordHostError").style.display = "block";
		document.getElementById("hs_password").select();
		return false;
	}
	return true;
}

function hideHostedErrors()
{
	document.getElementById("emailHostError").style.display = "none";
	document.getElementById("emailHostInvalidError").style.display = "none";
	document.getElementById("passwordHostError").style.display = "none";
}


function checkFormXTrackExp()
{
	xteuser = document.getElementById("xte_username").value;
	xtepin = document.getElementById("xte_pincode").value;
	
	if (xteuser == "" || xteuser == null)
	{
		hideXTEErrors();
		document.getElementById("userXTEError").style.display = "block";
		document.getElementById("xte_username").select();
		return false;
	}
	else if (!isValidEmail(xteuser))
	{
		hideXTEErrors();
		document.getElementById("userXTEInvalidError").style.display = "block";
		document.getElementById("xte_username").select();
		return false;
	}
	else if (xtepin.length != 4)
	{
		hideXTEErrors();
		document.getElementById("passwordXTEError").style.display = "block";
		document.getElementById("xte_pincode").select();
		return false;
	}
	return true;
}

function hideXTEErrors()
{
	document.getElementById("userXTEError").style.display = "none";
	document.getElementById("userXTEInvalidError").style.display = "none";
	document.getElementById("passwordXTEError").style.display = "none";
}

function checkFormXTrackPro()
{
	iPbe = 1;
	accnum = document.getElementById("acc").value;
	uname = document.getElementById("usr").value;
	pword = document.getElementById("pwd").value;
	
	if (accnum == "" || accnum == null)
	{
		hideXTPErrors();
		document.getElementById("accXTPError").style.display = "block";
		document.getElementById("acc").select();
		return false;
	}
	else if (uname == "" || uname == null)
	{
		hideXTPErrors();
		document.getElementById("userXTPError").style.display = "block";
		document.getElementById("usr").select();
		return false;
	}
	else if (pword == "" || pword == null)
	{
		hideXTPErrors();
		document.getElementById("pwordXTPError").style.display = "block";
		document.getElementById("pwd").select();
		return false;
	}
	
	var w = (screen.availWidth-8);
	var h = (screen.availHeight-20);
	var x = 0;
	var y = 0;
	//self.open("http://tracking.genesis.co.uk/cgi-bin/waa1gate.exe?WAA_PACKAGE=sup&WAA_FORM=MainEntry&lgn=1&acc="+accnum+"&usr="+uname+"&pwd="+pword+"&pbe="+iPbe, "sup1", "left="+x+",top="+y+",screenX="+x+",screenY="+y+",width="+w+",height="+h+",resizable=1");
	self.open("http://tracking.genesis.co.uk/2/sideentry.aspx?acc="+accnum+"&usr="+uname+"&pwd="+pword, "sup1", "left="+x+",top="+y+",screenX="+x+",screenY="+y+",width="+w+",height="+h+",resizable=1");
	return true;
}

function hideXTPErrors()
{
	document.getElementById("accXTPError").style.display = "none";
	document.getElementById("userXTPError").style.display = "none";
	document.getElementById("pwordXTPError").style.display = "none";
}


function checkFormPUK()
{
	accnum = document.getElementById("puk_accnum").value;
	phone = document.getElementById("puk_phonenum").value;
	
	if (accnum == "" || accnum == null)
	{
		hidePUKErrors();
		document.getElementById("accPUKError").style.display = "block";
		document.getElementById("puk_accnum").select();
		return false;
	}
	else if (phone == "" || phone == null)
	{
		hidePUKErrors();
		document.getElementById("phonePUKError").style.display = "block";
		document.getElementById("puk_phonenum").select();
		return false;
	}
	else if (!isValidPhone(phone))
	{
		hidePUKErrors();
		document.getElementById("phonePUKInvalidError").style.display = "block";
		document.getElementById("puk_phonenum").select();
		return false;
	}
	return true;
}

function hidePUKErrors()
{
	document.getElementById("accPUKError").style.display = "none";
	document.getElementById("phonePUKInvalidError").style.display = "none";
	document.getElementById("phonePUKError").style.display = "none";
}

function checkFormSupport()
{
	usname = document.getElementById("su_username").value;
	pcode = document.getElementById("su_postcode").value;
	pword = document.getElementById("su_password").value;
	
	if (usname == "" || usname == null)
	{
		hideSupErrors();
		document.getElementById("userSupError").style.display = "block";
		document.getElementById("su_username").select();
		return false;
	}
	else if ((pcode == "" || pcode == null) && (pword == "" || pword == null))
	{
		hideSupErrors();
		document.getElementById("pwordSupError").style.display = "block";
		document.getElementById("su_password").select();
		return false;
	}
	return true;
}

function hideSupErrors()
{
	document.getElementById("userSupError").style.display = "none";
	document.getElementById("pwordSupError").style.display = "none";
}

function checkFormPayments()
{
	usname = document.getElementById("pay_username").value;
	pword = document.getElementById("pay_password").value;
	
	if (usname == "" || usname == null)
	{
		hidePayErrors();
		document.getElementById("userPayError").style.display = "block";
		document.getElementById("pay_username").select();
		return false;
	}
	else if (pword == "" || pword == null)
	{
		hidePayErrors();
		document.getElementById("pwordPayError").style.display = "block";
		document.getElementById("pay_password").select();
		return false;
	}
	return true;
}

function hidePayErrors()
{
	document.getElementById("userPayError").style.display = "none";
	document.getElementById("pwordPayError").style.display = "none";
}



function isValidPhone(str)
{
	var reCheckPhone = /^0[0-9]{9,10}$/;
	return reCheckPhone.test(str);
}

function isValidEmail(str)
{
	return (str.indexOf(".") > 1) && (str.indexOf("@") > 0);
}
