// JavaScript Document
$(document).ready(function() {
	$("#contact_form").submit(function() {
		var return_validation = '';
		form_valid = true;
		
		
		// Check all the required fields to ensure they are not empty
		$('.required').each(function(){
			$(this).removeClass('error_input');	// lets reset the highlighting if its the second time around								 
			if($(this).val() == ''){
		   
				return_validation = return_validation + '* "' + $(this).attr('title') + '" is required. <br />';
				$(this).addClass('error_input');
				form_valid = false;
				
		  	}
		 });
		 
		 
		 // if the field is empty there is no need to further validate the fields 
		 if (form_valid != false){
		 			 
			 // Check if the email address is legit
			 var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			 if (!pattern.test($("input[name='email']").val())){
				return_validation = return_validation + '* Your email address is invalid. <br />'; 
				$("input[name='email']").addClass('error_input');
				form_valid = false; 
			 }
		 }
			 
		 
		 // If we have any failures on the validation above then lets stop things right now and return the error
		 if (form_valid == false){
		 	 $("#validation_return").html(return_validation).show();
		 	 window.scrollTo(0,0); // return the user to the top of the page so they can see the items needed
			 return false;
			
		 }
			 
		
		/*
		var dataString = $("#subscribe_form").serialize();
		
		$.ajax({  
			type: "POST",  
			url: "/wp-content/themes/bccurrents/mailing_list_api.php",  
			data: dataString,  
			success: function( returndata ) {  
				
				$("#subscribe span:first").hide();
				
				$('#return_data').html( returndata ).fadeIn(1000); 
				
			}  
		});  
		return false;  
		*/
		

			 
							  
	});
	

	$("input:first").select().focus();


});
