//聯邦房屋專用
function chk_NO(obj,myType){
var MyPhone =/[0-9]{1,10}/;
var NotMyPhone =/[^0-9\.]{1,}/;        
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) || NotMyPhone.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) || NotMyPhone.test(tmpStr)){
					alert("請輸入數字");
					obj.focus();
					obj.select();
					return false;}
				else 
					return true;
			break;
		case 2://特殊用法
			if (tmpStr.length==0){
				return false;}
			else	
				return true;
			break;
		default:
			alert("參數錯誤");
			return false;
			break;
	}
}

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=yes,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; 
	default:
	  alert ("參數錯誤")
  }
  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;
	default:
		alert ("參數錯誤");
	}
  strStatus = 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("參數錯誤");
		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_account(obj){
var MyStr=/[a-zA-Z]{1,}[a-zA-Z0-9_]{3,}/;
	if (MyStr.test(obj.value))
		return true;
	else{
		alert ("請輸入正確帳號");
		obj.focus();
		obj.select();
		return false;}
}
*/

function chk_account(obj){ //檢查帳號
var MyStr=/[a-zA-Z]{1,}[a-zA-Z0-9_]{4,14}/;
var MyStr1=/[a-zA-Z]{1}/;
//var MyStr2=/[a-zA-Z0-9_]{5,}/;
var MySymbol =/[\~\?\!\@\#\$\%\^\&\*\(\)\/\\\n\r\t\}\{\|\:\"\>\<\-\']{1,}/;
	if (obj.value==""){
		alert ("請填入帳號");
		obj.focus();
		obj.select();
		return false;}
	else
		if (MySymbol.test(obj.value)){
			alert ("帳號不可以包含特殊字元");
			obj.focus();
			obj.select();
			return false;}
		else	
			if (!MyStr1.test(obj.value)){
				alert ("第一個字母必須是英文");
				obj.focus();
				obj.select();
				return false;}
			else
				if (obj.value.length<3){
					alert ("帳號長度必須大於3個位元(含3個)");
					obj.focus();
					obj.select();
					return false;}
				else	
					return true;
}

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]{3,}\.[\w]{3,}/
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 MyPhone =/[0-9]{7,10}/;
var NotMyPhone =/[^0-9]{1,}/;        
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) || NotMyPhone.test(tmpStr)){
						alert("最少輸入7碼數字");
						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) || NotMyPhone.test(tmpStr)){
					alert("最少輸入7碼數字");
					obj.focus();
					obj.select();
					return false;}
				else 
					return true;
			break;
		case 2://特殊用法
			if (tmpStr.length==0){
				return false;}
			else	
				return true;
			break;
		default:
			alert("參數錯誤");
			return false;
			break;
	}
}

function chk_cell(obj,myType){
var MyPhone =/[0-9]{10,}/;
var NotMyPhone =/[^0-9]{1,}/;        
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) || NotMyPhone.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) || NotMyPhone.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("參數錯誤");
			return false;
			break;
	}
}

function IsEmpty(obj,msg){
var MyType=obj.type;
	switch(MyType){
		case "text":
			if (obj.value==""){
				alert("請填寫" + msg);
				obj.focus();
				return true;}
			else
				return false;			
			break;
		case "password":
			if (obj.value==""){
				alert("請填寫" + msg);
				obj.focus();
				return true;}
			else
				return false;
			break;
		case "textarea":
			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":
			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 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 overFontColor(MyObj,MyColor){
// onmouseover change font color
	MyObj.style.color=MyColor;
}
function outFontColor(MyObj){
// onmouseout rechange font color
	MyObj.style.color='';
}
