// Copyright (c)2004 OneTime.com, Inc. All rights reserved.

HCAL_LAYER='HCAL';HCAL_OPEN=null;HCAL_FIELD=null;HCAL_DATE=new Date();HCAL_STARTDATE=new Date();

function h_open(a){h_open_pos(a,getW(a),0);}
function h_open_pos(a,xpos,ypos){var o=getObject(HCAL_LAYER);var n=(HCAL_OPEN==null);if(HCAL_FIELD&&(a==HCAL_FIELD))return false;if(!n)hideObject(HCAL_OPEN);HCAL_OPEN=o;HCAL_FIELD=a;var d;if(a.name=='inDate'){d=new Date();d.setDate(d.getDate()+14);HCAL_STARTDATE=new Date();}else{d=new Date(HCAL_DATE.getFullYear(),HCAL_DATE.getMonth(),HCAL_DATE.getDate());d.setDate(d.getDate()+1);HCAL_STARTDATE=d;}h_renderMonth(d.getMonth()+1,d.getFullYear());moveObject(o,getX(a)+xpos,getY(a)+ypos);showObject(o);if(n)trackMouseClick(h_checkClose);}
function h_checkClose(e){if(HCAL_OPEN==null)return;var x=getEventX(e);var y=getEventY(e);if(!(isInside(HCAL_FIELD,x,y,0,0,4,0)||isInside(HCAL_OPEN,x,y)))h_close();}
function h_setDate(y,m,d){if(HCAL_OPEN==null)return;HCAL_FIELD.value=(m<10?'0':'')+m+'/'+(d<10?'0':'')+d+'/'+y;if(HCAL_FIELD.name=='inDate')HCAL_DATE=new Date(y,m-1,d);h_close();}
function h_close(){hideObject(HCAL_OPEN);if(HCAL_OPEN!=null)untrackMouseClick();HCAL_OPEN=null;HCAL_FIELD=null;}
function h_renderMonth(month,year){if(HCAL_OPEN==null)return;var t_y=HCAL_STARTDATE.getFullYear();var t_m=HCAL_STARTDATE.getMonth()+1;var t_d=HCAL_STARTDATE.getDate();var d=new Date(year,month-1,1);var max=(month==2?28+((year%4==0)&&((year%100!=0)||(year%400==0))?1:0):30+(month<8?1-((month-1)%2):(month-1)%2));var html='<table border=0 cellpadding=1 cellspacing=0 bgcolor="#305799"><tr><td><table border=0 cellpadding=3 cellspacing=1 width=150><tr bgcolor="#305799"><td align=center><a href="javascript:void(0)" onclick="h_renderMonth('+(month>1?month-1:12)+',' +(month>1?year:year-1)+');" style="color: white; font-weight: bold; text-decoration: none;">&laquo;</a></td><td colspan=5 align=center><font size=1 face="arial,helvetica" color=white><b>'+MONTHS[month-1].toUpperCase()+' '+year+'</b></font></td><td align=center><a href="javascript:void(0)" onclick="h_renderMonth('+(month<12?month+1:1)+','+(month<12?year:year+1)+');" style="color: white; font-weight: bold; text-decoration: none;">&raquo;</a></td></tr><tr bgcolor="#e1e1e1"><td align=center><font size=1 face="arial,helvetica">S</font></td><td align=center><font size=1 face="arial,helvetica">M</font></td><td align=center><font size=1 face="arial,helvetica">T</font></td><td align=center><font size=1 face="arial,helvetica">W</font></td><td align=center><font size=1 face="arial,helvetica">T</font></td><td align=center><font size=1 face="arial,helvetica">F</font></td><td align=center><font size=1 face="arial,helvetica">S</font></td></tr>';var offset=d.getDay()+1;var count=1, i, a;for (i=1;i<=max;i++){if(count==1)html+='<tr bgcolor=white>';if((i==1)&&(offset>1)){html+='<td colspan='+(offset-1)+' bgcolor="#e1e1e1"><font size=1>&nbsp;</font></td>';count=offset;}a=((year>t_y)||((year==t_y)&&((month>t_m)||((month==t_m)&&(i>=t_d)))));html+='<td align=center><font face="arial,helvetica" size=1'+(a?'><a href="javascript:void(0)" onclick="h_setDate('+year+','+month+','+i+')"><b>':' color=gray>')+i+(a?'</b></a>':'')+'</font></td>';if((i==max)&&(count<7)){html+='<td colspan='+(7-count)+' bgcolor="#e1e1e1"><font size=1>&nbsp;</font></td>';count=7;}count++;if(count>7){count=1;html+='</tr>';}}html+='</table></td></tr></table>';writeObject(HCAL_OPEN,html);}
function OTH_d(d,n){if(!d.value){alert('Please add a valid '+n+'.');return false;}var e1,e2;if((e1=d.value.match(/^(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])\/((20)?[0-9]{2})$/))||(e2=d.value.match(/^(3[01]|[12][0-9]|0?[1-9])\.\s*(1[0-2]|0?[1-9])\.\s*((20)?[0-9]{2})$/))){var d,m,y;if(e1){d=Number(e1[2]);m=Number(e1[1]);y=Number(e1[3]);}else{d=Number(e2[1]);m=Number(e2[2]);y=Number(e2[3]);}y=(y<2000?y+2000:y);if(d>(m==2?28+((y%4==0)&&((y%100!=0)||(y%400==0))?1:0):30+(m<8?1-((m-1)%2):(m-1)%2))){alert('The '+n+' does not seem to be a valid date.');return false;}d.value=(m<10?'0':'')+m+'/'+(d<10?'0':'')+d+'/'+y;}else{alert('The '+n+' does not seem to be a valid date.\nPlease provide a date in either the format\n"mm/dd/yyyy" or "dd. mm. yyyy".');return false;}return true;}
function OTH_t(f){if(f.city&&(!f.city.value)){alert('Please provide a city name\nfor your hotel search.');return false;}if(!OTH_d(f.inDate,'Check-In Date'))return false;if(!OTH_d(f.outDate,'Check-Out Date'))return false;var d1=f.inDate.value.match(/^(1[0-2]|0[1-9])\/(3[01]|[12][0-9]|0[1-9])\/(20[0-9]{2})$/);var d2=f.outDate.value.match(/^(1[0-2]|0[1-9])\/(3[01]|[12][0-9]|0[1-9])\/(20[0-9]{2})$/);if((d2[3]<d1[3])||((d2[3]==d1[3])&&((d2[1]<d1[1])||((d2[1]==d1[1])&&(d2[2]<=d1[2]))))){alert('The Check-Out Date must be AFTER the Check-In Date.\nPlease correct and try again.');return false;}return true;}

