// <![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 question us form
* @page question.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 question_name 		= true,
	question_phone 		= true,
	question_email 		= true,
	question_region 		= true,
	question_message		= true;

function validate( e ){
	// Set the variables for the script
	var focus_el = null, 
	    msg = '', 
	    prefix = "Your question form has had some errors:\n";

	e.question_name.value 		= e.question_name.value.trim();
	e.question_phone.value 		= e.question_phone.value.trim();
	e.question_reqion.value 		= e.question_reqion.value.trim();
	
	e.question_email.value 		= e.question_email.value.trim();
	e.question_message.value 	= e.question_message.value.trim();
		
	// Make sure that the title is selected
	if ( question_name && validation.empty ( e.question_name ) ) {
		msg += error[0];
		focus_el = focus_el || e.question_name;
	}
	// Make sure that the telephone number is filled in
	if ( question_phone && !validation.phone_number ( e.question_phone ) ) {
		msg += error[1];
		focus_el = focus_el || e.question_phone;
	}
	// Make sure that the email address is filled in
	if ( question_email) {
		if( validation.empty ( e.question_email ) ) {
		msg += error[3];
		focus_el = focus_el || e.question_email;
		}else{
			if (! validation.email ( e.question_email ) ) {
				msg += error[4];
				focus_el = focus_el || e.question_email;
			}
		}
	}
	
	
	if ( validation.selected ( e.question_reqion ) ) {
		msg += error[6];
		focus_el = focus_el || e.question_region;
	}
	// Make sure that the title is selected
	if ( question_message && validation.empty ( e.question_message ) ) {
		msg += error[7];
		focus_el = focus_el || e.question_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.
}
// ]]>