﻿//畫面切換
function MenuChange(obj1){
	location.href=obj1 + ".asp";
}
//關於畫面控制的FUNCTION
function sbar(st,pColor) {
	st.style.backgroundColor = pColor;
}

function cbar(st) {
	st.style.backgroundColor = '';
}
function setBgColor(st,pColor) {
	st.style.backgroundColor = pColor;
}

function cleanBgColor(st) {
	st.style.backgroundColor = '';
}
function overFontColor(MyObj,MyColor){
// onmouseover change font color
	MyObj.style.color=MyColor;
}
function outFontColor(MyObj){
// onmouseout rechange font color
	MyObj.style.color='';
}
///cookies
function chkSource(xStr){ //防止惡意入侵檢查程式
	//xStr='';
	if(xStr.indexOf(window.name)==-1){
		//window.close();
		//alert("window.name不等於<%''=GetFilename(MyPage)%>");
		document.location="../USER_Status.asp?rtnMsg=操作錯誤";
	}
}

function checkBeforeDelete(pForm){//刪除前檢查
//pForm 傳入的form物件
//檢查checkbox 是否有選取 
//有選取則詢問是否確定要刪除
//將傳進來的form submit出去
	wFlg=false;
	for(var i=0; i<=pForm.elements.length-1; i++){
		if (pForm.elements[i].type=="checkbox"){
			if(pForm.elements[i].checked==true){
				wFlg=true;
				break;}
		}
	}
	if(wFlg==true){
		if (confirm('確定要刪除選取的資料嗎？')){
			pForm.submit();}
	}else{
		alert('請先選取要刪除的資料');
	}
}

function checkBeforeSubmit(pForm, pFldName, pMsg){//前檢查 (包含刪除前檢查)
//pForm 傳入的form物件
//pFldName 要檢查的checkbox物件名稱字串
//檢查checkbox 是否有選取 
//有選取則詢問是否確定要執行
//將傳進來的form submit出去
	wFlg=false;
	for(var i=0; i<=pForm.elements.length-1; i++){
		if (pForm.elements[i].type=="checkbox"){
			if (pForm.elements[i].name.indexOf(pFldName)>=0) {
				if(pForm.elements[i].checked==true){
					wFlg=true;
					break;}
			}
		}
	}
	if(wFlg==true){
		if (confirm('確定要' + pMsg +'選取的項目嗎？')){
			pForm.submit();
		}
	}else{
		alert('請先選取要' + pMsg + '的資料');
	}
}

function changeSelect(pForm){//全選全不選   不正常請部要使用本function
//pForm 傳入的form物件
// from 裡面的所有 checkbox 名稱不可相同
//將form中所有的checkbox物件全部設為與第一個checkbox相同選取狀態
	for(var i=0; i<=pForm.elements.length-1; i++){
		if (pForm.elements[i].type=="checkbox"){
			pForm.elements[i].checked =!pForm.elements[i].checked
			changAllCheckbox(pForm,pForm.elements[i].checked);
			break;}
	}
}
function changAllCheckbox(pForm,pBoolean){// 設定checkbox的值
//pForm 傳入的form物件
//pBoolean 傳入的布林值
	for(var i=0; i<=pForm.elements.length-1; i++){
		if (pForm.elements[i].type=="checkbox")
			pForm.elements[i].checked=pBoolean;
	}
}
//////////////////////////////

function OpenAutoWin(pPhotoSrc){//開啟隨圖檔調整大小的視窗
var mySrc=pPhotoSrc
var Win=window.open("","AutoWindow","width=150,height=100,status=no,resizeable=no");
Win.document.open();
Win.document.write("<html>");
Win.document.write("<head>");
Win.document.write("<title>看圖視窗-(點圖自動關閉視窗)</title>");
Win.document.write("</head>");
Win.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="javascript:window.resizeTo(myImg.width+10,myImg.height+30);" onblur="window.close();">');
Win.document.write('<img src="' + mySrc + '" id="myImg" title="點圖關閉視窗"  onclick="window.close();" alt="圖檔遺失..">');
Win.document.write("</body>");
Win.document.write("</html>");
Win.document.close();
}
function OpenWin(theURL,x,y,MyType,MyWinName) { 
//  var x_screen=screen.availWidth;
//  var y_screen=screen.availHeight;
  var x_screen=screen.Width;
  var y_screen=screen.Height;
  var wk_left=(x_screen-x)/2;
  var wk_top=(y_screen-y)/2;
  var features;
  switch (MyType){
  	case 0: //固定大小的視窗，無狀態列無網址列無捲軸
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=" + wk_top + ",left=" + wk_left;
	  features+=",status=no,resizable=no,scrollbars=no,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=no,titlebar=no";
	  break;
	case 1: //一般的ie視窗
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=" + wk_top + ",left=" + wk_left;
	  features+=",status=yes,resizable=yes,scrollbars=auto,location=yes,menubar=yes";
	  features+=",channelmode=no,directories=yes,fullscreen=no,titlebar=yes";
  	  break;
	case 2: //無狀態列無網址列，可調整大小，捲軸自動
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=" + wk_top + ",left=" + wk_left;
	  features+=",status=yes,resizable=yes,scrollbars=yes,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=no,titlebar=no";
	  break;
  	case 3: //全螢幕視窗
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=" + wk_top + ",left=" + wk_left;
	  features+=",status=no,resizable=no,scrollbars=no,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=yes,titlebar=no";
	  break;
	case 4: //左上角視窗
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=0,left=0";
	  features+=",status=yes,resizable=yes,scrollbars=yes,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=no,titlebar=no";
	  break;
	case 5: //左上角視窗(圖片用)
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=0,left=0";
	  features+=",status=no,resizable=yes,scrollbars=no,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=no,titlebar=no";
	  break;
	case 6: //右上角視窗
		var wRight=x_screen-x-10;
	  features="Height=" + y + ",Width=" + x;
	  features+=",top=0,left=" + wRight ;
	  features+=",status=no,resizable=no,scrollbars=no,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=no,titlebar=no";
	  break;


	default:
	  alert ("error");
	  break; 
  }
  window.open(theURL,MyWinName,features);
}
function OpenWinDialog(theURL,x,y,MyType) { 
  var strStatus;
  var features;
  window.status="";
  switch(MyType){
  	case 0:
	  features="dialogHeight=" + y + "px;dialogWidth=" + x + "px";
	  features+=";status=no;resizable=no;scrollbars=auto;help=no;center=yes";
	  break;
  	case 1:
	  features="dialogHeight=" + y + "px;dialogWidth=" + x + "px";
	  features+=";status=no;resizable=yes;scrollbars=auto;help=no;center=yes";
	  break;
	case 2: //無狀態列無網址列，可調整大小，捲軸自動
	  features="dialogHeight=" + y + "px;dialogWidth=" + x + "px";
	  //features+=",top=0" + wk_top + ",left=" + wk_left;
	  features+=",status=yes,resizable=yes,scrollbars=yes,location=no,menubar=no";
	  features+=",channelmode=no,directories=no,fullscreen=no,titlebar=no";
	  break;
	default:
		alert ("error");
		break;
	}
  return window.showModalDialog(theURL,"winName",features);
 //  strStatus=window.Modeless(theURL,winName,features);
}
function imageProtect(mousebutton) { 
if (navigator.appName == "Microsoft Internet Explorer") {
	if (mousebutton == 2 || mousebutton == 3 || mousebutton == 6 || mousebutton == 7) {
		alert('如果您有任何操作上的問題請向系統維護人員反映謝謝！'); 
		return false;
		}
	}
	else if (navigator.appName == "Netscape") {
		if (mousebutton == 3) {
		alert('如果您有任何操作上的問題請向系統維護人員反映謝謝！'); 
			return false;
		}
	}
	else return true;
}

function imageProtect(mousebutton) { //3.0
if (navigator.appName == "Microsoft Internet Explorer") {
	if (mousebutton == 2 || mousebutton == 3 || mousebutton == 6 || mousebutton == 7) {
		alert('如果您有任何操作上的問題請向系統維護人員反映謝謝！'); 
		return false;
		}
	}
	else if (navigator.appName == "Netscape") {
		if (mousebutton == 3) {
		alert('如果您有任何操作上的問題請向系統維護人員反映謝謝！'); 
			return false;
		}
	}
	else return true;
}
function J_reload(){
	location.reload();
}

function chk_date(obj,myType){
var MyDate=/[0-9]{8}/;
var tmpStr = obj.value;
var tmpStr1=tmpStr.toString();
var tmpYr=tmpStr1.substr(0,4);
var tmpMon=tmpStr1.substr(4,2);
var tmpDay=tmpStr1.substr(6,2);
var intYr = Number(tmpYr);
var intMon = Number(tmpMon);
var intDay = Number(tmpDay);
var maxDay = 0;
switch (myType)	{
	case 0:
		if (tmpStr.length!=0){
			if (!MyDate.test(tmpStr)){
				alert ("請輸入8位數西元年月日，例如2001年9月11日，請輸入'20010911'");
				obj.focus();
				obj.select();
				//date_birthday();
				return false;
				}
			if (intMon < 1 || intMon > 12){
				alert ("月份錯誤，請輸入月份介於 1 月至 12 月！");
				obj.focus();
				obj.select();
				return false;
				}
			if (intMon == 2)
				if ((intYr % 400 == 0) || (intYr % 100 != 0) && (intYr % 4 == 0))
					maxDay = 29;
				else
					maxDay = 28;
			else
				if (((intMon * 6 / 7) % 2) <=1 )
					maxDay = 31; //alert (tmpMon + "  大月");
				else
					maxDay = 30; //alert (tmpMon + "  小月");
				
			if (intDay < 1 || intDay > maxDay){
				alert ("日期錯誤，請輸入" + tmpMon + "月份日期介於 1 至 " + maxDay.toString() + "！");
				obj.focus();
				obj.select();
				return false;
				}
				return true;
			}
		else
			return true;
		break;
	case 1:
			if (!MyDate.test(tmpStr)){
				alert ("請輸入8位數西元年月日，例如2001年9月11日，請輸入'20010911'");
				obj.focus();
				obj.select();
				//date_birthday();
				return false;
				}
			if (intMon < 1 || intMon > 12){
				alert ("月份錯誤，請輸入月份介於 1 月至 12 月！");
				obj.focus();
				obj.select();
				return false;
				}
			if (intMon == 2)
				if ((intYr % 400 == 0) || (intYr % 100 != 0) && (intYr % 4 == 0))
					maxDay = 29;
				else
					maxDay = 28;
			else
				if (((intMon * 6 / 7) % 2) <=1 )
					maxDay = 31; //alert (tmpMon + "  大月");
				else
					maxDay = 30; //alert (tmpMon + "  小月");
				
			if (intDay < 1 || intDay > maxDay){
				alert ("日期錯誤，請輸入" + tmpMon + "月份日期介於 1 至 " + maxDay.toString() + "！");
				obj.focus();
				obj.select();
				return false;
				}
				return true;
			break;
	default:
		alert('error');
		return false;
		break;
	}
}


function chk_Year(obj){
var MyYYMM=/[0-9]{4}/;
var tmpStr =obj.value;
	if (!MyYYMM.test(tmpStr)){
		alert ("請輸入4位數西元年度，例如2001年，請輸入'2001'");
		obj.focus();
		obj.select();
		return false;
		}
	return true;
}
function chk_YYMM(obj){
var MyYYMM=/[0-9]{6}/;
var tmpStr =obj.value;
	if (!MyYYMM.test(tmpStr)){
		alert ("請輸入6位數西元年月，例如2001年11月，請輸入'200111'");
		obj.focus();
		obj.select();
		return false;
		}
var tmpStr1=tmpStr.toString();
var tmpYr=tmpStr1.substr(0,4);
var tmpMon=tmpStr1.substr(4,2);
var intYr=Number(tmpYr);
var intMon=Number(tmpMon);
if (intMon < 1 || intMon > 12){
	alert ("月份錯誤，請輸入月份介於 1 月至 12 月！");
	obj.focus();
	obj.select();
	return false;
	}
	return true;
}
function chk_MMDD(obj){
var MyDate=/[0-9]{4}/;
var tmpStr = obj.value;
var tmpStr1=tmpStr.toString();
var tmpMon=tmpStr1.substr(0,2);
var tmpDay=tmpStr1.substr(2,2);
var intMon = Number(tmpMon);
var intDay = Number(tmpDay);
var maxDay = 0;

	if (tmpStr.length!=0){
		if (!MyDate.test(tmpStr)){
			alert ("請輸入4位數月日，例如9月11日，請輸入'0911'");
			obj.focus();
			obj.select();
			//date_birthday();
			return false;
			}
		if (intMon < 1 || intMon > 12){
			alert ("月份錯誤，請輸入月份介於 1 月至 12 月！");
			obj.focus();
			obj.select();
			return false;
			}
		if (intMon == 2)
			if ((intYr % 400 == 0) || (intYr % 100 != 0) && (intYr % 4 == 0))
				maxDay = 29;
			else
				maxDay = 28;
		else
			if (((intMon * 6 / 7) % 2) <=1 )
				maxDay = 31; //alert (tmpMon + "  大月");
			else
				maxDay = 30; //alert (tmpMon + "  小月");
			
		if (intDay < 1 || intDay > maxDay){
			alert ("日期錯誤，請輸入" + tmpMon + "月份日期介於 1 至 " + maxDay.toString() + "！");
			obj.focus();
			obj.select();
			return false;
			}
			return true;
		}
		else
			return true;
		
}

function chk_account(obj){
var MyStr=/^[a-zA-Z]{1}[\w]{3,19}$/;
		if(MyStr.test(obj.value)){
			return true;
		}else{
			alert ("請輸入正確帳號\n第一個字必須是英文字，至少4字，最多20字\n且全為英文字、數字、或底線");
			obj.focus();
			obj.select();
			return false;
		}
}

function chk_account_KS(obj,wMsg){
var MyStr=/^[a-z0-9]{4,20}$/;
		if(obj.value.match(MyStr)!=null){
			return true;
		}else{
			if (obj.value.length < 4){
				alert (wMsg + "至少需4個字");
			} else if (obj.value.length > 20) {
				alert (wMsg + "最多20個字");
			}else {
				alert ("請輸入正確" + wMsg + "\n僅能為小寫英文字或數字，至少4個字，最多20字");
			}
			obj.focus();
			obj.select();
			return false;
		}
}

function chk_pwd(obj1,obj2){
	if (IsEmpty(obj1,"密碼")){
		obj1.focus();
		obj1.select();
		return false;}
	else 
		if(IsEmpty(obj2,"密碼確認")){
			obj2.focus();
			obj2.select();
			return false;}
		else
			if (obj1.value==obj2.value)
				return true;
			else{
				alert("密碼確認不正確!!請再輸入一次!!");
				obj2.focus();
				obj2.select();
				return false;}
}

function chk_email(obj,myType){
var MyStr=/[a-zA-Z_0-9\.]{2,}@[\w]{1,}\.[\w]{3,}/;

if (obj.value.indexOf(',')>0)
	alert("請輸入正確的電子郵件信箱");
if (myType=="0") //可以空白
	if (obj.value!="")
		if (MyStr.test(obj.value))
			return true;
		else{
			alert ("請輸入正確的電子郵件信箱");
			obj.focus();
			obj.select();
			return false;}
	else
		return true;
else
	if (MyStr.test(obj.value))
		return true;
	else{
		alert ("請輸入正確的電子郵件信箱");
		obj.focus();
		obj.select();
		return false;}
}

function chk_email_edu(obj,myType){
var MyStr=/[\w\.]{2,}@\w{1,}(\.\w{2,}){0,}\.edu/;
if (obj.value.indexOf('＠')>0){
	alert('請改以半形符號輸入');
}else{
	if (myType=="0") //可以空白
		if (obj.value!="")
			if (MyStr.test(obj.value))
				return true;
			else{
				alert ("請輸入正確的學校電子郵件信箱");
				obj.focus();
				obj.select();
				return false;
			}
		else
			return true;
	else
		if (MyStr.test(obj.value))
			return true;
		else{
			alert ("請輸入正確的學校電子郵件信箱");
			obj.focus();
			obj.select();
			return false;
		}
	}
}

function chk_phone(obj,myType){
var validAll=/^(\([0-9]{2}\)-?|[0-9]{2}-?){0,1}[0-9]{3,4}-?[0-9]{4}((-|#)[0-9]{1,}){0,1}$/;//完全比對(02)1234-5678#123
var MyPhone =/[0-9]{7,}/;
var NotMyPhone =/[^0-9()#-]/;
var tmpStr = "" + obj.value;
var tmpStrNum = tmpStr.replace(/[^0-9]/g,"");
	switch(myType){
		case 0://可以空白
			if (tmpStr!=""){
				if (NotMyPhone.test(tmpStr)){
					alert("不可以有數字,#,-,(,)以外的字元");
					obj.focus();
					obj.select();
					return false;
				}else if (!MyPhone.test(tmpStrNum)){
					alert("最少輸入7碼數字");
					obj.focus();
					obj.select();
					return false;
				}else{
					//return true;
					if(validAll.test(tmpStr)){
						return true;
					}else{
						alert("難以辨識的電話格式");
						obj.focus();
						obj.select();
						return false;
					}
				}
			}else{
				return true;
			}
			break;
		case 1://一定要輸入
			if (NotMyPhone.test(tmpStr)){
				alert("不可以有數字,#,-,(,)以外的字元");
				obj.focus();
				obj.select();
				return false;
			}else if (!MyPhone.test(tmpStrNum)){
				alert("最少輸入7碼數字");
				obj.focus();
				obj.select();
				return false;
			}else{
				//return true;
				if(validAll.test(tmpStr)){
					return true;
				}else{
					alert("難以辨識的電話格式");
					obj.focus();
					obj.select();
					return false;
				}
			}
			break;
		case 2://特殊用法
			if (tmpStr.length==0)
				return false;
			else	
				return true;
			break;
		default:
			alert("error");
			return false;
			break;
	}
}
function chk_cell(obj,myType){
var MyPhone =/[0-9]{10}/;
var NotMyPhone =/[^0-9]/;        
var tmpStr = obj.value;
	switch(myType){
		case 0://可以空白
			if (tmpStr!=""){
				if (NotMyPhone.test(tmpStr)){
					alert("不可以有數字以外的字元");
					obj.focus();
					obj.select();
					return false;
				}else if (!MyPhone.test(tmpStr)){
					alert("請輸入10碼數字");
					obj.focus();
					obj.select();
					return false;
				}else{
					return true;
				}
			}else{
				return true;
			}
			break;
		case 1://一定要輸入
			if (NotMyPhone.test(tmpStr)){
				alert("不可以有數字以外的字元");
				obj.focus();
				obj.select();
				return false;
			}else if (!MyPhone.test(tmpStr)){
				alert("請輸入10碼數字");
				obj.focus();
				obj.select();
				return false;
			}else{
					return true;
			}
			break;
		case 2://特殊用法
			if (tmpStr.length==0)
				return false;
			else	
				return true;
			break;
		default:
			alert("error");
			return false;
			break;
	}
}
function chk_empty(obj,msg){
	if (IsEmpty(obj,msg)){
		event.returnValue=false;}
	else
		event.returnValue=true;
}
function chk_number(obj,str){
	if (!IsNumber(obj,str)){
		event.returnValue=false;}
	else
		event.returnValue=true;
}
function IsFloat(obj,myType){
var NotNumber =/[^0-9]{1,}/;
var Float=/[0-9]{1,}.?[0-9]*/;
var tmpStr = obj.value;
	switch(myType){
		case 1:			
			if (tmpStr!=""){
				if (!Float.test(tmpStr)){
					obj.focus();
					obj.select();
					alert("不可以有數字以外的字元");
					return false;}
				else{
					return true;}
			}else{
				obj.focus();
				alert("請輸入數字");
				return false;
			}
			break;
		case 0: //可以空白
			if (tmpStr!=""){
				if (!Float.test(tmpStr)){
					obj.focus();
					obj.select();
					alert("不可以有數字以外的字元");
					return false;}
				else
					return true;
			}else{
				return true;
			}
			break;
		default:
			alert("error")
			return true;
			break;
			
	}

}

function IsNumber(obj,myType){
var NotNumber =/[^0-9]{1,}/;        
var tmpStr = obj.value;
	switch(myType){
		case 1:			
			if (tmpStr!=""){
				if (NotNumber.test(tmpStr)){
					obj.focus();
					obj.select();
					alert("不可以有數字以外的字元");
					return false;}
				else{
					return true;}
			}else{
				obj.focus();
				alert("請輸入數字");
				return false;
			}
			break;
		case 0: //可以空白
			if (tmpStr!=""){
				if (NotNumber.test(tmpStr)){
					obj.focus();
					obj.select();
					alert("不可以有數字以外的字元");
					return false;}
				else
					return true;
			}else{
				return true;
			}
			break;
		default:
			alert("error")
			return true;
			break;
			
	}

}

function HaveSymbol(obj,msg){
	var RuleStr=/\W/;
	if (RuleStr.test(obj.value)){
		alert('( ' + msg + ' ) 不可以有數字、英文、底線以外的特殊符號');
		return true;
	}else{ return false;}
	
}

function IsEmptyNoMsg(obj){
var MyType=obj.type;
	switch(MyType){
		case "text":
			obj.value.replace(' ','');
			if (obj.value==""){
				return true;
				break;
				}
			else{
				return false;
				break;}
		case "password":
			obj.value.replace(' ','');
			if (obj.value==""){
				return true;
				break;}
			else{
				return false;
				break;}
		case "textarea":
			obj.value.replace(' ','');
			if (obj.value==""){
				return true;
				break;}
			else{
				return false;
				break;}
		case "checkbox":
			return true;
			break;
		case "radio":
			if (msg=='0')
			    if (!obj.checked){
					return true;
					break;}
			    else{
					return false;
					break;}
			else
			    if (!obj.checked){
					return true;}
			    else{
					return false;
					break;}
		case "select-one":
			if (obj.options[0].selected){
				return true;
				break;}
			else{
				return false;
				break;}
		case "select-multiple":
			if (!obj.selected){
				return true;
				break;}
			else{
				return false;
				break;}
		case "hidden":
			obj.value.replace(' ','');
			if(obj.value.length==0){
				return true;
				break;}
			else{
				return false;
				break;}
		case "file":
			if(obj.value.length==0){
				return true;
				break;}
			else{
				return false;
				break;}
		default:
			alert("不明的錯誤1")
			return true;
			break;
	}

}

function IsEmptyNoMsg_checkbox(obj){
//Modify by Peter,20070205
//檢查checkbox是否有選擇
//當多個checkbox為同一名字時，存在一個選項被勾選則回傳false
	
var ItemCnt,MyType,j

	MyType=obj.type;
	if (MyType=='checkbox'){
		if (!obj.checked){
			return true;
		} else {
			return false;
		}
	} else {
		ItemCnt=obj.length;
		if (ItemCnt > 1){
			for (j=0;j < ItemCnt;j++){
				MyType=obj[j].type;
				if (MyType=='checkbox'){
					if (obj[j].checked){
						return false;
					}
				} else {
					alert('存在名稱相同但類型不同之物件，請檢查！');
					return true;
				}
			}
			return true;
		} else {
			alert("不明的錯誤！引用錯誤的檢查函式？");
		}
	}
}

function IsEmpty_checkbox(obj,msg){
//Modify by Peter,20070205
//檢查checkbox是否有選擇
//當多個checkbox為同一名字時，存在一個選項被勾選則回傳false

var ItemCnt,MyType,j

	MyType=obj.type;
	if (MyType=='checkbox'){
		if (!obj.checked){
			alert("請選擇" + msg);
			obj.focus();
			return true;
		} else {
			return false;
		}
	} else {
		ItemCnt=obj.length;
		if (ItemCnt > 1){
			for (j=0;j < ItemCnt;j++){
				MyType=obj[j].type;
				if (MyType=='checkbox'){
					if (obj[j].checked){
						return false;
					}
				} else {
					alert('存在名稱相同但類型不同之物件，請檢查！');
					return true;
				}
			}
			alert("請選擇" + msg);
			return true;
		} else {
			alert("不明的錯誤！引用錯誤的檢查函式？");
		}
	}
}

function IsEmpty(obj,msg){
var MyType=obj.type;
	switch(MyType){
		case "text":
			obj.value.replace(' ','');
			if (obj.value==""){
				alert("請填寫" + msg);
				obj.focus();
				return true;}
			else
				return false;			
			break;
		case "password":
			obj.value.replace(' ','');
			if (obj.value==""){
				alert("請填寫" + msg);
				obj.focus();
				return true;} 
			else 
				return false;
			break;
		case "textarea":
			obj.value.replace(' ','');
			if (obj.value==""){
				alert("請填寫" + msg);
				obj.focus();
				return true;}
			else
				return false;
			break;
		case "checkbox":
			return true;
			break;
		case "radio":
			if (msg=='0')
			    if (!obj.checked){
				obj.focus();
				return true;}
			    else
				return false;
			else
			    if (!obj.checked){
				alert("請選擇" + msg)
				obj.focus();
				return true;}
			    else
				return false;
			break;
		case "select-one":
			if (obj.options[0].selected){
				alert("請選取" + msg);
				obj.focus();
				return true;}
			else
				return false;
			break;
		case "select-multiple":
			if (!obj.selected){
				alert("未完成");
				obj.focus();
				return true;}
			else
				return false;
			break;
		case "hidden":
			obj.value.replace(' ','');
			if(obj.value.length==0){
			    alert("請輸入" + msg);
				return true;}
			else
				return false;
			break;
		case "file":
			if(obj.value.length==0){
			    alert("請輸入" + msg);
				return true;}
			else
				return false;
			break;
		default:
			alert("不明的錯誤")
			return true;
			break;
	}

}

function IsChecked(obj,msg){
	wLen=obj.length;
	for(i=0;i<wLen;i++){
		if(obj[i].checked){return true;}
	}
	alert("請選擇" + msg);
	return false;
}

function IsCheckedDiffNM(pForm, pFldName, pMsg){//前檢查 (包含刪除前檢查)
//pForm 傳入的form物件
//pFldName 要檢查的checkbox物件名稱字串
//檢查checkbox 是否有選取
//有選取則詢問是否確定要執行
//將傳進來的form submit出去
	wFlg=false;
	for(var i=0; i<=pForm.elements.length-1; i++){
		if (pForm.elements[i].type=="checkbox"){
			if (pForm.elements[i].name.indexOf(pFldName)>=0) {
				if(pForm.elements[i].checked==true){
					wFlg=true;
					break;}
			}
		}
	}
	if(wFlg==true){
		return true;
	}else{
		alert( pMsg );
		return false;
	}
}

function maxWords(obj,pNum){

	if (obj.value.length>pNum){
		alert("字數超過" + pNum + "字");
		obj.focus();
		obj.select();
		return false;
	}else
		return true;
}

function chk_gui(pa_gui_no_obj){
	var pa_gui_no=pa_gui_no_obj.value;
	var I=0;
	var j=0;
	var get_str=new Array(8);
	var times_num=new Array(8); 
	var tot_num=new Number;
	times_num[1]=1;
	times_num[2]=2;
	times_num[3]=1;
	times_num[4]=2;
	times_num[5]=1;
	times_num[6]=2;
	times_num[7]=4;
	times_num[8]=1;
	tot_num=0;
	if (pa_gui_no.length==0) {
	   return true;}
	if (pa_gui_no.length!=8){
	   alert("請輸入正確的統一編號");
	   pa_gui_no_obj.focus();
	   pa_gui_no_obj.select();
	   return false;}
	var tmpStr=new String;
	for (I=1;I<=8;++I){
		get_str[I] = parseInt(pa_gui_no.substr(I-1,1)) * times_num[I];
		tmpStr=get_str[I].toString();
		for (j=0;j<tmpStr.length;j++){
			tot_num = tot_num + parseInt(tmpStr.substr(j,1));
		}
	}
	if ((tot_num % 10) == 0){
		return true;
	}
	else{
		if (pa_gui_no.substr(6,1) != "7"){
			alert("請輸入正確的統一編號");
			pa_gui_no_obj.focus();
			pa_gui_no_obj.select();
			return false;
		}
		else{
			get_str[7] = 1;
			tot_num = 0;
			for (I=1;I<=8;++I){
				tmpStr=get_str[I].toString();
				for (j=0;j<tmpStr.length;j++){
					tot_num = tot_num + parseInt(tmpStr.substr(j,1));
				}
			}
			alert(tot_num);
			if (tot_num % 10 == 0){
				return true;
			}
			else{
				get_str[7] = 0;
				tot_num = 0;
				for (I=1;I<=8;++I){
					tmpStr=get_str[I].toString();
					for (j=0;j<tmpStr.length;j++){
						tot_num = tot_num + parseInt(tmpStr.substr(j,1));
					}
				}
				alert(tot_num);
				if (tot_num % 10 == 0){
					return true;
				}
				else{
					alert("請輸入正確的統一編號");
					pa_gui_no_obj.focus();
					pa_gui_no_obj.select();
					return false;
				}
			}
		}
	}
}//End Function

function changCheckbox(pForm,OName,pBoolean){// 設定checkbox的值
//Peter,950927
//pForm 傳入的form物件
//OName 傳入的物件名稱
//pBoolean 傳入的布林值
	for(var i=0; i<=pForm.elements.length-1; i++){
		if (pForm.elements[i].type=="checkbox")
			if (pForm.elements[i].name.substring(0,OName.length).toUpperCase() == OName.toUpperCase())
				if (! pForm.elements[i].disabled){
					pForm.elements[i].checked=pBoolean;
				}
	}
}

function changCheckboxH(cCheckNM,pBoolean){
// 設定checkbox的值，母帶子水平調整
//Peter,950927
//cCheckNM 傳入的要改變的子項目名稱
//pBoolean 傳入的布林值
	var i
	//alert(cCheckNM.length);
	if (cCheckNM.length==undefined){
		cCheckNM.checked=pBoolean;
	}else{
		for (i=0;i<cCheckNM.length;i++){
			cCheckNM[i].checked=pBoolean;
		}
	}
}

function CheckDupKey(wForm,CheckNM,KeyFieldNM,wMethod){
///Peter,950928
///檢查多筆新增時，是否有重複的Key值
///wForm 表單名稱
///CheckNM 註記是否要存檔的標籤名稱
///KeyFieldNM 資料為資料庫KEY值的欄位名稱，多個可用','隔開
	var flgDup,i,widx,j,wStr,k,flgNoCheck;
	if (KeyFieldNM.indexOf(',') != -1){
		xAry = KeyFieldNM.splite(',');
	}else{
		var xAry = new Array();
		xAry[0]=KeyFieldNM;
	}
	var IdxAry = new Array();
	var KeyAry = new Array();
	flgDup=false;
	j=0;
	flgNoCheck=true;
	for (i=0;i<=wForm.elements.length -1;i++){
		if (wForm.elements[i].type == "checkbox"){
			if (wForm.elements[i].name.substring(0,CheckNM.length).toUpperCase()==CheckNM.toUpperCase()){
				if (wForm.elements[i].checked && wForm.elements[i].name.toUpperCase()!=CheckNM.toUpperCase()){
					flgNoCheck=false;
					j++;
					widx=wForm.elements[i].name.substring(CheckNM.length,wForm.elements[i].name.length)
					wStr=""
					for (k=0;k<xAry.length;k++){
						wStr += '_'+wForm.elements[xAry[k]+widx].value
					}
					IdxAry[j-1]=widx
					KeyAry[j-1]=wStr.substring(1,wStr.length).toUpperCase();
					//alert(KeyAry[j-1]);
					if (j-1 > 0) {
						for (k=0;k<j-1;k++){
							if (KeyAry[k]!=''){
								if (KeyAry[k]==KeyAry[j-1]){//假如現在的KEY值與之前已記錄者相同
									flgDup=true;
									alert('目前輸入畫面上，第'+IdxAry[j-1]+'筆資料與第'+IdxAry[k]+'筆資料KEY值重複，請檢查！');
									wForm.elements[CheckNM].checked=false;
									wForm.elements[CheckNM+widx].checked=false;
									wForm.elements[xAry[0]+widx].focus();
									wForm.elements[xAry[0]+widx].select();
									break;
								}
							}
						}
					}
					if (flgDup){
						break;
					}
				}
			}
		}
	}
	if (flgNoCheck){
		alert('請先選取要' + wMethod + '的資料');
	}else{
		if (!flgDup){
			//alert(flgDup);
			if (confirm('確定要' + wMethod + '選取的項目嗎？')){
				wForm.submit();
			}						
		}
		//return flgDup;
	}
}

//TextArea 的任一游標處插入文字
//Peter,20061113
 function storeCaret (textEl) {
   if (textEl.createTextRange)
	 textEl.caretPos = document.selection.createRange().duplicate();
 }
 
 function insertAtCaret (textEl, text) {
   if (textEl.createTextRange && textEl.caretPos) {
	 var caretPos = textEl.caretPos;
	 caretPos.text =
	   caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		 text + ' ' : text;
   }
   else
	 textEl.value  = text;
   textEl.focus();
 }
////上傳檔案相關FUNCTION

function DeleteFileAsp(){
//0:顯示回傳值物件名稱 1:檔案名稱 2:檔案刪除路徑 3:上傳按鈕名稱 4:刪除按鈕名稱
	var pAry=DeleteFileAsp.arguments;
	var wStr;
	var wAry=new Array(4);
	wStr='/UpLoad/DeleteFile.asp?';
	wAry[0]='ObjNM';
	wAry[1]='FileNM';
	wAry[2]='FilePath';
	wAry[3]='UpLoadBtnNM';
	wAry[4]='DeleteBtnNM';

	for(var i=0; i<pAry.length; i++){
		wStr += wAry[i] + '=' + pAry[i];
		if (i<pAry.length){wStr += '&' }
	}
	OpenWin(wStr,350,150,0,'UpLoadPic');
}

function UpLoadFileAsp(){
//0:顯示回傳值物件名稱 1:檔案上傳路徑 2:上傳按鈕名稱 3:刪除按鈕名稱 4:最大檔案SIZE限制(單位Kbytes) 5:可上傳的檔案格式設定 6:是否覆蓋同檔名檔案
	var pAry=UpLoadFileAsp.arguments;
	var wStr;
	var wAry=new Array(6);
	wStr='/UpLoad/UpLoad.asp?';
	wAry[0]='ObjNM';
	wAry[1]='FilePath';
	wAry[2]='UpLoadBtnNM';
	wAry[3]='DeleteBtnNM';
	wAry[4]='MaxFileSize';
	wAry[5]='FileType';
	wAry[6]='IsCover';
	for(var i=0; i<pAry.length; i++){
		wStr += wAry[i] + '=' + pAry[i];
		if (i<pAry.length){wStr += '&' }
	}
	OpenWin(wStr,350,180,0,'UpLoadFile');
}
//處理上傳及刪除按鈕的disable狀態,1:檔案名稱,2:上傳按鈕名稱,3:刪除按鈕名稱
function IsUpload(pObj1,pObj2,pObj3){
	if(pObj1.value==""){
		pObj2.disabled=false;
		pObj3.disabled=true;
	}else{
		pObj2.disabled=true;
		pObj3.disabled=false;
	}
}
/**
* This function is to clear a form (or a container of implements such as table,tr ..).
* formObj:the checked form
* exceptObjName:the name of whitch need not be checked;
* For example:clearForm(document.frm,'ACheckbox,BRadio,CSelect');
*/
function clearForm(formObj,exceptObjName)
{
	if(formObj==null) formObj=document.forms[0];
	if(exceptObjName==null) exceptObjName=="";
	var selectObjs=formObj.getElementsByTagName("SELECT");//For Select Obj
	for(var i=0;i<selectObjs.length;i++)
	{
		if((selectObjs[i].name=="")||(eval("/(^|,)"+selectObjs[i].name+"(,|$)/g").test(exceptObjName))) continue;
		selectObjs[i].value="";
	}

	var inputObjs=formObj.getElementsByTagName("INPUT");//For Input Obj
	for(var i=0;i<inputObjs.length;i++)
	{
		if((inputObjs[i].name=="")||(eval("/(^|,)"+inputObjs[i].name+"(,|$)/g").test(exceptObjName))) continue;
		if(inputObjs[i].type.toUpperCase()=="TEXT") 
			inputObjs[i].value="";
		else if((inputObjs[i].type.toUpperCase()=="RADIO")||(inputObjs[i].type.toUpperCase()=="CHECKBOX"))
			inputObjs[i].checked=false;
	}

	var textareaObjs=formObj.getElementsByTagName("TEXTAREA");//For textarea Obj
	for(var i=0;i<textareaObjs.length;i++)
	{
		if((textareaObjs[i].name=="")||(eval("/(^|,)"+textareaObjs[i].name+"(,|$)/g").test(exceptObjName))) continue;
		textareaObjs[i].value="";
	}
}
// 去字串前後空白
function trim(str) {
	while (str.indexOf(" ")==0) {
		str = str.substring(1, str.length);
	}
	while ((str.length>0) && (str.indexOf(" ")==(str.length-1))) {
		str = str.substring(0, str.length-1);
	}
	return str;
}

