function checkAllFields(fieldname)
{
	// create a shortened variable fro "s_msg" (success message)
	var ag = "s_msg"; //look in the big IF statement, this just shortens the code
	
	// create a variable called "failed" that will store the class name of the element we are working on.
	var failed = document.getElementById(fieldname + '_msg').className;

	// create variables of all the class names that are in our form regarding error/success messages.
	var f1 = document.getElementById('fn_msg').className;
	var f2 = document.getElementById('ln_msg').className;
	var f3 = document.getElementById('email_msg').className;
	var f4 = document.getElementById('phone_msg').className;
    var f5 = document.getElementById('message_msg').className;
        
	
	// if our failed variable is set to "f_msg" then our validation must have failed somewhere so diable the submit button
	if (failed == "f_msg")
	{
		document.getElementById('submit').disabled="disabled";
	}
	else //  else run the following last check
	{
		// if all our variables (class names) are equal to our variable "ag" which is "s_msg" (success message) then enable the submit button
		if (f1 == ag && f2 == ag && f3 == ag && f4 == ag && f5 == ag)
		{
			document.getElementById('submit').disabled="";
		}
		else // else keep the button disabled.
		{
			document.getElementById('submit').disabled="disabled";
		}
	}
}// end the function checkAllFields.
/*****************************************************
	Required - all feilds 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').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" />';
        document.getElementById(fieldname+'_msg').className="f_msg";

	}
// otherwise provide success message.
	else
		{
                document.getElementById(fieldname+'_msg').className="s_msg";
		document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />';
		
		}
	return true;
	
}// end the function rqNotEmpty.

 /*****************************************************
	Required - Alphabets  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').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" />';
                    document.getElementById(fieldname+'_msg').className="f_msg";
		}
		// otherwise provide a success message.
		else 
		{
			
            document.getElementById(fieldname+'_msg').className="s_msg";
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />';
                        return true;
		}
		
	}
 
}// end alphaonly function.

/*****************************************************
	Required - Email Only
*****************************************************/
//checks emails only
function rqCheckEmail(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
	{
	// initialise the regular expression and place in a variable called regexy.
		regexy = /^[\w\.]+@[a-zA-Z_]+?\.[a-zA-Z\.]{2,6}$/;
		// 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').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" />';
                        document.getElementById(fieldname+'_msg').className="f_msg";
		}
		// otherwise provide a success message.
		else 
		{
			
                        document.getElementById(fieldname+'_msg').className="s_msg";
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />';
			return true;
		}
	}
}// end the function rqCheckEmail.

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

 // check for Numeric characters 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
	{
	// initialise the regular expression and place in a variable called regexy.
		regexy = /^[1-9.]{1}[0-9.]*$/;
		// 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').className="f_msg";
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/error.gif" alt="Error: Please try again." align="absmiddle" />';
		}
		// otherwise display a success message.
		else
		{
			
            document.getElementById(fieldname+'_msg').className="s_msg";
			document.getElementById(fieldname+'_msg').innerHTML='<img src="images/green-tick.gif" />';
			return true;
		}
	}
} // end  numbers only function



