var dimensions={screenPos:function(obj){var curleft=curtop=0;if(obj.offsetParent){do{if(obj.getBoundingClientRect){obj=obj.getBoundingClientRect();curleft+=obj.left;curtop+=obj.top;}else{curleft+=obj.offsetLeft;curtop+=obj.offsetTop;};}while(obj=obj.offsetParent);return[curleft,curtop];};},scrollPos:function(){var scrollX=document.documentElement.scrollLeft||0;var scrollY=document.documentElement.scrollTop||0;return[scrollX,scrollY];}};var datepicker={months:[["January",31],["February",28],["March",31],["April",30],["May",31],["June",30],["July",31],["August",31],["September",30],["October",31],["November",30],["December",31]],days:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],timeout:false,init:function(){var INPUTs=tag("input");for(var i=0;i<INPUTs.length;i++){if(INPUTs[i].className.indexOf("_date")>-1){var LABEL=tag("label",INPUTs[i].parentNode)[0];A=LABEL.appendChild(document.createElement("a"));A.onmouseover=function(){datepicker.show('ftArrival');};A.onmouseout=function(){datepicker.timeout=setTimeout("datepicker.hide()",500);};A.id="dp_"+ INPUTs[i].id;A.className="datepicker";};};},hide:function(){document.body.removeChild(id("datepicker"));if(id("dp_iframe"))document.body.removeChild(id("dp_iframe"));},show:function(field,month,year){if(datepicker.timeout)clearTimeout(datepicker.timeout);if(id("datepicker")){if(isNaN(month)||month==null)return;datepicker.hide();};field=id(field);var selectedDate=/\d\d\/\d\d\/\d\d\d\d/.test(field.value)?new Date(field.value.substr(6,4),field.value.substr(3,2)- 1,field.value.substr(0,2)):new Date();month=(isNaN(month)||month==null)?selectedDate.getMonth():month;year=(isNaN(year)||year==null)?selectedDate.getFullYear():year;thisDate=new Date();thisDate=new Date(thisDate.getFullYear(),thisDate.getMonth(),thisDate.getDate());firstDay=new Date(year,month,1);firstDay.setDate(firstDay.getDate()-(firstDay.getDay()||7)+ 1);var picker=document.createElement("div");picker.id="datepicker";picker.appendChild(document.createElement("h5")).appendChild(document.createTextNode(datepicker.months[month][0]+" "+ year));table=picker.appendChild(document.createElement("table"))
tr=table.appendChild(document.createElement("thead")).appendChild(document.createElement("tr"));for(i=0;i<7;i++){th=tr.appendChild(document.createElement("th"));th.appendChild(document.createTextNode(datepicker.days[i].substr(0,1)));th.setAttribute("scope","col")
th.setAttribute("abbr",datepicker.days[i])
th.setAttribute("title",datepicker.days[i])
if(i>4)th.className="wend";};day=firstDay;tbody=table.appendChild(document.createElement("thead"))
do{tr=tbody.appendChild(document.createElement("tr"));for(i=0;i<7;i++){td=tr.appendChild(document.createElement("td"));if(day<thisDate){td.appendChild(document.createElement("span")).appendChild(document.createTextNode(day.getDate()));}else{a=td.appendChild(document.createElement("a"));a.appendChild(document.createTextNode(day.getDate()));var dateString=(day.getDate()<10?"0":"")+ day.getDate()+"/"+(day.getMonth()<9?"0":"")+(day.getMonth()+ 1)+"/"+ day.getFullYear()
a.href="javascript:datepicker.set('"+ field.id+"', '"+ dateString+"');";};if(i>4)td.className+=" wend";if(day.getMonth()!==month)td.className="preview";if(day.toDateString()==thisDate.toDateString())td.className+=" today";if(day.toDateString()==selectedDate.toDateString())td.className+=" selected";day.setDate(day.getDate()+ 1);};}while(day.getMonth()<=month&&day.getFullYear()<=year);ul=picker.appendChild(document.createElement("ul"))
a=ul.appendChild(document.createElement("li")).appendChild(document.createElement("a"));a.appendChild(document.createTextNode("prev"));a.parentNode.className="prev";a.href="javascript:datepicker.show('"+ field.id+"', "+(month- 1<0?11:month- 1)+", "+(month- 1<0?year- 1:year)+");"
a=ul.appendChild(document.createElement("li")).appendChild(document.createElement("a"));a.appendChild(document.createTextNode("next"));a.parentNode.className="next";a.href="javascript:datepicker.show('"+ field.id+"', "+(month+ 1>11?0:month+ 1)+", "+(month+ 1>11?year+ 1:year)+");"
var linkPos=dimensions.screenPos(id("dp_ftArrival"));var scrollPos=dimensions.scrollPos();var ltIE7=false;if(ltIE7){iframe=document.createElement("iframe");iframe.setAttribute("id","dp_iframe");iframe.setAttribute("src","about:blank");iframe.setAttribute("scrolling","no");iframe.setAttribute("frameBorder","0");iframe.className="datepicker";document.body.appendChild(iframe);};picker.onmouseout=function(){datepicker.timeout=setTimeout("datepicker.hide()",500);};picker.onmouseover=function(){clearTimeout(datepicker.timeout);};document.body.appendChild(picker);picker.style.left=(linkPos[0]+ scrollPos[0]+ 23- picker.offsetWidth)+"px";picker.style.top=(linkPos[1]+ scrollPos[1]+ 22)+"px";if(ltIE7){iframe.style.height=picker.offsetHeight+"px";iframe.style.width=picker.offsetWidth+"px";iframe.style.left=(linkPos[0]+ scrollPos[0]+ 23- picker.offsetWidth)+"px";iframe.style.top=(linkPos[1]+ scrollPos[1]+ 22)+"px";};},set:function(fieldId,value){id(fieldId).value=value;datepicker.hide();}};addDOMLoadEvent(datepicker.init);
