﻿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(myId){
	var theId =myId;
	if(theId.length != 10){
		return false;
	}
	
	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.substring(1,9);
	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;
	}
}

