// JavaScript Document
$(function() {
	
    });


function validate_form(f)
{
	
	turnToWhiteBg(f);
	
	var errors = false;
	var errorMsg = "<p class='error'>You have errors in the submission form.  Please see the highlighted fields below.</p>";
	
	if(f.apt_fname.value == "")
	{
		errors = true;
		f.apt_fname.style.backgroundColor = "#f1a5a5";		
	}
	if(f.apt_lname.value == "")
	{
		errors = true;
		f.apt_lname.style.backgroundColor = "#f1a5a5";		
	}
	if(f.apt_phone.value == "")
	{
		errors = true;
		f.apt_phone.style.backgroundColor = "#f1a5a5";		
	}
	
	
	//Check Email
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = f.apt_email.value;
   if(reg.test(address) == false) {
      
      errors = true;
	  f.apt_email.style.backgroundColor = "#f1a5a5";
   }
	
	if(errors)
	{
		$("#error").html(errorMsg);
		return false;
	}
	
	
	return true;
	
}

function turnToWhiteBg(f)
{
	for(var i=0; i < f.elements.length; i++)
	{
		if(f.elements[i].type == "submit") continue;
		
		f.elements[i].style.backgroundColor = "#ffffff";
	}
}
