// <![CDATA[
/*
* Copyright: 2005 - this.year() SI Works Internet Solutions
* If you have come across this page, its cause you are snooping through code, and are generally a developer as such
* If you would like to use some of the code on this page, please simply email support@siworks.co.za and ask permission
* it would be much appreciated, as we have worked very hard on these func.tions() and scri.pts()
* 
* Note: All functions below are to make sure that we are sticking to standards and make sure that 
* all data that is put in the database is safe and clean
*
* This script validates the contact us form
* @page contact.form.js
* @version 2.1
* @author Greg Shiers, Jarratt Ingram (SI Works Internet)
* @copyright: SI Works Internet Solutions 2005 - 2007
*/
/* 
* Setting the below we can turn certain field validations on or off by setting
* true for on and false for off
*/
var contact_name 		= true,
	contact_phone 		= true,
	contact_emaill 		= true,
	contact_message		= true;

function validate( e ){
	// Set the variables for the script
	var focus_el = null, 
	    msg = '', 
	    prefix = "Your contact form has had some errors:\n";

	e.contact_name.value 		= e.contact_name.value.trim();
	e.contact_phone.value 		= e.contact_phone.value.trim();
	e.contact_emaill.value 		= e.contact_emaill.value.trim();
	e.contact_message.value 	= e.contact_message.value.trim();
		
	// Make sure that the title is selected
	if ( contact_name && validation.empty ( e.contact_name ) ) {
		msg += error[0];
		focus_el = focus_el || e.contact_name;
	}
	// Make sure that the telephone number is filled in
	if ( contact_phone && !validation.phone_number ( e.contact_phone ) ) {
		msg += error[1];
		focus_el = focus_el || e.contact_phone;
	}
	// Make sure that the email address is filled in
	if ( contact_emaill && validation.empty ( e.contact_emaill ) ) {
		msg += error[3];
		focus_el = focus_el || e.contact_emaill;
	}
	// If the email address is filled in
	if ( !validation.empty ( e.contact_emaill ) ) {
		// Make sure that the email address is valid
		if ( !validation.email ( e.contact_emaill ) ) {
			msg += error[4];
			focus_el = focus_el || e.contact_emaill;
		}
	}
	// Make sure that the title is selected
	if ( contact_message && validation.empty ( e.contact_message ) ) {
		msg += error[5];
		focus_el = focus_el || e.contact_message;
	}
	// Script has found some one or more errors, now we run the alert
	if ( msg != '' ) {
		alert(prefix+msg);
			if ( focus_el.focus ) { focus_el.focus(); }
		return false; // If there are errors, dont submit the form.
	}
	return true; // If there are no errors, go ahead and send the form through.
}
// ]]>
