/**
 * @author Ben J Walker
 */

function validate_contact_form()
{

	valid = true;
	
	req_bg = '#d32b2b';
	req_color = '#ffffff';
	
	lessreq_bg = '#e97979';
	lessreq_color = '#42444F';	
	
	bg = '#FFFFFF';
	color = '#42444F';	
	
	document.getElementById('name').style.background = bg;
	document.getElementById('name').style.color = color;
	document.getElementById('email').style.background = bg;
	document.getElementById('email').style.color = color;
	document.getElementById('tel').style.background = bg;
	document.getElementById('tel').style.color = color;
	document.getElementById('address').style.background = bg;
	document.getElementById('address').style.color = color;	
	document.getElementById('security_code').style.background = bg;
	document.getElementById('security_code').style.color = color;		
	
	if ( document.contact_form.name.value == "" )
	{
		//alert ( "Please complete all fields marked with *." );
		document.getElementById('name').style.background = req_bg;
		document.getElementById('name').style.color = req_color;
		
		valid = false;
	}   
	
	
	if ( document.contact_form.email.value == "" && document.contact_form.tel.value == "" )
	{
		//alert ( "Please complete all fields marked with *." );
		document.getElementById('email').style.background = lessreq_bg;
		document.getElementById('email').style.color = lessreq_color;
		
		document.getElementById('tel').style.background = lessreq_bg;
		document.getElementById('tel').style.color = lessreq_color;		
		
		valid = false;
	}   	
	
	if ( document.contact_form.callback.checked == 1 && document.contact_form.tel.value == "" )
	{
		//alert ( "Please complete all fields marked with *." );
		document.getElementById('tel').style.background = req_bg;
		document.getElementById('tel').style.color = req_color;		
		
		valid = false;
	} 	
	
	if ( document.contact_form.brochure.checked == 1 && document.contact_form.address.value == "" )
	{
		//alert ( "Please complete all fields marked with *." );
		document.getElementById('address').style.background = req_bg;
		document.getElementById('address').style.color = req_color;		
		
		valid = false;
	} 		
	
	if (document.contact_form.captcha_code.value == "")
	{
		document.getElementById('security_code').style.background = req_bg;
		document.getElementById('security_code').style.color = req_color;		
		
		valid = false;		
	}
	
	if (document.contact_form.email.value != "")
	{
		apos = document.contact_form.email.value.indexOf("@");
		dotpos = document.contact_form.email.value.lastIndexOf(".");
		
		if (apos < 1 || dotpos - apos < 2)
		{
			document.getElementById('email').style.background = lessreq_bg;
			document.getElementById('email').style.color = lessreq_color;			
			
			valid = false;
		}
	}
	
	showLoader(valid);
	return valid;

}

function validate_sidecontact_form()
{

	valid = true;
	
	req_bg = '#d32b2b';
	req_color = '#ffffff';
	
	lessreq_bg = '#e97979';
	lessreq_color = '#42444F';	
	
	bg = '#FFFFFF';
	color = '#42444F';	
	
	document.getElementById('name').style.background = bg;
	document.getElementById('name').style.color = color;
	
	document.getElementById('callback_label').style.background = bg;
	document.getElementById('callback_label').style.color = color;
	
	document.getElementById('brochure_label').style.background = bg;
	document.getElementById('brochure_label').style.color = color;	
	
	document.getElementById('other_label').style.background = bg;
	document.getElementById('other_label').style.color = color;	

	document.getElementById('security_code').style.background = bg;
	document.getElementById('security_code').style.color = color;

	
	if ( document.sidecontact_form.name.value == "" )
	{
		//alert ( "Please complete all fields marked with *." );
		document.getElementById('name').style.background = req_bg;
		document.getElementById('name').style.color = req_color;
		
		valid = false;
	}   
	
		
	if ( document.sidecontact_form.callback.checked == 1 )
	{
		document.getElementById('tel').style.background = bg;
		document.getElementById('tel').style.color = color;
		
		if(document.sidecontact_form.tel.value == "" )
		{
			//alert ( "Please complete all fields marked with *." );
			document.getElementById('tel').style.background = req_bg;
			document.getElementById('tel').style.color = req_color;		
			
			valid = false;
		}
	} 	
	
	if ( document.sidecontact_form.brochure.checked == 1 )
	{
		document.getElementById('address').style.background = bg;
		document.getElementById('address').style.color = color;	
		
		if( document.sidecontact_form.address.value == "" )
		{
			//alert ( "Please complete all fields marked with *." );
			document.getElementById('address').style.background = req_bg;
			document.getElementById('address').style.color = req_color;		
			
			valid = false;
		}
	} 	
	
	if ( document.sidecontact_form.other.checked == 1 )
	{
		document.getElementById('message').style.background = bg;
		document.getElementById('message').style.color = color;		
		
		if( document.sidecontact_form.message.value == "" )
		{
			//alert ( "Please complete all fields marked with *." );
			document.getElementById('message').style.background = req_bg;
			document.getElementById('message').style.color = req_color;		
			
			valid = false;
		}
	} 		
	
	if( document.sidecontact_form.callback.checked == 0 && document.sidecontact_form.brochure.checked == 0 && document.sidecontact_form.other.checked == 0 )
	{
		document.getElementById('callback_label').style.background = lessreq_bg;
		document.getElementById('callback_label').style.color = lessreq_color;
		
		document.getElementById('brochure_label').style.background = lessreq_bg;
		document.getElementById('brochure_label').style.color = lessreq_color;	
		
		document.getElementById('other_label').style.background = lessreq_bg;
		document.getElementById('other_label').style.color = lessreq_color;		
		
		valid = false;			
	}
	
	if (document.sidecontact_form.captcha_code.value == "")
	{
		document.getElementById('security_code').style.background = req_bg;
		document.getElementById('security_code').style.color = req_color;		
		
		valid = false;		
	}		
	


	showLoader(valid);
	return valid;

}

function showLoader(valid)
{
	if(valid==true)
	{
		document.getElementById('overlay').style.display = 'block';
		document.getElementById('overlay_message').style.display = 'block';
	}

}