/****************************************

*

*	Caledonia Bands

*	Site JavaScript

*

*	Requires jQuery

*	http://jquery.com/

*

****************************************/



// code that runs upon document ready

$(function(){

	// mark the list item that holds the navigation anchor which corresponds

	// to this page as class active

	var currentPage = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);

	if (currentPage.length == 0) currentPage = 'index.html';

	$('#navigation a[href$=' + currentPage + ']').parent().addClass('active');

	

	// setup form validation

	if ($('#contactUsForm').length == 1)

	{

		$('#contactUsForm').submit(function(){

			var emailRe = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

			var errors = [];

			

			if ($('input[name=name]', this).val().length == 0)

				errors.push('You must enter your name.');

				

			if ($('input[name=email]', this).val().length == 0)

				errors.push('You must enter an e-mail address.');

				

			if ($('input[name=email]', this).val().length > 0 &&

				emailRe.test($('input[name=email]', this).val()) == false)

				errors.push('The e-mail address you entered is not a valid e-mail address.');

				

			if ($('input[name=subject]', this).val().length == 0)

				errors.push('You must enter a subject.');



			if ($('select[name=topic] option:selected', this).length == 0)

				errors.push('You must select a topic.');

				

			if ($('textarea[name=body]', this).val().length == 0)

				errors.push('You must enter a message.');

			

			$('#errors').remove();

			

			if (errors.length)

			{

				$('<ul id="errors"></ul>').prependTo(this);

				$.each(errors, function(i, v){

					$('<li>').text(v).appendTo('#errors');

				});

				

				return false;

			}

		});

	}

});