﻿function trim(instr){
  return instr.replace(/^[\s]*/gi,"").replace(/[\s]*$/gi,"");
}


function checkEnter(){
if (window.event.keyCode == 13){
document.getElementById("ibtnOK").focus();
}
}

function getByteLength(strIN){
//計算byte
  var i, cnt=0;
  for (i=0; i<strIN.length; i++){
    if (escape(strIN.charAt(i)).length >= 4) cnt+=2;
    else cnt++;
  }
  return cnt;
}
function checklogin(txtUSER_ID,txtPASSWORD){
var txt;			
	if (document.getElementById(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入帳號');
		txt.focus();       
		return false;
		}		
	if (document.getElementById(txtPASSWORD).value==''){
	    txt=document.getElementById(txtPASSWORD);
		alert('請輸入密碼');
		txt.focus();       
		return false;
		}		
}

function checkforget(txtUSER_ID,txtemail){
var txt;			
	if (document.getElementById(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入帳號');
		txt.focus();       
		return false;
		}		
	if (document.getElementById(txtemail).value==''){
	    txt=document.getElementById(txtemail);
		alert('請輸入電子信箱');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtemail).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtemail);
                alert("請輸入正確的電子信箱"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
}

function checkcontact(txtUSER_ID,txttel,txtemail,txtsubject,txtq){
var txt;			
	if (document.getElementById(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入帳號');
		txt.focus();       
		return false;
		}		
	if (document.getElementById(txttel).value==''){
	    txt=document.getElementById(txttel);
		alert('請輸入連絡電話');
		txt.focus();       
		return false;
		}
	if (document.getElementById(txtemail).value==''){
	    txt=document.getElementById(txtemail);
		alert('請輸入連絡信箱');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtemail).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtemail);
                alert("請輸入正確的連絡信箱"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
	
		if (document.getElementById(txtsubject).value==''){
	    txt=document.getElementById(txtsubject);
		alert('請輸入主旨');
		txt.focus();       
		return false;
		}
			if (document.getElementById(txtq).value==''){
	    txt=document.getElementById(txtq);
		alert('請輸入說明');
		txt.focus();       
		return false;
		}
}

function checkddl(ddlyear,ddlmonth){
var txt;
var yy="";
var mm="";
	if (document.getElementById(ddlyear).value=='請選擇'){
	    txt=document.getElementById(ddlyear);
		alert('請選擇(年)');
		txt.focus();       
		return false;
		}else{
		yy=document.getElementById(ddlyear).value;
		}	
	if (document.getElementById(ddlmonth).value=='請選擇'){
	    /*txt=document.getElementById(ddlmonth);
		alert('請選擇(月)');
		txt.focus();       
		return false;*/
		}else{
		mm=document.getElementById(ddlmonth).value;
		}	
location.href='news.aspx?year='+yy+'&month='+mm;								
return false;

}



function checkjoin(txtUSER_ID,txtPASSWORD,txtR_PASSWORD,txtemail,txtNAME,ddlyear,ddlmonth,ddlday,rblF,rblM,txtimgcheck,ddlMember){
var txt;	    
	if (document.getElementById(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入帳號');
		txt.focus();       
		return false;
		}
			
	if (document.getElementById(txtPASSWORD).value==''){
	    txt=document.getElementById(txtPASSWORD);
		alert('請輸入密碼');
		txt.focus();       
		return false;
		}		
	if (document.getElementById(txtR_PASSWORD).value==''){
	    txt=document.getElementById(txtR_PASSWORD);
		alert('請輸入確認密碼');
		txt.focus();       
		return false;
		}			
	
		if (document.getElementById(txtPASSWORD).value!=document.getElementById(txtR_PASSWORD).value){
	    txt=document.getElementById(txtPASSWORD);
		alert('密碼與確認密碼不符');
		txt.focus();       
		return false;
		}	
		
		if (document.getElementById(txtemail).value==''){
	    txt=document.getElementById(txtemail);
		alert('請輸入電子信箱');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtemail).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtemail);
                alert("請輸入正確的電子信箱"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
	
	
	if (document.getElementById(ddlMember).value=='請選擇'){
	    txt=document.getElementById(ddlMember);
		alert('請選擇成員身分');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtNAME).value==''){
	    txt=document.getElementById(txtNAME);
		alert('請輸入網路代稱');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(ddlyear).value=='請選擇'){
	    txt=document.getElementById(ddlyear);
		alert('請選擇生日(年)');
		txt.focus();       
		return false;
		}		
	   if (document.getElementById(ddlmonth).value=='請選擇'){
	    txt=document.getElementById(ddlmonth);
		alert('請選擇生日(月)');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(ddlday).value=='請選擇'){
	    txt=document.getElementById(ddlday);
		alert('請選擇生日(月)');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(rblF).checked==false&&document.getElementById(rblM).checked==false){
				 txt=document.getElementById(rblF);
		alert('請選擇性別');
		txt.focus();       
		return false;
		}			
		
			if (document.getElementById(txtimgcheck).value==''){
	    txt=document.getElementById(txtimgcheck);
		alert('請輸入圖片驗證');
		txt.focus();       
		return false;
		}
				

}


function checkinfo(txtPASSWORD,txtR_PASSWORD,txtemail,txtNAME,ddlyear,ddlmonth,ddlday,rblF,rblM,ddlMember){
var txt;	
if (document.getElementById(txtPASSWORD).value!=''||document.getElementById(txtR_PASSWORD).value!=''){
if (document.getElementById(txtPASSWORD).value==''){
	    txt=document.getElementById(txtPASSWORD);
		alert('請輸入密碼');
		txt.focus();       
		return false;
		}		
	if (document.getElementById(txtR_PASSWORD).value==''){
	    txt=document.getElementById(txtR_PASSWORD);
		alert('請輸入確認密碼');
		txt.focus();       
		return false;
		}			
	
		if (document.getElementById(txtPASSWORD).value!=document.getElementById(txtR_PASSWORD).value){
	    txt=document.getElementById(txtPASSWORD);
		alert('密碼與確認密碼不符');
		txt.focus();       
		return false;
		}	
}
	
		
		if (document.getElementById(txtemail).value==''){
	    txt=document.getElementById(txtemail);
		alert('請輸入電子信箱');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtemail).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtemail);
                alert("請輸入正確的電子信箱"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
	
	if (document.getElementById(ddlMember).value=='請選擇'){
	    txt=document.getElementById(ddlMember);
		alert('請選擇成員身分');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtNAME).value==''){
	    txt=document.getElementById(txtNAME);
		alert('請輸入網路代稱');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(ddlyear).value=='請選擇'){
	    txt=document.getElementById(ddlyear);
		alert('請選擇生日(年)');
		txt.focus();       
		return false;
		}		
	   if (document.getElementById(ddlmonth).value=='請選擇'){
	    txt=document.getElementById(ddlmonth);
		alert('請選擇生日(月)');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(ddlday).value=='請選擇'){
	    txt=document.getElementById(ddlday);
		alert('請選擇生日(月)');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(rblF).checked==false&&document.getElementById(rblM).checked==false){
				 txt=document.getElementById(rblF);
		alert('請選擇性別');
		txt.focus();       
		return false;
		}	
}

//檢查身份證
function gfcChkID(pID)
{
    //var tobjRtn = new Object();
    var tobjRtn = true;
    var ixI;
    var tAreaNo;
    var tSum;
    var tAreaCode;
    var tSecondID;         //身份證第二碼

    if (pID == "" || pID == null)
    {
        //tobjRtn.eErr = false;
        tobjRtn = false;
        return tobjRtn;
    }
    tobjRtn.eErr = true;
    pID = pID.toUpperCase(); 
    if (pID.length != 10)//確定身份證字號有10碼
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S010');
        tobjRtn = false;
        return tobjRtn;             
    }       
    tAreaCode = pID.substr(0,1);
    if (tAreaCode.valueOf() < "A" || tAreaCode.valueOf() > "Z")//確定首碼在A-Z之間
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S011');
        tobjRtn = false;
        return tobjRtn;
    }  
    if (isNaN(parseInt(pID.substring(1,10),10)) == true) //確定2-10碼是數字
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S012');
        tobjRtn = false;
        return tobjRtn;
    }   
    //身份證號碼第 2 碼必須為 1 或 2
    tSecondID = pID.substr(1,1);
    if (tSecondID != "1" && tSecondID != "2")
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S013');
        tobjRtn = false;
        return tobjRtn;
    }
    //取得首碼對應的區域碼，A ->10, B->11, ..H->17,I->34, J->18...
    tAreaNo = "ABCDEFGHJKLMNPQRSTUVXYWZIO".search(tAreaCode) + 10;
    pID = tAreaNo.toString(10) + pID.substring(1,10);   
   
    //  取得CheckSum的值
    //  核對身份證號碼是否正確
    //  A  = 身份證號碼區域碼第 1碼
    //  A0 = 身份證號碼區域碼第 2碼 * (10 - 1)
    //  A1 = 身份證號碼第 2碼 * (10 - 2)
    //  A2 = 身份證號碼第 3碼 * (10 - 3)
    //  A3 = 身份證號碼第 4碼 * (10 - 4)
    //  A4 = 身份證號碼第 5碼 * (10 - 5)
    //  A5 = 身份證號碼第 6碼 * (10 - 6)
    //  A6 = 身份證號碼第 7碼 * (10 - 7)
    //  A7 = 身份證號碼第 8碼 * (10 - 8)
    //  A8 = 身份證號碼第 9碼 * (10 - 9)
    //  CheckSum = A + A0 + A1 + A2 + ........ + A7 + A8

    tSum = parseInt(pID.substr(0,1),10) + parseInt(pID.substr(10,1),10);   

    for(ixI=1;ixI<=9;ixI++)
    {   
        tSum = tSum + parseInt(pID.substr(ixI,1),10)*(10-ixI);
    }  
	
    if ((tSum % 10) != 0)
    {
        //tobjRtn.eErrDesc = gfcGetErrDesc('S013');
        tobjRtn = false;
        return tobjRtn;
    }
    //tobjRtn.eErr = false;
    tobjRtn = true;
    return tobjRtn;
}

function testNu2m(){
//48~57是數字0~9
//40~57是數字0~9跟一些電話號碼符號
//35是#號
if ( !(window.event.keyCode>=35 && window.event.keyCode<=57 ))
      window.event.keyCode = 0;
}

function r_imgcheck(id){
document.getElementById(id).outerHTML='<img style="cursor:hand" id=imgcheck onclick="r_imgcheck(this.id);" src=imgcheck.aspx>';
}

