function CalendarRange(C,B,D,A){this.setHowManyDays=CalendarRange_setHowManyDays;this.setFullMonthsOnly=CalendarRange_setFullMonthsOnly;this.draw=CalendarRange_draw;this.setDate=CalendarRange_setDate;this.getStartDateFromString=CalendarRange_getStartDateFromString;this.getStartDateFrom=CalendarRange_getStartDateFrom;this.getEndDateFromString=CalendarRange_getEndDateFromString;this.getEndDateFrom=CalendarRange_getEndDateFrom;this.parseUserDateInput=CalendarRange_parseUserDateInput;this.refReturnField=CalendarRange_refReturnField;this.selectWeekends=CalendarRange_selectWeekends;this.selectWorkdays=CalendarRange_selectWorkdays;this.selectMonth=CalendarRange_selectMonth;this.selectDays=CalendarRange_selectDays;this.getFromBitfield=CalendarRange_getFromBitfield;this.setToBitfield=CalendarRange_setToBitfield;this.returnWindow=C;this.name=A;this.returnForm=B;this.returnTextfield=D;this.startday=null;this.startmonth=null;this.startyear=null;this.endday=null;this.endmonth=null;this.endyear=null;this.howmanydays=1;this.howmanymonths=1;this.fullMonthsOnly=true;this.monthsTexts=new Array();this.weekdaysTexts=new Array();this.readOnly=false}function CalendarRange_setFullMonthsOnly(A){this.fullMonthsOnly=A;this.setHowManyDays(90)}function CalendarRange_setHowManyDays(D){if(this.fullMonthsOnly==true){this.startday=1;var B=new Date(this.startyear,this.startmonth,this.startday);this.howmanydays=0;var E=-1;var C=0;while(C<=this.howmanymonths){this.howmanydays++;if(B.getMonth()!=E){E=B.getMonth();C++}B.setDate(B.getDate()+1)}B.setDate(B.getDate()-2);this.endyear=B.getFullYear();this.endmonth=B.getMonth();this.endday=B.getDate()}else{this.howmanydays=D;var B=new Date(this.startyear,this.startmonth,this.startday);var A=new Date(this.endyear,this.endmonth,this.endday);if((B!=null)&&(A!=null)){while((B.getTime()<A.getTime())&&(D>=0)){B.setDate(B.getDate()+1);D--}if(B.getTime()<=A.getTime()){this.endyear=B.getFullYear();this.endmonth=B.getMonth();this.endday=B.getDate()}}}}function CalendarRange_getStartDateFrom(ioField){eval("userInput = "+this.returnWindow+"."+this.returnForm+"."+ioField+".value;");this.getStartDateFromString(userInput)}function CalendarRange_getStartDateFromString(D){var C=this.parseUserDateInput(D);this.startday=C.getDate();this.startmonth=C.getMonth();this.startyear=C.getFullYear();var A=new Date(this.endyear,this.endmonth,this.endday);if((C!=null)&&(A!=null)){var B=0;while(C.getTime()<=A.getTime()){C.setDate(C.getDate()+1);B++}this.howmanydays=B}}function CalendarRange_getEndDateFrom(ioField){eval("userInput = "+this.returnWindow+"."+this.returnForm+"."+ioField+".value;");this.getEndDateFromString(userInput)}function CalendarRange_getEndDateFromString(D){var A=this.parseUserDateInput(D);this.endday=A.getDate();this.endmonth=A.getMonth();this.endyear=A.getFullYear();var C=new Date(this.startyear,this.startmonth,this.startday);if(C!=null&&A!=null){var B=0;while(C.getTime()<=A.getTime()){C.setDate(C.getDate()+1);B++}this.howmanydays=B}}function CalendarRange_parseUserDateInput(A){var B=/(\d+)\D+(\d+)\D+(\d+)\D*/;var C=B.exec(A);userInput_day=RegExp.$1;userInput_month=RegExp.$2;userInput_year=RegExp.$3;if(!C){return new Date()}userInput_day*=1;userInput_month*=1;userInput_year*=1;if(userInput_month!=""){userInput_month-=1;if(userInput_month<0){userInput_month=11}else{if(userInput_month>11){userInput_month=0}}}if(userInput_year!=""){if(userInput_year<100){if(userInput_year<50){userInput_year+=2000}else{userInput_year+=1900}}else{if(userInput_year<1000){if(userInput_year<200){userInput_year+=1900}else{userInput_year+=1000}}}}return new Date(userInput_year,userInput_month,userInput_day)}function CalendarRange_refReturnField(){return this.returnWindow+"."+this.returnForm+"."+this.returnTextfield}function CalendarRange_setDate(A){var B=document.getElementById(A);B.className=(B.className=="active")?"enabled":"active"}function CalendarRange_draw(){if((this.lastdrawstartday!=this.startday)||(this.lastdrawstartmonth!=this.startmonth)||(this.lastdrawstartyear!=this.startyear)||(this.lastdrawendday!=this.endday)||(this.lastdrawendmonth!=this.endmonth)||(this.lastdrawendyear!=this.endyear)){this.lastdrawstartday=this.startday;this.lastdrawstartmonth=this.startmonth;this.lastdrawstartyear=this.startyear;this.lastdrawendday=this.endday;this.lastdrawendmonth=this.endmonth;this.lastdrawendyear=this.endyear;var div=document.getElementById(this.name);var numMonths=0;var table=document.getElementById(this.name+"_table");if(table==null){table=document.createElement("TABLE");div.insertBefore(table,div.firstChild);table.id=this.name+"_table";table.className="calendar";table.setAttribute("cellspacing","0")}var tbody=document.getElementById(this.name+"_tbody");if(tbody!=null){tbody.parentNode.removeChild(tbody)}tbody=document.createElement("TBODY");table.appendChild(tbody);tbody.id=this.name+"_tbody";tempdate=new Date(this.startyear,this.startmonth,1);var tempstartdate=new Date(this.startyear,this.startmonth,this.startday);var tempenddate=new Date(this.endyear,this.endmonth,this.endday);var maxMonthReached=false;var maxMonthsPerRow=6;var latestHeader=null;calendarRow=0;while(tempenddate>=tempdate){var cell=null;++calendarRow;numMonths=0;daystoskip=(tempdate.getDay()-1<0)?6:tempdate.getDay()-1;var newmonth=true;var oldtempcolspan=0;var colspan=1;var w=-1;var newWeekNeeded=true;var numWeeksInMonth=0;while(newWeekNeeded==true){++w;++numWeeksInMonth;if(tempdate.getDate()==1&&newmonth==true){numWeeksInMonth=1;++numMonths;daystoskip=(tempdate.getDay()-1<0)?6:tempdate.getDay()-1;var current_row=document.getElementById(this.name+"_monthrow_"+calendarRow);if(current_row==null){current_row=document.createElement("TR");current_row.id=this.name+"_monthrow_"+calendarRow;mycurrent_cell=document.createElement("TH");mycurrent_cell.className="disabled";mycurrent_cell.innerHTML="&nbsp";current_row.appendChild(mycurrent_cell)}mycurrent_cell=document.createElement("TH");latestHeader=mycurrent_cell;mycurrent_cell.innerHTML="<b>"+this.monthsTexts[tempdate.getMonth()]+"&nbsp;"+tempdate.getFullYear()+"</b>";mycurrent_cell.setAttribute("style","text-align: center;");mycurrent_cell.className="enabled";mycurrent_cell.id=this.name+"_heading_months"+tempdate.getMonth()+"-"+tempdate.getFullYear();if(this.readOnly==false){mycurrent_cell.onclick=function(){var calid=this.id.substring(0,this.id.indexOf("_heading_months"));var month=this.id.substring(this.id.indexOf("_heading_months")+15,this.id.indexOf("-"));var year=this.id.substring(this.id.indexOf("-")+1,this.id.length);var test=eval("calid")+".selectMonth(month,year);";eval(test)}}current_row.appendChild(mycurrent_cell);if(numMonths==1){tbody.insertBefore(current_row,null)}}for(var d=0;d<7;d++){current_row=document.getElementById(this.name+"_row_"+d+"_"+calendarRow);if(current_row==null){current_row=document.createElement("TR");current_row.id=this.name+"_row_"+d+"_"+calendarRow;cell=document.createElement("TH");cell.id=this.name+"_heading_"+d;cell.innerHTML="<b>"+this.weekdaysTexts[d]+"</b>";cell.className="enabled";if(this.readOnly==false){cell.onclick=function(){var calid=this.id.substring(0,this.id.indexOf("_heading_"));var day=this.id.substring(this.id.indexOf("_heading_")+9,this.id.length);var test=eval("calid")+".selectDays(day);";eval(test)}}cell.style.width="40px";current_row.appendChild(cell);tbody.appendChild(current_row)}var nextDay=new Date(tempdate);nextDay.setDate(tempdate.getDate()+1);newmonth=(nextDay.getMonth()!=tempdate.getMonth());cell=document.createElement("TD");if(daystoskip<=0){if((tempdate>tempenddate)||(tempdate<tempstartdate)){cell.className="disabled";cell.innerHTML=tempdate.getDate();cell.onclick=null}else{cell.innerHTML=tempdate.getDate();cell.id=this.name+"_df_"+tempdate.getFullYear()+"/"+(tempdate.getMonth())+"/"+tempdate.getDate();cell.className="enabled";if(this.readOnly==false){cell.onclick=function(){var calid=this.id.substring(0,this.id.indexOf("_df"));var test=eval("calid")+".setDate(this.id);";eval(test)}}}tempdate.setDate(tempdate.getDate()+1)}else{cell.className="disabled";cell.innerHTML="&nbsp;";cell.onclick=null;daystoskip-=1}current_row.appendChild(cell);if(newmonth){latestHeader.setAttribute("colSpan",numWeeksInMonth);for(var e=d;e<6;e++){cell=document.createElement("TD");cell.className="disabled";cell.innerHTML="&nbsp;";current_row=document.getElementById(this.name+"_row_"+(e+1)+"_"+calendarRow);if(current_row!=null){current_row.appendChild(cell)}}break}}if(((tempdate>tempenddate)||(numMonths>=maxMonthsPerRow))&&(tempdate.getDate()==1)){newWeekNeeded=false}if(numMonths>=maxMonthsPerRow){maxMonthReached=true}}}document.getElementById(this.name).style.width="auto";if(maxMonthReached==true){calendarWidth=1*maxMonthsPerRow*120+60+"px"}else{addWidth=(numMonths==1)?85:60;calendarWidth=1*numMonths*120+1*addWidth+"px"}document.getElementById(this.name).style.width=calendarWidth}}function CalendarRange_selectWeekends(D){var C=new Date(this.startyear,this.startmonth,this.startday);var B=null;var A=null;for(i=0;i<=this.howmanydays;i++){if(C.getDay()==6||C.getDay()==0){A=this.name+"_df_"+C.getFullYear()+"/"+(C.getMonth())+"/"+C.getDate();B=document.getElementById(A);if(B!=null){B.className=(D==true)?"active":"enabled"}}C.setDate(C.getDate()+1)}}function CalendarRange_selectWorkdays(C){var B=new Date(this.startyear,this.startmonth,this.startday);for(i=0;i<=this.howmanydays;i++){if(B.getDay()>=1&&B.getDay()<=5){var A=this.name+"_df_"+B.getFullYear()+"/"+(B.getMonth())+"/"+B.getDate();elem=document.getElementById(A);if(elem!=null){elem.className=(C)?"active":"enabled"}}B.setDate(B.getDate()+1)}}function CalendarRange_selectDays(D){var C=new Date(this.startyear,this.startmonth,this.startday);var B=null;var A=null;for(i=0;i<=this.howmanydays;i++){A=C.getDay()-1;A=(A==-1)?6:A;if(A==D){elem=document.getElementById(this.name+"_df_"+C.getFullYear()+"/"+(C.getMonth())+"/"+C.getDate());if(elem!=null){if(B==null){B=(elem.className=="active")?1:0}elem.className=(B==1)?"enabled":"active"}i+=6;C.setDate(C.getDate()+7)}else{C.setDate(C.getDate()+1)}}}function CalendarRange_selectMonth(F,E){var C=new Date(E,F,1);var B=null;var D=null;var A=null;for(i=0;i<=this.howmanydays;i++){D=C.getMonth();if(D==F){A=true;elem=document.getElementById(this.name+"_df_"+C.getFullYear()+"/"+(C.getMonth())+"/"+C.getDate());if(elem!=null){if(B==null){B=(elem.className=="active")?1:0}elem.className=(B==1)?"enabled":"active"}}else{if(A==true){break}}C.setDate(C.getDate()+1)}}function CalendarRange_getFromBitfield(bitfield){if(bitfield==null){eval("bitfield = "+this.refReturnField()+".value;")}var tempdate=new Date(this.startyear,this.startmonth,this.startday);for(i=0;i<this.howmanydays;i++){elem=document.getElementById(this.name+"_df_"+tempdate.getFullYear()+"/"+(tempdate.getMonth())+"/"+tempdate.getDate());if(elem!=null){elem.className=(bitfield.charAt(i)=="0")?"enabled":"active"}tempdate.setDate(tempdate.getDate()+1)}}function CalendarRange_setToBitfield(){var tempdate=new Date(this.startyear,this.startmonth,this.startday);var bitfield="";var lastactive="";var firstactive="";for(i=0;i<this.howmanydays;i++){elem=document.getElementById(this.name+"_df_"+tempdate.getFullYear()+"/"+(tempdate.getMonth())+"/"+tempdate.getDate());if(elem!=null){if(elem.className=="active"){if(firstactive==""){firstactive=elem}bitfield+="1";lastactive=elem}else{bitfield+="0"}}tempdate.setDate(tempdate.getDate()+1)}bitfield=bitfield+"";eval(this.refReturnField()+'.value = "'+bitfield+'"')}function isLeapYear(A){if(((A%4)==0&&(A%100)!=0)||(A%400)==0){return true}}function openCalDiv(A,C){var B=window.document.getElementById(A);if(B.style.display=="none"){cal2.getStartDateFrom(C+"Date1");cal2.getEndDateFrom(C+"Date2");cal2.draw();cal2.getFromBitfield();B.style.display="block"}else{B.style.display="none"}}function openCal(A){cal2.readOnly=true;cal2.draw();cal2.getFromBitfield()};
