function openWin(url,title,h,w){
    var hWnd;
    hWnd = window.open(url,title, "width="+w+",height="+h+",history=no,status=no,resizable=no,scrollbars=no,menubar=no");
    hWnd.moveTo((screen.width - w) / 2,(screen.height - h) / 2);
    hWnd.focus();
}


function openWinS(url,title,h,w){
    var hWnd;
    hWnd = window.open(url,title, "width="+w+",height="+h+",history=no,status=no,resizable=no,scrollbars=yes,menubar=no");
    hWnd.moveTo((screen.width - w) / 2,(screen.height - h) / 2);
    hWnd.focus();
}


function openWin_scroll(url,title,h,w){
    var hWnd;
    hWnd = window.open(url,title, "width="+w+",height="+h+",history=no,status=no,resizable=no,scrollbars=yes,menubar=no");
    hWnd.moveTo((screen.width - w) / 2,(screen.height - h) / 2);
    hWnd.focus();
}

// Resizable and scrollable
function openWin_RS(url,title,h,w){
    var hWnd;
    hWnd = window.open(url,title, "width="+w+",height="+h+",history=no,status=no,resizable=yes,scrollbars=yes,menubar=no");
    hWnd.moveTo((screen.width - w) / 2,(screen.height - h) / 2);
    hWnd.focus();
}


 function newWindow(url,title,h,w){
    //showx = event.screenX - event.offsetX-8 ; // + deltaX;
    //showy = event.screenY - event.offsetY+20 ; // + deltaY;

    showx=(screen.width - w) /2 ;
    showy=(screen.height - h) / 2;

    newWINwidth = 200 ;
    retval = window.showModalDialog(url,"", "dialogWidth:"+w+"px; dialogHeight:"+h+"px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:yes;Resizable=yes; "  );

 }
 

function checkDate(inString)
{
    var tempDate;
    var aryStr=inString.split("/");
    
    if (aryStr.length!=3){
		return false;
    }
    else{
		inString=aryStr[0]+"/"+(aryStr[1]*1)+"/"+(aryStr[2]*1);
    }
               
    var a=new Date(inString);
    var y=a.getFullYear();
    var m=a.getMonth()+1;
    var d=a.getDate();
    var myday=y + "/" + m + "/" + d
    if (myday!=inString) 
		return false;     
	else    
		return true; 
}


//檢查身份証字號
function ChkId(id)
{
	var ID=id.toUpperCase()
	if (ID.length!=10){
		return false;
	}
	
	var aryid= new Array(10)
	for (var i=0;i<10;i++) {
		aryid[i]=ID.charAt(i)
	}
	var strChr='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	aryid[0]=strChr.indexOf(aryid[0])
	if(aryid[0]==-1){
		return false;
	}
	
	if(aryid[1]!=1 && aryid[1]!=2){	
		return false;
	}
	var code=new Array(26)
	code[0]=1;code[1]=10;code[2]=19;code[3]=28;code[4]=37;code[5]=46;	
	code[6]=55;code[7]=64;code[8]=39;code[9]=73;code[10]=82;code[11]=2;
	code[12]=11;code[13]=20;code[14]=48;code[15]=29;code[16]=38;code[17]=47;	
	code[18]=56;code[19]=65;code[20]=74;code[21]=83;code[22]=21;code[23]=3;	
	code[24]=12;code[25]=30;
	
	var result=code[aryid[0]]
	
	for (var idi=1;idi<10;idi++){
		var strnum='0123456789'
		aryid[idi]=strnum.indexOf(aryid[idi])
		if(aryid[idi]==-1){
			return false;
		}
		else{
			result+=aryid[idi]*(9-idi)
		}
	}
	result+=1*aryid[9]
	if(result%10!=0){
		return false;
	}			
	return true;		
		
}


//--------------檢查是否為數字----------------
function ChkNum(num,len){
	var isOK;
	if (num.length<len) return false;
	isOK=true;
	for (ium=0;ium<num.length;ium++){
		if (num.charCodeAt(ium)<48 || num.charCodeAt(ium)>57){
			isOK=false;
			break;
		}	
	}
	return isOK;

}

//---------------檢查電子郵件------------------
function ChkEmail(em){
	var isAt,isDot;
	isAt=0;
	isDot=0;
	if (em.length<5) return false;
	//alert(em);
	if (em.indexOf('@')>1) isAt++;
	if (em.indexOf('.')>1) isDot++;
	if (isAt!=1 ) return false;
	if (isDot<1) return false;
	return true;
}

//---------------檢查統一編號-------------------
function ChkBAN(id){
    var BAN_Load = id

    if (BAN_Load.length != 8){
      //alert('統一編號需為8位!\r\n')
      return (false)
    }

    var BAN_Input = new Array(8)

    for (var i=0 ; i < 8 ; i++){
      var NumString = '0123456789'
      BAN_Input[i] = NumString.indexOf(BAN_Load.charAt(i))
      if (BAN_Input[i] == -1){
        //alert('字元應為數字!\r\n')
        return (false)
      }
    }

    var NumArray = new Array(8)
    NumArray[0] = 1 ; NumArray[1] = 2 ; NumArray[2] = 1 ;
    NumArray[3] = 2 ; NumArray[4] = 1 ; NumArray[5] = 2 ;
    NumArray[6] = 4 ; NumArray[7] = 1

    var sum = 0

    for (var i = 0; i < 8; i++){
        var temp = NumArray[i] * BAN_Input[i]
        sum = sum + temp % 10
        var temp1 = Math.floor(temp / 10)
        sum = sum + temp1
    }

    sum = sum % 10
    if ( sum == 9 && BAN_Input[6] == '7') return(true);

    if ( sum == 0 ){
      return(true);
    }
    else{
      //alert('\r\n邏輯檢查錯誤!')
      return (false)
    }
}