
(function($){$.siteInit=function(){$('.hover_items.hover').css({opacity:0,visibility:'visible'}).bind({mouseenter:function(){$(this).stop().animate({opacity:1},500);},mouseleave:function(){$(this).stop().animate({opacity:0},500);},click:function(){document.location=$('#'+$(this).attr('id').replace('_hover','')).attr('href');}});var $dc=$('#drawer-wrapper'),$h=$('#handle'),dcHeight=500,$c=$('#close-drawer');$dc.css('height',0).data('closed',true);$h.click(function(){if($dc.data('closed')){$dc.animate({height:dcHeight}).data('closed',false);}else{$dc.animate({height:0}).data('closed',true);}});$c.click(function(){$dc.animate({height:0}).data('closed',true);});$('#booking-form').ajaxForm('#drawer',{validateTip:'right',disableSubmit:true});$("#date-picker").datepicker({dateFormat:'dd/mm/yy',firstDay:1,minDate:1});};})(jQuery);jQuery.fn.ajaxForm=function(responseDiv,options){if(!this)
return false;if(!responseDiv)
return this;if(typeof responseDiv=='string')
responseDiv=$(responseDiv);var defaults={url:'',submitClass:'submit',errorClass:'error',loadingDiv:'',validate:true,validateSubmit:true,onSuccess:$.noop,onSubmit:$.noop,onFinished:$.noop,onError:$.noop,disableSubmit:false,validateTip:'bottom',tipWrapperClass:'validate',tipStartDistance:25,tipEndDistance:5,tipShowSpeed:350,tipHideSpeed:250,tipEffect:'linear',jsonResponse:{success:'success',html:'html',status:'status',server:'server'},validation:{email:{text:'This must be a valid email address'},required:{text:'This field is required'},length:{text:'This must be a minimum of ^ characters in length'},url:{text:'This must be a valid URL'},nohtml:{text:'This cannot contain HTML code'},noexecution:{text:'This contains forbidden content'},phone:{text:'This must be a valid phone number'},username:{text:'Username must be 3-20 characters long and contain only letters and numbers'},password:{text:'Password must be 6-20 characters long and contain only standard characters and symbols'},passwordmatch:{text:'Passwords must match'},postcode:{text:'This should be a valid postcode'},creditcard:{text:'This should be a valid credit card number'},digit:{text:'This should only contains digits from 0-9'},decimal:{text:'This should be a decimal number'}}};var options=$.extend(true,defaults,options),frm=$(this),d=new Date(),submit=false,invalid=[],tips={},toValidate={},cDate=d.getTime(),tmp;if(options.validateSubmit||options.validate){$('input[type="text"],input[type="password"],input[type="hidden"],textarea',frm).each(function(){var name=$(this).attr('name');if(!toValidate[name])toValidate[name]=[];if($.inArray(this,toValidate[name])==-1)toValidate[name].push('noexecution');});if(tmp=$('input[name="validate"]',frm).val()){tmp=tmp.split(',');$.each(tmp,function(){var tmp=this.split('=');if(tmp.length==2){var name=tmp[0],vals=tmp[1].split('|'),el=$('input[name="'+name+'"],textarea[name="'+name+'"],select[name="'+name+'"]',frm),val=el.val();if(vals.length>0)$.each(vals,function(){if(!toValidate[name])toValidate[name]=[];if($.inArray(this,toValidate[name])==-1)toValidate[name].push(this);});}});}}
var createValidationTips=function(name,checks){if(inputEl=$('[name="'+name+'"]',frm)){var first,second;if(options.validateTip=='top'||options.validateTip=='bottom'){first='top';second='bottom';}else{first='left';second='right';}
$.each(checks,function(){var el=document.createElement("div"),validationObj={},check=this,val=0;if(check.indexOf("-")>-1){var tmp=check.split('-');check=tmp[0];val=tmp[1];}
if(options.validation[check]){frm.append(el);$(el).addClass(options.tipWrapperClass).css({visibility:'hidden',position:'absolute'}).html('<div class="'+first+'"></div><div class="middle">'+options.validation[check].text.replace(/\^/g,val)+'</div><div class="'+second+'"></div>');validationObj[check]=el;if(!$(inputEl).data('tips'))$(inputEl).data('tips',{});$.extend($(inputEl).data('tips'),validationObj);}});}};if(options.validateTip)$.each(toValidate,function(name,checks){createValidationTips(name,checks);});if(!options.url)
options.url=$(this).attr('action');var closeTips=function(el){$.each(el.data('tips'),function(name,tip){$(tip).animate({opacity:0},options.tipHideSpeed,options.tipEffect,function(){$(this).css('visibility','hidden');});});};var invalidField=function(el,name,type,newText){el.addClass(options.errorClass);if($.inArray(name,invalid)==-1)
invalid.push(name);if(el.data('tips')){closeTips(el);if(newText)$('.middle',el.data('tips')[type]).html(newText);var validateTip=$(el.data('tips')[type]),pos=el.position(),w=el.outerWidth(),h=el.outerHeight(),tipW=validateTip.outerWidth(),tipH=validateTip.outerHeight(),startProps={visibility:'visible',opacity:0},endProps={opacity:1},left,top;switch(options.validateTip){case'bottom':left=(tipW>w)?pos.left-Math.floor((tipW-w)/2):pos.left+Math.floor((w-tipW)/2);$.extend(startProps,{top:pos.top+h+options.tipStartDistance,left:left});$.extend(endProps,{top:pos.top+h+options.tipEndDistance,left:left});break;case'top':left=(tipW>w)?pos.left-Math.floor((tipW-w)/2):pos.left+Math.floor((w-tipW)/2);$.extend(startProps,{top:pos.top-tipH-options.tipStartDistance,left:left});$.extend(endProps,{top:pos.top-tipH-options.tipEndDistance,left:left});break;case'left':top=(tipH>h)?pos.top-Math.floor((tipH-h)/2):pos.top+Math.floor((h-tipH)/2);$.extend(startProps,{top:top,right:pos.left-options.tipStartDistance});$.extend(endProps,{top:top,right:pos.left-options.tipEndDistance});break;default:top=(tipH>h)?pos.top-Math.floor((tipH-h)/2):pos.top+Math.floor((h-tipH)/2);$.extend(startProps,{top:top,left:pos.left+w+options.tipStartDistance});$.extend(endProps,{top:top,left:pos.left+w+options.tipEndDistance});}
validateTip.css(startProps).stop(true).animate(endProps,options.tipShowSpeed,options.tipEffect);}
return false;};var validField=function(el,name,type){el.removeClass(options.errorClass);var idx=$.inArray(name,invalid);if(idx>-1)
invalid.splice(idx);if(el.data('tips'))
closeTips(el);return true;};var getFieldValue=function(el){var val=el.val(),type=el.attr('type');if(type=="checkbox"){if(!el.attr('checked'))
val='';}else if(type=="select-multiple"){if(val===null)
val='';}
return val;};var luhn=function(cc){var sum=0,i;for(i=cc.length-2;i>=0;i-=2){sum+=Array(0,2,4,6,8,1,3,5,7,9)[parseInt(cc.charAt(i),10)];}
for(i=cc.length-1;i>=0;i-=2){sum+=parseInt(cc.charAt(i),10);}
return(sum%10)==0;};var getDigits=function(str){return str.replace(/[^\d]/g,"");};var checkChars=function(str,validChars){if(!validChars)
validChars="0123456789.";var strChar,result=true;if(str.length==0)return false;for(i=0;i<str.length&&result==true;i++){strChar=str.charAt(i);if(validChars.indexOf(strChar)==-1)
result=false;}
return result;};var validateProcess=function(el,name,check,param,val){var result=true,resultText='';if(options.validation[check]&&options.validation[check].action){if($.inArray(name,invalid)>-1)
invalid.push(name);result=(resultText=options.validation[check].action(el,val))?false:true;}else{switch(check){case"required":result=((!param||(param&&getFieldValue($('[name="'+param+'"]',frm))!=""))&&val=="")?false:true;break;case"noexecution":result=(val!=""&&val.toLowerCase().indexOf("content-type:")>-1||val.toLowerCase().indexOf("content-transfer-encoding")>-1||val.toLowerCase().indexOf("mime-version")>-1||val.toLowerCase().indexOf("bcc:")>-1)?false:true;if(!result)$.ajax({url:options.url+'?ban_ip'});break;case"digit":result=(val!=""&&checkChars(val,'0123456789'))?true:false;break;case"decimal":result=(val==""||(val!=""&&val.indexOf(".")>=0&&checkChars(val)))?true:false;break;case"length":result=(val!=""&&val.length<param)?false:true;break;case"email":var aPos=val.indexOf("@"),dPos=val.lastIndexOf(".");result=(val!=""&&(aPos<1||dPos<aPos+2||dPos+2>=val.length))?false:true;break;case"phone":var RegExp=/^0\d{2,4}[ -]{1}[\d]{3}[\d -]{1}[\d -]{1}[\d]{1,4}$/;result=(val==""||RegExp.test(val))?true:false;break;case"username":var RegExp=/^[A-Za-z0-9_]{3,20}$/;result=(val==""||RegExp.test(val))?true:false;break;case"creditcard":if(val!=""){var ccList=[["34",15],["37",15],["6011",16],["51",16],["52",16],["53",16],["54",16],["55",16],["4",13],["4",16]],cc=getDigits(val);result=false;if(luhn(cc)){for(var i in ccList){if(cc.indexOf(ccList[i][0])==0){if(ccList[i][1]==cc.length){result=true;break;}}}}}
break;case"postcode":var RegExp=/^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}$/;result=(val==""||RegExp.test(val))?true:false;break;case"url":var RegExp=/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;result=(val==""||RegExp.test(val))?true:false;break;case"password":var RegExp=/^[A-Za-z0-9!@#$%^&*()_]{6,20}$/;result=(val==""||RegExp.test(val))?true:false;break;case"passwordmatch":result=(val!=""&&val!=$('input[name="'+param+'"]',frm).val())?false:true;break;case"nohtml":var RegExp=/<(\S+).*>(.*)<\/\1>/;result=(val!=""&&RegExp.test(val))?false:true;}}
return(result)?validField(el,name,check):invalidField(el,name,check,resultText);};var validateField=function(el){var name=el.attr('name'),result=true,val=getFieldValue(el),tmp;if(toValidate[name]){$.each(toValidate[name],function(){var params=this.split('-');if(result)result=validateProcess(el,name,params[0],(params[1])?params[1]:0,val);});}
return result;};if(options.validate)$('input,textarea,select,checkbox',frm).each(function(){$(this).blur(function(){validateField($(this));});});$(this).append('<input type="hidden" name="creation-date" value="'+cDate+'" /><input type="hidden" name="ajax" value="1" />').submit(function(e){if(invalid.length>0)
return false;if(options.validateSubmit||options.validate)$('input,textarea,select,checkbox',frm).each(function(){validateField($(this));});if(invalid.length>0)
return false;if(options.disableSubmit)
$('input[type="submit"]').attr('disabled',true);options.onSubmit();$.ajaxSetup({cache:false});frm.ajaxError(function(e,xhr){submit=false;frm.data('failed',0);var html='<h3 class="error">Request Result</h3><p class="error">'+((xhr.status>201)?'The request could not be completed. This may be due to a temporary server issue.':'The request completed, but no JSON string was returned to process.')+' The response code returned was:<br /><br /><i>'+xhr.status;switch(xhr.status){case 200:html+=' OK';break;case 404:html+=' Not Found';break;case 500:html+=' Internal Server Error';break;case 504:html+=' Gateway Timeout';}
html+='</i></p>';responseDiv.empty().html(html);options.onFinished();options.onError();});$.post(options.url,frm.serialize(),function(data){submit=false;frm.data('failed',(data[options.jsonResponse.success])?0:1);var html=(data[options.jsonResponse.html])?(data[options.jsonResponse.html]):'<h3>No Response</h3>';responseDiv.empty().html(html);options.onFinished();(data[options.jsonResponse.success])?options.onSuccess():options.onError();},"json");return false;});if($('#file-uploader').length>0){var prefix=cDate+'-';var uploader=new qq.FileUploader({element:document.getElementById('file-uploader'),action:'fileuploader.php',onComplete:function(id,fileName,responseJSON){fileName=prefix+fileName
if($('input[name="uploads"]',frm).length>0){var el=$('input[name="uploads"]',frm),files=el.val().split(',');if($.inArray(files,fileName)==-1)files.push(fileName);el.val(files.join(','));}else{frm.append('<input name="uploads" type="hidden" value="'+fileName+'" />');}},multiple:false,params:{qqfileprefix:prefix},debug:true});}
return this;};
