
///////////////////////////////////////////////////////////////////////
//
// Project		:	National Children's Bureau
// Developer	:	Clive Howard
// Created		:	March 2006
// Updated		:	March 2006
//
// Overview		:	
//
// copyright (c) 2005 National Children's Bureau
// http://www.ncb.org.uk
//
// developed by: agencyX limited
// http://www.agencyx.tv
//
///////////////////////////////////////////////////////////////////////	

function testIsBlank(strValue)
{
	for(i = 0; i < strValue.length; i++)
 		{
		var c = strValue.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t'))
			return false;
	}
	return true;
}


function GetTodaysDate()
{
	var objDate = new Date();
	
	var strDate = "";
	var strMonth = "";
	var strDay = "";
	
	var intDay = objDate.getDate()
	var intMonth = objDate.getMonth() + 1;
	
	switch(intMonth)
	{
		case 1: strMonth = "Jan"; break;
		case 2: strMonth = "Feb"; break;
		case 3: strMonth = "Mar"; break;
		case 4: strMonth = "Apr"; break;
		case 5: strMonth = "May"; break;
		case 6: strMonth = "Jun"; break;
		case 7: strMonth = "Jul"; break;
		case 8: strMonth = "Aug"; break;
		case 9: strMonth = "Sep"; break;
		case 10: strMonth = "Oct"; break;
		case 11: strMonth = "Nov"; break;
		case 12: strMonth = "Dec"; break;
	}
	
	strDate += intDay + " ";
	strDate += strMonth + " ";
	strDate += objDate.getYear();
	
	document.write(strDate);
}


function rndTopBar(strColor)
{
	intRndNo = parseInt(12*Math.random())+1;
	strImg = "images/template/topbars/" + intRndNo + strColor + ".jpg";
	
	var objDiv = document.all ? document.all['divPageOptions'] :
					document.getElementById ?
					document.getElementById('divPageOptions') : null;
	if (objDiv)
		objDiv.style.background = "url(" + strImg + ")";
}

function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.frmContact.name.value=="") {
themessage = themessage + " - First Name";
}
if (document.frmContact.last.value=="") {
themessage = themessage + " -  Last Name";
}
if (document.frmContact.email.value=="") {
themessage = themessage + " -  E-mail";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.frmContact.submit();
}
else {
alert(themessage);
return false;
   }
}

function validate() {
mNv=frmContact.name.value;
if (mNv=='') {
alert('Your name is required. Please try again.');
event.returnValue=false;
}
if (!(frmContact.telephone[0].value || frmContact.telephone[1].value)) {
alert('Your telephone is required. Please try again.');
event.returnValue=false;
}


function validateQuickRegister()
{
	try
	{
		if (testIsBlank(document.frmContact.name.value) == true)
		{
			alert("You must enter your name(s)");
			document.frmContact.name.focus();
			return false;
		}
		
		
		if (document.frmRegister.Type[1].checked == true)
		{
			if (testIsBlank(document.frmContact.telephone.value) == true)
			{
				alert("You must enter your telephone number");
				document.frmContact.telephone.focus();
				return false;
			}
		}
		
		if (testIsBlank(document.frmContact.Email.value) == true)
		{
			alert("You must enter your email address");
			document.frmContact.Email.focus();
			return false;
		}
		
		if (testIsBlank(document.frmRegister.Password.value) == true)
		{
			alert("You must enter your password");
			document.frmRegister.Password.focus();
			return false;
		}
		
		var strPassword = document.frmRegister.Password.value;
		var intLen = strPassword.length;
		var booOkay = false;
		var booNumber = false;
		
		if (intLen < 6)
		{
			alert("Your password must be at least six characters in length");
			document.frmRegister.Password.focus();
			return false;
		}
		
		for(i = 0; i < intLen; i++)
		{
			strChar = strPassword.charCodeAt(0);
			
			booOkay = false;
			
			if ((strChar >= 48) && (strChar <= 57))
			{
				booOkay = true;
				booNumber = true;
			}
			
			if (((strChar >= 65) && (strChar <= 90)) || ((strChar >= 97) && (strChar <= 122)))
				booOkay = true;		
				
			if (booOkay == false)
				break;
			
			strPassword = strPassword.substr(1);
		}
		
		if (booOkay == false)
		{
			alert("Your password can only contain letters and numbers");
			document.frmRegister.Password.focus();
			return false;
		}		
		
		if (booNumber == false)
		{
			alert("Your password must contain at least one number");
			document.frmRegister.Password.focus();
			return false;
		}
		
		
		if (testIsBlank(document.frmRegister.Confirm.value) == true)
		{
			alert("You must confirm your password");
			document.frmRegister.Confirm.focus();
			return false;
		}
		
		if (document.frmRegister.Confirm.value != document.frmRegister.Password.value)
		{
			alert("Password entries must be the same");
			document.frmRegister.Password.focus();
			return false;
		}
		
		document.frmRegister.submit();
	}
	catch(e)
	{
		alert("Sorry, an error occurred.\nPlease check that you have JavaScript enabled.")
	}
}