
function checkEmail( )
{
	var sUrl    = "ajax/main/check-email.php"; 
	var sParams = ("Email=" + $F('txtEmail'));
	
	new Ajax.Request(sUrl, { method:'post', parameters:sParams, onSuccess:_checkEmail }); 
}


function _checkEmail(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		if (sResponse.responseText == "AVAILABLE")
		{
			$('EmailResult').setStyle({ fontSize:'11px', color:'#0000ff' }); 
			$('EmailResult').innerHTML = 'The specified Email Address is Available!';
		}
			
		else if (sResponse.responseText == "NOT_AVAILABLE")
		{
			$('EmailResult').setStyle({ fontSize:'11px', color:'#ff0000' }); 
			$('EmailResult').innerHTML = 'The specified Email Address is NOT Available!';
		}
		
		if (sResponse.responseText != "")
			$('Email').show( );
	}
}


function showLoginForm( )
{
	$('frmPassword').reset( );
	$('Password').hide( );
	$('Result').hide( );
	$('Login').show( );
}


function showPasswordForm( )
{
	$('Login').hide( );
	$('Result').hide( );
	$('Password').show( );	
}


function validateLoginForm( )
{
	var objFV = new FormValidator("frmLogin");

	if (!objFV.validate("txtEmail", "B,E", "Please enter your valid Email Address."))
		return false;
		
	if (!objFV.validate("txtPassword", "B,L(5)", "Please enter the valid Password."))
		return false;
		
	return true;
}

function validatePasswordForm( )
{
	var objFV = new FormValidator("frmPassword");

	if (!objFV.validate("txtEmail", "B,E", "Please enter your valid Email Address."))
		return false;
		
	if (!objFV.validate("ddMonth", "B", "Please choose your Date of Birth (Month)."))
		return false;
		
	if (!objFV.validate("ddDay", "B", "Please choose your Date of Birth (Day)."))
		return false;
		
	if (!objFV.validate("ddYear", "B", "Please choose your Date of Birth (Year)."))
		return false;
		
	if (!isValidDate($F('ddDay'), $F('ddMonth'), $F('ddYear')))
	{
		alert("Please select a valid Date of Birth.");
		
		return false;
	}
	
	$('Processing').show( );
	$('BtnGetNow').disable( );
	
	var sUrl    = "ajax/main/get-password.php"; 
	var sParams = $('frmPassword').serialize( );
	
	new Ajax.Request(sUrl, { method:'post', parameters:sParams, onFailure:_showError, onSuccess:_getPassword });
}

function _getPassword(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		var sParams = sResponse.responseText.split('|-|');
		
		if (sParams[0] == "OK")
		{
			$('Result').innerHTML = sParams[1];

			$('Password').hide( );
			$('Result').show( );
		}
			
		else
			_showError(sParams[1]);
			
		$('Processing').hide( );
		$('BtnGetNow').enable( );
	}
	
	else
		_showError( );
}

function validateRegisterForm( )
{
	var objFV = new FormValidator("frmRegister");
	
	if (!objFV.validate("txtName", "B", "Please enter your Full Name."))
		return false;
		
	if (!objFV.validate("txtEmail", "B,E", "Please enter your valid Email Address."))
		return false;
		
	if (!objFV.validate("txtRetypeEmail", "B,E", "Please re-type the correct Email Address."))
		return false;
		
	if (objFV.value("txtEmail") != objFV.value("txtRetypeEmail"))
	{
		alert("The Emails does not MATCH. Please re-type the correct Email Address.");

		objFV.focus("txtRetypeEmail");
		objFV.select("txtRetypeEmail");

		return false;
	}		
		
	if (!objFV.validate("txtPassword", "B,L(5)", "Please enter the valid Password (Min Length = 5)."))
		return false;
		
	if (!objFV.validate("txtRetypePassword", "B,L(5)", "Please re-type the correct Password (Min Length = 5)."))
		return false;		

	if (objFV.value("txtPassword") != objFV.value("txtRetypePassword"))
	{
		alert("The Passwords does not MATCH. Please re-type the correct Password.");

		objFV.focus("txtRetypePassword");
		objFV.select("txtRetypePassword");

		return false;
	}
		
	if (!objFV.validate("ddType", "B", "Please choose your Type."))
		return false;
		
	if (!objFV.validate("ddGender", "B", "Please choose your Gender."))
		return false;
	
	if (!objFV.validate("ddMonth", "B", "Please choose your Date of Birth (Month)."))
		return false;
		
	if (!objFV.validate("ddDay", "B", "Please choose your Date of Birth (Day)."))
		return false;
		
	if (!objFV.validate("ddYear", "B", "Please choose your Date of Birth (Year)."))
		return false;
		
	if (!isValidDate($F('ddDay'), $F('ddMonth'), $F('ddYear')))
	{
		alert("Please select a valid Date of Birth.");
		
		return false;
	}

	if (!objFV.validate("ddCountry", "B", "Please choose your Country."))
		return false;
		
	if (!objFV.validate("txtLocation", "B", "Please enter your Location."))
		return false;
		
	if (!objFV.validate("txtCode", "B,L(5)", "Please enter the valid Spam Protection Code as shown."))
		return false;
	
	if (objFV.isChecked("cbAgree") == false)
	{
		alert("Please Agree with Terms of Use and Privacy Policy to continue.");
		
		return false;
	}
	
	return true;
}