/* http://keith-wood.name/datepick.html
Datepicker Validation extension for jQuery 4.1.0.
Requires Jörn Zaefferer's Validation plugin (http://plugins.jquery.com/project/validate).
Written by Keith Wood (kbwood{at}iinet.com.au).
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
Please attribute the author if you use it. */
(function($){if($.fn.validate){$.datepick.selectDateOrig=$.datepick.selectDate;$.extend($.datepick.regional[''],{validateDate:'Please enter a valid date',validateDateMin:'Please enter a date on or after {0}',validateDateMax:'Please enter a date on or before {0}',validateDateMinMax:'Please enter a date between {0} and {1}',validateDateCompare:'Please enter a date {0} {1}',validateDateToday:'today',validateDateOther:'the other date',validateDateEQ:'equal to',validateDateNE:'not equal to',validateDateLT:'before',validateDateGT:'after',validateDateLE:'not after',validateDateGE:'not before'});$.extend($.datepick._defaults,$.datepick.regional['']);$.extend($.datepick,{selectDate:function(a,b){this.selectDateOrig(a,b);var c=$.data(a,$.datepick.propertyName);if(!c.inline&&$.fn.validate){var d=$(a).parents('form').validate();if(d){d.element('#'+a.id)}}},errorPlacement:function(a,b){var c=$.data(b[0],$.datepick.propertyName);if(c){a[c.options.isRTL?'insertBefore':'insertAfter'](c.trigger.length>0?c.trigger:b)}else{a.insertAfter(b)}},errorFormat:function(c,d){var e=($.datepick.curInst?$.datepick.curInst.options.dateFormat:$.datepick._defaults.dateFormat);$.each(d,function(a,b){c=c.replace(new RegExp('\\{'+a+'\\}','g'),$.datepick.formatDate(e,b)||'nothing')});return c}});var l=null;$.validator.addMethod('dpDate',function(a,b){l=b;return this.optional(b)||validateEach(a,b)},function(a){var b=$.data(l,$.datepick.propertyName);var c=b.get('minDate');var d=b.get('maxDate');var e=$.datepick._defaults;return(c&&d?$.datepick.errorFormat(e.validateDateMinMax,[c,d]):(c?$.datepick.errorFormat(e.validateDateMin,[c]):(d?$.datepick.errorFormat(e.validateDateMax,[d]):e.validateDate)))});function validateEach(a,b){var c=$.data(b,$.datepick.propertyName);var d=(c.options.multiSelect?a.split(c.options.multiSeparator):(c.options.rangeSelect?a.split(c.options.rangeSeparator):[a]));var f=(c.options.multiSelect&&d.length<=c.options.multiSelect)||(!c.options.multiSelect&&c.options.rangeSelect&&d.length==2)||(!c.options.multiSelect&&!c.options.rangeSelect&&d.length==1);if(f){try{var g=c.options.dateFormat;var h=c.get('minDate');var j=c.get('maxDate');var k=$(b);$.each(d,function(i,v){d[i]=$.datepick.parseDate(g,v);f=f&&(!d[i]||(k.datepick('isSelectable',d[i])&&(!h||d[i].getTime()>=h.getTime())&&(!j||d[i].getTime()<=j.getTime())))})}catch(e){f=false}}if(f&&c.options.rangeSelect){f=(d[0].getTime()<=d[1].getTime())}return f}$.validator.addClassRules('dpDate',{dpDate:true});var m={equal:'eq',same:'eq',notEqual:'ne',notSame:'ne',lessThan:'lt',before:'lt',greaterThan:'gt',after:'gt',notLessThan:'ge',notBefore:'ge',notGreaterThan:'le',notAfter:'le'};$.validator.addMethod('dpCompareDate',function(a,b,c){if(this.optional(b)){return true}c=normaliseParams(c);var d=$(b).datepick('getDate');var e=extractOtherDate(b,c[1]);if(d.length==0||e.length==0){return true}l=b;var f=true;for(var i=0;ie[0].getTime());break;case'le':f=(d[i].getTime()<=e[0].getTime());break;case'ge':f=(d[i].getTime()>=e[0].getTime());break;default:f=true}if(!f){break}}return f},function(a){var b=$.datepick._defaults;var c=$.data(l,$.datepick.propertyName);a=normaliseParams(a);var d=extractOtherDate(l,a[1],true);d=(a[1]=='today'?b.validateDateToday:(d.length?$.datepick.formatDate(c.options.dateFormat,d[0],c.getConfig()):b.validateDateOther));return b.validateDateCompare.replace(/\{0\}/,b['validateDate'+(m[a[0]]||a[0]).toUpperCase()]).replace(/\{1\}/,d)});function normaliseParams(a){if(typeof a=='string'){a=a.split(' ')}else if(!$.isArray(a)){var b=[];for(var c in a){b[0]=c;b[1]=a[c]}a=b}return a}function extractOtherDate(a,b,c){if(b.constructor==Date){return[b]}var d=$.data(a,$.datepick.propertyName);var f=null;try{if(typeof b=='string'&&b!='today'){f=$.datepick.parseDate(d.options.dateFormat,b,d.getConfig())}}catch(e){}f=(f?[f]:(b=='today'?[$.datepick.today()]:(c?[]:$(b).datepick('getDate'))));return f}}})(jQuery);