function doMouseOver2(){
	objItem = window.event.srcElement;
	objItem.parentElement.className = "hover";
}

function doMouseOut2(){
	objItem = window.event.srcElement;
	if(objItem.parentElement.rowIndex%2==1){
		objItem.parentElement.className = "row1";
	}else{
		objItem.parentElement.className = "row2";
	}
}

function doMouseOverb(){
	objItem = window.event.srcElement;
	objItem.parentElement.className = "bhover";
}

function doMouseOutb(){
	objItem = window.event.srcElement;
	if(objItem.parentElement.rowIndex%2==1){
		objItem.parentElement.className = "brow1";
	}else{
		objItem.parentElement.className = "brow2";
	}
}

// 設定選取狀態
function setChkChecked(objItem){
	if(isNaN(objItem.length)){
		objItem.checked = window.event.srcElement.checked;
	}else{
		for(i=0;i<objItem.length;i++){
			objItem[i].checked = window.event.srcElement.checked;
		}
	}
}

//身份証字號驗証
function checkID(id) /*函數宣告*/
{
    var pass=0; /*為了通過後面的防呆所以...*/
    var num=new Array(11); /*用來存轉換碼加九個數字 */
    var sum=0; /*計算經過公式後的加總*/
    input=id; /*存文字框的內容*/
    var table=new Array(10,11,12,13,14,15,16,17,18,34,19,20,21,22,35,23,24,25,26,27,28,29,32,30,31,33); /*轉換的對照表*/
    /*以下是防呆*/
    if(input.length!=10)
        alert("身份証字號 長度不符");
    else if(input.charCodeAt(0)<"A".charCodeAt(0)||input.charCodeAt(0)>"Z".charCodeAt(0))
        alert("身份証字號 第一個字母要大寫英文");
    else if(input.charCodeAt(1)!="1".charCodeAt(0)&&input.charCodeAt(1)!="2".charCodeAt(0))
        alert("身份証字號 第一個數字必須是1或2");
    else
    {
        for(p=2;p<10;p++)
        {
            if(input.charCodeAt(p)<"0".charCodeAt(0)||input.charCodeAt(p)>"9".charCodeAt(0))
            {
                alert("身份証字號 後九碼要皆為數字");
                break;
            }
            else
                pass++;
        }
    }
    if(pass!=8)
        return false;
    /*以上是防呆*/
    num[1]=table[input.charCodeAt(0)-65]%10;
    num[0]=(table[input.charCodeAt(0)-65]-num[1])/10;
    for(p=1;p<10;p++)
        num[p+1]=input.charCodeAt(p)-48;
    for(p=1;p<9;p++)
        num[p]=num[p]*(10-p); /*套用公式*/
    for(p=0;p<11;p++)
        sum+=num[p];
    if(sum%10==0) /*檢查*/
        return true;
    else
        return false;
}

//==============================================================================================
//	Date:			2002-04-17
//	FileName:	checkdata.js
//	Author:		Hark Chen
//	Version:	1.0
//==============================================================================================

// 數字 0 至 9 ：48~57
// 英文字母 A 至 Z ：65~90
// 英文字母 a 至 z ：97~122
// -：45
// .：46
// _：95
// 只可包含 a 至 z，A 至 Z，0 至 9，並且大小寫視為不同字
function chkPassword(fieldName,msg){
	var str=document.all(fieldName).value;
	var len=str.length;
	var flag=0;
	for(var i=0;i<len;i++){
		var no=str.charCodeAt(i);
		if((no>122)||(no<48)){    
			alert("【"+msg+"】只能輸入英文字母 a 至 z，A 至 Z，或數字 0 至 9 ！");  document.all(fieldName).focus(); return false;            
		}else if((no>57)&&(no<65)){
			alert("【"+msg+"】只能輸入英文字母 a 至 z，A 至 Z，或數字 0 至 9 ！");  document.all(fieldName).focus(); return false;            
		}else if((no>90)&&(no<97)){
			alert("【"+msg+"】只能輸入英文字母 a 至 z，A 至 Z，或數字 0 至 9 ！");  document.all(fieldName).focus(); return false;            
		}else{
			flag++;
		}
	}   
	if(flag==len){
		return true; 
	}else{ 
		alert("【"+msg+"】輸入錯誤!");  document.all(fieldName).focus(); return false;            
	}
}

// 數字 0 至 9 ：48~57
// 英文字母 A 至 Z ：65~90
// 英文字母 a 至 z ：97~122
// -：45
// .：46
// _：95
//檢查是否符合代號之規定,代號只能輸入英文字母,數字  . - _  不符則回傳 false 
function chkID(fieldName,msg){
var str=document.all(fieldName).value;
var len=str.length;
var flag=0;
for(var i=0;i<len;i++){
var no=str.charCodeAt(i);
if((no>122)||(no<45)){    
alert("【"+msg+"】只能輸入英文字母,數字及 . - _ ");  document.all(fieldName).focus(); return false;            
}else if((no>57)&&(no<65)){
alert("【"+msg+"】只能輸入英文字母,數字及 . - _");  document.all(fieldName).focus(); return false;            
}else if(no==91){
alert("【"+msg+"】只能輸入英文字母,數字及 . - _");  document.all(fieldName).focus(); return false;            
}else if((no>92)&&(no<97)){
alert("【"+msg+"】只能輸入英文字母,數字及 . - _");  document.all(fieldName).focus(); return false;            
}else{
flag++;
}
}   
if(flag==len){ return true; 
}else{ 
alert("【"+msg+"】輸入錯誤!");  document.all(fieldName).focus(); return false;            
}
}

// 檢查【密碼】欄位與【確認密碼】欄位是否輸入相同值
function chkSamePwd(fieldNameS,fieldNameC,msgS,msgC){
	if(document.all(fieldNameS).value.trim() != document.all(fieldNameC).value.trim()){
		alert("【"+msgS+"】與【"+msgC+"】必須輸入相同值!");
		document.all(fieldNameC).value = "";
		document.all(fieldNameC).focus();
		return false;
	}
	return true;
}

// 檢查 E-Mail 信箱
function chkEmail(fieldName,msg){
	var email = document.all(fieldName).value;
	var len = email.length;
	for(var i=0;i<len;i++){
		var c = email.charAt(i);
		if(!( (c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || (c >= "0" && c <= "9") || (c == "-") || (c == "_") || (c == ".") || (c == "@") )){
			// 電子郵件地址只能是數字,英文字母及'-','_','.','@'等符號,其他的符號都不能使用
			alert("【"+msg+"】輸入錯誤!");
			document.all(fieldName).focus();
			return false;
		}
	}
	
	if((email.indexOf("@") == -1) || (email.indexOf("@") == 0) || (email.indexOf("@") == (len-1))){
		// 沒有@ 或 第一個字元為@ 或 最後一個字元為@
		alert("【"+msg+"】輸入錯誤 ！"); 
		document.all(fieldName).focus();
		return false;
	}else if((email.indexOf("@") != -1) && (email.substring(email.indexOf("@")+1,len).indexOf("@") != -1)){
		// 有兩個 @
		alert("【"+msg+"】輸入錯誤 ！");
		document.all(fieldName).focus();
		return false;
	}else if((email.indexOf(".") == -1) || (email.indexOf(".") == 0) || (email.lastIndexOf(".") == (len-1))){
		// 沒有或第一個或最後一個字為.
		alert("【"+msg+"】輸入錯誤 ！");
		document.all(fieldName).focus();
		return false;
	}else if((email.indexOf("@.") != -1) || (email.indexOf(".@") != -1)||(email.indexOf("..") != -1)){
		// . 與 @ 或 .連在一起
		alert("【"+msg+"】輸入錯誤 ！");
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

// 檢查中華民國國民身分證字號
function chkChineseID(fieldName,msg){
	var myid = document.all(fieldName).value;
	myid = myid.toUpperCase();																		// 先將 ID 轉成大寫
	if(myid.length != 10){																				// 身分證字號不等於10個英數字
		alert("【"+msg+"】必須輸入10個英數字 ！");
		document.all(fieldName).focus();
		return false;
	}else if(myid.charAt(0) < "A" || myid.charAt(0) > "Z"){				// 身分證字號第一碼必須是英文字母
		alert("【"+msg+"】第一碼必須是英文字母 ！");
		document.all(fieldName).focus();
		return false;
	}else if(myid.charAt(1) != "1" && myid.charAt(1) != "2"){			// 身分證字號第二碼非 1 即 2
		alert("【"+msg+"】第二碼必須輸入1或2 ！");
		document.all(fieldName).focus();
		return false;
	}else if(isNaN(myid.substring(1,10))){												// 身分證字號第二到十碼非數字
		alert("【"+msg+"】第二碼到第十碼必須輸入數字 ！");
		document.all(fieldName).focus();
		return false;
	}
	
	var alph = new Array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","X","Y","W","Z","I","O");
	var num  = new Array("10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35");
	var n=0;
	for(i=0;i<alph.length;i++){
		if(myid.charAt(0)==alph[i])
		n=i;
	}
	var tot1 = parseFloat(num[n].charAt(0)) + (parseFloat(num[n].charAt(1)) * 9);
	var tot2 = 0;
	for(i=1;i<myid.length-1;i++){
		tot2 = tot2 + parseFloat(myid.charAt(i))*(9-i);
	}
	var tot3 = parseFloat(myid.charAt(9));
	var tot4 = tot1 + tot2 + tot3;
	if((tot4 % 10)!=0){																						// 身分證字號有問題
		alert("【"+msg+"】輸入錯誤 ！");  document.all(fieldName).focus(); return false;
	}
	
	return true;
}

//==============================================================================================
//================================== 欄位長度 ==================================
// 檢查欄位長度之範圍
function chkMinMaxLen(fieldName,minLen,maxLen,msg){
	if(!chkMinLen(fieldName,minLen,msg)) return false;
	if(!chkMaxLen(fieldName,maxLen,msg)) return false;
	
	return true;
}

// 檢查欄位之最小長度
function chkMinLen(fieldName,minLen,msg){
	if(getLength(document.all(fieldName)) < minLen){
		alert("【"+msg+"】必須輸入至少 "+minLen+" 個英數字");
		//document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

// 檢查欄位之最大長度
function chkMaxLen(fieldName,maxLen,msg){
	if(getLength(document.all(fieldName)) > maxLen){
		alert("【"+msg+"】不可輸入超過 "+maxLen+" 個英數字");
		//document.all(fieldName).value="";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

// 檢查欄位之長度
function chkLen(fieldName,len,msg){
	if(getLength(document.all(fieldName)) != len){
		alert("【"+msg+"】必須輸入 "+len+" 個英數字");
		//document.all(fieldName).value="";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

// Get two-bytes length
function getLength(obj){
	var i,len;
	len=0;
	for(i=0;i<obj.value.trim().length;i++){
		if(obj.value.charCodeAt(i) >= 0 && obj.value.charCodeAt(i) <= 255)
			len += 1;
		else
			len += 2;
	}
	
	return len;
}
//==============================================================================================
//================================== 數值 ==================================
// 檢查是否為數值
function chkNum(fieldName,msg){
	if(isNaN(document.all(fieldName).value)){
		alert("【"+msg+"】必須輸入數值 ！");
		document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

// 檢查是否為整數值
function chkInt(fieldName,msg){
	if(chkNum(fieldName,msg) == false){
		return false;
	}else if(document.all(fieldName).value.indexOf('.') != -1){
		alert("【"+msg+"】必須輸入整數 ！");
		document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

//============================
// 函數名稱：chkPositiveInt
// 功能描述：檢查是否為正整數
//
//============================
function chkPositiveInt(fieldName,msg){
	if(!chkInt(fieldName,msg)){
		return false;
	}else{
		if(document.all(fieldName).value < 0){
			alert("【"+msg+"】必須輸入正整數 ！");
			document.all(fieldName).value = "";
			document.all(fieldName).focus();
			return false;
		}
	}
	
	return true;
}

//============================
// 函數名稱：chkNegativeInt
// 功能描述：檢查是否為負整數
//
//============================
function chkNegativeInt(fieldName,msg){
	if(!chkInt(fieldName,msg)){
		return false;
	}else{
		if(document.all(fieldName).value > 0){
			alert("【"+msg+"】必須輸入負整數 ！");
			document.all(fieldName).value = "";
			document.all(fieldName).focus();
			return false;
		}
	}
	
	return true;
}

// 檢查數值之範圍
function chkNumRange(fieldName,minL,maxL,msg){
	if(document.all(fieldName).value > maxL || document.all(fieldName).value < minL){
		alert("【"+msg+"】請輸入 "+minL+" 到 "+maxL+" 的數字 ！");
		document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

// 檢查欄位是否為空值
function chkNull(fieldName,msg){
	if(document.all(fieldName).value.trim() == ""){
		alert("【"+msg+"】不可以空白 ！");
		document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false;
	}
	return true;
}


//==============================================================================================
//================================== 字串 ==================================
// 使用 String 物件之 prototype 屬性延伸 String 物件之方法
String.prototype.rTrim = rTrim;  
String.prototype.lTrim = lTrim;
String.prototype.trim = trim;

// 去除右邊之空白字元
function rTrim(){
	var orgStr = this.toString();							// 取得物件之字串
	var str = orgStr;													// 將字串放入一變數, 此變數內容將於程式中被修改
	 while(str.length > 0){
		if(str.charAt(str.length-1) != ' '){		// 檢查最後字元(str.length-1), 遇到非' '即停止
			break;																// 離開迴圈
		}
		str = str.substring(0,str.length-1);		// 遇到' '即將最後一個字元減去
	}
	
	return str;																// 回傳結果
}

// 去除左邊之空白字元
function lTrim(){
	var orgStr = this.toString();							// 自行解析
	var str = orgStr;
	while(str.length > 0){
		if(str.charAt(0) != ' '){
			break;
		}
		str = str.substring(1,str.length);
	}
	
	return str;
}

// 去除左右兩邊之空白字元
function trim(){
	var orgStr = this.toString(); 		 				// 自行解析
	var str = orgStr;
	
	return str=(str.lTrim()).rTrim(); 
}


//==============================================================================================
//================================== 日期 ==================================
// 檢查日期格式是否正確  ex.1971-04-27
// 檢查日期是否符合規定
function isCorrectDate(Y,M,D){
	//var Y=year;            //var Y=parseInt(year);
	//var M=month;           //var M=parseInt(month);
	//var D=dat;             //var D=parseInt(dat);
	if((Y<1900)||(M<1)||(D<1)||(Y>2100)||(M>12)||(D>31)){
		return false;
	}else if((M==4)||(M==6)||(M==9)||(M==11)){
		return (D>30)?false:true;   //4, 6, 9, 11月有30天
	}else if((M==2)&&(((Y%4==0)&&(Y%100!=0))||(Y%400==0))){
		return (D>29)?false:true; //是否閏年                 //閏年2月29天, 其餘28天
	}else if(M==2){
		return (D>28)?false:true;
	}else{
		return true;
	}
}

// 檢查日期格式是否正確  ex.1971-04-27
function chkDate(fieldName,msg){
	var str = document.all(fieldName).value;
	var theYear = str.substring(0,4);
	var theMonth = str.substring(5,7);
	var theDate = str.substring(8,10);
	
	if((str.length != 10) || (str.charAt(4) != '-') || (str.charAt(7) != '-')){
		alert("【"+msg+"】請輸入 YYYY-MM-DD ！");
		//document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false; 
	}else if(isNaN(theYear) || isNaN(theMonth) || isNaN(theDate)){
		alert("【"+msg+"】請輸入 YYYY-MM-DD ！");
		//document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false; 
	}else if(!isCorrectDate(theYear,theMonth,theDate)){
		alert("【"+msg+"】請輸入合理的日期 ！");
		//document.all(fieldName).value = "";
		document.all(fieldName).focus();
		return false;
	}
	
	return true;
}

function chkDateFormat(strDate,strMsg){

}

//============================
// 功能描述：判斷某日期2是否比某日期1還早
// 日期格式：YYYY-MM-DD
// 輸入值：某日期1(strDate1)；某日期2(strDate2)
// 輸出值：
//			1.true：某日期2比某日期1還早。
//			2.false：某日期2比某日期1還晚。
function isBeforeDate1(strDate1,strDate2,strMsg1,strMsg2){
	if(strDate2 > strDate1){
		alert("【"+strMsg2+"】不可比【"+strMsg1+"】還晚 ！");
		return false;
	}
	return true;
}

//============================
// 功能描述：判斷某日期2是否與某日期1為同一天
// 日期格式：YYYY-MM-DD
// 輸入值：某日期1(strDate1)；某日期2(strDate2)
// 輸出值：
//			1.true：某日期2與某日期1為同一天。
//			2.false：某日期2與某日期1為不同天。
function isEqualDate1(strDate1,strDate2,strMsg1,strMsg2){
	if(strDate2 != strDate1){
		alert("【"+strMsg2+"】必須與【"+strMsg1+"】為同一天 ！");
		return false;
	}
	return true;
}

//============================
// 功能描述：判斷某日期2是否與某日期1為不同天
// 日期格式：YYYY-MM-DD
// 輸入值：某日期1(strDate1)；某日期2(strDate2)
// 輸出值：
//			1.true：某日期2與某日期1為不同天。
//			2.false：某日期2與某日期1為同一天。
function isNotEqualDate1(strDate1,strDate2,strMsg1,strMsg2){
	if(strDate2 == strDate1){
		alert("【"+strMsg2+"】不可與【"+strMsg1+"】為同一天 ！");
		return false;
	}
	return true;
}

//============================
// 功能描述：判斷某日期2是否比某日期1還晚
// 日期格式：YYYY-MM-DD
// 輸入值：某日期1(strDate1)；某日期2(strDate2)
// 輸出值：
//			1.true：某日期2比某日期1還晚。
//			2.false：某日期2比某日期1還早。
function isAfterDate1(strDate1,strDate2,strMsg1,strMsg2){
	if(strDate2 < strDate1){
		alert("【"+strMsg2+"】不可比【"+strMsg1+"】還早 ！");
		return false;
	}
	return true;
}

// YYYY-MM-DD
// intDays以後
function getDays(intDays,strDate){
	for(i=0;i<intDays;i++){
		strDate = getNextDate(strDate);
	}

	return strDate;
}

// YYYY-MM-DD
function getNextDate(strDate){
	var strNextDate = "";
	var theYear = strDate.substring(0,4)*1;
	var theMonth = strDate.substring(5,7)*1;
	var theDate = strDate.substring(8,10)*1;

	theDate++;
	if(theDate > 31){
		theDate = 1;
		theMonth++;
		if(theMonth > 12){
			theMonth = 1;
			theYear++;
			strNextDate = makeDate(theYear,theMonth,theDate);
		}else{
			strNextDate = makeDate(theYear,theMonth,theDate);
		}
	}else{
		strNextDate = makeDate(theYear,theMonth,theDate);
	}

	if(!isDateCorrect(strNextDate)){
		strNextDate = getNextDate(strNextDate);
	}
	
	return strNextDate;
}

// YYYY-MM-DD
function chkDateCorrect(strDate,strMsg){
	if(!isDateCorrect(strDate)){
		alert("【"+strMsg+"】請輸入合理的日期 ！");
		return false;
	}
	return true;
}

function isDateCorrect(strDate){
	var theYear = strDate.substring(0,4)*1;
	var theMonth = strDate.substring(5,7)*1;
	var theDate = strDate.substring(8,10)*1;

	if((theYear<1900)||(theMonth<1)||(theDate<1)||(theYear>2100)||(theMonth>12)||(theDate>31)){
		return false;
	}else if((theMonth==4)||(theMonth==6)||(theMonth==9)||(theMonth==11)){
		return (theDate>30)?false:true;   //4, 6, 9, 11月有30天
	}else if((theMonth==2)&&(((theYear%4==0)&&(theYear%100!=0))||(theYear%400==0))){
		// 表示遇到閏年，而閏年之2月有29天
		return (theDate>29)?false:true;
	}else if(theMonth==2){
		// 表示遇到閏年，而閏年之2月有28天
		return (theDate>28)?false:true;
	}else{
		return true;
	}
}

// YYYY-MM-DD
function makeDate(theYear,theMonth,theDate){
	theYear *= 1;
	theMonth *= 1;
	theDate *= 1;
	
	if(theMonth < 10){
		theMonth = "0" + theMonth;
	}
	if(theDate < 10){
		theDate = "0" + theDate;
	}
	
	return theYear+"-"+theMonth+"-"+theDate;
}
