/* 

/******************************************************

Author:		Matt Evans
Contact:	mattevans@xtra.co.nz

Website developed for Transcold Group Limited.
© 2008 Transcold Group Limited - All rights reserved.

/******************************************************

*/


/*****************************************************
	Required - Not Empty
*****************************************************/


function rqNotEmpty(entered,fieldname)
{
	// if the value (entered) of the field is empty (length == 0) then provide error message.
	if(entered.length==0)
	{
		//document.getElementById(fieldname +'_msg').style.backgroundColor='#ff0000';
		document.getElementById(fieldname+'_msg').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" /> Please fill this field in.';
	}
	// otherwise provide success message.
	else
	{
		//document.getElementById(fieldname+'_msg').style.backgroundColor='#ffFFFF';
		document.getElementById(fieldname+'_msg').innerHTML='<img src="images/tick.gif" alt="Thank you" align="absmiddle" /> ';
	}
	
	return true;
} // end the function rqNotEmpty.



/*****************************************************
	Required - Alpha Only
*****************************************************/

// check for alpha characters only.
function alphonly(entered,fieldname)
{
	// if the value (entered) of the name field is empty (length == 0) then send to the function rqNotEmpty to give empty error message.
	if(entered.length==0)
	{
		rqNotEmpty(entered,fieldname);
	}
	// otherwise check it is alpha only (no numbers).
	else
	{
	
		// initialise the regular expression and place in a variable called regexy.
		var regexy = /[0123456789.\/\\.<>?:";',\[\]\{\}=\+\*\)\(&^%$#@!]/;
		
		// check to see if regexy test on the value (entered) was incorrect, if so give error message
		if (regexy.test(entered))
		{
			document.getElementById(fieldname+'_msg').style.backgroundColor='#cc0000';
			document.getElementById(fieldname+'_msg').style.visibility='visible';
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" /> Letter\s Only Please.';
		}
		// otherwise provide a success message.
		else 
		{
			document.getElementById(fieldname+'_msg').style.backgroundColor='#ffFFFF';
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />  ';
			return true;
		}
	}
}// end alphaonly function.



/*****************************************************
	Required - Numbers Only.
*****************************************************/

function numbersOnly(entered,fieldname)
{
	// if the value (entered) of the name field is empty (length == 0) then send to the function rqNotEmpty to give empty error message.
	if(entered.length==0)
	{
		rqNotEmpty(entered,fieldname);
	}
	// otherwise check it is numeric.
	else
	{
		var regexy = /^[1-9.]{1}[0-9.]*$/;
		if (!regexy.test(entered))
		{
			document.getElementById(fieldname+"_msg").style.backgroundColor='red';
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" /> Numbers Only Please.';
		}
		else
		{
			document.getElementById(fieldname+"_msg").style.backgroundColor='#fffFFF';
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />';
			return true;
		}
	}
} // end  numbers only function




/*****************************************************
	Required - Email Only.
*****************************************************/

// email check if field is required
function rqCheckEmail(entered,fieldname)
{
	// if the value (entered) of the email field is empty (length == 0) then send to the function rqNotEmpty to give empty error message.
	if(entered.length==0)
	{
		rqNotEmpty(entered,fieldname);
	}
	// otherwise check if the value (entered) is a proper email.
	else
	{
		// set a variable called regexy to the value of a regular expression which will check an email.
		regexy = /^[\w\.]+@[a-zA-Z_]+?\.[a-zA-Z\.]{2,6}$/;
		
		// run the regexy test on the value (entered) and if it DOESN'T validate (note the !) then it will display an error message.
		if (!regexy.test(entered))
		{
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" /> Please enter a valid email.';
		}
		// otherwise display a success message.
		else 
		{
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />';
			return true;}/**/
		}
}// end the function rqCheckEmail.