function getFirstDay(a,b){return(new Date(a,b,1)).getDay()}function getMonthLen(a,b){a=new Date(a,b+1,1);a.setHours(a.getHours()-3);return a.getDate()}
function populateTable(a,b,c){var d,k;var f=a.chooseMonth.selectedIndex;var g=parseInt(a.chooseYear.options[a.chooseYear.selectedIndex].text,10);null==b&&(b="undefined"!=typeof window.dialogArguments?window.dialogArguments:getPopArgs(),c&&(b=b.replace(/\//g,"")),b=new Date(b.substring(0,4),b.substring(4,6)-1,b.substring(6,8)));var n=HYBS_CAL_START_MON?(getFirstDay(g,f)+6)%7:getFirstDay(g,f);var m=getMonthLen(g,f);var e="";if(0!=a.chooseYear.selectedIndex||0!=a.chooseMonth.selectedIndex)e="<input type='button' value='<<' onClick='changeMonth( "+
g+","+(f+1)+","+b.getDate()+",-1 );' />  ";var h="0"+(f+1);e=e+g+" / "+h.slice(h.length-2);if(a.chooseYear.selectedIndex!=a.chooseYear.length-1||a.chooseMonth.selectedIndex!=a.chooseMonth.length-1)e=e+"  <input type='button' value='>>' onClick='changeMonth( "+g+","+(f+1)+","+b.getDate()+",1 );' />";document.getElementById("tableHeader").innerHTML=e;a=1;for(e=document.getElementById("tableBody");0<e.rows.length;)e.deleteRow(0);for(d=!1;!d;)if(h=e.insertRow(e.rows.length))for(k=0;7>k;k++){var l=h.insertCell(h.cells.length);
1==e.rows.length&&k<n?l.innerHTML="&nbsp;":(a==m&&(d=!0),a<=m?(null!=b&&b.getFullYear()==g&&b.getMonth()==f&&b.getDate()==a&&(l.id="today"),l.innerHTML="<a href='#'onclick='chooseDate("+a+","+f+","+g+","+c+"); return false;'>"+a+"</a>",a++):l.innerHTML="&nbsp;")}else d=!0;setWinSize()}function fillYears(a){var b;var c=a.getFullYear();var d=document.dateChooser.chooseYear;for(b=c-1;b<c+5;b++)d.options[d.options.length]=new Option(b,b);setCurrMonth(a)}
function setCurrMonth(a){document.dateChooser.chooseYear.selectedIndex=1;document.dateChooser.chooseMonth.selectedIndex=a.getMonth()}function chooseDate(a,b,c,d){c=c.toString();b=9<=b?(b+1).toString():"0"+(b+1).toString();a=10<=a?a.toString():"0"+a.toString();d?rtnPopup(c+"/"+b+"/"+a):rtnPopup(c+b+a);"undefined"!=typeof window.dialogArguments&&window.close()}
function initCalendar(){var a=getPopArgs();var b=0<=a.indexOf("/");b&&(a=a.replace(/\//g,""));var c=null==a||8!=a.length?new Date:new Date(a.substring(0,4),a.substring(4,6)-1,a.substring(6,8));window.returnValue=a;fillYears(c);populateTable(document.dateChooser,c,b);document.getElementById("calendar").style.visibility="visible";window.focus()}
function setWinSize(){var a,b;if(a=document.getElementById("calendarTable")){var c=b=0;if(document.all){var d=getInternetExplorerVersion();7>d&&(c=6,b=52);window.dialogWidth=a.offsetWidth+c+"px";window.dialogHeight=a.offsetHeight+b+"px"}else{d=10;do c=a.offsetWidth-(document.documentElement.clientWidth||document.body.clientWidth),b=a.offsetHeight-(document.documentElement.clientHeight||document.body.clientHeight),window.resizeBy(c,b),d--;while((0<c||0<c)&&0<d)}}}
function changeMonth(a,b,c,d){b=Number(b)+d;d=a;0==b?(b=12,d=Number(a)-1,--document.dateChooser.chooseYear.selectedIndex):13==b&&(b=1,d=Number(a)+1,document.dateChooser.chooseYear.selectedIndex+=1);a=new Date(d,b-1,c);document.dateChooser.chooseMonth.selectedIndex=b-1;populateTable(document.dateChooser,a)};
