// JavaScript Document
//函數名：chkSpace
//功能：檢查是否有空字格
//參數說明：要檢查的字符串
//返回值：0有；1無；2字符串為空
function chkSpace(string)
{
   var strLeng0=string.length;
   var chrLoc=0;
   var strLeng1=0;
   
   while (strLneg1<strLeng0)
   {
      if (string.charAt(chrLoc)!="")
      {
         strLeng1++;
      }
      strLoc++;
   }
   if (strLeg1==0)
   {
      return 2;
   }
   if (strLeng1!=strLeng0)
   {
      return 0;
   }
   else
   {
      return 1;
   }     
}

//函數名：chkPhone
//功能：檢查是否有合法的電話號碼
//參數說明：要檢查的字符串
//返回值：0合法；1非法；2字符串為空
function chkPhone(string)
{
   var strLeng=string.length;
   var i,strLoc,strTemp;
   strTemp="0123456789-+()# ";
   if (strLeng>0)
   {
     
       for (i=0;i<strLeng;i++)
       {
          strLoc=strTemp.indexOf(string.charAt(i));
          if (strLoc==-1)
          {
             return 1;//說明有字符不合法
          }      
       }
       return 0;//說明合法
  }
  return 2;//說明字符串為空
}       
       
//函數名：chkIsNumber
//功能：檢查是否全部是數字字符
//參數說明：要檢查的字符串
//返回值：0是；1否；2字符串為空
function chkIsNumber(string)
{
   var i,strLeng;
   var strTemp="0123456789";
   var strLeng=string.length;
   if (strLeng>0)
   {
      for (i=0;i<strLeng;i++)
      {
         if (strTemp.indexOf(string.charAt(i))==-1)
         {
             return 1;//說明有非數字字符
         }
      }
      return 0;//說明全部是數字字符
   }
   return 2;//說明字符串為空
}   

//函數名：chkEmail
//功能：檢查是否合法的email
//參數說明：要檢查的字符串
//返回值：0合法；1非法；2字符串為空
function chkEmail(string)
{
   var strLeng=string.length;
   var chrLoc1=string.indexOf("@");
   var chrLoc2=string.indexOf(".");
   
   if (strLeng > 0 )
   {
      if (chrLoc1 > 1)    //"@"前面不少于一個字符
      {
         if ((strLeng - chrLoc1) > 3) //"@"後面不少于三個字符
         {
            if ((strLeng - chrLoc2) > 1 ) //"."後面不少于一個字符
            {
              return 0; //說明合法
            }
         }
      }
      return 1;
   }
   return 2;
}

//函數名：chkLength
//功能：檢查字符串的長度
//參數說明：要檢查的字符串
//返回值：字符串的長度
function chkLength(string)
{
   var strLeng,i,sum;
   sum=0;
   strLeng=string.length;
   for (i=0;i<strLeng;i++)
   {
      if (string.charAt(i)>=0 && string.charAt(i) <= 255)  //單字節字符
      {
         sum++;
      }
      else         //雙字節字符
      {
         sum=sum+2; 
      }
   }
   return sum;
}      


function chkInMember()
{
   if (document.frmInMember.Nature.value == ""){    
      alert("“留言主題”不得為空！請重選。");   //“留言主題”不得為空！請重選。
      document.frmInMember.Nature.focus();
      return false;   
   }
   
   if (document.frmInMember.content.value == "")
   {    
      alert("“留言內容”不得為空！請重填");   //“其他産品”不得為空！請重填。
      document.frmInMember.content.focus();
      return false;   
   }

   if (document.frmInMember.name.value == "")
   {    
      alert("“姓名”不得為空！請重填。");   //“姓名”不得為空！請重填。
      document.frmInMember.name.focus();
      return false;   
   }
         
//   if (document.frmInMember.Duty.value == "")
//   {    
//      alert("“公司名稱”不得為空！請重填。");   //“公司名稱”不得為空！請重填。
//      document.frmInMember.Duty.focus();
//      return false;   
//   }
   
//   if (document.frmInMember.Situation.value == "")
//   {    
//      alert("“傳真”不得為空！請重填。");   //“傳真”不得為空！請重填。
//      document.frmInMember.Situation.focus();
//      return false;   
//   }
//      
//     if (chkPhone(document.frmInMember.Situation.value)==1 || chkLength(document.frmInMember.Situation.value) < 5)
//   {
//     alert("“傳真”填寫不合理，且不能少于5位！請重填。");   //“傳真”填寫不合理，且不能少于5位！請重填。
//     document.frmInMember.Situation.focus();
//     return false;
//   }
   
   
    if (document.frmInMember.telephone.value == "")
   {    
      alert("“聯络電話”不得為空！請重填。");   //“聯络電話”不得為空！請重填。
      document.frmInMember.telephone.focus();
      return false;   
   }
      
     if (chkPhone(document.frmInMember.telephone.value)==1 || chkLength(document.frmInMember.telephone.value) < 5)
   {
     alert("“聯络電話”填寫不合理，且不能少于5位！請重填。");   //“聯络電話”填寫不合理，且不能少于5位！請重填。
     document.frmInMember.telephone.focus();
     return false;
   }
   
   if (document.frmInMember.email.value == "")
   {    
      alert("“電子郵箱”不得為空！請重填。");   //“電子郵箱”不得為空！請重填。
      document.frmInMember.email.focus();
      return false;   
   }
  
     if (chkEmail(document.frmInMember.email.value)==1)
   {
      alert("“電子郵箱”填寫不正確！請重填。");   //“電子郵箱”填寫不正確！請重填。
      document.frmInMember.email.focus();
      return false; 
   } 
    
   document.frmInMember.submit();     
  
}
