var hideCalendarTimer=new Array();function calendarTimer(objname){this.objname=objname;this.timers=new Array();}
function toggleCalendar(objname,auto_hide,hide_timer){var div_obj=document.getElementById('div_'+objname);if(div_obj!=null){if(div_obj.style.visibility=="hidden"){div_obj.style.visibility='visible';document.getElementById(objname+'_frame').contentWindow.adjustContainer();if(auto_hide){if(hide_timer<3000)hide_timer=3000;prepareHide(objname,hide_timer);}}else{div_obj.style.visibility='hidden';}}}
function showCalendar(objname){var div_obj=document.getElementById('div_'+objname);if(div_obj!=null){div_obj.style.visibility='visible';document.getElementById(objname+'_frame').contentWindow.adjustContainer();}}
function hideCalendar(objname){var div_obj=document.getElementById('div_'+objname);if(div_obj!=null){div_obj.style.visibility='hidden';}}
function prepareHide(objname,timeout){cancelHide(objname);var timer=setTimeout(function(){hideCalendar(objname)},timeout);var found=false;for(i=0;i<this.hideCalendarTimer.length;i++){if(this.hideCalendarTimer[i].objname==objname){found=true;this.hideCalendarTimer[i].timers[this.hideCalendarTimer[i].timers.length]=timer;}}
if(!found){var obj=new calendarTimer(objname);obj.timers[obj.timers.length]=timer;this.hideCalendarTimer[this.hideCalendarTimer.length]=obj;}}
function cancelHide(objname){for(i=0;i<this.hideCalendarTimer.length;i++){if(this.hideCalendarTimer[i].objname==objname){var timers=this.hideCalendarTimer[i].timers;for(n=0;n<timers.length;n++){clearTimeout(timers[n]);}
this.hideCalendarTimer[i].timers=new Array();break;}}}
function setValue(objname,d){var changed=(document.getElementById(objname).value!=d)?true:false;updateValue(objname,d);var dp=document.getElementById(objname+"_dp").value;if(dp)toggleCalendar(objname);checkPairValue(objname,d);if(document.getElementById(objname+"_och").value!=""&&changed)
calendar_onchange(objname);var date_array=document.getElementById(objname).value.split("-");tc_submitDate(objname,date_array[2],date_array[1],date_array[0]);}
function updateValue(objname,d){document.getElementById(objname).value=d;var dp=document.getElementById(objname+"_dp").value;if(dp==true){var date_array=d.split("-");var inp=document.getElementById(objname+"_inp").value;if(inp==true){document.getElementById(objname+"_day").value=padString(date_array[2].toString(),2,"0");document.getElementById(objname+"_month").value=padString(date_array[1].toString(),2,"0");document.getElementById(objname+"_year").value=padString(date_array[0].toString(),4,"0");tc_updateDay(objname,date_array[0],date_array[1],date_array[2]);}else{if(date_array[0]>0&&date_array[1]>0&&date_array[2]>0){var myDate=new Date();myDate.setFullYear(date_array[0],(date_array[1]-1),date_array[2]);var dateFormat=document.getElementById(objname+"_fmt").value;var dateTxt=myDate.format(dateFormat);}else var dateTxt="Select Date";document.getElementById("divCalendar_"+objname+"_lbl").innerHTML=dateTxt;}}}
function tc_submitDate(objname,dvalue,mvalue,yvalue){var obj=document.getElementById(objname+'_frame');var year_start=document.getElementById(objname+'_year_start').value;var year_end=document.getElementById(objname+'_year_end').value;var dp=document.getElementById(objname+'_dp').value;var da1=document.getElementById(objname+'_da1').value;var da2=document.getElementById(objname+'_da2').value;var sna=document.getElementById(objname+'_sna').value;var aut=document.getElementById(objname+'_aut').value;var frm=document.getElementById(objname+'_frm').value;var tar=document.getElementById(objname+'_tar').value;var inp=document.getElementById(objname+'_inp').value;var fmt=document.getElementById(objname+'_fmt').value;var dis=document.getElementById(objname+'_dis').value;var pr1=document.getElementById(objname+'_pr1').value;var pr2=document.getElementById(objname+'_pr2').value;var prv=document.getElementById(objname+'_prv').value;var path=document.getElementById(objname+'_pth').value;var spd=document.getElementById(objname+'_spd').value;var spt=document.getElementById(objname+'_spt').value;var och=document.getElementById(objname+'_och').value;var str=document.getElementById(objname+'_str').value;var rtl=document.getElementById(objname+'_rtl').value;var wks=document.getElementById(objname+'_wks').value;var int=document.getElementById(objname+'_int').value;var hid=document.getElementById(objname+'_hid').value;var hdt=document.getElementById(objname+'_hdt').value;obj.src=path+"calendar_form.php?objname="+objname.toString()+"&selected_day="+dvalue+"&selected_month="+mvalue+"&selected_year="+yvalue+"&year_start="+year_start+"&year_end="+year_end+"&dp="+dp+"&da1="+da1+"&da2="+da2+"&sna="+sna+"&aut="+aut+"&frm="+frm+"&tar="+tar+"&inp="+inp+"&fmt="+fmt+"&dis="+dis+"&pr1="+pr1+"&pr2="+pr2+"&prv="+prv+"&spd="+spd+"&spt="+spt+"&och="+och+"&str="+str+"&rtl="+rtl+"&wks="+wks+"&int="+int+"&hid="+hid+"&hdt="+hdt;obj.contentWindow.submitNow(dvalue,mvalue,yvalue);}
function tc_setDMY(objname,dvalue,mvalue,yvalue){var obj=document.getElementById(objname);obj.value=yvalue+"-"+mvalue+"-"+dvalue;tc_submitDate(objname,dvalue,mvalue,yvalue);}
function tc_setDay(objname,dvalue){var obj=document.getElementById(objname);var date_array=obj.value.split("-");if(!isDateAllow(objname,dvalue,date_array[1],date_array[0])||!checkSpecifyDate(objname,dvalue,date_array[1],date_array[0])){restoreDate(objname);}else{if(isDate(dvalue,date_array[1],date_array[0])){tc_setDMY(objname,dvalue,date_array[1],date_array[0]);}else document.getElementById(objname+"_day").selectedIndex=date_array[2];}
checkPairValue(objname,obj.value);var changed=(document.getElementById(objname).value!=d)?true:false;if(document.getElementById(objname+"_och").value!=""&&changed)
calendar_onchange(objname);}
function tc_setMonth(objname,mvalue){var obj=document.getElementById(objname);var date_array=obj.value.split("-");if(!isDateAllow(objname,date_array[2],mvalue,date_array[0])||!checkSpecifyDate(objname,date_array[2],mvalue,date_array[0])){restoreDate(objname);}else{if(document.getElementById(objname+'_dp').value&&document.getElementById(objname+'_inp').value){date_array[2]=tc_updateDay(objname,date_array[0],mvalue,date_array[2]);}
if(isDate(date_array[2],mvalue,date_array[0])){tc_setDMY(objname,date_array[2],mvalue,date_array[0]);}else document.getElementById(objname+"_month").selectedIndex=date_array[1];}
checkPairValue(objname,obj.value);var changed=(document.getElementById(objname).value!=d)?true:false;if(document.getElementById(objname+"_och").value!=""&&changed)
calendar_onchange(objname);}
function tc_setYear(objname,yvalue){var obj=document.getElementById(objname);var date_array=obj.value.split("-");if(!isDateAllow(objname,date_array[2],date_array[1],yvalue)||!checkSpecifyDate(objname,date_array[2],date_array[1],yvalue)){restoreDate(objname);}else{if(document.getElementById(objname+'_dp').value&&document.getElementById(objname+'_inp').value){date_array[2]=tc_updateDay(objname,yvalue,date_array[1],date_array[2]);}
if(isDate(date_array[2],date_array[1],yvalue)){tc_setDMY(objname,date_array[2],date_array[1],yvalue);}else document.getElementById(objname+"_year").value=date_array[0];}
checkPairValue(objname,obj.value);var changed=(document.getElementById(objname).value!=d)?true:false;if(document.getElementById(objname+"_och").value!=""&&changed)
calendar_onchange(objname);}
function yearEnter(e){var characterCode;if(e&&e.which){e=e;characterCode=e.which;}else{e=event;characterCode=e.keyCode;}
if(characterCode==13){return true;}else return false;}
var minYear=1900;var maxYear=2100;function isInteger(s){var i;for(i=0;i<s.length;i++){var c=s.charAt(i);if(((c<"0")||(c>"9")))return false;}
return true;}
function stripCharsInBag(s,bag){var i;var returnString="";for(i=0;i<s.length;i++){var c=s.charAt(i);if(bag.indexOf(c)==-1)returnString+=c;}
return returnString;}
function is_leapYear(year){return(year%4==0)?!(year%100==0&&year%400!=0):false;}
function daysInMonth(month,year){var days=new Array(31,28,31,30,31,30,31,31,30,31,30,31);return(month==2&&year>0&&is_leapYear(year))?29:days[month-1];}
function isDate(strDay,strMonth,strYear){return true}
function isDateAllow(objname,strDay,strMonth,strYear){var da1=parseInt(document.getElementById(objname+"_da1").value);var da2=parseInt(document.getElementById(objname+"_da2").value);var da1_ok=!isNaN(da1);var da2_ok=!isNaN(da2);strDay=parseInt(parseFloat(strDay));strMonth=parseInt(parseFloat(strMonth));strYear=parseInt(parseFloat(strYear));if(strDay>0&&strMonth>0&&strYear>0){if(da1_ok||da2_ok){var date=new Date(strYear,strMonth-1,strDay);da2Set=date.getTime()/1000;if((!da1_ok||da2Set>=da1)&&(!da2_ok||da2Set<=da2)){return true;}else{var dateFormat=document.getElementById(objname+"_fmt").value;if(da1_ok){date.setTime(da1*1000);da1Str=date.format(dateFormat);}
if(da2_ok){date.setTime(da2*1000);da2Str=date.format(dateFormat);}
if(!da1_ok)
alert("Please choose a date before "+da2Str);else if(!da2_ok)
alert("Please choose a date after "+da1Str);else
alert("Please choose a date between\n"+da1Str+" and "+da2Str);return false;}}}
return true;}
function restoreDate(objname){var storeValue=document.getElementById(objname).value;var storeArr=storeValue.split('-',3);document.getElementById(objname+'_day').value=storeArr[2];document.getElementById(objname+'_month').value=storeArr[1];document.getElementById(objname+'_year').value=storeArr[0];}
Date.prototype.format=function(format){var returnStr='';var replace=Date.replaceChars;for(var i=0;i<format.length;i++){var curChar=format.charAt(i);if(replace[curChar]){returnStr+=replace[curChar].call(this);}else{returnStr+=curChar;}}
return returnStr;};Date.replaceChars={shortMonths:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],longMonths:['January','February','March','April','May','June','July','August','September','October','November','December'],shortDays:['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],longDays:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],d:function(){return(this.getDate()<10?'0':'')+this.getDate();},D:function(){return Date.replaceChars.shortDays[this.getDay()];},j:function(){return this.getDate();},l:function(){return Date.replaceChars.longDays[this.getDay()];},N:function(){return this.getDay()+1;},S:function(){return(this.getDate()%10==1&&this.getDate()!=11?'st':(this.getDate()%10==2&&this.getDate()!=12?'nd':(this.getDate()%10==3&&this.getDate()!=13?'rd':'th')));},w:function(){return this.getDay();},z:function(){return"Not Yet Supported";},W:function(){return"Not Yet Supported";},F:function(){return Date.replaceChars.longMonths[this.getMonth()];},m:function(){return(this.getMonth()<9?'0':'')+(this.getMonth()+1);},M:function(){return Date.replaceChars.shortMonths[this.getMonth()];},n:function(){return this.getMonth()+1;},t:function(){return"Not Yet Supported";},L:function(){return"Not Yet Supported";},o:function(){return"Not Supported";},Y:function(){return this.getFullYear();},y:function(){return(''+this.getFullYear()).substr(2);},a:function(){return this.getHours()<12?'am':'pm';},A:function(){return this.getHours()<12?'AM':'PM';},B:function(){return"Not Yet Supported";},g:function(){return this.getHours()%12||12;},G:function(){return this.getHours();},h:function(){return((this.getHours()%12||12)<10?'0':'')+(this.getHours()%12||12);},H:function(){return(this.getHours()<10?'0':'')+this.getHours();},i:function(){return(this.getMinutes()<10?'0':'')+this.getMinutes();},s:function(){return(this.getSeconds()<10?'0':'')+this.getSeconds();},e:function(){return"Not Yet Supported";},I:function(){return"Not Supported";},O:function(){return(-this.getTimezoneOffset()<0?'-':'+')+(Math.abs(this.getTimezoneOffset()/60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()/60))+'00';},T:function(){var m=this.getMonth();this.setMonth(0);var result=this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/,'$1');this.setMonth(m);return result;},Z:function(){return-this.getTimezoneOffset()*60;},c:function(){return"Not Yet Supported";},r:function(){return this.toString();},U:function(){return this.getTime()/1000;}};function padString(stringToPad,padLength,padString){if(stringToPad.length<padLength){while(stringToPad.length<padLength){stringToPad=padString+stringToPad;}}else{}
return stringToPad;}
function tc_updateDay(objname,yearNum,monthNum,daySelected){var totalDays=(monthNum>0&&yearNum>0)?daysInMonth(monthNum,yearNum):((monthNum>0)?daysInMonth(monthNum,2008):31);var dayObj=document.getElementById(objname+"_day");if(dayObj.options[0].value==0||dayObj.options[0].value=="")
dayObj.length=1;else dayObj.length=0;for(d=1;d<=totalDays;d++){var newOption=document.createElement("OPTION");newOption.text=d;newOption.value=d;dayObj.options[d]=new Option(newOption.text,padString(newOption.value,2,"0"));}
if(daySelected>totalDays)
dayObj.value=padString(totalDays,2,"0");else dayObj.value=padString(daySelected,2,"0");return dayObj.value;}
function checkPairValue(objname,d){var dp1=document.getElementById(objname+"_pr1").value;var dp2=document.getElementById(objname+"_pr2").value;var this_value=document.getElementById(objname).value;var this_dates=this_value.split('-');var this_time=new Date(this_dates[0],this_dates[1]-1,this_dates[2]).getTime()/1000;if(dp1!=""&&document.getElementById(dp1)!=null){document.getElementById(dp1+"_prv").value=d;var dp1_value=document.getElementById(dp1).value;var dp1_dates=dp1_value.split('-');var dp1_time=new Date(dp1_dates[0],dp1_dates[1]-1,dp1_dates[2]).getTime()/1000;if(this_time<dp1_time){document.getElementById(objname+"_prv").value="";tc_submitDate(dp1,"00","00","0000");}else{tc_submitDate(dp1,dp1_dates[2],dp1_dates[1],dp1_dates[0]);}}
if(dp2!=""&&document.getElementById(dp2)!=null){document.getElementById(dp2+"_prv").value=d;var dp2_value=document.getElementById(dp2).value;var dp2_dates=dp2_value.split('-');var dp2_time=new Date(dp2_dates[0],dp2_dates[1]-1,dp2_dates[2]).getTime()/1000;if(this_time>dp2_time){document.getElementById(objname+"_prv").value="";tc_submitDate(dp2,"00","00","0000");}else{tc_submitDate(dp2,dp2_dates[2],dp2_dates[1],dp2_dates[0]);}}}
function checkSpecifyDate(objname,strDay,strMonth,strYear){var spd=document.getElementById(objname+"_spd").value;var spt=document.getElementById(objname+"_spt").value;var sp_dates;if(typeof(JSON)!="undefined"){sp_dates=JSON.parse(spd);}else{if(spd!=""&&spd.length>2){var tmp_spd=spd.substring(2,spd.length-2);var sp_dates=tmp_spd.split("],[");for(i=0;i<sp_dates.length;i++){var tmp_str=sp_dates[i];if(tmp_str=="")
sp_dates[i]=new Array();else sp_dates[i]=tmp_str.split(",");}}else sp_dates=new Array();}
var found=false;for(var key in sp_dates[2]){if(sp_dates[2].hasOwnProperty(key)){this_date=new Date(sp_dates[2][key]*1000);if(this_date.getDate()==parseInt(parseFloat(strDay))&&(this_date.getMonth()+1)==parseInt(parseFloat(strMonth))){found=true;break;}}}
if(!found){for(var key in sp_dates[1]){if(sp_dates[1].hasOwnProperty(key)){this_date=new Date(sp_dates[1][key]*1000);if(this_date.getDate()==parseInt(parseFloat(strDay))){found=true;break;}}}}
if(!found){var choose_date=new Date(strYear,strMonth-1,strDay);var choose_time=choose_date.getTime()/1000;for(var key in sp_dates[0]){if(sp_dates[0].hasOwnProperty(key)){if(choose_time==sp_dates[0][key]){found=true;break;}}}}
switch(spt){case 0:default:if(found){alert("You cannot choose this date");return false;}
break;case 1:if(!found){alert("You cannot choose this date");return false;}
break;}
return true;}
function urldecode(str){return decodeURIComponent((str+'').replace(/\+/g,'%20'));}
function calendar_onchange(objname){var fc=document.getElementById(objname+"_och").value;eval(urldecode(fc));}
function focusCalendar(objname){var obj=document.getElementById("container_"+objname);if(obj!=null){obj.style.zIndex=999;}}
function unFocusCalendar(objname,zidx){var obj=document.getElementById("container_"+objname);if(obj!=null){obj.style.zIndex=zidx;}}