﻿  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 checkReg()
{
	
   var strValue=document.getElementById('snid').value.Trim();
   if( !(strValue.length==27 || strValue.length==24) )
   {
     alert("請輸入正確的序列號碼!!");
	 thefrm.snid.focus();
	 return false;
   } 
   else if(!checksn(strValue))
   {
     alert("請輸入正確的序列號碼!");
	 thefrm.snid.focus();
	 return false;  
   }   
   else if(document.getElementById('tel').value.Trim().length>0&&!fucCheckTEL(document.getElementById('tel').value.Trim()))
   {
     alert("請輸入正確的電話號碼!");
	 thefrm.tel.focus();
	 return false;  
   }
   else   if(document.getElementById('email').value.Trim().length==0)
   {
     alert("請輸入您的Email!");
	 thefrm.email.focus();
	 return false;
   }
   else if(!checkEmail(document.getElementById('email').value))
   {
     alert("您輸入的Email有誤!!");
	 thefrm.email.focus();
	 return false;   
   }
   else   if(document.getElementById('re_email').value.Trim().length==0)
   {
     alert("請輸入您的確認Email!");
	 thefrm.re_email.focus();
	 return false;
   }
   else if(!checkEmail(document.getElementById('re_email').value))
   {
     alert("確認Email有誤");
	 thefrm.re_email.focus();
	 return false;   
   }   
   else   if(document.getElementById('email').value.Trim()!=document.getElementById('re_email').value.Trim())
   {
     alert("您輸入的Email不一致，請重新輸入!");
	 thefrm.re_email.focus();
	 return false;
   }   
   else{
	   	var con=window.confirm("請確認您的序列號碼正確，否則不能獲得優惠！")
		if (con)
		{
			 return true;
		}
		else
		{
			return false
		}
	   }
   
}


function checknumber(String) 
{ 
	var Letters = "1234567890-"; 
	var i; 
	var c; 
	for( i = 0; i < String.length; i ++ ){ 
		c = String.charAt( i ); 
		if (Letters.indexOf( c ) == -1) { 
			return true; 
		} 
	} 
	return false; 
} 


function checksn(strSource){
	if(checknumber(strSource))return false;
	else return true;
	/*
	var str1=strSource.substring(0,6);
	var str2=strSource.substring(6,7);
	var str3=strSource.substring(7,13);
	var str4=strSource.substring(13,14);
	var str5=strSource.substring(14,20);
	var str6=strSource.substring(20,21);
	var str7=strSource.substring(21,27);

	if(checknumber(str1))return false;
	else if(str2!='-')return false;
	else if(checknumber(str3))return false;
	else if(str4!='-')return false;
	else if(checknumber(str5))return false;
	else if(str6!='-')return false;
	else if(checknumber(str7))return false;
	else return true;*/
}

function checkFill()
{
   if(document.getElementById('company').value.Trim().length==0)
   {
     alert("請輸入公司或機構名稱!");
	 thefrm.company.focus();
	 return false;
   }   
   else   if(document.getElementById('contact').value.Trim().length==0)
   {
     alert("請輸入聯繫人名稱");
	 thefrm.contact.focus();
	 return false;
   }	
   else if(document.getElementById('tel').value.Trim().length>0&&!fucCheckTEL(document.getElementById('tel').value.Trim()))
   {
     alert("請輸入正確的電話號碼!");
	 thefrm.tel.focus();
	 return false;  
   }
   else   if(document.getElementById('email').value.Trim().length==0)
   {
     alert("請輸入您的Email!");
	 thefrm.email.focus();
	 return false;
   }
   else if(!checkEmail(document.getElementById('email').value))
   {
     alert("您輸入的Email有誤!!");
	 thefrm.email.focus();
	 return false;   
   }
   else   if(document.getElementById('re_email').value.Trim().length==0)
   {
     alert("請輸入您的確認Email!");
	 thefrm.re_email.focus();
	 return false;
   }
   else if(!checkEmail(document.getElementById('re_email').value))
   {
     alert("確認Email有誤");
	 thefrm.re_email.focus();
	 return false;   
   }   
   else   if(document.getElementById('email').value.Trim()!=document.getElementById('re_email').value.Trim())
   {
     alert("您輸入的Email不一致，請重新輸入!");
	 thefrm.re_email.focus();
	 return false;
   }   
   else{	   	
			 return true;
		
	   }
   
}