/* Copyright Ignition Components */
/* Design By Sam Rudge :: www.samrudge.co.uk */

function contact_form_validate() {
	//Validate fields in order of there appearence on the form
	//Get all our variables to make it more simple to form IF statements
	valf_name_length=document.Contact_Form.Name.value.length;
	valf_email_value=document.Contact_Form.Email.value;
	valf_email_length=document.Contact_Form.Email.value.length;
	valf_phone_length=document.Contact_Form.Phone.value.length;
	valf_message_value=document.Contact_Form.Message.value;
	valf_message_length=document.Contact_Form.Message.value.length;
	
	//Validtaion returns true if this var reaches the end of statement without
	//changing
	var formreturn = true;
	
	//First validate name, requirements; not empty, more than 3 chars
	if ( valf_name_length <= 3 ) {
		formreturn = false;
		document.getElementById('Name').style.backgroundColor="#FF0000";
	}
	
	//Check for valid email using string functions, requirements; not empty, valid string
	var validemailchars = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(valf_email_value.match(validemailchars)){} else {
		formreturn = false;
		document.getElementById('Email').style.backgroundColor="#FF0000";
	}
	
	//Check for message, requirements; not empty, more than 5 charicters
	if(valf_message_length <= 5 ) {
		formreturn = false;
		document.getElementById('Message').style.backgroundColor="#FF0000";
	}
	if(valf_message_value == 'Click To Enter Your Message...' ) {
		formreturn = false;
		document.getElementById('Message').style.backgroundColor="#FF0000";
	}
	
	//Although it is optional it would be better to have a phone number
	
	if(valf_phone_length==0) {
		if ( formreturn == true ) {
			if(confirm("Although we do not require a phone number and can communicate through email, it is reccomended that you add one to make it easyer for us to contact you regarding your query!\nDo you wish to continue anyway?")) {}else{
				document.Contact_Form.Submit.disabled = false;
				document.Contact_Form.Submit.value = 'Send Message';
				formreturn = false;
			}
		}
	}
	
	if ( formreturn == false ) {
		document.Contact_Form.Submit.disabled = false;
		document.Contact_Form.Submit.value = 'Send Message';
	}
	return formreturn;
}