/*****************************************************
	Disabler
*****************************************************/

function disabler(id)
{	
	var checked = document.getElementById(id).checked;
	var choccake = document.getElementById('submit');

	if (checked != true || counter >= 1)
	{
			choccake.disabled="disabled";
	}
	else
	{
		choccake.disabled="";
	}
}


/*****************************************************
	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='<span style="color:#f6d300; font-size=10px; background-color=#fff;"><img src="images1/error.gif" alt="" align="absmiddle" /></span>';
		counter += "1";
		disabler('contactcheckbox');
	}
	// otherwise provide success message.
	else
	{
		//document.getElementById(fieldname+'_msg').style.backgroundColor='#ffFFFF';
		document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; "><img src="images1/green-tick.gif" alt="" align="absmiddle" /></span> ';
		counter = "0";
		disabler('contactcheckbox');
	}
} // end the function rqNotEmpty.



 

// 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='#fff';
			document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; font-family=arial;"><img src="images1/error.gif" /> </span>';
			counter += "1";
			disabler('contactcheckbox');
		}
		// otherwise provide a success message.
		else 
		{
			document.getElementById(fieldname+'_msg').style.backgroundColor='#fff';
			document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; font-family=arial;"><img src="images1/green-tick.gif" /> </span> ';
			counter = "0";
			disabler('contactcheckbox');
		}
	}
}// 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='#fff';
			document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; font-family=arial;"><img src="images1/error.gif" /></span>';
			counter += "1";
			disabler('contactcheckbox');	
		}
		else
		{
			document.getElementById(fieldname+"_msg").style.backgroundColor='#fff';
			document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; font-family=arial;"><img src="images1/green-tick.gif" /></span>';
			counter += "0";
			disabler('contactcheckbox');
		}
	}
} // 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").style.backgroundColor='#FFFFFF';
			document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; font-family=arial;"><img src="images1/error.gif" /></span>';
			counter += "1";
			disabler('contactcheckbox');
		}
		// otherwise display a success message.
		else 
		{
			document.getElementById(fieldname+"_msg").style.backgroundColor='#fff';
			document.getElementById(fieldname+'_msg').innerHTML='<span style="color:#f6d300; font-size=10px; background-Color=#fff; font-family=arial;"><img src="images1/green-tick.gif" /></span>';
			counter = "0";
			disabler('contactcheckbox');
		}
	}
}// end the function rqCheckEmail.





