function fadeHeader(){var currentImage=$("#scroll .img_fade:visible").index(".img_fade");var lastImage=$("#scroll .img_fade").last().index(".img_fade");if(currentImage!=lastImage){$(".img_fade").eq(currentImage).css({position:"absolute",zIndex:2,top:0,left:0});$(".img_fade").eq(currentImage+1).css({position:"absolute",zIndex:1,top:0,left:0}).show();$(".img_fade").eq(currentImage).fadeOut(1000)}else{$(".img_fade").eq(currentImage).css({position:"absolute",zIndex:2,top:0,left:0});$(".img_fade").eq(0).css({position:"absolute",zIndex:1,top:0,left:0}).show();$(".img_fade").eq(currentImage).fadeOut(1000)}}function showDifferentFooter(){var number=Math.floor(Math.random()*101);if(number%2){$("#strand").hide();$("#exmouth").show()}else{$("#strand").show();$("#exmouth").hide()}}function setInputDefaults(){$("input:not(':submit'),textarea").each(function(){var defaultVal=$(this).attr("rel");$(this).val(defaultVal)})}function processForm(formId){var elems=[];$("#"+formId+" input:not(':submit'),#"+formId+" textarea").each(function(){elems.push({name:$(this).attr("name"),id:$(this).attr("id"),value:$(this).val(),defaultV:$(this).attr("rel")})});if(formId=="contactform"){var check=validate(formId,elems);if(check){$.post($("#"+formId).attr('action'),$("#"+formId).serialize(),function(){$("#"+formId+" input:not(':submit'),#"+formId+" textarea").each(function(){$(this).val("")});$("#thank_you_sent").slideDown("slow").delay(4000).slideUp("slow");setInputDefaults()});return false}else{return false}}else if(formId=="subForm"){var check=validate(formId,elems);if(check){$.post($("#"+formId).attr('action'),$("#"+formId).serialize(),function(){$("#"+formId+" input:not(':submit'),#"+formId+" textarea").each(function(){$(this).val("")});$("#signup_form").fadeOut("slow",function(){$("#signup_thanx").fadeIn("slow").delay(4000).fadeOut("slow",function(){$("#signup_teaser").fadeIn()})});setInputDefaults()});return false}else{return false}}else{return validate(formId,elems)}}function validate(formId,array){var isEmail=false;var isNotEmpty=false;var isPostcode=false;$.each(array,function(i,v){if(v.value!=""&&v.value!=v.defaultV){$("#"+formId+" #"+v.id).closest(".txt_wrap").removeClass("error");if(v.id=="email"){isEmail=checkEmail(v.value);if(!isEmail){$("#"+formId+" #"+v.id).closest(".txt_wrap").addClass("error");$("#"+formId+" .sub_butt").addClass("nope")}}if(v.id=="directorio"){isPostcode=isValidPostcode(v.value);if(!isPostcode){$("#"+formId+" #"+v.id).closest(".txt_wrap").addClass("error");$("#"+formId+" .sub_butt").addClass("nope")}}}else{isNotEmpty=true;$("#"+formId+" #"+v.id).closest(".txt_wrap").addClass("error");$("#"+formId+" .sub_butt").addClass("nope")}});if(formId!="direction"){if(isNotEmpty||!isEmail){return false}else{$("#"+formId+" .sub_butt").removeClass("nope");return true}}else{if(isNotEmpty&&isPostcode){return true}else{return false}}}function initMap(lat,lon){var latlng=new google.maps.LatLng(lat,lon);var myOptions={zoom:15,center:latlng,mapTypeId:google.maps.MapTypeId.ROADMAP,disableDefaultUI:true,navigationControl:true,mapTypeControl:false,scaleControl:true};var map=new google.maps.Map(document.getElementById("googlemap"),myOptions);var img='http://royalpub.co.uk/wp-content/themes/royal/images/marker.png';var marker=new google.maps.Marker({position:latlng,map:map,icon:img});marker.setMap(map)}function checkEmail(email){var regex=/^(("[\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;return regex.test(email)}function isValidPostcode(p){var postcodeRegEx=/[A-Z]{1,2}[A-Z0-9]{1,2} ?[0-9][A-Z]{2}/i;return postcodeRegEx.test(p)}
