function c_isValidDate(a,b){a=c_trim(a);if(a.length<6||a.length>10)return false;if(b==null)b="MDY";b=b.toUpperCase();if(b.length!=3)b="MDY";if(b.indexOf("M")==-1||b.indexOf("D")==-1||b.indexOf("Y")==-1)b="MDY";if(b.substring(0,1)=="Y")var d=/^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/,c=/^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;else if(b.substring(1,2)=="Y"){d=/^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/;c=/^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/}else{d=/^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/;c=/^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/}if(d.test(a)== false&&c.test(a)==false)return false;var e=a.split(RegExp.$1);d=b.substring(0,1)=="M"?e[0]:b.substring(1,2)=="M"?e[1]:e[2];c=b.substring(0,1)=="D"?e[0]:b.substring(1,2)=="D"?e[1]:e[2];e=b.substring(0,1)=="Y"?e[0]:b.substring(1,2)=="Y"?e[1]:e[2];if(parseFloat(e)<=50)e=(parseFloat(e)+2E3).toString();if(parseFloat(e)<=99)e=(parseFloat(e)+1900).toString();e=new Date(parseFloat(e),parseFloat(d)-1,parseFloat(c),0,0,0,0);if(parseFloat(c)!=e.getDate())return false;if(parseFloat(d)-1!=e.getMonth())return false; return true}function c_trim(a){var b=/^(\s*)$/;if(b.test(a)){a=a.replace(b,"");if(a.length==0)return a}b=/^(\s*)([\W\w]*)(\b\s*$)/;if(b.test(a))a=a.replace(b,"$2");return a}function c_isDateInPast(a,b,d){var c=new Date;c=new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);a=c_trim(a);if(!c_isDateFieldEmpty(a)&&c_isValidDate(a,b)){a=c_prepareDateObject(a,b,d);if(Date.parse(c)>Date.parse(a))return true}else return false}function c_isDateFieldEmpty(a){return c_trim(a)==""?true:false} function c_compareDates(a,b,d,c){var e=false;a=c_trim(a);b=c_trim(b);if(c_isDateFieldEmpty(a)||c_isDateFieldEmpty(b))alert("You must enter the check in and check out dates.");else if(c_isValidDate(a,d))if(c_isValidDate(b,d))if(c_isDateInPast(a,d,c))alert("The check in date can't be in the past.");else if(c_isDateInPast(b,d,c))alert("The check out date can't be in the past.");else if(Date.parse(a)==Date.parse(b))alert("The check-out date can't be the same day as the check-in date.");else if(Date.parse(a)> Date.parse(b))alert("The check in date can't be after the check out date.");else e=true;else alert("You must enter a valid check out date.");else alert("You must enter a valid check in date.");return e} function c_testSingleField(a,b,d,c,e){var g=false,f="";a=c_trim(a);if(c==1)f=e==1?"check in":"check out";else if(c==2)f=e==1?"arrival":"departure";if(c_isDateFieldEmpty(a))alert("You must enter the "+f+" date.");else if(c_isValidDate(a,b))if(c_isDateInPast(a,b,d))alert("The "+f+" date can't be in the past.");else g=true;else alert("You must enter a valid "+f+" date.");return g} function c_compareDatesFlex(a,b,d,c,e){var g=false,f="",h="";if(e==1){f="check in";h="check out"}else if(e==2){f="arrival";h="departure"}a=c_trim(a);b=c_trim(b);if(c_isDateFieldEmpty(a)||c_isDateFieldEmpty(b))alert("You must enter the "+f+" and "+h+" dates.");else if(c_isValidDate(a,d))if(c_isValidDate(b,d))if(c_isDateInPast(a,d,c))alert("The "+f+" date can't be in the past.");else if(c_isDateInPast(b,d,c))alert("The "+h+" date can't be in the past.");else if(Date.parse(a)==Date.parse(b))alert("The "+ h+" date can't be the same day as the "+f+" date.");else if(Date.parse(a)>Date.parse(b))alert("The "+f+" date can't be after the "+h+" date.");else g=true;else alert("You must enter a valid "+h+" date.");else alert("You must enter a valid "+f+" date.");return g} function c_prepareDateObject(a,b,d){var c=a.split(d);a=b.substring(0,1)=="M"?c[0]:b.substring(1,2)=="M"?c[1]:c[2];d=b.substring(0,1)=="D"?c[0]:b.substring(1,2)=="D"?c[1]:c[2];b=b.substring(0,1)=="Y"?c[0]:b.substring(1,2)=="Y"?c[1]:c[2];if(parseFloat(b)<=50)b=(parseFloat(b)+2E3).toString();if(parseFloat(b)<=99)b=(parseFloat(b)+1900).toString();return new Date(parseFloat(b),parseFloat(a)-1,parseFloat(d),0,0,0)} function c_dateDifferenceInDays(a,b,d,c){var e=1;if(c_isDateFieldEmpty(a)||c_isDateFieldEmpty(b))alert("You must enter the check in and check out dates.");else if(c_isValidDate(a,d))if(c_isValidDate(b,d)){a=c_prepareDateObject(a,d,c);b=c_prepareDateObject(b,d,c);e=Math.ceil((b-a)/864E5);if(e<0)e=1}else alert("You must enter a valid check out date.");else alert("You must enter a valid check in date.");return e} function c_dateAddFormatted(a,b,d,c,e,g){var f=a;if(c_isDateFieldEmpty(a))alert("You must enter a date.");else if(c_isValidDate(a,d)){if(b>0){a=c_prepareDateObject(a,d,c);f=new Date(a);f.setDate(parseInt(a.getDate())+parseInt(b));f=c_dateFormatToField(f,d,c,e,g)}}else alert("You must enter a valid date.");return f} function c_dateFormatToField(a,b,d,c,e){monthDate=a.getMonth()+1;if(e&&monthDate<10)monthDate="0"+monthDate;dayDate=a.getDate();if(e&&dayDate<10)dayDate="0"+dayDate;yearDate=a.getFullYear();dateFormatted=b.replace(b.substring(1,2),d+b.substring(1,2)+d);dateFormatted=dateFormatted.replace("M",monthDate);dateFormatted=dateFormatted.replace("D",dayDate);return dateFormatted=c==4?dateFormatted.replace("Y",yearDate):dateFormatted.replace("Y",yearDate.toString().substring(2,4))} function c_removeLeadingZero(a){if(a.length==2&&a.substr(0,1)=="0")a=a.substr(1,1);return a}function c_return3LettersMonth(a,b){var d=Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),c="";if(a>=1&&a<=12){c=d[a];if(b==1)c=c.toUpperCase(c);else if(b==2)c=c.toLowerCase(c)}return c} function c_isDateInRange(a,b,d){var c=new Date;c.getFullYear();c.getMonth();c.getDate();c=new Date(c.getFullYear()+1,c.getMonth(),c.getDate(),0,0,0);return c_isDateFieldEmpty(a)?false:c_isValidDate(a,b)?c_prepareDateObject(a,b,d)>c?true:false:false};
