/* SVN FILE: $Id: contact-form.js 197 2007-12-19 02:25:17Z ryan.blunden $ */
/**
 * Contact form validation
 *
 * Copyright 2007, FreemanFox Ltd
 * Level 11, 1 Eagle St Brisbane, QLD, Australia 4000
 *
 * Licensed under The Creative Commons License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright       Copyright 2007, FreemanFox Ltd
 * @version         $Revision: 197 $
 * @modifiedby      $LastChangedBy: ryan.blunden $
 * @lastmodified    $Date: 2007-12-19 12:25:17 +1000 (Wed, 19 Dec 2007) $
 * @license			http://creativecommons.org/licenses/by/3.0/ The Creative Commons License
 */

var ContactForm = 
{
	_formLength: null,
	validator: null,
	validation: 
	{
		rules: 
		{
			fullname: 'required',
			email: 
			{
				required: true,
				email: true
			}
		},
		messages: 
		{
			fullname: 'Please enter your Full Name',
			email: 
			{
				required: 'Please enter your email address',
				email: 'That email address does not appear to be valid'
			}
		}
	},

	
	init: function(validation)
	{
		// Check to ensure contact-form exists
		if($('#contact-form').length === 0)
		{
			alert('The contact form must have an id of #contact-form, aborting validator setup');
			return false;
		}
		
		// Use validation argument if it was supplied
		if(validation != undefined) { this.validation = validation; }
		
		// Setup Validation plugin and check to make sure validator plugin exists
		try
		{
			$.validator.setDefaults(
			{
				submitHandler: function() { ContactForm.handleSubmit(); }
			});
		}
		catch(e)
		{
			alert('Validator jQuery plugin does not seem to exist, aborting validator Setup');
			return false;
		}

		/**
		 * For top page error reporting, make cursor into pointer on hover,
		 * or older browsers that don't support psueudo classes on elements apart from links
		 */
		$('#error-sucess-notice .error label').hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); });
		
		this.validator = $('#contact-form').validate(this.validation);
	},
		

	handleSubmit: function()
	{
		if(this.validator.form() === true)
		{
			$('#contact-form')[0].submit();
		}
		else
		{
			this.validator.focusInvalid();
		}
	},
	
	
	requiredStar: function()
	{
		return ' <em><img src="http://www.freemanfoxmedia.com/img/required-star.gif" alt="required" class="required"></em>';
	}	
};
	
$(document).ready(function() 
{ 
	ContactForm.init(); 
	$('#contact-details').append('<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;time=&amp;date=&amp;ttype=&amp;q=99+Creek+St,+Brisbane,+Australia+4000&amp;sll=37.0625,-95.677068&amp;sspn=47.167389,82.265625&amp;ie=UTF8&amp;om=1&amp;s=AARTsJoV2iY1LzVSoRS4JFmPNGqaxDoSgw&amp;ll=-27.464509,153.028629&amp;spn=0.005712,0.006437&amp;z=16&amp;iwloc=addr&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;time=&amp;date=&amp;ttype=&amp;q=99+Creek+St,+Brisbane,+Australia+4000&amp;sll=37.0625,-95.677068&amp;sspn=47.167389,82.265625&amp;ie=UTF8&amp;om=1&amp;ll=-27.464509,153.028629&amp;spn=0.005712,0.006437&amp;z=16&amp;iwloc=addr&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>');
});