﻿<!--
var borderWidth = "1";
var borderColor = "#FF626F";
var bgColor = "#FFEDED";

function keypress() {
    var obj = event.srcElement;
    if (obj.tagName.toLowerCase() == 'input' || obj.tagName.toLowerCase()=='textarea') {
        if (obj.value.length >= 0) {
            obj.style.borderColor = '';
            obj.style.backgroundColor = '';
        }
    }

}
        
function checkEmpty(obj,msg){
	var valid = true;
	if(obj.value.length<=0){
		alert(msg);
		obj.focus();
		obj.style.borderWidth = borderWidth;
	    obj.style.borderColor = borderColor;
	    obj.style.backgroundColor = bgColor;
		valid = false;
	}
	return valid;
}

function checkSelected(obj, msg){
    var valid = true;
    if(obj.selectedIndex<=0){
        alert(msg);
        obj.focus();
        valid = false;
    }
    return valid;
}

function checkLength(obj, sMin, sMax){
	var valid = true
	if((sMin=='')||(sMin==null))	sMin = 2;
	if((sMax=='')||(sMax==null))	sMax = 40;
	if((obj.value.length<sMin)||(obj.value.length>sMax)){
		valid = false
		obj.value = "";
		obj.focus();
	}
	return valid
}

function countLength(stringToCount)  
{ 
    //計算有幾個全型字、中文字...  
    var c = stringToCount.match(/[^ -~]/g);  
    return stringToCount.length + (c ? c.length : 0);  
}

//驗證E-mail是否正確
function checkEmail(obj, msg) {
    var valid = true;
    var regInvalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
    var regValid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    valid = (!regInvalid.test(obj.value) && regValid.test(obj.value));
    if(!valid){
        alert(msg);
        obj.value = "";
        obj.focus();
    }
    return valid;
}

function checkPassword(oField1,oField2){
	var valid = true
	if(oField1.value!=oField2.value){
		alert("密碼輸入不正確！請重新輸入！\n");
		valid = false;
		oField1.value = "";
		oField2.value = "";
		oField1.focus();
	}
	return valid
}

function checkAlphaNumber(obj,txt){
	var allValid = true;
	if(obj.value.length>0){
		var checkOK = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var checkStr = obj.value;
		for (i = 0;  i < checkStr.length;  i++){
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
		        		break;
			if (j == checkOK.length){
				allValid = false;
				break;
			}
		}

		if(!allValid) {
			obj.value="";
			obj.focus();
			alert(txt + "只能輸入英文字母及數字！請重新輸入！\n");
		}
	}else{
		allValid = false
	}
	return allValid
}

function checkFloat(){
    var obj = document.getElementById(event.srcElement.id);
    var iKeyCode = event.keyCode;
    if(!(((iKeyCode >= 48) && (iKeyCode <= 57)) || (iKeyCode == 13) || (iKeyCode == 46) || (iKeyCode == 45) || (iKeyCode == 37) || (iKeyCode == 39) || (iKeyCode == 8)))
    {
        alert("只能輸入小數點及數字！");
        obj.value = "";
        obj.focus();
        return false;
    }
}
    
function checkNumberCode(){
    var obj = document.getElementById(event.srcElement.id);
    var iKeyCode = event.keyCode;
    if(!(((iKeyCode >= 48) && (iKeyCode <= 57)) || (iKeyCode == 13) || (iKeyCode == 45) || (iKeyCode == 37) || (iKeyCode == 39) || (iKeyCode == 8) || (iKeyCode == 9) || (iKeyCode>=96 && iKeyCode<=105)))
    {
        alert("只能輸入數字！");
        obj.value = "";
        obj.focus();
        return false;
    }
}

function checkNum(obj){
    var allValid = true;
	if(obj.value.length>0){
		var checkOK = "1234567890.";
		var checkStr = obj.value;
		for (m = 0;  m < checkStr.length;  m++){
			ch = checkStr.charAt(m);
			for (n = 0;  n < checkOK.length;  n++)
				if (ch == checkOK.charAt(n))
		        		break;
			if (n == checkOK.length){
				allValid = false;
				break;
			}
		}
	}
	return allValid;
}

function checkNumber(obj,txt){
	var allValid = true;
	if(obj.value.length>0){
		var checkOK = "1234567890.";
		var checkStr = obj.value;
		for (m = 0;  m < checkStr.length;  m++){
			ch = checkStr.charAt(m);
			for (n = 0;  n < checkOK.length;  n++)
				if (ch == checkOK.charAt(n))
		        		break;
			if (n == checkOK.length){
				allValid = false;
				break;
			}
		}

		if(!allValid) {
			obj.value="";
			obj.focus();
			alert(txt+"只能輸入數字！請重新輸入！\n");
		}
	}
	return allValid;
}

function checkNumberLen(oField, min, max, sText){
	var checkOK = "0123456789";
	var checkStr = oField.value;
	var valid = true;
	
	if((checkStr.length < min)||(checkStr.length > max)){
		alert(sText + "長度不正確");
		valid = false;
		oField.value = "";
		oField.focus();
	}else{
		for(n=0; n<checkStr.length; n++){
			ch = checkStr.charAt(n);
			for(m=0; m < checkOK.length; m++){
				if(ch==checkOK.charAt(m)) break;
				if(m==checkOK.length){
					valid = false;
					break;
				}
			}
			if(!valid){
				alert(sText + "只能輸入數字！請重新輸入！\n");
				oField.value = "";
				oField.focus();
				break;
			}
		}
	}
	return valid;
}

function checkIdnumber(obj, sText){
	if(obj.value.length>0)
	{
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	  var checkOK1 = "1234567890";
	  var checkStr = obj.value;
	  var allValid = true;
	  ch = checkStr.charAt(0);
	  for (a = 0;  a < checkOK.length;  a++)
    	if (ch == checkOK.charAt(a)) break;
	  if (a == checkOK.length) allValid = false;
	else {
    	for (b = 1;  b < checkStr.length;  b++) {
	      ch = checkStr.charAt(b);
    	  for (a = 0;  a < checkOK1.length;  a++)
	        if (ch == checkOK1.charAt(a))
    	      break;
	      if (a == checkOK1.length)
    	  {
	        allValid = false;
    	    break;
	      }
    	}
	  }
	  ch2 = checkStr.charAt(1);
	  if ((ch2 != "1" && ch2 != "2") || (Obj.value.length != 10)) allValid = false;
	  if(!allValid) {
			alert(sText+"字號格式不正確！請重新輸入！\n");
			obj.value="";
			obj.focus();
	  }
	  return allValid
	}
}

/*檢查只能輸入中文*/
function checkChinese(obj,msg) {
    var tempChar;
    var tempValue;
    var isChinese;
    tempValue=obj.value.toUpperCase();
    for (i=0;i<tempValue.length;i++) {
       tempChar = tempValue.charAt(i);
       if(tempChar.charCodeAt(0) >= 65 && tempChar.charCodeAt(0) <= 90) {
           alert(msg);
           obj.select();
           return false;
        }
    }     
     /* 如果不是只有數字就 ok */
    isChinese = false;
    for(z=0; z<obj.value.length;z++) {
        c = obj.value.charAt(z);
        if("0123456789".indexOf(c,0) < 0) {   
            isChinese = true;
        } 
    }      
    if (!isChinese) {
       alert(msg);
       obj.select();
       return false;
    }
    else {
        return true;
    }
}

function compareDate(ed,cd,msg){
	var exceptSignDate=ed.value;
	var createDate=cd.value;
	//alert(exceptSignDate);
	//2007-04-27
	if(exceptSignDate>createDate){
		return true;
	}
	else{
		alert(msg);
	}
}


//----------------------------------------------------------------------
//	validate form field functions
//----------------------------------------------------------------------
function chkTextBox(obj){
	var valid = true
	if(obj.value==""){
		valid = false;
		obj.focus();
	}
	return valid
}

function chkRadio(obj){
	var valid = false
	for(j=0; j<obj.length; j++){
		if(obj[j].checked==true){
			valid = true;
			break;
		}
	}
	return valid
}

function chkCheckBox(obj){
	var valid = false
	for(i=0; i<obj.length; i++){
		if(obj[i].checked==true){
			valid = true;
			break;
		}
	}
	return valid
}

function chkSelect(obj){
	var valid = true
	if((obj.value=='')||(obj.value==null)||(obj.value==0)){
		valid = false
		obj.focus();
	}
	return valid
}
function chkTextArea(obj){
	if(obj.value=="")
		return false
	else
		return true
}
//-->

