/*JQUERY STARTS */ var $ = jQuery.noConflict(); var main_form_name = $(document.forms[0]).attr("name"); //Set the name of the main form used by the plugin new function() { jQuery.fn.validate = { init: function(o) { if(jQuery(o).hasClass('string')) this.validate_string(o); if(jQuery(o).hasClass('text_size')) this.validate_text_size(o); if(jQuery(o).hasClass('email')) { this.validate_email(o) }; if(jQuery(o).hasClass('digit')) this.validate_digit(o); if(jQuery(o).hasClass('spam_question') || jQuery(o).hasClass('children_age') ) doValidate(o); if(jQuery(o).attr("id") =="first_night") doValidate(o); }, validate_string: function(o) { var valid_chars = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/; if (!o.value.match(valid_chars)) return this.validate_text_size(o); else doError(o,'
No special characters allowed'); }, validate_text_size: function(o) { if(o.type=='textarea') o.size = o.rows; if(o.value.length ==0) return doError(o,'
This field cannot be empty.'); if(o.value.length < o.size) //Validate for a minimum size string based on the size of the input box return doError(o,'
Please be more specific.'); doSuccess(o); }, validate_digit: function(o) { //if (o.value.match(/([0-9]{4,10})(\s*)/g) == null) if (o.value.match(/[^a-zA-Z]([0-9]{8,})/) == null) doError(o,'
Phone number is invalid'); else doSuccess(o); }, validate_email: function(o) { var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (o.value.match(email)) { doSuccess(o); } else { doError(o,'
Not a valid email'); }; }, dob: function(o) { var dob = /(0[1-9]|1[012])+\/(0[1-9]|[12][0-9]|3[01])+\/(19|20)\d\d/; if (o.value.match(dob)) { doSuccess(o); } else { doError(o,'not a valid date'); }; } }; //private helper, validates each type after check function doValidate(o) { jQuery(o).parent().addClass("loading"); var params = jQuery(".validate :input").serialize() +'&task=' +jQuery(o).attr("class"); jQuery.post(jQuery(".validate").attr("action"), params, function(json) { eval("var args = " + json); if (args.success == true) doSuccess(o); else doError(o,args.msg); });//ends $.post }; }; function submit_validate_form(){ var params = jQuery(".validate :input").serialize() +'&task=' +jQuery(".validate").attr("name"); jQuery.post(jQuery(".validate").attr("action"), params, function(json) { eval("var args = " + json); jQuery("#return").html(args.msg); });//ends $.post } function doSuccess(o) { jQuery(o).parent().removeClass("loading"); jQuery(o).parent().removeClass("error"); jQuery(o).parent().addClass("success"); jQuery("#error_"+ jQuery(o).attr("name")).remove(); //Removes the error message to the first span or element after the input box } function doError(o,m) { jQuery(o).parent().removeClass("loading"); jQuery(o).parent().addClass("error"); jQuery("#error_"+ jQuery(o).attr("name")).remove(); //remove the old one jQuery(o).after(''+m+''); //Adds the error message to the first span or element after the input box jQuery(o).parent().removeClass("success"); } function init_validation_form(form_class){ jQuery("." + form_class + " :input").blur(function() { jQuery(this).validate.init(this); }); /* jQuery("." + form_class + " :input").parent().mouseover(function() { //Gets the first element containing each input from a form with class validate jQuery(this).addClass("selected"); }); jQuery("." + form_class + " :input").parent().mouseout(function() { jQuery(this).removeClass("selected"); });*/ jQuery("." + form_class).submit( function () { jQuery("." + form_class + " :input").trigger("blur"); if(jQuery("." + form_class + " :input").parent().hasClass('error')){ jQuery("#return").attr('class','return_error'); jQuery("#return").html('Please correct the errors below before continuing.

'); }else{ jQuery("#return").html(' '); jQuery("#return").attr('class','loading'); submit_validate_form(); jQuery("#return").attr('class','return_success'); jQuery("." + form_class).get(0).reset(); } return false; }); //ends jQuery(".validate").submit }//ends function//Home page functionality jQuery(document).ready(function(){ jQuery(".enquire a, .popup_enquire a").click(function() { jQuery("#element_id").val(jQuery(this).attr('rel')); jQuery("#form_caption").html(jQuery(this).html()); var position = jQuery(this).position(); jQuery("#popup_contact_form").css('left', position.left -120 + 'px'); jQuery("#popup_contact_form").css('top', position.top +221 + 'px'); jQuery("#popup_contact_form").show('fast'); return false; }); jQuery(".close_popup").click(function() { jQuery(this).parent().hide('fast'); return false; }); jQuery("#open_privacy_disclaimer").click(function() { jQuery("#privacy_disclaimer").show('fast'); return false; }); jQuery(".view_rates").click(function() { var position = jQuery(this).position(); jQuery("#popup_display_rates").css('left', position.left -120 + 'px'); jQuery("#popup_display_rates").css('top', position.top + 'px'); jQuery("#popup_display_rates").show('fast'); return false; }); //jQuery(".times").mouseout(function() {jQuery("#extra_info").fadeOut('fast');}); //jQuery(".date_picker").datepicker({ appendText: '(dd-mm-yyyy)',closeText: 'X', dateFormat: 'dd-mm-yy' }); init_validation_form("validate"); });//ends document).ready