function caleTDMove(e){e.style.borderColor="#ffffff #333333 #333333 #ffffff"}
function caleTDOut(e){e.style.border="solid 1pt #c6c6c6"}
function hideCale(){popCale.hide()}
function yearChange(){ //重寫年份的<SELECT>
var e=popCale.document.all('yearSel')
e.options.length=0
for (i=nYear-4;i<parseInt(nYear)+5;i++){
e.options.length++
e.options[e.options.length - 1].value=i
e.options[e.options.length - 1].text=i
}
e.selectedIndex=4
}
function CaleClick(e){ //選定某一天時
if(isNaN(parseInt(e.innerText))){ //如果是點擊"今天"而觸發
var d=new Date()
tarObject.value=d.getFullYear()+'/'+(d.getMonth()+1)+'/'+d.getDate()
e.style.borderColor="#848484"
}
else{tarObject.value=nYear+'/'+(parseInt(nMonth)+1)+'/'+e.innerText
e.style.borderColor="#c6c6c6"
}
popCale.hide()
}
function changeYM(e,n){ //改變年份或月份﹐或點>>和<<時觸發
if (e.tagName=='SELECT'){
if(e.value.length==4){nYear=e.value;yearChange()}
else{nMonth=e.value}
}
else{nMonth=parseInt(nMonth)+n
switch(nMonth){
case 12:nYear++;nMonth=0;
yearChange()
popCale.document.all('monthSel').selectedIndex=0;break;
case -1:nYear--;nMonth=11;
yearChange()
popCale.document.all('monthSel').selectedIndex=11;break;
default:popCale.document.all('monthSel').selectedIndex=nMonth;break;
}
}
rewriteCale()
}
function rewriteCale(){ //重寫日歷
var newTb,newTR,newTD
newTb=popCale.document.all('LiuzxCale').tBodies[0]
for (i=0;i<=newTb.rows.length;i++)newTb.deleteRow(2)
qtyDay=(new Date(nYear,parseInt(nMonth)+1,1) - new Date(nYear,nMonth,1))/24/3600/1000
fDay=1-(new Date(nYear,nMonth,1).getDay())
for (i=0;i<42;i++){
if (i % 7==0)newTR=newTb.insertRow(newTb.rows.length - 2)
newTD=newTR.insertCell()
if (fDay>0 && fDay<=qtyDay)newTD.innerText=fDay
newTD.style.border="solid 1pt #c6c6c6"
newTD.align='center'
newTD.onmouseover=Function("parent.caleTDMove(this)")
newTD.onmouseout=Function("parent.caleTDOut(this)")
newTD.onclick=Function("parent.CaleClick(this)")
fDay++
}
}
function isDate(str){ //判斷日期是否是合法的
var reg = /^(\d{4})(-|\/)(0?[1-9]|1[0-2])(-|\/)(0?[1-9]|[12][0-9]|3[01])$/g;
var r = reg.exec(str);
if(r==null)return false;
var d = new Date(r[1], r[3]-1,r[5]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
var reg=/(\/|-)(0*)( *)([1-9])/g
var t=str.replace(reg,'$1$4')
if (newStr==t)return true;
return false;
}
function getDATE(s){ //設定那個控件加入萬年歷
tarObject=s
if ((s.value!='')&&(isDate(s.value))){ //如果控件原來有日期并且是合法的
var reg=/(\d{4})(\/)(\d{1,2})(\/)(\d{1,2})/
var r=reg.exec(s.value);
nYear=r[1];nMonth=r[3] - 1;
}
else{
var d=new Date()
nYear=d.getFullYear();nMonth=d.getMonth();
}
var e=event.srcElement
popCale.show(-70,e.clientHeight+5,185,172,e)
popCale.document.all('monthSel').selectedIndex=nMonth
yearChange()
rewriteCale()
}
function tdMove(e){e.style.border="outset 2pt #ffffff"}
function tdOut(e){e.style.border="solid 2pt #c6c6c6"}
function yearRoll(n){
var e=popup.document.all('yMonth')
e.cells[1].innerText = parseInt(e.cells[1].innerText) + parseInt(n)
e.cells[2].innerText = parseInt(e.cells[2].innerText) + parseInt(n)
e.cells[3].innerText = parseInt(e.cells[3].innerText) + parseInt(n)
e.cells[4].innerText = parseInt(e.cells[4].innerText) + parseInt(n)
var reg=/(\d{4})(\/)(\d{1,2})/
var r=reg.exec(tarObject.value)
tarObject.value=(parseInt(r[1])+n)+'/'+r[3]
}
function selectClicked(e){
var p=e.parentElement
switch(p.rowIndex){
case 0:for(var i=1;i<5;i++){
p.cells[i].style.backgroundColor='#000000';
p.cells[i].style.color='#ffffff';
}
e.style.backgroundColor='#ffffff';
e.style.color='#ff0000';
tarObject.value=tarObject.value.replace(/(\d{4})(\/)(\d{1,2})/,e.innerText+'/$3');
break;
case 3:tarObject.value=sYear+'/'+sMonth;
popup.hide();
break;
default:
tarObject.value=tarObject.value.replace(/(\d{4})(\/)(\d{1,2})/,'$1/'+e.innerText);
e.style.border="solid 1pt #c6c6c6"
popup.hide();
break;
}
}
function hidePop(){popup.hide()}
function getYM(s){
tarObject=s
if (s.value=='')s.value=sYear+'/'+sMonth
var reg=/(\d{4})(\/)(\d{1,2})/
var r=reg.exec(s.value)
if (r==null){s.value=sYear+'/'+sMonth;
r=reg.exec(s.value)}
var e=popup.document.all('yMonth').rows[0]
for (var i=1;i<5;i++){
if (e.cells[i].style.color=='#ff0000'){
s.value=e.cells[i].innerText+'/'+r[3]
yearRoll(r[1] - e.cells[i].innerText);
break;
}
}
var e=event.srcElement
popup.show(-70,e.clientHeight+5,196,84,e)
}