
Date.prototype.savedDate=null;Date.prototype.getMonthName=dateGetMonthName;Date.prototype.getDays=dateGetDays;Date.prototype.addDays=dateAddDays;Date.prototype.addMonths=dateAddMonths;Date.prototype.addYears=dateAddYears;var targetDate=new Date();var initd=false;function setCal(str){initd=true;l=str.length;f=0;pyear="";pmonth="";pday="";for(i=0;i<l;i++){ch=str.charAt(i);if(ch=="-"){f=f+1;}else{if(f==0){pyear=pyear+ch;}
if(f==1){pmonth=pmonth+ch;}
if(f==2){pday=pday+ch;}}}
myDate=new Date();myDate.setFullYear(pyear);myDate.setMonth(pmonth-1);myDate.setDate(pday);targetDate=myDate;setCalendar();}
function setCalendar(event){initd=true;var el,tableEl,rowEl,cellEl,linkEl;var tmpDate,tmpDate2;var i,j;document.body.style.display="none";el=document.getElementById("calendarHeader").firstChild;el.nodeValue=targetDate.getMonthName()+"\u00a0"+targetDate.getFullYear();tmpDate=new Date(Date.parse(targetDate));tmpDate.setDate(1);while(tmpDate.getDay()!=0){tmpDate.addDays(-1);}
tableEl=document.getElementById("calendar");for(i=2;i<=7;i++){rowEl=tableEl.rows[i];for(j=0;j<rowEl.cells.length;j++){cellEl=rowEl.cells[j];linkEl=cellEl.firstChild;if(tmpDate.getMonth()==targetDate.getMonth()){linkEl.date=new Date(Date.parse(tmpDate));s=tmpDate.toString().split(" ");linkEl.firstChild.nodeValue=tmpDate.getDate();linkEl.style.visibility="";}
else
linkEl.style.visibility="hidden";if(cellEl.oldClass==null)
cellEl.oldClass=cellEl.className;else if(cellEl.oldClass.match("weekend"))
cellEl.oldClass="weekend";else
cellEl.oldClass="";if(Date.parse(tmpDate)==Date.parse(targetDate))
cellEl.className=cellEl.oldClass+" target";else
cellEl.className=cellEl.oldClass;tmpDate.addDays(1);}}
document.body.style.display="";}
function addMonths(event,n,str){if(!initd){setCal(str);}
targetDate.addMonths(n);setCalendar(event);}
function addYears(event,n,str){if(!initd){setCal(str);}
targetDate.addYears(n);setCalendar(event);}
function setTargetDate(event,link){if(link.date==null){window.location=link;}else{targetDate=new Date(Date.parse(link.date));setCalendar(event);var mylink=calref+"?date="+formatDate(targetDate);window.location=mylink;}}
function displayDate(event){alert(formatDate(targetDate));}
function formatDate(){var mm,dd,yyyy;mm=String(targetDate.getMonth()+1);while(mm.length<2)
mm="0"+mm;dd=String(targetDate.getDate());while(dd.length<2)
dd="0"+dd;yyyy=String(targetDate.getFullYear());while(yyyy.length<4)
yyyy="0"+yyyy;return yyyy+"-"+mm+"-"+dd;}
function dateGetMonthName(){return this.monthNames[this.getMonth()];}
function dateGetDays(){var tmpDate,d,m;tmpDate=new Date(Date.parse(this));m=tmpDate.getMonth();d=28;do{d++;tmpDate.setDate(d);}while(tmpDate.getMonth()==m);return d-1;}
function dateAddDays(n){this.setDate(this.getDate()+n);this.savedDate=this.getDate();}
function dateAddMonths(n){if(this.savedDate==null)
this.savedDate=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+n);this.setDate(Math.min(this.savedDate,this.getDays()));}
function dateAddYears(n){if(this.savedDate==null)
this.savedDate=this.getDate();this.setDate(1);this.setFullYear(this.getFullYear()+n);this.setDate(Math.min(this.savedDate,this.getDays()));}
