$(document).ready(function(){
	// fade out congrats message
	setTimeout("$('#mailsent').fadeOut();",2000);
	// validate form
	$('#send').click(function(){
		var errors = Array();
		if ($('input[name="Email"]').val().match(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/) == null){
			errors.push('Email Address must be correctly formatted');
		}
		$('label.required').each(function(){
			if ($(this).siblings(':input[name='+$(this).attr('for')+']').val() == ''){
				errors.push($(this).text().toString().substr(0,$(this).text().toString().length - 1) + ' is a required field');
			}
		});
		if (errors.length > 0){
			RedBar(errors);
			return false;
		}
		return true;
	});
	$('#directions').click(MapSearch);
	$('.postcode form').submit(MapSearch);
	$('#entercode').blur(function(){if($(this).val() == '')$(this).val('enter your postcode')}).focus(function(){if($(this).val() == 'enter your postcode')$(this).val('')});
});
function MapSearch() {
	if($('#entercode').val() == 'enter your postcode' || $('#entercode').val() == ''){
		RedBar(new Array('Please enter your post code'));
		return false;
	}
	window.open('http://maps.google.co.uk/maps?saddr='+$('#entercode').val()+'&daddr=PO9+6BW,+UK');
	return false;
}
function RedBar(probs){
	$('#redbar').remove();
	var er = '';
	for (i in probs){
		if (!$.isFunction(probs[i])){
			er += '<p>'+probs[i]+'</p>';
		}
	}
	var redbar = '<div id="redbar">'+er+'<p><a href="#" id="hide">Hide</a></p></div>';
	$('body').prepend(redbar);
	$('#redbar').css({top:'-'+($('#redbar').height()+4)+'px'}).animate({top:0},1000);
	$('#hide').click(function(){$('#redbar').animate({top:'-'+($('#redbar').height()+4)+'px'},1000);return false});
}