var LegalID = "0123456789"
var LegalUserName = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_."

function idCheck(id)
{   
   var fResult=true;
   var value = 0;
   var sId=id;
   if(sId.length<10 || 
		sId == 'a123456789' || 
		sId == 'A123456789') fResult=false;
   else
   {
     if((sId.charAt(0)=='A') || (sId.charAt(0)=='a')) value=10
     else if((sId.charAt(0)=='B') || (sId.charAt(0)=='b')) value=11
     else if((sId.charAt(0)=='C') || (sId.charAt(0)=='c')) value=12
     else if((sId.charAt(0)=='D') || (sId.charAt(0)=='d')) value=13
     else if((sId.charAt(0)=='E') || (sId.charAt(0)=='e')) value=14
     else if((sId.charAt(0)=='F') || (sId.charAt(0)=='f')) value=15
     else if((sId.charAt(0)=='G') || (sId.charAt(0)=='g')) value=16
     else if((sId.charAt(0)=='H') || (sId.charAt(0)=='h')) value=17
     else if((sId.charAt(0)=='J') || (sId.charAt(0)=='j')) value=18
     else if((sId.charAt(0)=='K') || (sId.charAt(0)=='k')) value=19
     else if((sId.charAt(0)=='L') || (sId.charAt(0)=='l')) value=20
     else if((sId.charAt(0)=='M') || (sId.charAt(0)=='m')) value=21
     else if((sId.charAt(0)=='N') || (sId.charAt(0)=='n')) value=22
     else if((sId.charAt(0)=='P') || (sId.charAt(0)=='p')) value=23
     else if((sId.charAt(0)=='Q') || (sId.charAt(0)=='q')) value=24
     else if((sId.charAt(0)=='R') || (sId.charAt(0)=='r')) value=25
     else if((sId.charAt(0)=='S') || (sId.charAt(0)=='s')) value=26
     else if((sId.charAt(0)=='T') || (sId.charAt(0)=='t')) value=27
     else if((sId.charAt(0)=='U') || (sId.charAt(0)=='u')) value=28
     else if((sId.charAt(0)=='V') || (sId.charAt(0)=='v')) value=29
     else if((sId.charAt(0)=='X') || (sId.charAt(0)=='x')) value=30
     else if((sId.charAt(0)=='Y') || (sId.charAt(0)=='y')) value=31
     else if((sId.charAt(0)=='W') || (sId.charAt(0)=='w')) value=32
     else if((sId.charAt(0)=='Z') || (sId.charAt(0)=='z')) value=33
     else if((sId.charAt(0)=='I') || (sId.charAt(0)=='i')) value=34
     else if((sId.charAt(0)=='O') || (sId.charAt(0)=='o')) value=35
     else fResult = false ;
     //alert('Value='+value) ;
   }
   if(fResult==true)
   {
     value = Math.floor(value/10) + (value%10)*9 +
             parseInt(sId.charAt(1))*8+
             parseInt(sId.charAt(2))*7+
             parseInt(sId.charAt(3))*6+
             parseInt(sId.charAt(4))*5+
             parseInt(sId.charAt(5))*4+
             parseInt(sId.charAt(6))*3+
             parseInt(sId.charAt(7))*2+
             parseInt(sId.charAt(8))+
             parseInt(sId.charAt(9)) ;
     value = value % 10 ;
     if(value!=0) fResult = false ;

     var i;
     var c;
     for (i = 1; i < sId.length; i++)
     {
      c = sId.charAt(i);
      if (LegalID.indexOf(c) == -1) fResult = false;
     }
    }
    return fResult ;
}


function isEmpty(s)
{
	if ((s.length==0) || (s=="")) {return (true);}
	var allspace = false;
	for (var i=0 ; i < s.length ; i++)
	{
		if (s[i]==" ")
		{
			allspace=true;
		}
		else
		{
			allspace=false;
		}
		return allspace;
	}
	return (false);
}


function isEmail(elm)
{
	if (elm.value.indexOf('@') != "-1" && elm.value.indexOf('.') != "-1" &&
		 elm.value.indexOf(' ') == "-1" && elm.value.indexOf("'") == "-1" &&
  		 elm.value.indexOf("!") == "-1" && elm.value.indexOf("#") == "-1" &&
  		 elm.value.indexOf("$") == "-1" && elm.value.indexOf("%") == "-1" &&
  		 elm.value.indexOf("^") == "-1" && elm.value.indexOf("&") == "-1" &&
  		 elm.value.indexOf("*") == "-1" && elm.value.indexOf("(") == "-1" &&
  		 elm.value.indexOf(")") == "-1" && elm.value.indexOf("^") == "-1" &&
  		 elm.value.indexOf("+") == "-1" && elm.value.indexOf("|") == "-1" &&		 		
  		 elm.value.indexOf("/") == "-1" && elm.value.indexOf("=") == "-1" &&		 		 		 
  		 elm.value.indexOf("{") == "-1" && elm.value.indexOf("}") == "-1" &&
  		 elm.value.indexOf("[") == "-1" && elm.value.indexOf("]") == "-1" &&	
  		 elm.value.indexOf("?") == "-1" && elm.value.indexOf("`") == "-1" &&
  		 elm.value.indexOf("~") == "-1" && elm.value.indexOf(":") == "-1" &&		 		 		 
  		 elm.value.indexOf(";") == "-1" && elm.value.indexOf(">") == "-1" &&		 		 		 
  		 elm.value.indexOf("<") == "-1" && elm.value.indexOf(",") == "-1" &&
		 elm.value.length > 5)
	return true;
	else return false;
}

function isInt(elm){
  for(var i=0;i<elm.length;i++){
    if (elm.charAt(i)<"0" || elm.charAt(i)>"9")
      return true;
    else return false;
  } 
}


function data_check(theform)
{   
  /*check_select(theform);*/
  var Username = theform.Username.value;
  if (isEmpty(Username))
  {
    alert("請輸入帳號!") ;
    theform.Username.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Username.indexOf("'") != -1)
  {
    alert("帳號中不可有【'】這個字!") ;
    theform.Username.focus();
    SubmitMe=false ; 
    return false;
  }  
    
  var pswd = theform.Password.value;
  if (isEmpty(pswd))
  {
    alert("請輸入密碼!") ;
    theform.Password.focus();
    return false;
  }

  if (pswd.indexOf("'") != -1)
  {
    alert("密碼不可有【'】這個字!") ;
    theform.Password.focus();
    return false;
  }
  
  if(theform.Password.value != theform.pwdconfirm.value)
  {
    alert("您的確認密碼與實際密碼不一致, 請重新輸入!") ;
    theform.Password.focus();
    SubmitMe=false ;
    return false;
  }
  
  var Customer_Name = theform.Customer_Name.value;
  if (isEmpty(Customer_Name))
  {
    alert("請輸入會員姓名!") ;
    theform.Customer_Name.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Customer_Name.indexOf("'") != -1)
  {
    alert("會員姓名不可有【'】這個字!") ;
    theform.Customer_Name.focus();
    SubmitMe=false ; 
    return false;
  }
  
  var Nickname = theform.Nickname.value;
  if (isEmpty(Nickname))
  {
    alert("請輸入暱稱!") ;
    theform.Nickname.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Nickname.indexOf("'") != -1)
  {
    alert("暱稱中不可有【'】這個字!") ;
    theform.Nickname.focus();
    SubmitMe=false ; 
    return false;
  }  
      
  if(idCheck(theform.ID_Number.value)==false)
  {
    alert("您的身份證字號有誤, 請檢查後重新輸入!");
    theform.ID_Number.focus();
    SubmitMe=false ;
    return false;
  }
       
  var yyyy = theform.yyyy.value;
  if (yyyy.length != 4)
  {
    alert("您輸入的生日格式不正確,請注意是四位西元日期");
	theform.yyyy.focus();
	submitme=false;
	return false;
  }
  var mm = theform.mm.value;
  if (mm.length != 2)
  {
    alert("您輸入的生日格式不正確,請注意是兩位,不足請在前面補0");
	theform.mm.focus();
	submitme=false;
	return false;
  }
  var dd = theform.dd.value;
  if (dd.length != 2)
  {
    alert("您輸入的生日格式不正確,請注意是兩位,不足請在前面補0");
	theform.dd.focus();
	submitme=false;
	return false;
  }
  get_birthday(theform);
    
  var City = theform.City.value ;
  if (isEmpty(City))
  {
    alert("請選擇縣市別!") ;
    theform.City.focus();
    SubmitMe=false ; 
    return false; 
  }
  var District = theform.District.value ;
  if (theform.District.selectedIndex <= 0) 
  {
    alert("請選擇鄉鎮市!") ;
    theform.District.focus();
    SubmitMe=false ; 
    return false; 
  }  
  var Postal_Code = theform.Postal_Code.value;
  if (isEmpty(Postal_Code))
  {
    alert("請檢查您的縣市別和鄉鎮市!") ;
    theform.Postal_Code.focus();
    return false;
  }
  var add = theform.Address.value;
  if (isEmpty(add))
  {
    alert("請輸入您的正確地址");
	theform.Address.focus();
	submitMe=false;
	return false;
  }
  if (add.indexOf("'") != -1)
  {
    alert("地址不可有【'】這個字!") ;
    theform.Address.focus();
    SubmitMe=false ; 
    return false;
  }
      
  var Mtel = theform.Mtel.value;    
  if ((Mtel.indexOf("'") != -1) || (Mtel.length > 15))
  {
    alert("行動電話不可有【'】這個字或超過15個字的長度!") ;
    theform.Mtel.focus();
    SubmitMe=false ; 
    return false;
  }
  
  var Htel = theform.Htel.value;
  if ((Htel.indexOf("'") != -1) || (Htel.length > 15))
  {
    alert("家裡電話不可有【'】這個字或超過15個字的長度!") ;
    theform.Htel.focus();
    SubmitMe=false ; 
    return false;
  }  
  var Otel = theform.Otel.value;
  if ((Otel.indexOf("'") != -1) || (Otel.length > 15))
  {
    alert("公司電話不可有【'】這個字或超過15個字的長度!") ;
    theform.Otel.focus();
    SubmitMe=false ; 
    return false;
  }  

  if ((Htel.length == 0) && (Otel.length == 0))
  {
    alert("家裡或工作地點電話請至少留一個!") ;
    theform.Htel.focus();
    SubmitMe=false ; 
    return false;
  }
          
  if (isEmail(theform.E_mail)==false)
  {
    alert("您的電子郵件地址有誤1!") ;
    theform.E_mail.focus();
    return false;
  }
  
  if (isEmail(theform.E_mail)==false)
  {
    alert("您的電子郵件地址有誤2!") ;
    theform.mail.focus();
    return false;
  }
        
  var Receiver = theform.Receiver.value;
  if (isEmpty(Receiver))
  {
    alert("請輸入預設收件人姓名!") ;
    theform.Receiver.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Receiver.indexOf("'") != -1)
  {
    alert("收件人姓名不可有【'】這個字!") ;
    theform.Receiver.focus();
    SubmitMe=false ; 
    return false;
  }
  var Send_PostalCode = theform.Send_PostalCode.value;
  if (isEmpty(Send_PostalCode))
  {
    alert("請輸入收件郵遞區號!") ;
    theform.Send_PostalCode.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Send_PostalCode.indexOf("'") != -1)
  {
    alert("收件郵遞區號不可有【'】這個字!") ;
    theform.Send_PostalCode.focus();
    SubmitMe=false ; 
    return false;
  }  
  
  var Send_Address = theform.Send_Address.value;
  if (isEmpty(Send_Address))
  {
    alert("請輸入收件地址!") ;
    theform.Send_Address.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Send_Address.indexOf("'") != -1)
  {
    alert("收件地址不可有【'】這個字!") ;
    theform.Send_Address.focus();
    SubmitMe=false ; 
    return false;
  }
  if (isInt(Postal_Code))
  {
    alert("請檢查您的郵遞區號!必須是數字");
    theform.Postal_Code.focus();
    return false;
  }     
  if (isInt(Send_PostalCode))
  {
    alert("請檢查您的預設郵遞區號!必須是數字");
    theform.Send_PostalCode.focus();
    return false;
  }    
    
  return true;
}



function data_check_upd(theform)
{   

  if (isEmail(theform.E_mail)==false)
  {
    alert("您的電子郵件地址有誤3!") ;
    theform.E_mail.focus();
    return false;
  }

  if (isEmail(theform.mail)==false)
  {
    alert("您的電子郵件地址有誤4!") ;
    theform.mail.focus();
    return false;
  }

  var pswd = theform.Password.value;
  if (isEmpty(pswd))
  {
    alert("請輸入密碼!") ;
    theform.Password.focus();
    return false;
  }

  if (pswd.indexOf("'") != -1)
  {
    alert("密碼不可有【'】這個字!") ;
    theform.Password.focus();
    return false;
  }

  if(theform.Password.value != theform.pwdconfirm.value)
  {
    alert("您的確認密碼與實際密碼不一致, 請重新輸入!") ;
    theform.Password.focus();
    SubmitMe=false ;
    return false;
  }  
  
  var Customer_Name = theform.Customer_Name.value;
  if (isEmpty(Customer_Name))
  {
    alert("請輸入會員姓名!") ;
    theform.Customer_Name.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Customer_Name.indexOf("'") != -1)
  {
    alert("會員姓名不可有【'】這個字!") ;
    theform.Customer_Name.focus();
    SubmitMe=false ; 
    return false;
  }
   
  var Username = theform.Username.value;
  if (isEmpty(Username))
  {
    alert("請輸入帳號!") ;
    theform.Username.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Username.indexOf("'") != -1)
  {
    alert("帳號中不可有【'】這個字!") ;
    theform.Username.focus();
    SubmitMe=false ; 
    return false;
  }  

  var Nickname = theform.Nickname.value;
  if (isEmpty(Nickname))
  {
    alert("請輸入暱稱!") ;
    theform.Nickname.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Nickname.indexOf("'") != -1)
  {
    alert("暱稱中不可有【'】這個字!") ;
    theform.Nickname.focus();
    SubmitMe=false ; 
    return false;
  }  
  
  if(idCheck(theform.ID_Number.value)==false)
  {
    alert("您的身份證字號有誤,請檢查後重新輸入!");
    theform.ID_Number.focus();
    SubmitMe=false ;
    return false;
  }
  
  var yyyy = theform.yyyy.value;
  if (yyyy.length != 4)
  {
    alert("您輸入的生日格式不正確,請注意是四位西元日期");
	theform.yyyy.focus();
	submitme=false;
	return false;
  }
  var mm = theform.mm.value;
  if (mm.length != 2)
  {
    alert("您輸入的生日格式不正確,請注意是兩位,不足請在前面補0");
	theform.mm.focus();
	submitme=false;
	return false;
  }
  var dd = theform.dd.value;
  if (dd.length != 2)
  {
    alert("您輸入的生日格式不正確,請注意是兩位,不足請在前面補0");
	theform.dd.focus();
	submitme=false;
	return false;
  }
  get_birthday(theform);
  var Mtel = theform.Mtel.value;    
  if (Mtel.indexOf("'") != -1 || (Mtel.length > 15))
  {
    alert("行動電話不可有【'】這個字或超過15個字的長度!") ;
    theform.Mtel.focus();
    SubmitMe=false ; 
    return false;
  }
  
  var Htel = theform.Htel.value;
  if (Htel.indexOf("'") != -1 || (Htel.length > 15))
  {
    alert("家裡電話不可有【'】這個字或超過15個字的長度!") ;
    theform.Htel.focus();
    SubmitMe=false ; 
    return false;
  }  
  var Otel = theform.Otel.value;
  if (Otel.indexOf("'") != -1 || (Otel.length > 15))
  {
    alert("公司電話不可有【'】這個字或超過15個字的長度!") ;
    theform.Otel.focus();
    SubmitMe=false ; 
    return false;
  }  

  if ((Htel.length == 0) && (Otel.length == 0))
  {
    alert("家裡或工作地點電話請至少留一個!") ;
    theform.Htel.focus();
    SubmitMe=false ; 
    return false;
  }
/* 
  var City = theform.City.value ;
  if (isEmpty(City))
  {
    alert("請選擇縣市別!") ;
    theform.City.focus();
    SubmitMe=false ; 
    return false; 
  }
  var District = theform.District.value ;
  if (theform.District.selectedIndex <= 0) 
  {
    alert("請選擇鄉鎮市!") ;
    theform.District.focus();
    SubmitMe=false ; 
    return false; 
  }  
  var Postal_Code = theform.Postal_Code.value;
  if (isEmpty(Postal_Code))
  {
    alert("請檢查您的縣市別和鄉鎮市!") ;
    theform.Postal_Code.focus();
    return false;
  }
*/
  var add = theform.Address.value;
  if (isEmpty(add))
  {
    alert("請輸入您的正確地址");
	theform.Address.focus();
	submitMe=false;
	return false;
  }
  if (add.indexOf("'") != -1)
  {
    alert("地址不可有【'】這個字!") ;
    theform.Address.focus();
    SubmitMe=false ; 
    return false;
  } 

  var Receiver = theform.Receiver.value;
  if (isEmpty(Receiver))
  {
    alert("請輸入預設收件人姓名!") ;
    theform.Receiver.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Receiver.indexOf("'") != -1)
  {
    alert("收件人姓名不可有【'】這個字!") ;
    theform.Receiver.focus();
    SubmitMe=false ; 
    return false;
  }
  var Send_PostalCode = theform.Send_PostalCode.value;
  if (isEmpty(Send_PostalCode))
  {
    alert("請輸入收件郵遞區號!") ;
    theform.Send_PostalCode.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Send_PostalCode.indexOf("'") != -1)
  {
    alert("收件郵遞區號不可有【'】這個字!") ;
    theform.Send_PostalCode.focus();
    SubmitMe=false ; 
    return false;
  }  
  
  var Send_Address = theform.Send_Address.value;
  if (isEmpty(Send_Address))
  {
    alert("請輸入收件地址!") ;
    theform.Send_Address.focus();
    SubmitMe=false ; 
    return false; 
  }
  if (Send_Address.indexOf("'") != -1)
  {
    alert("收件地址不可有【'】這個字!") ;
    theform.Send_Address.focus();
    SubmitMe=false ; 
    return false;
  }
  var Postal_Code = theform.Postal_Code.value;
  if (isInt(Postal_Code))
  {
    alert("請檢查您的郵遞區號!必須是數字");
    theform.Postal_Code.focus();
    return false;
  }     
  if (isInt(Send_PostalCode))
  {
    alert("請檢查您的預設郵遞區號!必須是數字");
    theform.Send_PostalCode.focus();
    return false;
  }      
      
  return true;
}




function data_check_back(theform)
{       
  var City = theform.City.value ;
  if (isEmpty(City))
  {
    alert("請選擇縣市別!") ;
    theform.City.focus();
    SubmitMe=false ; 
    return false; 
  }
  var District = theform.District.value ;
  if (theform.District.selectedIndex <= 0) 
  {
    alert("請選擇鄉鎮市!") ;
    theform.District.focus();
    SubmitMe=false ; 
    return false; 
  }  
  var Postal_Code = theform.Postal_Code.value;
  if (isEmpty(Postal_Code))
  {
    alert("請檢查縣市別和鄉鎮市!") ;
    theform.Postal_Code.focus();
    return false;
  }
      
  return true;
}


