﻿//------------------------------------ 年歷表選單控制碼區段開始 ------------------------------------>
//(1)版權聲明:開放
//(2)最好在HTTP標頭裡寫上字型.f10樣式表(CSS)如右邊寫法----->.f10{ font-family: Arial; font-size: 10pt }
//   以免字型太大,當然你也可以自訂字型樣式表.
//(3)底下的JavaScript某些行後面有寫註解"<參數>"者,表示可以變動的數值或文字.
//(4)Cal(RegFrm.T3,...)函數裡所寫指的是
//   "RegFrm"-->是表單名稱(如上面所寫的<form method="POST" name="RegFrm" action="">),
//   "T3"------>是表單裡其中個元件名稱(如上面所寫的<input type="text" name="T3" size="20">)
//(5)來源網站:http://dob.tnc.edu.tw/themes/old/showPage.php?open_discuss=1&t=6&s=1484

//====================月曆表HTML==========================================================================
showcalendar();
function showcalendar()
{
document.writeln("<style type=\"text/css\">");
document.writeln("<!--");
document.writeln(".f10{ font-family: Arial; font-size: 10pt }");
document.writeln(".style2 {color: red;font-size: 10px;}");
document.writeln("-->");
document.writeln("</style>");
document.writeln("  <table id=TabCal borderColor='#EDF1FE' border='1' cellpadding='0' cellspacing='0' width='180' bgcolor='#EDF1FE' style='position:absolute;display:none;z-index:1;MARGIN: 180px 0px 0px -222px;float: right;' ><form name='YType'>");
document.writeln("<tr><td >");
document.writeln("  <table id=aaa border='0' cellpadding='0' cellspacing='0' width='180' bgcolor='#EDF1FE' >");
document.writeln("    <tr>");
document.writeln("      <td colspan='7' width='175'  height='0' align='center' onmousedown='EveDm()' onmouseup='EveUp()' onmousemove='EveMv(event)' style='cursor:move'>");
document.writeln("        <span class='f10' id=StrCap style='filter:glow(color=#555555,strength=5);height:5px; color:white'></span>");

document.writeln("      </td>");
document.writeln("    </tr>");
document.writeln("<tr><td colspan=7 height='40' align='center' >");
document.writeln("            <select align='top' size='1' name='YrNum' class='f10' onChange='YChange();' >");//YChange()
document.writeln("            <option value='2007'>2007</option>");
document.writeln("            <option value='2008'>2008</option>");
document.writeln("            <option value='2009'>2009</option>");
document.writeln("            <option value='2010'>2010</option>");
document.writeln("            <option value='2011'>2011</option>");
document.writeln("            <option value='2012'>2012</option>");
document.writeln("            <option value='2013'>2013</option>");
document.writeln("            <option value='2014'>2014</option>");
document.writeln("            <option value='2015'>2015</option>");
document.writeln("            <option value='2016'>2016</option>");
document.writeln("            <option value='2017'>2017</option>");
document.writeln("            <option value='2018'>2018</option>");
document.writeln("            <option value='2019'>2019</option>");
document.writeln("            <option value='2020'>2020</option>");
document.writeln("            </select><span class='f10'> 年 </span>");
document.writeln("            <select align='top' size='1' name='MnNum' class='f10' onChange='MChange();' >");//YChange()
document.writeln("            <option value='1'>一月</option>");
document.writeln("            <option value='2'>二月</option>");
document.writeln("            <option value='3'>三月</option>");
document.writeln("            <option value='4'>四月</option>");
document.writeln("            <option value='5'>五月</option>");
document.writeln("            <option value='6'>六月</option>");
document.writeln("            <option value='7'>七月</option>");
document.writeln("            <option value='8'>八月</option>");
document.writeln("            <option value='9'>九月</option>");
document.writeln("            <option value='10'>十月</option>");
document.writeln("            <option value='11'>十一月</option>");
document.writeln("            <option value='12'>十二月</option>");
document.writeln("            </select><span class='f10'> 月 </span>");
document.writeln("      </td>");
document.writeln("    </tr>");
document.writeln("    <tr align='center' class='f10'>");
document.writeln("      <td style='color:red;background-color: white;font-weight:bold;'>日</td>");
document.writeln("      <td style='color:#003366;background-color: white;font-weight:bold;'>一</td>");
document.writeln("      <td style='color:#003366;background-color: white;font-weight:bold;'>二</td>");
document.writeln("      <td style='color:#003366;background-color: white;font-weight:bold;'>三</td>");
document.writeln("      <td style='color:#003366;background-color: white;font-weight:bold;'>四</td>");
document.writeln("      <td style='color:#003366;background-color: white;font-weight:bold;'>五</td>");
document.writeln("      <td  style='color:green;background-color: white;font-weight:bold;'>六</td>");
document.writeln("    </tr>");
var cont_cals_ij = 0;
for(i=1;i<7;i++)
{ document.writeln("    <tr align='center' class='f10'>");
  for(j=1;j<8;j++)
  { cont_cals_ij++;
    switch (j)
    { case 1:
        document.writeln("      <td bgcolor='#ffe0e0'");
        break;
      case 7:
        document.writeln("      <td bgcolor='#e0ffff'");
        break;
      default:
        document.writeln("      <td                  ");
    }
document.write(" id=s" + cont_cals_ij + " onmouseover='inMou(s"+cont_cals_ij+",event)' onmouseout='outMou(s"+cont_cals_ij+",event)' onmousedown='ClickSel()' ></td>")

  }
  document.writeln("    </tr>");
}
document.writeln("    </form>");
document.writeln("  </table>");
document.writeln("  </td></tr></table>");
}
function ChangeCalColor(obj,Bg_Ft,nm)
{ if (Bg_Ft==0)
  { switch (nm)
    { case 1:
        obj.style.background="green";
        break;    
      case 2:
        obj.style.background="white";
        break;    
      case 3:
        obj.style.background="black";
        break;    
      case 4:
        obj.style.background="red";
		obj.style.fontWeight="bold";
        break;    
      default:
        obj.style.background="#ffffe0";
    }
  }
  else
  { switch (nm)
    { case 1:
        obj.style.color="green";
        break;    
      case 2:
        obj.style.color="white";
        break;    
      case 3:
        obj.style.color="black";
        break;    
      case 4:
        obj.style.color="red";
		obj.style.fontWeight="bold";
        break;    
      default:
        obj.style.color="#ffffe0"
    }  
  }
}
//====================月曆表程式==========================================================================
var DefautStrCt = "";     //預設標題.---------------------------------------------<參數>
var StrCt;
var curCX;
var YearNumber;
var ListTop;                 
var NowDate = new Date();//---------------------------------------------------------------------<參數>
/*
訂出日期基準點,new Date()=以現在日期為基準點.
若以其他日期為基準點可改寫為new Date("yyyy/mm/dd").
*/
var nStaShelter; 
var bForBack;
var OutType;
var isDg = 0;
var nYearTypeNn = 0;
var oSeleOject;
var forw;
var bacw;
//var TabId=document.getElementById("TabCal");
var IDCopy = "＊"
var dStartPointDay;
var sYMDSel = toString();
var CloseDisplayTime = 2;//關閉顯示時間(單位:秒)------------------------------------------------<參數>
var mCloseDisplayTime = CloseDisplayTime*1000;
var CloseTabCalTimekeeperPro; //關閉顯示計時器程序
var ioffsettop=0;
var ioffsetleft=0;
function Cal(SelectObjectEle,OutTp,pForw,pBacw,nSS,FB,CaptionName,fevent) //-----------------------------------------<參數>
/*
==SelectObjectEle,OutTp,Forw,Bacw,nSS,FB 各參數意義說明=====================================
(1)***SelectObjectEle***
指定輸出元件,譬如上列SelectObjectEle<=RegFrm.T2),那oSeleOject物件參照為RegFrm.T2.

(2)***OutTp*** 
輸出日期形式 1=>yyyy/mm/dd,0=>西元(或民國)年月日.

(3)***Forw,Bacw***
Forw=>向後年計數截止年.
Bacw=>向前年計數截止年.
注意:Forw及Bacw的值必須是大於等於0的整數值.

(4)***nSS*** 
訂出日期基準點(=NowDate)之遮蔽點,若以日期基準點之昨日為遮蔽點,則改寫為nSS = -1.
若以日期基準點之今日為遮蔽點,則改寫為nSS = 0.nSS的整數值範圍為-998 ~ +998.
但nSS>=999或nSS<=-999則無遮蔽,既完全開放.
所謂的遮蔽,指的是當你點選某日時,無法將日期輸出至指定的表單元件裡.也既無作用.

(5)***FB*** 
向前或向後遮蔽,1=>向前日遮蔽,0=>向後日遮蔽.但nSS>=999或nSS<=-999則無作用.

(6)***CaptionName*** 
標題名稱.若為空集合則為預設標題

============================================================================================
*/
{ 
	var e1=new awp_elements();
	e1.setvalue("YrNum",NowDate.getFullYear());
	e1.setvalue("MnNum",(NowDate.getMonth()+1));
	var Yget=document.YType.YrNum.value;//NowDate.getFullYear();
	var Mget=document.YType.MnNum.value;//NowDate.getMonth()+1;

	oSeleOject=new Object(SelectObjectEle);//--(參1)
	OutType = OutTp;//-------------------------(參2)
	forw = NowDate.getFullYear() + pForw;//----(參3)
	bacw = NowDate.getFullYear() - pBacw;//----(參4)
	nStaShelter = nSS;//-----------------------(參5)
	bForBack = FB;//---------------------------(參6)
	if(CaptionName==""){StrCt=DefautStrCt;}//--(參7)
		else{StrCt=CaptionName;}

	//預設為選擇的日期
	mydate=new Date();
	mydate.setFullYear(Yget);
	mydate.setMonth(Mget);
	dStartPointDay = mydate.getTime() + 86400000*nStaShelter;

	YearNumber=Yget;
	document.getElementById("TabCal").style.display="none";
	ListPri(Yget,Mget);
	/*
	if (typeof(event)=="undefined") 
	{ 
		document.getElementById("TabCal").style.left= document.body.scrollLeft+fevent.clientX -0+ioffsetleft;
		document.getElementById("TabCal").style.top = document.body.scrollTop+fevent.clientY-0+ioffsettop;
	}
	else
	{
		document.getElementById("TabCal").style.left= document.body.scrollLeft+event.clientX-5+ioffsetleft;
		document.getElementById("TabCal").style.top = document.body.scrollTop+event.clientY-5+ioffsettop;
	}
*/
	document.getElementById("StrCap").innerHTML=StrCt;
	document.getElementById("TabCal").style.display="block";
	//CloseTabCalTimekeeperPro=setTimeout("document.getElementById('TabCal').style.display='none'",5000);
}


function ListSeIn()
{ document.getElementById("TabCal").style.display="block";
}

function ClickSel()
{ 
  var IDCo = document.getElementById(IDCopy).innerHTML;
  var hBGround = document.getElementById(IDCopy).style.background;
  var bCanPut = 1;
  if(Math.abs(nStaShelter)<999 && !(IDCo=="＊"))
  { var DateN = new Date(sYMDSel + IDCo);
    if(bForBack==1){if(dStartPointDay >= DateN.getTime()){bCanPut = 0;}}
    else{if(dStartPointDay <= DateN.getTime()){bCanPut = 0;}}
  }

  if (!(IDCo == "＊") && bCanPut == 1)
  { var PrintStrin= document.YType.YrNum.value;
    var InPri;
	nYearTypeNn=0;
    sYearTp='西元';
    InPri=PrintStrin;
	  
    PrintStrin += "年";
    InPri += "/";
    PrintStrin += document.YType.MnNum.value;
    InPri += document.YType.MnNum.value;
    PrintStrin += "月";
    InPri += "/";
    PrintStrin += IDCo + "日";
    InPri += IDCo;
    if ( OutType == 1 )
    { //oSeleOject.value = "aaa"+InPri;
		//重新取出當天的資料
		reload_action(InPri,"d");
    }
    else
    { 
	oSeleOject.value = sYearTp+PrintStrin;
    }
    //document.getElementById("TabCal").style.display="none";
  }
}
//重新取出當天的資料
function reload_action(InPri,type)
{
	document.getElementById("newsdate").value=InPri;
	starttablemaker2('menu1',InPri,type,'');
}
//設定每個欄位的顏色
function ListPri(YP,MP)
{ var ss;
  var Num_i=1;
  var MonD=0;
  var Str_YMD=YP + "/" + MP + "/";
  var TheDate=new Date(Str_YMD+"1");
  var WeekFirst = TheDate.getDay();
  var tfYMD=0;
  sYMDSel = Str_YMD;
  if(TheDate.getFullYear()==NowDate.getFullYear()  && TheDate.getMonth()==NowDate.getMonth()){tfYMD=1;}
  for(i=1;i<43;i++)
  { var sid = document.getElementById("s"+ i);
    if(i=='1' || i=='8' || i=='15' || i=='22' || i=='29' || i=='36')
    { sid.style.background='#ffe0e0';
    }
    else if(i=='7' || i=='14' || i=='21' || i=='28' || i=='35' || i=='42')
    { sid.style.background='#e0ffff';
    }
    else
    { 
		//設定顯示日期的背景色
		sid.style.background='#eeeeee';//ffffe0
    }
    sid.style.cursor='default';
  }
  for(i=0;i<7;i++)
  { var sid = document.getElementById("s"+(i+1));
    if(WeekFirst==i)
    { ss=i+1;
      i=7;
    }
    else
    { 
		//一號前的空格顏色設定
		sid.style.background='white';//#a9a9a9
		sid.innerHTML="＊";
		sid.style.fontWeight='normal';
		sid.style.color='white';//#a9a9a9
    }
  }
  for(i=ss;i<43;i++)
  { var sid = document.getElementById("s"+i);
    var DateN = new Date(Str_YMD + Num_i);
    if((DateN.getMonth()+1)==MP)
    {
      sid.innerHTML=Num_i;
      if(Math.abs(nStaShelter)>=999)
      { sid.style.cursor='hand';
      }
      else
      { if(bForBack==1)
        { if(dStartPointDay >= DateN.getTime())
          { sid.style.cursor='default';
            sid.style.background='#a9a9a9';//#a9a9a9
          }
          else{sid.style.cursor='hand';}
        }
        else
        { if(dStartPointDay <= DateN.getTime())
          { sid.style.cursor='default';
            sid.style.background='#a9a9a9';//
          }
          else{sid.style.cursor='hand';}
        }
      }
      sid.style.color='black';
	  //註記今天日期為紅色
      if(tfYMD==1 && NowDate.getDate()==Num_i)
      { 
		sid.style.color='red';
        sid.style.fontWeight='bold';
      }
      else{sid.style.fontWeight='normal';}
    }
    else
    { 
		//補空格顯示的顏色字型
		sid.style.background='white';//#a9a9a9
		sid.style.fontWeight='normal';
		sid.style.color='white';//#a9a9a9
		sid.innerHTML="＊";
    }
    Num_i++
  } 
}

//設定滑鼠移動顯示的背景色跟字型
function inMou(SN,fevent)
{
//alert(SN);
var sidC = SN;//document.getElementById(SN);
  IDCopy=SN.id;
  if(sidC.innerHTML!="＊")
  { 

  var DateN = new Date(sYMDSel + sidC.innerHTML);
    curCX=sidC.style.color;
    if(Math.abs(nStaShelter)<999)
    { if(bForBack==1)
      { if(dStartPointDay < DateN.getTime())
        { 		
		sidC.style.background='#FFE188';
          sidC.style.color='#462300';
		  sidC.style.fontWeight='bold';
        }
      }
      else
      { 
	  if(dStartPointDay > DateN.getTime())
        { sidC.style.background='#FFE188';
          sidC.style.color='#462300';
		  sidC.style.fontWeight='bold';
        }
      }
    }
    else
    {
		sidC.style.background='#FFE188';
      sidC.style.color='#462300';
	  sidC.style.fontWeight='bold';
	  //sidC.style.font="14px";
    }
  }
} 

function outMou(SN,event)
{

var IDCopy="＊";
  var sidC = SN;//document.getElementById(SN);

    var DateN = new Date(sYMDSel + sidC.innerHTML);
	
  if(SN=='s1' || SN=='s8' || SN=='s15' || SN=='s22' || SN=='s29' || SN=='s36')
  { sidC.style.background='#ffe0e0';
  }
  else if(SN=='s7' || SN=='s14' || SN=='s21' || SN=='s28' || SN=='s35' || SN=='s42')
  { sidC.style.background='#e0ffff';
  }
  else
  { 
	//設定星期一到五滑鼠移過的顏色
	sidC.style.background='#eeeeee';//#ffffe0
  }
    //設定滑鼠移開的字行
  sidC.style.color=curCX;
  if (curCX=='red')
  {
	//設定今天日期在滑鼠移過之後還是粗體
	sidC.style.fontWeight='bold';
  }
  else
  {
	sidC.style.fontWeight='normal';
	}
  
if(sidC.innerHTML=="＊")
  {
	//設定無日期的框框顏色
	sidC.style.background='white';//#a9a9a9
	sidC.style.color='white';//#a9a9a9
  }
  else
  { if(Math.abs(nStaShelter)<999)
    { var DateN = new Date(sYMDSel + sidC.innerHTML);
      if(bForBack==1)
      { if(dStartPointDay >= DateN.getTime())
        { sidC.style.background='#a9a9a9';
          sidC.style.color='black';
        }
      }
      else
      { if(dStartPointDay <= DateN.getTime())
        { sidC.style.background='#a9a9a9';
          sidC.style.color='black';
        }
      }    
    }
  }
} 

function YChange()
{  
 var tf=0;
 var NumSY=document.YType.YrNum.value;
 ListPri(NumSY,new Number(document.YType.MnNum.value));
 YearNumber=NumSY;
 
	document.getElementById("newsdate").value="";
	//alert(document.YType.YrNum.value);
	starttablemaker2('menu1',document.YType.YrNum.value,'y','');

}
function MChange()
{  
 var tf=0;
 var NumSY=document.YType.YrNum.value;
 ListPri(NumSY,new Number(document.YType.MnNum.value));
 YearNumber=NumSY;
 document.getElementById("newsdate").value="";
 starttablemaker2('menu1',document.YType.MnNum.value,'m',document.YType.YrNum.value);
 // reload_action(InPri,"m");
}
timeout1=null;

function EveDm(){
isDg=1;}

function EveUp(){

isDg=0;}

function EveMv(fevent)
{
if(isDg==1 && document.getElementById("TabCal").style.display=="block")
  {
	if (typeof(event)=="undefined") 
	{ 
		document.getElementById("TabCal").style.left=fevent.clientX-90;
		document.getElementById("TabCal").style.top=fevent.clientY-12;  
	}
	else
	{
	  document.getElementById("TabCal").style.left=event.clientX-90;
    document.getElementById("TabCal").style.top=event.clientY-12;  
	}
  }
  else
  { isDg==0;
  }
}

function StatusDisplay(Nm)
{ if(Nm==0)
  { CloseTabCalTimekeeperPro=setTimeout("document.getElementById('TabCal').style.display='none'",mCloseDisplayTime);}
  else
  { clearTimeout(CloseTabCalTimekeeperPro);}
}