$(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;
                });
                $('.btnGetDirections').click(MapSearch);
                $('.directions form').submit(MapSearch);
                $('#postCode2').blur(function(){if($(this).val() == '')$(this).val('Enter post code')}).focus(function(){if($(this).val() == 'Enter post code')$(this).val('')});
        });
        function MapSearch() {
                if($('#postCode2').val() == 'Enter post code' || $('#postCode2').val() == ''){
                        RedBar(new Array('Please enter your post code'));
                        return false;
                }
                window.open('http://maps.google.co.uk/maps?saddr='+$('#postCode2').val()+'&daddr=PO20+0FJ,+UK');
        }
        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});
        }
