// call back
function facebox_validate_form_call() {
	// SET VARIABLES
	var testType = "";
	var errors = 0;
	var parentElement = "li";
	var errorClass = "error";
	
	// LOOP EACH REQUIRED FIELD
	$("#facebox input[required], #facebox textarea[required], #facebox select[required]").each(function(){
		var fieldType = $(this).attr("type");
		// SET REGEX FOR FIELD TYPES
		if (fieldType == "email") {
			testType = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/;
		} else {
			testType = /\w+/;
		}
		// TEST CURRENT FIELD
		if (testType.test($(this).val())) {
			$(this).parent(parentElement).removeClass(errorClass);
		} else {
			errors = 1;
			$(this).parent(parentElement).addClass(errorClass);
		}
	});
	// END LOOP
	
	// CHECK FOR ERRORS
	if (errors == 1) {
		return false;
	} else {
		return (true);
	}
}
// launch the boxes
jQuery(document).ready(function($) {
	$("#representative a").facebox(); // vehicle enquiry
	$("#content .vcard a").not("#content .vcard .tel a").facebox(); // contact enquiry
	$(".confirmation .action").facebox(); // notifications
	$("#team a").facebox(); // team contact
	$("#content .vcard .tel a").facebox(); // call back
	$(".actions .email").facebox(); // send to friend
});
// bind for when the popup has triggered 
jQuery(document).bind("reveal.facebox", function(){ // call back
	$("#facebox form").submit(function() {
		result = facebox_validate_form_call();
		$(this).find("button").blur();
		return result;
	});
});
