// Blis Web Agency: Sebastian Jordan
// Form Validation Function

function submitHouseAdd() {
	
	var passed = true;
  	
	if ($('#course_title').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the course title.')});
		passed = false;
	} else if ($('#course_description').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the course description.')});
		passed = false;
	} else if ($('#sa_works_course').val() == "--") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please select if this course is a SA Works Course.')});
		passed = false;
	} else if ($('#delivery_mode').val() == "--") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please select a delivery mode.')});
		passed = false;
	} else if ($('#commencement_date').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the commencement date of the course.')});
		passed = false;
	} else if ($('#completion_date').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the completion date of the course.')});
		passed = false;
	} else if ($('#training_location').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter details of the training location.')});
		passed = false;
	} else if ($('#start_time').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the course start time.')});
		passed = false;
	} else if ($('#finish_time').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the course finish time.')});
		passed = false;
	} else if ($('#cost_to_participant').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the cost to participant.')});
		passed = false;
	} else if ($('#payable').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter who is payable.')});
		passed = false;
	} else if ($('#prerequisites').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter any prerequisites.')});
		passed = false;
	} else if ($('#company_name').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter your company name.')});
		passed = false;
	} else if ($('#contact_person').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the name of the company contact.')});
		passed = false;
	} else if ($('#contact_number').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter a contact number.')});
		passed = false;
	} else if ($('#contact_email').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the contacts email address.')});
		passed = false;
	} else if ($('#facsimile').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the contacts FAX number.')});
		passed = false;
	} else if ($('#website_url').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter the companies web site URL.')});
		passed = false;
	} else if ($('#additional_info').val() == "") {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter any additional information.')});
		passed = false;
	}
	
	// Now check is email address entered is valid
	
	if (checkRegexp($('#contact_email'),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i) == false && passed == true) {
		$('#error_msg').fadeOut(200, function(){$('#error_msg').fadeIn(200).html('*Required: Please enter a valid email address.')});
		passed = false;
	}

	
	if (passed == true) {
		$('#publishForm').submit();
	}
	
}

// Part of email checking function

function checkRegexp(o,regexp) {

  if ( !( regexp.test( o.val() ) ) ) {	  
	  return false;
  } else {
	  return true;
  }

}

