// <![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
*/
function initialize ( ) {
	if ( $('send_to_friend_form') ) { attachEventListener (  $('send_to_friend_form') , "submit" , validateSendToFriend  , false); }
}
function validateSendToFriend ( event ){
	if (typeof event == "undefined") {
    	event = window.event;
	}
	// Set the variables for the script
	var focus_el = null;
	var msg = [];
	
	var news_tellafriend_your_name 		= true,
		news_tellafriend_your_email		= true,
		news_tellafriend_friend_name 	= true,
		news_tellafriend_friend_email	= true;

	// Check your name is filled in
	if ( news_tellafriend_your_name && validation.empty ( $('news_tellafriend_your_name') ) ) {
		msg += error[14];
		focus_el = focus_el || $('news_tellafriend_your_name');
	}
	// Check your email is filled in
	if ( news_tellafriend_your_email && validation.empty ( $('news_tellafriend_your_email') ) ) {
		msg += error[15];
		focus_el = focus_el || $('news_tellafriend_your_email');
	}
	// If you email is filled in, check that the email address is valid
	if ( !validation.empty ( $('news_tellafriend_your_email') ) ) {
		if ( !validation.email ( $('news_tellafriend_your_email') ) ) {
			msg += error[16];
			focus_el = focus_el || $('news_tellafriend_your_email');
		}
	}
	// Check friends name is filled in
	if ( news_tellafriend_friend_name && validation.empty ( $('news_tellafriend_friend_name') ) ) {
		msg += error[17];
		focus_el = focus_el || $('news_tellafriend_friend_name');
	}
	// Check friends eamil is fille din
	if ( news_tellafriend_friend_email && validation.empty ( $('news_tellafriend_friend_email') ) ) {
		msg += error[18];
		focus_el = focus_el || $('news_tellafriend_friend_email');
	}
	// If friends email is filled in, check that the email address is valid
	if ( !validation.empty ( $('news_tellafriend_friend_email') ) ) {
		if ( !validation.email ( $('news_tellafriend_friend_email') ) ) {
			msg += error[19];
			focus_el = focus_el || $('news_tellafriend_friend_email');
		}
	}
	// Script has found some one or more errors, now we run the alert
	if ( msg != '' ) {
		// Add the errors to the innerHTML
		$('validate').innerHTML = "<div class=\"error\">" + msg + "</div>";
		if ( focus_el.focus ) {
			focus_el.focus();
		}
		// Stop the default action
		stopDefaultAction( event );
	}
	else {
		$('validate').innerHTML = '';
		return true; // If there are no errors, go ahead and send the form through.	
	}
}
addLoadListener( initialize );
// ]]>