﻿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 checkdiagnose(txtSSUBJECT,txtPIC1_TITLE,txtPIC1_DESC,txtPIC2_TITLE,txtSUBJECT,txtCONTENT){
 var txt;

	  if (document.getElementById(txtSSUBJECT).value==""){
		txt=document.getElementById(txtSSUBJECT);
		alert('請輸入聯絡人');
		txt.focus();       
		return false;
	    }
	    
	     if (document.getElementById(txtPIC1_TITLE).value==""){
		txt=document.getElementById(txtPIC1_TITLE);
		alert('請輸入聯絡電話');
		txt.focus();       
		return false;
	    }
	    
	     if (document.getElementById(txtPIC1_DESC).value==''){
	    txt=document.getElementById(txtPIC1_DESC);
		alert('請輸入E-MAIl');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtPIC1_DESC).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtPIC1_DESC);
                alert("請輸入正確的E-MAIl"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
	       if (document.getElementById(txtPIC2_TITLE).value==""){
		txt=document.getElementById(txtPIC2_TITLE);
		alert('請輸入居住地址');
		txt.focus();       
		return false;
	    }
	    
	     if (document.getElementById(txtSUBJECT).value==""){
		txt=document.getElementById(txtSUBJECT);
		alert('請輸入標題');
		txt.focus();       
		return false;
	    }
	    
	
	    
	    if (document.getElementById(txtCONTENT).value==""){
		txt=document.getElementById(txtCONTENT);
		alert('請輸入內容');
		txt.focus();       
		return false;
	    }	    	 		
}

function checkTrade(rbl1,rbl2,rbl3,rbl4,rbl5){
 var txt;
 if (document.getElementById(rbl1).checked==false&&document.getElementById(rbl2).checked==false&&document.getElementById(rbl3).checked==false&&document.getElementById(rbl4).checked==false&&document.getElementById(rbl5).checked==false){
	txt=document.getElementById(rbl1);
	alert('請選擇捐款方式');
	txt.focus();       
	return false;
	}		
}


function checkps(txtUSER_ID,id){
 var txt;
 if (document.getElementById(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入E-mail 帳號');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtUSER_ID).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtUSER_ID);
                alert("請輸入正確的E-mail 帳號"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
	
	if (document.getElementById(id).value==''){
	txt=document.getElementById(id);
	alert('請輸入身分證字號');
	txt.focus();       
	return false;
	}		
}

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 checktxt(type,txtUSER_ID,txtPASSWORD,txtPASSWORD_R,txtNAME,txtSNAME,txtTELEPHONE1,rblC_TELEPHONE1_Y,txtCELLPHONE1,txtemail,ddlCITY_COD,hidAREA_COD,txtADDRESS,rblM,rblF,ddlOCCUPATION,rblINCOME_00,rblINCOME_01){
var txt;
 		
   if (document.getElementById(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入帳號');
		txt.focus();       
		return false;
		}
		
 if (type=='true'){
	if (document.getElementById(txtPASSWORD).value==''){
	txt=document.getElementById(txtPASSWORD);
	alert('請輸入密碼');
	txt.focus();       
	return false;
	}		
	
	if (document.getElementById(txtPASSWORD_R).value==''){
	    txt=document.getElementById(txtPASSWORD_R);
		alert('請輸入確認密碼');
		txt.focus();       
		return false;
		}
	}
	
	if (document.getElementById(txtPASSWORD).value!=document.getElementById(txtPASSWORD_R).value){
	    txt=document.getElementById(txtPASSWORD);
		alert('密碼與確認密碼不符');
		txt.focus();       
		return false;
		}
	
	
	
		if (document.getElementById(txtNAME).value==''){
	    txt=document.getElementById(txtNAME);
		alert('請輸入聯絡人姓名');
		txt.focus();       
		return false;
		}
		
				 if (document.getElementById(txtSNAME).value==''){
	    txt=document.getElementById(txtSNAME);
		alert('請輸入暱稱');
		txt.focus();       
		return false;
		}

    
    if (document.getElementById(rblM).checked==false&&document.getElementById(rblF).checked==false){
	    txt=document.getElementById(rblM);
		alert('請選擇性別');
		txt.focus();       
		return false;
		}
		
	
		
		if (document.getElementById(txtTELEPHONE1).value==''){
	    txt=document.getElementById(txtTELEPHONE1);
		alert('請輸入聯絡電話');
		txt.focus();       
		return false;
		}
		
		
		
	if (document.getElementById(rblC_TELEPHONE1_Y).checked==true){
		if (document.getElementById(txtCELLPHONE1).value==''){
			txt=document.getElementById(txtCELLPHONE1);
			alert('請輸入行動電話');
			txt.focus();       
			return false;
		}else{
		   if (document.getElementById(txtCELLPHONE1).value.charAt(0)!='0'){
		    alert('請輸入正確行動電話格式');
		    return false;
		  }
		   if (document.getElementById(txtCELLPHONE1).value.charAt(1)!='9'){
		    alert('請輸入正確行動電話格式');
		    return false;
		  }
		  if (document.getElementById(txtCELLPHONE1).value.length!=10){
		    alert('請輸入正確行動電話格式');
		    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(ddlCITY_COD).value=='請選擇'){
	    txt=document.getElementById(ddlCITY_COD);
		alert('請選擇通訊地址(縣市)');
		txt.focus();       
		return false;
		}				
	
		if (document.getElementById(hidAREA_COD).value=='請選擇'||document.getElementById(hidAREA_COD).value==''){
	    //txt=document.getElementById(hidAREA_COD);
		alert('請選擇通訊地址(地區)');
		//txt.focus();       
		return false;
		}				
		
		if (document.getElementById(txtADDRESS).value==''){
	    txt=document.getElementById(txtADDRESS);
		alert('請選擇通訊地址');
		txt.focus();       
		return false;
		}
	
		if (document.getElementById(ddlOCCUPATION).value=='00'){
	    txt=document.getElementById(ddlOCCUPATION);
		alert('請選擇如何知道本網站');
		txt.focus();       
		return false;
		}
	
	  if (document.getElementById(rblINCOME_00).checked==false&&document.getElementById(rblINCOME_01).checked==false){
	    txt=document.getElementById(rblINCOME_00);
		alert('請選擇是否訂閱電子報');
		txt.focus();       
		return false;
		}
}

function checktxt_u(txtPASSWORD_old,txtPASSWORD,txtPASSWORD_r,rblM,rblF,ddlyear,ddlMonth,ddlDay,txtTELEPHONE1_1,txtTELEPHONE1_2,txtTELEPHONE2_1,txtTELEPHONE2_2,txtCELLPHONE1,ddlCITY_COD,ddlAREA_COD,hidAREA_COD,txtADDRESS){
var txt;		
	
	
	if (document.getElementById(txtPASSWORD_old).value==''){
	txt=document.getElementById(txtPASSWORD_old);
	alert('請輸入網路會友密碼');
	txt.focus();       
	return false;
	}		
	
	if (document.getElementById(txtPASSWORD).value==''){
	txt=document.getElementById(txtPASSWORD);
	alert('請輸入密碼');
	txt.focus();       
	return false;
	}		
	
	if (document.getElementById(txtPASSWORD_r).value==''){
	    txt=document.getElementById(txtPASSWORD_r);
		alert('請輸入確認密碼');
		txt.focus();       
		return false;
		}
	
	if (document.getElementById(txtPASSWORD).value!=document.getElementById(txtPASSWORD_r).value){
	    txt=document.getElementById(txtPASSWORD);
		alert('密碼與確認密碼不符');
		txt.focus();       
		return false;
		}
		

	
		if (document.getElementById(rblM).checked==false&&document.getElementById(rblF).checked==false){
	    txt=document.getElementById(rblM);
		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(txtTELEPHONE1_1).value==''){
	    txt=document.getElementById(txtTELEPHONE1_1);
		alert('請輸入聯絡電話(日) 區碼');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtTELEPHONE1_2).value==''){
	    txt=document.getElementById(txtTELEPHONE1_2);
		alert('請輸入聯絡電話(日)電話號碼');
		txt.focus();       
		return false;
		}
		
			if (document.getElementById(txtTELEPHONE2_1).value==''){
	    txt=document.getElementById(txtTELEPHONE2_1);
		alert('請輸入聯絡電話(夜) 區碼');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtTELEPHONE2_2).value==''){
	    txt=document.getElementById(txtTELEPHONE2_2);
		alert('請輸入聯絡電話(夜)電話號碼');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtCELLPHONE1).value==''){
	    txt=document.getElementById(txtCELLPHONE1);
		alert('請輸入手機號碼');
		txt.focus();       
		return false;
		}		
		
		if (document.getElementById(ddlCITY_COD).value=='請選擇'){
	    txt=document.getElementById(ddlCITY_COD);
		alert('請選擇居住地址(縣市)');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(hidAREA_COD).value=='請選擇'||document.getElementById(hidAREA_COD).value==''){
	    txt=document.getElementById(ddlAREA_COD);
		alert('請選擇居住地址(鄉鎮市區)');
		txt.focus();       
		return false;
		}								
			
		if (document.getElementById(txtADDRESS).value==''){
	    txt=document.getElementById(txtADDRESS);
		alert('請選擇居住地址(地址)');
		txt.focus();       
		return false;
		}
}


function checkCart(txtmoney,txtname,rblM,rblF,txtUSER_ID,ddlyear,ddlMonth,ddlDay,txtTELEPHONE1_1,txtTELEPHONE1_2,txtTELEPHONE2_1,txtTELEPHONE2_2,txtCELLPHONE1,ddlCITY_COD,ddlAREA_COD,hidAREA_COD,txtADDRESS,rblTITLE,rblOCCUPATION,rblscrip_y,rblscrip_n,rblscrip_y_man,rblscrip_y_co,txtscrip_id,txtscrip_y_NAME,rblscrip_y_m,rblscrip_y_f,txtscrip_y_ADDRESS){

var txt;
   	if (document.getElementById(txtmoney).value==''){
	txt=document.getElementById(txtmoney);
	alert('請輸入急難救濟金');
	txt.focus();       
	return false;
	}else{
	 if (isNaN(document.getElementById(txtmoney).value)==true){
	  txt=document.getElementById(txtmoney);
	  alert('急難救濟金請以阿拉伯數字輸入');
	  txt.focus();       
	  return false;
	 }
	 	if (document.getElementById(txtmoney).value=='0'){
	txt=document.getElementById(txtmoney);
	alert('急難救濟金必須大於0元以上');
	txt.focus();       
	return false;
	}
	}		
	
		if (document.getElementById(rblM).checked==false&&document.getElementById(rblF).checked==false){
	    txt=document.getElementById(rblM);
		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(txtUSER_ID).value==''){
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入E-mail');
		txt.focus();       
		return false;
		}else{
		    var fobj=document.getElementById(txtUSER_ID).value;
            var check=/.+@.+\..+/;
            if (fobj.match(check) ==null ){
                txt=document.getElementById(txtUSER_ID);
                alert("請輸入正確的E-mail"); 
                txt.focus(); 
                txt.value="";
                return false;
              } 
	
	} 
				
		if (trim(document.getElementById(txtname).value)==''){
	    txt=document.getElementById(txtname);
		alert('請輸入中文姓名');
		txt.focus();       
		return false;
	    }
	    /*
	    else{	    
	     if ((trim(document.getElementById(txtname).value).length*2)!=getByteLength(document.getElementById(txtname).value)){
	      txt=document.getElementById(txtname);
		  alert('請輸入正確中文姓名\n請勿輸入其他字元');
		  txt.focus();       
		  return false;
	     }
	    }*/	
				
		
		
		if (document.getElementById(txtTELEPHONE1_1).value==''){
	    txt=document.getElementById(txtTELEPHONE1_1);
		alert('請輸入聯絡電話(日) 區碼');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtTELEPHONE1_2).value==''){
	    txt=document.getElementById(txtTELEPHONE1_2);
		alert('請輸入聯絡電話(日)電話號碼');
		txt.focus();       
		return false;
		}
		
			if (document.getElementById(txtTELEPHONE2_1).value==''){
	    txt=document.getElementById(txtTELEPHONE2_1);
		alert('請輸入聯絡電話(夜) 區碼');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtTELEPHONE2_2).value==''){
	    txt=document.getElementById(txtTELEPHONE2_2);
		alert('請輸入聯絡電話(夜)電話號碼');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(txtCELLPHONE1).value==''){
	    txt=document.getElementById(txtCELLPHONE1);
		alert('請輸入手機號碼');
		txt.focus();       
		return false;
		}		
		
		if (document.getElementById(ddlCITY_COD).value=='請選擇'){
	    txt=document.getElementById(ddlCITY_COD);
		alert('請選擇居住地址(縣市)');
		txt.focus();       
		return false;
		}
		
		if (document.getElementById(hidAREA_COD).value=='請選擇'||document.getElementById(hidAREA_COD).value==''){
	    txt=document.getElementById(ddlAREA_COD);
		alert('請選擇居住地址(鄉鎮市區)');
		txt.focus();       
		return false;
		}								
			
		if (document.getElementById(txtADDRESS).value==''){
	    txt=document.getElementById(txtADDRESS);
		alert('請選擇居住地址(地址)');
		txt.focus();       
		return false;
		}
		
		
		if (document.getElementById(rblscrip_y).checked==false&&document.getElementById(rblscrip_n).checked==false){
	    txt=document.getElementById(rblscrip_y);
		alert('請選擇需不需要開立收據');
		txt.focus();       
		return false;
		}
		
	if (document.getElementById(rblscrip_y).checked==true){	  
	//需要的話
	
	    if (document.getElementById(rblscrip_y_man).checked==false&&document.getElementById(rblscrip_y_co).checked==false){	    
	       txt=document.getElementById(rblscrip_y_man);
		   alert('請選擇開立收據屬個人或公司');
		   txt.focus();       
		   return false;
		  } 
		   
		   if (document.getElementById(rblscrip_y_co).checked==true){
				if (document.getElementById(txtscrip_id).value==""){
				txt=document.getElementById(txtscrip_id);
				alert('請輸入開立收據公司統一編號');
				txt.focus();       
				return false;
				}else{
				if (document.getElementById(txtscrip_id).value.length!=8||isNaN(document.getElementById(txtscrip_id).value)==true){
					txt=document.getElementById(txtscrip_id);
					alert('請輸入正確的公司統一編號');
					txt.focus();
					return false;  
				}
		     }		   
		   }
		   
		   //捐款人收據資料
		   if (document.getElementById(txtscrip_y_NAME).value==''){
			txt=document.getElementById(txtscrip_y_NAME);
			alert('請輸入捐款收據收件人姓名');
			txt.focus();       
			return false;
			}
			
				if (document.getElementById(rblscrip_y_m).checked==false&&document.getElementById(rblscrip_y_f).checked==false){
			txt=document.getElementById(rblscrip_y_m);
			alert('請選擇捐款收據收件人性別');
			txt.focus();       
			return false;
			}
			
			 if (document.getElementById(txtscrip_y_ADDRESS).value==''){
			txt=document.getElementById(txtscrip_y_ADDRESS);
			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 testNum(){
if ( !(window.event.keyCode>=48 && window.event.keyCode<=57 ))
      window.event.keyCode = 0;
}

function testNu3m(){
if ( (window.event.keyCode>=58 && window.event.keyCode<=64)||(window.event.keyCode>=33 && window.event.keyCode<=46))
      window.event.keyCode = 0;
      //alert("請勿輸入@#$%..等特殊符號");
      return false;
}

function no_ctrl_v(){
if ((window.event.keyCode==17))
 //alert("請勿使用複製");
 return false;
     //window.event.keyCode = 0;
}
