Calendar.prototype.updateDaySelectOptions=function(){var f=this.dayField.options;var c=0;var b=0;var a=this.displayDate.getMonth();var h=this.displayDate.getDate();var e=new Date(this.displayDate);for(var g=1;g<=31;++g){e.setDate(g);if(a==e.getMonth()){if(e.dateWithinRanges(this.dateRanges)){if(g==h){b=c}f[c]=new Option(e.format(daySelectFormat),g);++c}}}f.length=c;this.dayField.selectedIndex=b};Calendar.prototype.updateMonthYearSelectOptions=function(){var l=this.monthYearField.options;var a=0;var d=0;var b=this.displayDate.getMonth();var f=this.displayDate.getFullYear();var e=this.endDate.getMonth();var j=this.endDate.getFullYear();var k=new Date(this.startDate);k.setDate(1);var c=k.getMonth();var g=k.getFullYear();while(g<j||(c<=e&&g<=j)){if(k.monthWithinRanges(this.dateRanges)){if(c==b&&g==f){d=a}var h=buildMonthYearSelectLabel(k.getShortMonth(),g);var i=(c+1)+","+g;l[a]=new Option(h,i);++a}k.setMonth(c+1);c=k.getMonth();g=k.getFullYear()}l.length=a;this.monthYearField.selectedIndex=d};Calendar.prototype.updateHourSelectOptions=function(){var d=this.hourField.options;var g=this.hourField.value;d.length=0;var c=new DateRange(new Date(this.displayDate),new Date(this.displayDate));c.from.setHours(0,0,0);c.to.setHours(11,59,59);var f=false;var a=null;if(this.isAnytime){if(this.isAnytimeSelected||!this.hasUserSetHour){a=d.length}d[d.length]=new Option(Date.time[0],"Anytime",false,false)}if(c.intersectsRanges(this.dateRanges)){if(this.hourRangeSelected&&c.withinRange(this.displayDate)&&a==null){a=d.length}d[d.length]=new Option(Date.time[1],"Morning",false,false)}c.from.setHours(12,0,0);c.to.setHours(17,59,59);if(c.intersectsRanges(this.dateRanges)){if(this.hourRangeSelected&&c.withinRange(this.displayDate)&&a==null){a=d.length}d[d.length]=new Option(Date.time[2],"Afternoon",false,false)}c.from.setHours(18,0,0);c.to.setHours(20,59,59);if(c.intersectsRanges(this.dateRanges)){if(this.hourRangeSelected&&c.withinRange(this.displayDate)&&a==null){a=d.length}d[d.length]=new Option(Date.time[3],"Evening",false,false)}var b=new Date(this.displayDate);for(var e=1;e<=23;++e){b.setHours(e,0,0);if(b.withinRanges(this.dateRanges)){if(a==null&&e==this.displayDate.getHours()){a=d.length}d[d.length]=new Option((e<10?("0"+e+":00"):(e+":00")),e,false,false)}}this.hourField.selectedIndex=a};Calendar.prototype.updateFormInputs=function(){if(this.haveFieldsBeenInserted){var a="YYYYmmDD0000";if(this.startDate.format("YYYYmmDDHH00")==this.displayDate.format("YYYYmmDDHH00")){a="YYYYmmDDHH00"}this.formattedField.value=this.displayDate.format(a);this.bookLeadFormattedField.value=this.startDate.format(a);this.timeField.value=this.displayDate.getTime();this.yearField.value=this.displayDate.getFullYear();this.monthField.value=this.displayDate.getMonth()+1;if(this.showMonthYearField){this.updateMonthYearSelectOptions()}else{this.monthYearField.value=this.monthField.value+","+this.yearField.value}if(this.showDayField){this.updateDaySelectOptions()}else{this.dayField.value=this.displayDate.getDate()}if(this.showHourField){this.updateHourSelectOptions()}else{this.hourField.value=this.displayDate.getHours()}}};Calendar.prototype.update=function(a){this.displayDate=new Date(a.getTime());if(!this.displayDate.withinRanges(this.dateRanges)){this.pullWithinRange()}this.updateFormInputs();this.divCalendar.innerHTML=this.createCalendarHtml();if(this.onChangeCallback!=null){this.onChangeCallback()}if(this.popup!=null){if(this.useIePopup){this.popup.document.body.innerHTML=this.divCalendar.innerHTML}else{this.popup=this.divCalendar}}};Calendar.prototype.pullWithinRange=function(){var b=false;var a=null;var d=null;var c=this.displayDate.getTime();for(var e=0;e<this.dateRanges.length;++e){var g=this.dateRanges[e].from.getTime();var f=this.dateRanges[e].to.getTime();if(f<c&&(a==null||(c-f)<(c-a.getTime()))){a=new Date(f)}else{if(c<g&&(d==null||(g-c)<(d.getTime()-c))){d=new Date(g)}}}if(a!=null&&a.getMonth()==this.displayDate.getMonth()){this.displayDate=a}else{if(d!=null&&d.getMonth()==this.displayDate.getMonth()){this.displayDate=d}else{this.displayDate=this.dateRanges[0].from}}};Calendar.prototype.updateDayOfMonth=function(b){var a=new Date(this.displayDate);a.setDate(b);if(this.hasUserSetHour==false&&this.defaultHour!=null&&this.defaultHour>=0&&this.defaultHour<=23){a.setHours(this.defaultHour,0,0)}this.update(a);this.adjustHourOfDay()};Calendar.prototype.updateMonthYear=function(c){var d=c.split(",");var a=d[0]-1;var e=d[1];var b=new Date(this.displayDate);b.setFullYear(e);b.setMonth(a);while(a!=b.getMonth()){b.setTime(b.getTime()-24*60*60*1000)}if(this.hasUserSetHour==false&&this.defaultHour!=null&&this.defaultHour>=0&&this.defaultHour<=23){b.setHours(this.defaultHour,0,0)}this.update(b);this.adjustHourOfDay()};Calendar.prototype.updateHourOfDay=function(c){this.hasUserSetHour=true;this.hourRangeSelected=isNaN(parseInt(c));var b=c.toString().toLowerCase();if("morning"==b){c=(this.isAnytime==true)?6:1}else{if("afternoon"==b){c=(this.isAnytime==true)?15:12}else{if("evening"==b){c=(this.isAnytime==true)?20:18}}}if("anytime"==b){this.isAnytimeSelected=true;c=12}else{this.isAnytimeSelected=false}var a=new Date(this.displayDate);a.setHours(c);this.update(a);this.adjustHourOfDay()};Calendar.prototype.adjustHourOfDay=function(){if(this.hourRangeSelected){var c=this.hourField.value;var b=c.toString().toLowerCase();if("morning"==b){c=(this.isAnytime==true)?6:1}else{if("afternoon"==b){c=(this.isAnytime==true)?15:12}else{if("evening"==b){c=(this.isAnytime==true)?20:18}}}if("anytime"==b){this.isAnytimeSelected=true;c=12}else{this.isAnytimeSelected=false}if(c!=this.displayDate.getHours()){var a=new Date(this.displayDate);a.setHours(c);this.update(a)}}};Calendar.prototype.createCalendarHtml=function(){var n='<table class="calendar" cellspacing="0" ';if(this.showCalendarIcon){n+='onmouseout="javascript:'+this.popupVarName()+'.mouseOut();" onmouseover="javascript:'+this.popupVarName()+'.mouseOver();"'}n+='>\n<tr>\n<td style="padding:0;">\n<table class="months" cellspacing="0">\n<tr>';var g=this.displayDate.getDate();var a=this.displayDate.getMonth();var h=this.displayDate.getFullYear();var e=this.endDate.getMonth();var o=this.endDate.getFullYear();var p=new Date(this.startDate);p.setDate(1);var b=p.getMonth();var l=p.getFullYear();var d=0;while(l<o||(b<=e&&l<=o)||d%7!=0){n+="<th ";if(p.monthWithinRanges(this.dateRanges)){var k=(b+1)+","+l;if(b==a&&l==h){n+=' class="active"'}else{n+=' class="month"';n+=' onclick="javascript:'+this.popupVarName()+".updateMonthYear('"+k+'\');" title="'+p.getShortMonth()+" "+l+'"';n+=" onmouseover=\"javascript:this.className+=' hover';\"";n+=" onmouseout=\"javascript:this.className=this.className.replace(/ hover/,'');\""}}else{n+=' class="disabled" '}n+=">"+p.getShortMonth()+"</th>";p.setMonth(b+1);b=p.getMonth();l=p.getFullYear();if(++d%7==0){n+="\n</tr>\n<tr>"}}n+="\n</tr>";n+="\n</table>";n+='\n<table class="date"><tr><th>'+this.displayDate.format(calendarDateDisplayFormat)+"</th></tr></table>";n+='\n<table class="days">';n+="\n<tr><th>"+p.getShortDayIndex(0)+"</th><th>"+p.getShortDayIndex(1)+"</th><th>"+p.getShortDayIndex(2)+"</th><th>"+p.getShortDayIndex(3)+"</th><th>"+p.getShortDayIndex(4)+"</th><th>"+p.getShortDayIndex(5)+"</th><th>"+p.getShortDayIndex(6)+"</th></tr>";var p=new Date(this.displayDate);p.setDate(1);var f=p.getDay();for(var d=0;d<6;++d){n+="\n<tr>";for(var c=0;c<7;++c){if((c+7*d)>=f&&p.getMonth()==this.displayDate.getMonth()){n+="<td ";if(this.dateRanges==null||p.dateWithinRanges(this.dateRanges)){if(p.getDate()==g&&p.getMonth()==a&&p.getYear()==h){n+=' class="active"'}else{n+=' class="date"';n+=" onmouseover=\"javascript:this.className=this.className+' hover';\"";n+=" onmouseout=\"javascript:this.className=this.className.replace(/ hover/ig,'');\""}n+=' onclick="javascript:'+this.popupVarName()+".hidePopup();"+this.popupVarName()+".updateDayOfMonth("+p.getDate()+');"'}else{n+=' class="disabled"'}n+=">"+p.getDate()+"</td>";p.setDate((c+7*d)+2-f)}else{n+="<td>&nbsp;</td>"}}n+="</tr>"}n+="\n</table>\n</td>\n</tr>\n</table>";return n};Calendar.prototype.millisecondTimeout=500;Calendar.prototype.useIePopup=(window.createPopup?true:false);Calendar.prototype.popupVarName=function(){return(this.useIePopup?("parent."+this.varName):this.varName)};Calendar.prototype.popupCreate=function(){this.clearPopupTimers();this.mouseOverCounter=0;this.popupX=0;this.popupY=this.dayField.offsetHeight+1;if(this.useIePopup){this.popup=this.win.createPopup();var b=this.popup.document.createElement("link");b.href=this.calendarCSS;b.rel="stylesheet";b.type="text/css";this.popup.document.body.parentNode.insertBefore(b,this.popup.document.body);this.popup.document.body.innerHTML=this.divCalendar.innerHTML;this.popup.show(0,this.monthYearField.offsetHeight,$j(this.divCalendar).width(),$j(this.divCalendar).height()+2,this.monthYearField)}else{var a=this.monthYearField;while(a.offsetParent!=null){a=a.offsetParent}this.popup=this.divCalendar;$j(this.popup).show()}this.mouseOver()};Calendar.prototype.mouseOver=function(){this.mouseOverCounter++};Calendar.prototype.mouseOut=function(){this.mouseOverCounter--;var a;(($j("body").find(".searchFragment").html()!=null||location.href.indexOf("showHeader=0")>-1)&&(this.useIePopup))?a=this.popupVarName().split(".")[1]:a=this.popupVarName();this.popupTimers.push(window.setTimeout(a+".timeoutPopup();",this.millisecondTimeout))};Calendar.prototype.timeoutPopup=function(){if(this.mouseOverCounter<=0){this.hidePopup()}};Calendar.prototype.clearPopupTimers=function(){while(this.popupTimers.length>0){window.clearTimeout(this.popupTimers.shift())}this.mouseOverCounter=0};Calendar.prototype.hidePopup=function(){this.clearPopupTimers();if(this.popup!=null){if(this.useIePopup){this.popup.hide()}else{$j(this.popup).hide()}}this.popup=null};Calendar.prototype.popupToggle=function(){if(this.popup==null&&!this.dayField.disabled&&!this.monthYearField.disabled){this.popupCreate()}else{this.hidePopup()}};Calendar.prototype.setEnabled=function(a){if(this.dayField.type!="hidden"){this.dayField.disabled=(!a)}if(this.monthYearField.type!="hidden"){this.monthYearField.disabled=(!a)}if(this.hourField.type!="hidden"){this.hourField.disabled=(!a)}if(a){this.calendarIcon.className=this.calendarIcon.className.replace(/disabled/ig,"")}else{this.calendarIcon.className+=" disabled"}};Calendar.prototype.createCalendar=function(b){this.fieldTag=this.doc.getElementById(this.fieldTagId);while(this.fieldTag.hasChildNodes()){this.fieldTag.removeChild(this.fieldTag.firstChild)}this.calendarTag=((this.calendarTagId==null)?null:this.doc.getElementById(this.calendarTagId));while(this.calendarTag!=null&&this.calendarTag.hasChildNodes()){this.calendarTag.removeChild(this.calendarTag.firstChild)}var a=this.doc.createElement("div");a.className="clearit";a.appendChild(this.monthYearField);a.appendChild(this.dayField);if(this.showCalendarIcon){a.appendChild(this.calendarIcon)}a.appendChild(this.hourField);a.appendChild(this.yearField);a.appendChild(this.monthField);a.appendChild(this.timeField);a.appendChild(this.formattedField);a.appendChild(this.bookLeadFormattedField);this.fieldTag.appendChild(a);this.haveFieldsBeenInserted=true;this.update(this.startDate);if(b){if(this.showCalendarIcon||this.calendarTagId==null){$j("#"+b).prepend(this.divCalendar)}else{this.calendarTag.appendChild(this.divCalendar)}}else{if(this.showCalendarIcon||this.calendarTagId==null){$j("#"+this.fieldTagId).prepend(this.divCalendar)}else{this.calendarTag.appendChild(this.divCalendar)}}};Calendar.prototype.setOnChangeCallback=function(a){this.onChangeCallback=a};Calendar.prototype.getDate=function(){return(this.displayDate==null?this.startDate:this.displayDate)};Calendar.prototype.setCalendarCSS=function(a){this.calendarCSS=a};Calendar.prototype.setDefaultHour=function(a){this.defaultHour=a};Calendar.prototype.setAnytime=function(a){this.isAnytime=a;if(this.showHourField){this.updateHourSelectOptions()}else{this.hourField.value=this.displayDate.getHours()}};Calendar.prototype.serialize=function(){return""+this.getDate().getTime()+"-"+(this.hourRangeSelected?1:0)+"-"+(this.hasUserSetHour?1:0)+"-"+(this.isAnytimeSelected?1:0)};Calendar.prototype.deserialize=function(b){var a=b.split("-");this.isAnytimeSelected=(a[3]=="1"?true:false);this.hasUserSetHour=(a[2]=="1"?true:false);this.hourRangeSelected=(a[1]=="1"?true:false);this.update(new Date(parseInt(a[0])))};Calendar.prototype.showHours=function(){this.hourField.style.visibility="visible"};Calendar.prototype.hideHours=function(){this.updateHourOfDay("Anytime");this.hourField.style.visibility="hidden"};function Calendar(f,g,j,e,h,i,k,b,c,a,d){this.win=window;this.doc=document;this.varName=f;this.fieldTagId=h;this.calendarTagId=a;this.isAnytime=false;this.isAnytimeSelected=true;this.dateRanges=e;this.startDate=e[0].from;this.endDate=e[e.length-1].to;this.displayDate=null;this.fieldsToHide=d;this.inputIdPrefix=g;this.inputNamePrefix=j;this.showMonthYearField=((i==true||i==null)?true:false);this.showDayField=((k==true||k==null)?true:false);this.showHourField=((b==true||b==null)?true:false);this.showCalendarIcon=((c==true||c==null)?true:false);this.contextURL=document.URL.substring(0,document.URL.indexOf("/",9));this.calendarCSS=this.contextURL+"/styles/themes/red08/common.css";this.onChangeCallback=null;this.hourRangeSelected=true;this.defaultHour=null;this.hasUserSetHour=false;this.haveFieldsBeenInserted=false;this.divCalendar=this.doc.createElement("div");this.divCalendar.id=this.inputIdPrefix+"CalendarPage";this.divCalendar.className="calendarPage";if(this.showCalendarIcon||this.calendarTagId==null){$j(this.divCalendar).attr("style","display: none")}this.formattedField=this.doc.createElement("input");this.formattedField.type="hidden";this.formattedField.name=j+"Formatted";this.formattedField.id=g+"Formatted";this.bookLeadFormattedField=this.doc.createElement("input");this.bookLeadFormattedField.type="hidden";this.bookLeadFormattedField.name=j+"BookLeadFormatted";this.bookLeadFormattedField.id=g+"BookLeadFormatted";this.timeField=this.doc.createElement("input");this.timeField.type="hidden";this.timeField.name=j+"Time";this.timeField.id=g+"Time";this.yearField=this.doc.createElement("input");this.yearField.type="hidden";this.yearField.name=j+"Year";this.yearField.id=g+"Year";this.monthField=this.doc.createElement("input");this.monthField.type="hidden";this.monthField.name=j+"Month";this.monthField.id=g+"Month";if(this.showMonthYearField){this.monthYearField=this.doc.createElement("select");this.monthYearField.onchange=new Function(f+".updateMonthYear(this.options[this.selectedIndex].value);"+f+".hidePopup();")}else{this.monthYearField=this.doc.createElement("input");this.monthYearField.type="hidden"}if(this.showDayField){this.dayField=this.doc.createElement("select");this.dayField.onchange=new Function(f+".updateDayOfMonth(this.options[this.selectedIndex].value);"+f+".hidePopup();")}else{this.dayField=this.doc.createElement("input");this.dayField.type="hidden"}if(this.showHourField){this.hourField=this.doc.createElement("select");this.hourField.onchange=new Function(f+".updateHourOfDay(this.options[this.selectedIndex].value);"+f+".hidePopup();")}else{this.hourField=this.doc.createElement("input");this.hourField.type="hidden"}this.monthYearField.className="calMonthYear";this.monthYearField.name=j+"MonthYear";this.monthYearField.id=g+"MonthYear";this.dayField.className="calDay";this.dayField.name=j+"Day";this.dayField.id=g+"Day";this.hourField.className="calHour";this.hourField.name=j+"Hour";this.hourField.id=g+"Hour";this.calendarIcon=this.doc.createElement("input");this.calendarIcon.type="text";this.calendarIcon.readOnly="readOnly";this.calendarIcon.className="calendarIcon";this.calendarIcon.id=g+"PopupCalendarIcon";this.calendarIcon.onclick=new Function(f+".popupToggle()");this.calendarIcon.onmouseover=new Function(f+".mouseOver()");this.calendarIcon.onmouseout=new Function(f+".mouseOut()");if(Calendar.title){this.calendarIcon.title=Calendar.title}else{this.calendarIcon.title="Click for a month-by-month calendar"}this.mouseOverCounter=0;this.popupTimers=new Array();this.popup=null;this.popupX=0;this.popupY=0;this.popupW=0;this.popupH=0}Calendar.prototype.setDateRange=function(a){this.dateRanges=a;this.startDate=a[0].from;this.endDate=a[a.length-1].to;this.displayDate=null;this.update(this.startDate)};
