function formCheck() 
{
  	if (document.pre_form.first_name.value=="") 
  	{           
        	alert("請輸入閣下姓名之姓。");
        	document.pre_form.first_name.focus();
        	return false;
	}
	if (document.pre_form.last_name.value=="")
	{
        	alert("請輸入閣下姓名之名。");
        	document.pre_form.last_name.focus();
        	return false;
	}

 	if (document.pre_form.company.value=="") 
 	{
      	        alert("請輸入閣下公司名稱。");
		document.pre_form.company.focus();
		return false;	
 	}
 	
 	if (document.pre_form.address1.value=="") 
 	{
       	        alert("請輸入閣下地址。");
		document.pre_form.address1.focus();
		return false;		
 	}
 	
  	if (document.pre_form.country_name.selectedIndex == 0)
     	{
        	alert("請選擇閣下的國家位置。");
        	document.pre_form.country_name.focus();
        	return false;
     	}
     		if (document.pre_form.tel_country.value=="") 
 	{
		alert("請輸入電話號碼 (國家)。");
		document.pre_form.tel_country.focus();
		return false;	
 	}
 	
 	if (document.pre_form.tel_no.value=="") 
 	{
		alert("請輸入電話號碼。");
		document.pre_form.tel_no.focus();
		return false;	
 	} 	

	 if (document.pre_form.tel_country.value!="") 
  	{           
  		document.pre_form.tel_country.value = replacenum(document.pre_form.tel_country.value);
		if (!isInteger(document.pre_form.tel_country.value)) {		
			alert("電話號碼必須是數字");
			document.pre_form.tel_country.focus();
			document.pre_form.tel_country.select();
			return false;
		}
	}
	
	if (document.pre_form.tel_area.value!="") 
  	{           
  		document.pre_form.tel_area.value = replacenum(document.pre_form.tel_area.value);
		if (!isInteger(document.pre_form.tel_area.value)) {		
			alert("電話號碼必須是數字");
			document.pre_form.tel_area.focus();
			document.pre_form.tel_area.select();
			return false;
		}
	}
     	
     	if (document.pre_form.tel_no.value!="") 
  	{           
  		document.pre_form.tel_no.value = replacenum(document.pre_form.tel_no.value);
		if (!isInteger(document.pre_form.tel_no.value)) {		
			alert("電話號碼必須是數字");
			document.pre_form.tel_no.focus();
			document.pre_form.tel_no.select();
			return false;
		}
	}
	
	 if (document.pre_form.fax_country.value!="") 
  	{           
  		document.pre_form.fax_country.value = replacenum(document.pre_form.fax_country.value);
		if (!isInteger(document.pre_form.fax_country.value)) {		
			alert("傳真號碼必須是數字");
			document.pre_form.fax_country.focus();
			document.pre_form.fax_country.select();
			return false;
		}
	}
	
	if (document.pre_form.fax_area.value!="") 
  	{           
  		document.pre_form.fax_area.value = replacenum(document.pre_form.fax_area.value);
		if (!isInteger(document.pre_form.fax_area.value)) {		
			alert("傳真號碼必須是數字");
			document.pre_form.fax_area.focus();
			document.pre_form.fax_area.select();
			return false;
		}
	}
	
	if (document.pre_form.fax_no.value!="") 
  	{           
  		document.pre_form.fax_no.value = replacenum(document.pre_form.fax_no.value);
		if (!isInteger(document.pre_form.fax_no.value)) {		
			alert("傳真號碼必須是數字");
			document.pre_form.fax_no.focus();
			document.pre_form.fax_no.select();
			return false;
		}
	}
	
	
 	if (document.pre_form.email_address.value=="")
 	{
       	        alert("請輸入閣下電子郵件地址。");
		document.pre_form.email_address.focus();
		return false;	
 	}
 	
 	if (!IsEmail(document.pre_form.email_address.value)) {
 		alert ("電子郵件格式有誤，請更正。");
 		document.pre_form.email_address.focus();
 		document.pre_form.email_address.select();	
 		return false;
 	}
	if (document.pre_form.org_country_office.selectedIndex == 0)
      {
         alert("請輸入閣下總公司所屬國家。");
         document.pre_form.org_country_office.focus();
         return false;
      }
 	
	var count = 0;
	for (var i=19; i <= 34; i++)
	{
		if (document.pre_form.elements[i].checked)
		{
			++count;
		}
		
	}	
	if (count <= 0)
	{
       	        alert("請閣下選擇其中一項業務性質。");
    	        return false;
	}
	
	var count1 = 0;
	for (var i=36; i <= 44; i++)
	{
		if (document.pre_form.elements[i].checked)
		{
			++count1;
		}
		
	}	
	if (count1 <= 0)
	{
	   alert("請閣下選擇其中一項產品經營。");
    	   return false;
	}
	/*
		var count2 = 0;
	for (var i=46; i <= 59; i++)
	{
		if (document.pre_form.elements[i].checked)
		{
			++count2;
		}
		
	}	
	if (count2 > 3)
	{
	   alert("閣下最多可選擇三本貿發局的產品雜誌。");
    	   return false;
	}
	*/
}

function checkOpt(opt){
  if (opt.checked) {
	alert("請注意: 選擇不收取貿發局宣傳電郵將不會影響閣下收取已訂閱的電郵通訊。")	
  }
}



function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function replacenum (s) 
{
var i, str;
str = "";
    for (i = 0; i < s.length; i++)
    {           
        var c = s.charAt(i);        
        
        switch (c) {
        	case "０": c = 0; break;
        	case "１": c = 1; break;
        	case "２": c = 2; break;
        	case "３": c = 3; break;
        	case "４": c = 4; break;
        	case "５": c = 5; break;
        	case "６": c = 6; break;
        	case "７": c = 7; break;
        	case "８": c = 8; break;
        	case "９": c = 9; break;        		        		
        }      
        
        str += c;     	
    
    }
    
    return str;
}

function isInteger (s)

{   var i;
   

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);               
        if (!isDigit(c)) return false;
    }
    
    return true;
}

function IsEmail(email)
{
	var i, countAt
	
	countAt = 0;
	 for (i = 0; i < email.length; i++)
	 {           
        	var c = email.charAt(i); 
		if (c == "@")
			countAt++;
	}
	

   return ((email != "") && (countAt == 1) && (email.indexOf(".") != -1) && (email.indexOf(",") < 0) && (email.indexOf(";") < 0) && (email.indexOf("?") < 0) && (email.indexOf("/") < 0) && (email.indexOf("&") < 0));
//   return ((email != "") && (email.indexOf("@") != -1) && (email.indexOf(".") != -1) && (email.indexOf(",") < 0) && (email.indexOf(";") < 0) && (email.indexOf("?") < 0) && (email.indexOf("/") < 0) && (email.indexOf("&") < 0));
}