﻿  String.prototype.Trim = function()
  {
      return this.replace(/(^\s*)|(\s*$)/g, "");
  }
  
function checkEmail(str)
{
if (str.charAt(0)=="." ||        
         str.charAt(0)=="@"||       
         str.indexOf('@', 0) == -1 || 
         str.indexOf('.', 0) == -1 || 
         str.lastIndexOf("@")==str.length-1 || 
         str.lastIndexOf(".")==str.length-1)
     {
      return false;
      }
	  else 
	  return true;
}

function fucCheckTEL1(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789-()# ";     
for (i=0;i<TEL.length;i++)     
{     
j=strTemp.indexOf(TEL.charAt(i));     
if (j==-1)     
{   
return false;     
}     
}       
return true;     
}  

function fucCheckTEL(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789-()"; 
if(TEL.length>14)
    return false;

for (i=0;i<TEL.length;i++)     
{     
j=strTemp.indexOf(TEL.charAt(i));     
if (j==-1)     
{   
return false;     
}     
}      

return true;     
}  

function check()
{
   if(document.getElementById('customer_name').value.Trim().length==0)
   {
     alert("請輸入您的姓名!!");
	 frmcustinfo.customer_name.focus();
	 return false;
   }
   else   if(document.getElementById('customer_email').value.Trim().length==0)
   {
     alert("請輸入您的Email!");
	 frmcustinfo.customer_email.focus();
	 return false;
   }
   else if(!checkEmail(document.getElementById('customer_email').value))
   {
     alert("您輸入的Email有誤!!");
	 frmcustinfo.customer_email.focus();
	 return false;   
   }
   else   if(document.getElementById('customer_emailre').value.Trim().length==0)
   {
     alert("請輸入您的確認Email!");
	 frmcustinfo.customer_emailre.focus();
	 return false;
   }
   else if(!checkEmail(document.getElementById('customer_emailre').value))
   {
     alert("確認Email有誤");
	 frmcustinfo.customer_emailre.focus();
	 return false;   
   }   
   else   if(document.getElementById('customer_email').value.Trim()!=document.getElementById('customer_emailre').value.Trim())
   {
     alert("您輸入的Email不一致，請重新輸入!");
	 frmcustinfo.customer_emailre.focus();
	 return false;
   }   
   else if(document.getElementById('customer_phone').value.Trim().length>0&&!fucCheckTEL(document.getElementById('customer_phone').value.Trim()))
   {
     alert("請輸入正確的電話號碼!");
	 frmcustinfo.customer_phone.focus();
	 return false;  
   }
   else if(document.getElementById('authinput').value.Trim().length==0)
   {
     alert("請輸入校驗碼!");
	 frmcustinfo.authinput.focus();
	 return false;   
   }
   else
    return true;
}

function check_order()
{
      if(document.getElementById('customer_email').value.Trim().length==0&&document.getElementById('order_number').value.Trim().length==0)
   {
     alert("請輸入您的電郵或訂購編號!!");
	 frm.customer_email.focus();
	 return false;
   }
   else
     return true;
}