

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function pageInit(isDefaultPage){
/*
	if(document.form1.Ma_footer1_footerTag!= null){
		if (isDefaultPage==0){
			if (document.form1.Ma_footer1_footerTag.value==""){
				alert("Session timeout!!\n\nPlease login again!!");
				location.href="default.aspx";
			}
		}
		self.status=document.form1.Ma_footer1_footer_status.value;
	}
*/
}

function confirmcheck(msg){
	if(confirm(msg)){
		return true;
	}else{
		return false;
	}
}
function clearSelfData(){
	this.value="";

}

function pagebak(){
	history.back(1);
}

//------------------------------  for this project
function OpenSelect(ctlname,ctlvalue,module_name,intWidth,intHeight){

	winspec="width=" + intWidth + ",height=" + intHeight + ",menubar=no,status=yes,scrollbars=yes,resizable=no";
	addr=module_name + "?rtn_ctl_name=" + ctlname + "&rtn_ctl_value=" + ctlvalue;
	
	window.open(addr,"newwin",winspec);
	return false;
}

function RtnSelectValue(rtnValue,rtnName){
	rtn_name=document.forms[0].elements['rtn_ctl_name'].value;
	rtn_value=document.forms[0].elements['rtn_ctl_value'].value;
	opener.document.forms[0].elements[rtn_name].value = rtnName;
	opener.document.forms[0].elements[rtn_value].value = rtnValue;
	window.close();
}

function LoginOpenNewWindow(addr,newname){
	url= addr;
	width = screen.availWidth;
	height = screen.availHeight;
	leftpos = 0;
	toppos = 0;
	winname = newname
	winstyle = "fullscreen,alwaysRaised=yes,status=yes,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,width=" + width + ",height=" + height + ",top=" + toppos + ",left=" + leftpos;
	newname = window.open(url,winname,winstyle)
}

function gotoHome(url){
	if(!reminder.closed){
		reminder.close();
	}
	location.href=url;
}

//身分證號驗證
function check_id(source, arguments){
	
	var idnumber = arguments.Value;
    tab = "ABCDEFGHJKLMNPQRSTUVWXYZIO"
    A1 = new Array (1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3 );
    A2 = new Array (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,2,0,1,3,4,5 );
	   Mx = new Array (9,8,7,6,5,4,3,2,1,1);
	   var check = true
   
	   if ( idnumber.length != 10 ) check = false;
	   i = tab.indexOf(idnumber.charAt(0));
	   if ( i == -1 ) check = false;
	   sum = A1[i] + A2[i]*9;

	   for ( i=1; i<10; i++ ) {
	      v = parseInt(idnumber.charAt(i));
	      if (isNaN(v)) check = false;
	      sum = sum + v * Mx[i];
		}

	if ( sum % 10 != 0 ) check = false
   
	if (check == false) {
		arguments.IsValid=false;
	}else{
		arguments.IsValid=true;
	}
}

//統一編號

function comidchk(source, arguments) {
	if(idchk(arguments.Value)){
		arguments.IsValid=true;
	}else{
		arguments.IsValid=false;
	}
}
function idchk(idvalue) {
   var tmp = new String("12121241");
   var sum = 0;
   re = /^\d{8}$/;
   if (!re.test(idvalue)) {
       //alert("格式不對！");
       return false;
    }
   for (i=0; i< 8; i++) {
     s1 = parseInt(idvalue.substr(i,1));
     s2 = parseInt(tmp.substr(i,1));
     sum += cal(s1*s2);
   }
   if (!valid(sum)) {
      if (idvalue.substr(6,1)=="7") return(valid(sum+1));
   }  
   return(valid(sum));
}
function valid(n) {
   return (n%10 == 0)?true:false;
}
function cal(n) {
   var sum=0;
   while (n!=0) {
      sum += (n % 10);
      n = (n - n%10) / 10;  // 取整數
     }
   return sum;
}

//frame 展開(取消下拉霸)
function resizeIframe(intHeight,framename) {

	i=parent.document.all(framename)
	iHeight = document.body.scrollHeight
	if(iHeight<480){
		iHeight=480;
	}
	i.style.height = iHeight + 0 + "px"
}

function CallPrint(strid){
	var prtContent = document.getElementById(strid);
	var WinPrint = window.open('','','width=10,height=10,toolbar=0,scrollbars=0,status=1,location=0,directories=0,menubar=0,resizable=0');
	WinPrint.document.write("<LINK href=css/css.css type=text/css rel=stylesheet>");
	WinPrint.document.write(prtContent.innerHTML);
	//WinPrint.document.write("<object id=\"ScriptX\" viewastext style=\"display:none\" classid=\"clsid:5445be81-b796-11d2-b931-002018654e2e\" codebase=\"mascripts/smsx.cab#Version=6,3,434,26\"></object>\n");
	WinPrint.document.write("<object id=ScriptX viewastext style=\"display:none\" classid=\"clsid:1663ed61-23eb-11d2-b92f-008048fdd814\" codebase=\".\\ScriptX.cab#Version=6,1,432,1\"> <\/object>");
	WinPrint.document.write("<script language=\"javascript\">\n");
	WinPrint.document.write("ScriptX.printing.header = \"\";\n");
	WinPrint.document.write("ScriptX.printing.footer = \"\";\n");
	WinPrint.document.write("ScriptX.printing.portrait = true;\n");
	WinPrint.document.write("ScriptX.printing.leftMargin = 10;\n");
	WinPrint.document.write("ScriptX.printing.topMargin = 10;\n");
	WinPrint.document.write("ScriptX.printing.rightMargin = 10;\n");
	WinPrint.document.write("ScriptX.printing.bottomMargin = 10;\n");
	WinPrint.document.write("ScriptX.printing.print(true);\n");
	WinPrint.document.write("<\/script>");
	WinPrint.close();
}

function chkword(source, arguments){
	var isErr;
	isErr=false;
		for( idx = 0 ; idx <arguments.Value.length ; idx++){
			if( !( ( arguments.Value.charAt(idx)>= 'A' && arguments.Value.charAt(idx) <= 'Z' ) || ( arguments.Value.charAt(idx)>= 'a' && arguments.Value.charAt(idx) <= 'z' ) || ( arguments.Value.charAt(idx)>= '0' && arguments.Value.charAt(idx) <= '9' ) || ( arguments.Value.charAt(idx) == '_' ) ) ){
				isErr=true;
			}
		}
		if(isErr){
			arguments.IsValid=false;
		}else{
			arguments.IsValid=true;
		}

}
