/* www.wsabstract.com/script/script2/buttoncalendar.shtml http://javascriptkit.com/script/script2/buttoncalendar.shtml */
function setDate(str) {if (str=="   ") return;mnth1=document.forms[0].month.value;mnth=mnth1;mnth++;
year=document.forms[0].year.value;dateStr=mnth+"/"+str+"/"+year;dateStr=trim(dateStr);document.forms[1].dateField.value=dateStr;}
function setDateWithSelect() {var mnth1=document.forms[0].selectMonth[document.forms[0].selectMonth.selectedIndex].value;
var mnth=mnth1;mnth++;var year=document.forms[0].selectYear[document.forms[0].selectYear.selectedIndex].value;
var mnthName=getMonthName(mnth1);
document.forms[0].month.value=mnth1;document.forms[0].myMonth.value=mnthName;document.forms[0].year.value=year;document.forms[0].myYear.value=year;
var str=mnth+"/1/"+year;var dt=new Date(str);var dayOfWeek=dt.getDay();var noOfDays=getNoOfDaysInMnth(mnth,year);
fillDates(dayOfWeek+1,noOfDays);}
function trim(str) {
res=""; for(var i=0;i< str.length; i++) 
if (str.charAt(i) != " ") res +=str.charAt(i);return res;}
function getMonthName(mnth) {
return months[mnth];}
function getNoOfDaysInMnth(mnth,yr) {
rem=yr % 4;if(rem==0) leap=1;else leap=0;noDays=0;
if ((mnth==1)||(mnth==3)||(mnth==5)||(mnth==7)||(mnth==8)||(mnth==10)||(mnth==12)) noDays=31;
else if (mnth==2) noDays=28+leap;else noDays=30;return noDays;}
function fillDates(dayOfWeek1,noOfDaysInmnth) {
for(var i=1;i<43;i++) {str="s"+i;document.forms[0].elements[str].value="   ";}
startSlotIndx=dayOfWeek1;slotIndx=startSlotIndx;
for(var i=1; i<(noOfDaysInmnth+1);i++) {
slotName="s"+slotIndx;val="";if (i<10) {val=" "+i+" ";} else {val=i;}
document.forms[0].elements[slotName].value=val;
slotIndx++;}}//fillDates()
/* The function that is called at the time of loading the page.
This function displays Today's date and also displays the calendar of the current month. */
function thisMonth() {dt=new Date();mnth=dt.getMonth(); /* 0-11*/
dayOfMnth=dt.getDate(); /* 1-31*/
dayOfWeek=dt.getDay(); /*0-6*/
yr=dt.getFullYear(); /*4-digit year*/
//alert("month:"+(mnth+1)+":dayofMnth:"+dayOfMnth+":dayofweek:"+dayOfWeek+":year:"+yr);
mnthName=getMonthName(mnth)+ " ";document.forms[0].month.value=mnth;document.forms[0].year.value=yr;
document.forms[0].currMonth.value=mnth;document.forms[0].currYear.value=yr;
document.forms[0].myMonth.value=mnthName;document.forms[0].myYear.value=yr;
document.forms[0].selectMonth.selectedIndex=mnth;document.forms[0].selectYear.selectedIndex=yr-1583;
document.forms[1].dateField.value=(mnth+1)+"/"+dayOfMnth+"/"+yr;startStr=(mnth+1)+"/1/"+yr;
dt1=new Date(startStr);dayOfWeek1=dt1.getDay(); /*0-6*/
noOfDaysInMnth=getNoOfDaysInMnth(mnth+1,yr);fillDates(dayOfWeek1+1,noOfDaysInMnth);document.forms[0].elements["s"+(dayOfMnth+dayOfWeek1)].focus();
}//thisMonth()
/* The function that will be used to display the calendar of the next month. */
function nextMonth() {var currMnth=document.forms[0].month.value;var currYr=document.forms[0].year.value;
if (currMnth=="11") nextMnth=0;else {nextMnth=currMnth;nextMnth++;}
mnthName = getMonthName(nextMnth);document.forms[0].month.value=nextMnth;document.forms[0].myMonth.value= mnthName;
document.forms[0].selectMonth.selectedIndex=nextMnth;str=(nextMnth+1)+"/1/"+currYr;
dt=new Date(str);dayOfWeek=dt.getDay();noOfDays=getNoOfDaysInMnth(nextMnth+1,currYr);fillDates(dayOfWeek+1,noOfDays);
}//nextMonth()
/* The method to display the calendar of the previous month. */
function prevMonth() {var currMnth=document.forms[0].month.value;var currYr=document.forms[0].year.value;
if (currMnth=="0") nextMnth=11;else {nextMnth=currMnth;nextMnth--;}
mnthName=getMonthName(nextMnth);document.forms[0].month.value=nextMnth;document.forms[0].myMonth.value=mnthName;
document.forms[0].selectMonth.selectedIndex=nextMnth;str=(nextMnth+1)+"/1/"+currYr;
dt=new Date(str);dayOfWeek=dt.getDay();noOfDays=getNoOfDaysInMnth(nextMnth+1,currYr);fillDates(dayOfWeek+1,noOfDays);
}//prevMonth()
function nextYear() {var currMnth=document.forms[0].month.value;var currYr=document.forms[0].year.value;
currYr++;document.forms[0].year.value=currYr;document.forms[0].myYear.value=currYr;
document.forms[0].selectYear.selectedIndex=currYr-1583;str=(currMnth+1)+"/1/"+currYr;
dt=new Date(str);dayOfWeek=dt.getDay();noOfDays = getNoOfDaysInMnth(currMnth+1,currYr);fillDates(dayOfWeek+1,noOfDays);}
function prevYear() {var currMnth=document.forms[0].month.value;var currYr=document.forms[0].year.value;currYr--;
document.forms[0].year.value=currYr;document.forms[0].myYear.value=currYr;document.forms[0].selectYear.selectedIndex=currYr-1583;
str=(currMnth+1)+"/1/"+currYr;
dt=new Date(str);dayOfWeek = dt.getDay();noOfDays=getNoOfDaysInMnth(currMnth+1,currYr);
fillDates(dayOfWeek+1,noOfDays);}