﻿// JScript 檔
//會員註冊
function checktxt(type,txtID,txtPW,txtPWConfirm,txtEMail,txtNAME,txtPhoneArea,txtPhone,txtPhoneNightArea,txtPhoneNight,txtCellPhone,txtAddress){
    var txt;
    if (document.getElementById(txtID).value == "" || document.getElementById(txtID).value == null)
    {
        txt=document.getElementById(txtID);
        alert('請輸入身份證字號');
        txt.focus();
        return false;
    }
    
    document.getElementById(txtID).value = document.getElementById(txtID).value.toUpperCase(); 
    if (document.getElementById(txtID).value.length != 10)//確定身份證字號有10碼
    {   
        txt=document.getElementById(txtID);
        alert('輸入無效的身份證字號 (ex:資料長度錯誤) !');
        txt.focus();
        return false;         
    }
    
    tAreaCode = document.getElementById(txtID).value.substr(0,1);
    if (tAreaCode.valueOf() < "A" || tAreaCode.valueOf() > "Z")//確定首碼在A-Z之間
    {   
        txt=document.getElementById(txtID);
        alert('輸入無效的身份證字號 (ex:首碼應介於A-Z之間) !');
        txt.focus();
        return false;        
    }
      
    if (isNaN(parseInt(document.getElementById(txtID).value.substring(1,10),10)) == true) //確定2-10碼是數字
    {   
        txt=document.getElementById(txtID);
        alert('輸入無效的身份證字號 (ex:第2-10碼須是數字) !');
        txt.focus();
        return false;          
    }
       
    //身份證號碼第 2 碼必須為 1 或 2
    tSecondID = document.getElementById(txtID).value.substr(1,1);
    if (tSecondID != "1" && tSecondID != "2")
    {   
        txt=document.getElementById(txtID);
        alert('輸入無效的身份證字號 !');
        txt.focus();
        return false;        
    }
    //取得首碼對應的區域碼，A ->10, B->11, ..H->17,I->34, J->18...
    var pUserID
    tAreaNo = "ABCDEFGHJKLMNPQRSTUVXYWZIO".search(tAreaCode) + 10;
    pUserID = tAreaNo.toString(10) + document.getElementById(txtID).value.substring(1,10);   
   
    tSum = parseInt(pUserID.substr(0,1),10) + parseInt(pUserID.substr(10,1),10);   

    for(ixI=1;ixI<=9;ixI++)
    {   
		
        tSum = tSum + parseInt(pUserID.substr(ixI,1),10)*(10-ixI);

    }  
	
    if ((tSum % 10) != 0)
    {
        txt=document.getElementById(txtID);
        alert('輸入無效的身份證字號 !');
        txt.focus();
        return false;
    }
    
    if (type=='true'){
        if (document.getElementById(txtPW).value==''){
            txt=document.getElementById(txtPW);
            alert('請輸入密碼');
            txt.focus();       
            return false;
        }
        
        if (document.getElementById(txtPW).value.length < 6 || document.getElementById(txtPW).value.length > 12){
            txt=document.getElementById(txtPW);
            alert('請輸入6~12位密碼');
            txt.focus();       
            return false;
        }

        if (document.getElementById(txtPWConfirm).value==''){
            txt=document.getElementById(txtPWConfirm);
	        alert('請輸入確認密碼');
	        txt.focus();       
	        return false;
	    }
    }

	
	if (document.getElementById(txtPW).value!=document.getElementById(txtPWConfirm).value){
	    txt=document.getElementById(txtPW);
		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(txtNAME).value==''){
        txt=document.getElementById(txtNAME);
        alert('請輸入姓名');
        txt.focus();       
        return false;
    }
    
    if (document.getElementById(txtPhoneArea).value==''){
        txt=document.getElementById(txtPhoneArea);
        alert('請輸入日間聯絡電話區碼');
        txt.focus();       
        return false;
    }
    
		
	if (document.getElementById(txtPhone).value==''){
	    txt=document.getElementById(txtPhone);
		alert('請輸入日間聯絡電話');
		txt.focus();       
		return false;
		}else{
        var i,j,strTemp;
        var TEL=document.getElementById(txtPhone).value;

        strTemp="0123456789";     

        for (i=0;i<TEL.length;i++) {     

            j=strTemp.indexOf(TEL.charAt(i));     

            if (j == -1){     
                txt=document.getElementById(txtPhone);
                alert("日間聯絡電話格式錯誤，請輸入0123456789");   
                txt.focus();
                return false;     

            }     
        }            

	}
		
    if (document.getElementById(txtPhoneNightArea).value==''){
        txt=document.getElementById(txtPhoneNightArea);
        alert('請輸入夜間電話區碼');
        txt.focus();       
        return false;
    }
    
		
	if (document.getElementById(txtPhoneNight).value==''){
	    txt=document.getElementById(txtPhoneNight);
		alert('請輸入夜間聯絡電話');
		txt.focus();       
		return false;
		}else{		    
            var i,j,strTemp;
            var TEL=document.getElementById(txtPhoneNight).value;

            strTemp="0123456789";     

            for (i=0;i<TEL.length;i++) {     

                j=strTemp.indexOf(TEL.charAt(i));     

                if (j == -1)     

                    {     
                        txt=document.getElementById(txtPhoneNight);
                        alert("夜間聯絡電話格式錯誤，請輸入0123456789");   
                        txt.focus();
                        return false;     

                }     
            }
	}
	
	if (document.getElementById(txtCellPhone).value==''){
	    txt=document.getElementById(txtCellPhone);
		alert('請輸入行動電話');
		txt.focus();       
		return false;
		}else{
		    if (document.getElementById(txtCellPhone).value.length != 10){
		            txt=document.getElementById(txtCellPhone);
		            alert("行動電話格式應為十碼數字");
		            txt.focus();
                    return false;
		        }else{
                    var i,j,strTemp;
                    var TEL=document.getElementById(txtCellPhone).value;

                    strTemp="0123456789";     

                    for (i=0;i<TEL.length;i++) {     

                        j=strTemp.indexOf(TEL.charAt(i));     

                        if (j == -1)     

                            {     
                                txt=document.getElementById(txtCellPhone);
                                alert("行動電話格式錯誤，請輸入0123456789");   
                                txt.focus();
                                return false;     

                        }     
                    }
                }
	}
		
	if (document.getElementById(txtAddress).value==''){
        txt=document.getElementById(txtAddress);
        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_u(txtEMail,txtPhoneArea,txtPhone,txtPhoneNightArea,txtPhoneNight,txtCellPhone,txtAddress){
var txt;
    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(txtPhone).value==''){
	    txt=document.getElementById(txtPhone);
		alert('請輸入日間聯絡電話');
		txt.focus();       
		return false;
		}else{		        
            var i,j,strTemp;
            var TEL=document.getElementById(txtPhone).value;

            strTemp="0123456789";     

            for (i=0;i<TEL.length;i++) {     

                j=strTemp.indexOf(TEL.charAt(i));     

                if (j == -1){     
                    txt=document.getElementById(txtPhone);
                    alert("日間聯絡電話格式錯誤，請輸入0123456789");   
                    txt.focus();
                    return false;     

                }     
            }
	}
		
    if (document.getElementById(txtPhoneNightArea).value==''){
        txt=document.getElementById(txtPhoneNightArea);
        alert('請輸入夜間電話區碼');
        txt.focus();       
        return false;
    }
    
		
	if (document.getElementById(txtPhoneNight).value==''){
	    txt=document.getElementById(txtPhoneNight);
		alert('請輸入夜間聯絡電話');
		txt.focus();       
		return false;
		}else{    
            var i,j,strTemp;
            var TEL=document.getElementById(txtPhoneNight).value;

            strTemp="0123456789";     

            for (i=0;i<TEL.length;i++) {     

                j=strTemp.indexOf(TEL.charAt(i));     

                if (j == -1)     

                    {     
                        txt=document.getElementById(txtPhoneNight);
                        alert("夜間聯絡電話格式錯誤，請輸入0123456789");   
                        txt.focus();
                        return false;     

                }     
            }
	}
	
	if (document.getElementById(txtCellPhone).value==''){
	    txt=document.getElementById(txtCellPhone);
		alert('請輸入行動電話');
		txt.focus();       
		return false;
		}else{
		    if (document.getElementById(txtCellPhone).value.length != 10){
		            txt=document.getElementById(txtCellPhone);
		            alert("行動電話格式應為十碼數字");
		            txt.focus();
                    return false;
		        }else{
                    var i,j,strTemp;
                    var TEL=document.getElementById(txtCellPhone).value;

                    strTemp="0123456789";     

                    for (i=0;i<TEL.length;i++) {     

                        j=strTemp.indexOf(TEL.charAt(i));     

                        if (j == -1)     

                            {     
                                txt=document.getElementById(txtCellPhone);
                                alert("行動電話格式錯誤，請輸入0123456789");   
                                txt.focus();
                                return false;     

                        }     
                    }
                }
	}
	
	if (document.getElementById(txtAddress).value==''){
        txt=document.getElementById(txtAddress);
        alert('請輸入地址');
        txt.focus();       
        return false;
    }	
	

}


function checktxt_Contact_us(txtName,txtPhone,txtCellPhone,txtEmail,txtMemo){
var txt;

    if (document.getElementById(txtName).value==''){
        txt=document.getElementById(txtName);
        alert('請輸入姓名');
        txt.focus();       
        return false;
    }
	
    if (document.getElementById(txtPhone).value=='' && document.getElementById(txtCellPhone).value==''){
        txt=document.getElementById(txtPhone);
	    alert('請輸入聯絡電話');
	    txt.focus();  
	    return false;          
        }else{
                if (document.getElementById(txtPhone).value!=''){
                    var i,j,strTemp;
                    var TEL=document.getElementById(txtPhone).value;
                    strTemp="0123456789-()# ";     
                    for (i=0;i<TEL.length;i++) {     
                        j=strTemp.indexOf(TEL.charAt(i));     
                        if (j == -1){     
                            alert("電話格式錯誤，請輸入0123456789-()# ");   
                            return false;     
                        }     
                    }
                }
                
                if (document.getElementById(txtCellPhone).value!=''){
                    var i,j,strTemp;
                    var TEL=document.getElementById(txtPhone).value;
                    strTemp="0123456789";
                    for (i=0;i<TEL.length;i++){     
                        j=strTemp.indexOf(TEL.charAt(i));     
                        if (j == -1){     
                            alert("手機號碼格式錯誤，請輸入0123456789");   
                            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(txtMemo).value==''){
	    txt=document.getElementById(txtMemo);
		alert('請輸入問題與建議');
		txt.focus();       
		return false;
		}
	
	
}


//會員資料修改
function checktxt_cart_001(txtName,txtEMail,txtPhone,txtCellPhone,txtAreaCod,txtAddress,txtName1,txtPhone1,txtCellPhone1,txtAreaCod1,txtAddress1){
var txt;

    if (document.getElementById(txtName).value==''){
        txt=document.getElementById(txtName);
        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(txtPhone).value==''){
	    txt=document.getElementById(txtPhone);
		alert('請輸入訂購人日間聯絡電話');
		txt.focus();       
		return false;
		}else{
            var i,j,strTemp;
            var TEL=document.getElementById(txtPhone).value;

            strTemp="0123456789-()# ";     

            for (i=0;i<TEL.length;i++) {     

                j=strTemp.indexOf(TEL.charAt(i));     

                if (j == -1)     

                    {     

                        alert("訂購人日間聯絡電話格式錯誤，請輸入0123456789-()# ");   

                        return false;     

                }     
            }

	}
		
	if (document.getElementById(txtCellPhone).value==''){
	    txt=document.getElementById(txtCellPhone);
		alert('請輸入訂購人手機號碼');
		txt.focus();       
		return false;
		}else{
            var i,j,strTemp;
            var TEL=document.getElementById(txtCellPhone).value;

            strTemp="0123456789";     

            for (i=0;i<TEL.length;i++) {     

                j=strTemp.indexOf(TEL.charAt(i));     

                if (j == -1)     

                    {     

                        alert("訂購人手機號碼格式錯誤，請輸入0123456789");   

                        return false;     

                }     
            }

	}

    if (document.getElementById(txtAreaCod).value==''){
        txt=document.getElementById(txtAreaCod);
        alert('請輸入訂購人郵遞區號前三碼');
        txt.focus();       
        return false;
    }
	
	if (document.getElementById(txtAddress).value==''){
        txt=document.getElementById(txtAddress);
        alert('請輸入訂購人地址');
        txt.focus();       
        return false;
    }	
	

    if (document.getElementById(txtName1).value==''){
        txt=document.getElementById(txtName1);
        alert('請輸入收件人姓名');
        txt.focus();       
        return false;
    }
    
	if (document.getElementById(txtPhone1).value==''){
	    txt=document.getElementById(txtPhone1);
		alert('請輸入收件人日間聯絡電話');
		txt.focus();       
		return false;
		}else{
            var i,j,strTemp;
            var TEL=document.getElementById(txtPhone1).value;

            strTemp="0123456789-()# ";     

            for (i=0;i<TEL.length;i++) {     

                j=strTemp.indexOf(TEL.charAt(i));     

                if (j == -1)     

                    {     

                        alert("收件人日間聯絡電話格式錯誤，請輸入0123456789-()# ");   

                        return false;     

                }     
            }

	}
		
if (document.getElementById(txtCellPhone).value==''){
	    txt=document.getElementById(txtCellPhone);
		alert('請輸入行動電話');
		txt.focus();       
		return false;
		}else{
		    if (document.getElementById(txtCellPhone).value.length != 10){
		            alert("行動電話格式應為十碼數字");
                    return false;
		        }else{
                    var i,j,strTemp;
                    var TEL=document.getElementById(txtCellPhone).value;

                    strTemp="0123456789";     

                    for (i=0;i<TEL.length;i++) {     

                        j=strTemp.indexOf(TEL.charAt(i));     

                        if (j == -1)     

                            {     

                                alert("行動電話格式錯誤，請輸入0123456789");   

                                return false;     

                        }     
                    }
                }
	}

    if (document.getElementById(txtAreaCod1).value==''){
        txt=document.getElementById(txtAreaCod1);
        alert('請輸入收件人郵遞區號前三碼');
        txt.focus();       
        return false;
    }
	
	if (document.getElementById(txtAddress1).value==''){
        txt=document.getElementById(txtAddress1);
        alert('請輸入收件人地址');
        txt.focus();       
        return false;
    }	

}
