﻿var t;
function setClock(){
	t = setTimeout("autoWinClose()", 50000);
}

function autoWinClose(){
	top.close();
}

function callWinClose(){
	top.close();
}

function doColor(strColor){
	window.event.srcElement.style.color=strColor;
}

function changeCursor(strCursor){
	window.event.srcElement.style.cursor= strCursor;
}

function changeRed(){
	window.event.srcElement.style.color="red";
}

function changeBack(){
	window.event.srcElement.style.color="#41509D";
}
	 
function changeCursorHand(strColor){
   window.event.srcElement.style.color=strColor;
   window.event.srcElement.style.cursor ="hand";
}
	 
function changeCursorDefault(strColor){
   window.event.srcElement.style.color=strColor;
	window.event.srcElement.style.cursor ="default";
}

var whoCallDate;
function callCal(callerTitle){
	whoCallDate = window.event.srcElement.id;
	var strFCal;
	strFCal = "dialogWidth=256px;dialogHeight=256px;center=yes;help=no;status=no;";
	var theResultCal;
	var strURL = "cal.aspx?callerTitle=" + escape(callerTitle);
	theResultCal = window.showModalDialog(strURL, "Calendar", strFCal)
	if(theResultCal != "" &&  theResultCal != null){
		for(var i = 0; i < frmForm.elements.length; i++){
			if(frmForm.elements[i].id == whoCallDate){
				frmForm.elements[i].value = theResultCal;
				break;
			}	
		}
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
}

function removeDate(){
	whoCallDate = window.event.srcElement.id;
	for(var i = 0; i < frmForm.elements.length; i++){
		if(frmForm.elements[i].id == whoCallDate){
			frmForm.elements[i].value = "";
			break;
		}	
	}
}

function checkWord(e){
	var intCode = e.keyCode;
	switch(intCode){
		case 34:
			alert("本程式禁止使用雙引號");
			return false;
			break;
		case 35:
			alert("本程式禁止使用井號");
			return false;
			break;
		case 38:
			alert("本程式禁止使用 '&' 這個符號");
			return false;
			break;
		case 39:
			alert("本程式禁止使用單引號");
			return false;
			break;
		case 92:
			alert("本程式禁止使用倒斜線符號");
			return false;
			break;
		case 94:
			alert("本程式禁止使用 '^' 這個符號");
			return false;
			break;
		case 124:
			alert("本程式禁止使用 '|' 這個符號");
			return false;
			break;
		default:
			return true;
	}
}

function checkPaste(){
	var strP;
	strP = window.clipboardData.getData("Text");
	var strDQ = String.fromCharCode(34);
	var strHS = String.fromCharCode(35);
	var strAnd = String.fromCharCode(38);
	var strSQ = String.fromCharCode(39);
	var strBS = String.fromCharCode(92);
	var strUp = String.fromCharCode(94);
	var strBar = String.fromCharCode(124);
	if(strP.indexOf(strDQ) != -1){
		alert("轉貼之字串含有雙引號");
		return false;
	}
	
	if(strP.indexOf(strHS) != -1){
		alert("轉貼之字串含有井號");
		return false;
	}
	
	if(strP.indexOf(strAnd) != -1){
		alert("轉貼之字串含有'&'符號");
		return false;
	}
	
	if(strP.indexOf(strSQ) != -1){
		alert("轉貼之字串含有單引號");
		return false;
	}
	
	if(strP.indexOf(strBS) != -1){
		alert("轉貼之字串含有倒斜線符號");
		return false;
	}
	
	if(strP.indexOf(strUp) != -1){
		alert("轉貼之字串含有'^'符號");
		return false;
	}
	
	if(strP.indexOf(strBar) != -1){
		alert("轉貼之字串含有'|'符號");
		return false;
	}
	
	return true;
	
}

function checkNum(e){
	var intCode = e.keyCode;
	if(intCode > 31 && (intCode < 48 || intCode > 57)){
		alert("本欄只可輸入數字!!");
		return false;
	}
	return true;
}

function checkNumPaste(){
	var strP;
	strP = window.clipboardData.getData("Text");
	if(isNaN(strP)){
		alert("轉貼之字串含有非數字字串");
		return false;
	}
	return true;
}

function checkNumFinal(strInput){
	if(isNaN(strInput)){
		return false;
	}
	else{
		return true;
	}
}

function checkId(inputID) {
    var theId = inputID.toUpperCase();
    if (theId.length != 10) {
        return false;
    }

    if (theId.substr(1, 1) == "1" || theId.substr(1, 1) == "2") {
        //if the second letter is 1 or 2, means the input is PID
        var fstId = theId.substr(0, 1).toUpperCase();
        if (fstId > "Z" || fstId < "A") {
            return false;
        }

        var idNo = 0;

        if (fstId <= "H" && fstId >= "A") {
            idNo = fstId.charCodeAt() - "A".charCodeAt() + 10;
        }

        if (fstId <= "N" && fstId >= "J") {
            idNo = fstId.charCodeAt() - "J".charCodeAt() + 18;
        }

        if (fstId <= "V" && fstId >= "P") {
            idNo = fstId.charCodeAt() - "P".charCodeAt() + 23;
        }

        if (fstId <= "Y" && fstId >= "X") {
            idNo = fstId.charCodeAt() - "X".charCodeAt() + 30;
        }

        if (fstId == "W") {
            idNo = 32;
        }

        if (fstId == "Z") {
            idNo = 33;
        }

        if (fstId == "I") {
            idNo = 34;
        }

        if (fstId == "O") {
            idNo = 35;
        }

        var idPhase = idNo + theId.substr(1, 8); //注意這裡原先使用substring(1,9), 其實等於substr(1,8)
        var theBase = "1987654321";
        var RstNo = 0;

        for (var i = 0; i < idPhase.length; i++) {
            RstNo = RstNo + (parseInt(idPhase.charAt(i)) * parseInt(theBase.charAt(i))) % 10;
        }

        if (((10 - (RstNo % 10)) % 10) == parseInt(theId.substr(9, 1))) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        //if the second letter is not 1 or 2, means the input is foreign resident ID
        if (isNaN(theId.substr(2, 8)) || (theId.substr(0, 1) < "A" || theId.substr(0, 1) > "Z") || (theId.substr(1, 1) < "A" || theId.substr(1, 1) > "Z")) {
            return false;
        }
        var head = "ABCDEFGHJKLMNPQRSTUVXYWZIO";
        var newId = (head.indexOf(theId.substr(0, 1)) + 10) + '' + ((head.indexOf(theId.substr(1, 1)) + 10) % 10) + '' + theId.substr(2, 8);
        var s = parseInt(newId.substr(0, 1)) +
		parseInt(newId.substr(1, 1)) * 9 +
		parseInt(newId.substr(2, 1)) * 8 +
		parseInt(newId.substr(3, 1)) * 7 +
		parseInt(newId.substr(4, 1)) * 6 +
		parseInt(newId.substr(5, 1)) * 5 +
		parseInt(newId.substr(6, 1)) * 4 +
		parseInt(newId.substr(7, 1)) * 3 +
		parseInt(newId.substr(8, 1)) * 2 +
		parseInt(newId.substr(9, 1)) +
		parseInt(newId.substr(10, 1));

        //判斷是否可整除
        if ((s % 10) != 0) {
            return false;
        }

        //統一證號碼正確
        return true;
    }
}


