function formCheck() 
{
  	if (document.pre_form.first_name.value=="") 
  	{           
        	alert("Please input your first name.");
        	document.pre_form.first_name.focus();
        	return false;
	}
	
	if (checkLength(document.pre_form.first_name.value) > 20) {
		alert ("The total characters of first name has exceeded, please verify");
		document.pre_form.first_name.focus();
		document.pre_form.first_name.select();
		return false;		
	}
		
	if (document.pre_form.last_name.value=="")
	{
        	alert("Please input your last name.");
        	document.pre_form.last_name.focus();
        	return false;
	}
	
	if (checkLength(document.pre_form.last_name.value) > 20) {
		alert ("The total characters of last name has exceeded, please verify");
		document.pre_form.last_name.focus();
		document.pre_form.last_name.select();
		return false;		
	}
	
	if (checkLength(document.pre_form.position.value) > 25) {
		alert ("The total characters of position has exceeded, please verify");
		document.pre_form.position.focus();
		document.pre_form.position.select();
		return false;		
	}

 	if (document.pre_form.company.value=="") 
 	{
		alert("Please input your company name.");
		document.pre_form.company.focus();
		return false;	
 	}
 	
 	if (checkLength(document.pre_form.company.value) > 55) {
		alert ("The total characters of company has exceeded, please verify");
		document.pre_form.company.focus();
		document.pre_form.company.select();
		return false;		
	} 	 	
 	
 	if (document.pre_form.address1.value=="") 
 	{
		alert("Please input your address.");
		document.pre_form.address1.focus();
		return false;		
 	}
 	
 	if (checkLength(document.pre_form.address1.value) > 35) {
		alert ("The total characters of address has exceeded, please verify");
		document.pre_form.address1.focus();
		document.pre_form.address1.select();
		return false;		
	} 	
	
	if (checkLength(document.pre_form.address2.value) > 35) {
		alert ("The total characters of address has exceeded, please verify");
		document.pre_form.address2.focus();
		document.pre_form.address2.select();
		return false;		
	} 	
	
	if (checkLength(document.pre_form.address3.value) > 35) {
		alert ("The total characters of address has exceeded, please verify");
		document.pre_form.address3.focus();
		document.pre_form.address3.select();
		return false;		
	} 	
	
	if (checkLength(document.pre_form.address4.value) > 35) {
		alert ("The total characters of address has exceeded, please verify");
		document.pre_form.address4.focus();
		document.pre_form.address4.select();
		return false;		
	} 	
 	
  	if (document.pre_form.country_name.selectedIndex == 0)
     	{
        	alert("Please select your country.");
        	document.pre_form.country_name.focus();
        	return false;
     	}
     	
     	  	if (document.pre_form.tel_country.value=="") 
 	{
		alert("Please input telephone number (Country Code).");
		document.pre_form.tel_country.focus();
		return false;	
 	}
 	
 	if (document.pre_form.tel_no.value=="") 
 	{
		alert("Please input telephone number.");
		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("Telephone data accepts number only. Symbols or spaces is not allowed");
			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("Telephone data accepts number only. Symbols or spaces is not allowed");
			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("Telephone data accepts number only. Symbols or spaces is not allowed");
			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("Fax data accepts number only. Symbols or spaces is not allowed");
			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("Fax data accepts number only. Symbols or spaces is not allowed");
			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("Fax data accepts number only. Symbols or spaces is not allowed");
			document.pre_form.fax_no.focus();
			document.pre_form.fax_no.select();
			return false;
		}
	}

 	if (document.pre_form.email_address.value=="")
 	{
 		alert("Please input your email address.");
		document.pre_form.email_address.focus();
		return false;	
 	}
 	
 	if (!IsEmail(document.pre_form.email_address.value)) {
 		alert ("The email format is invalid, please check");
 		document.pre_form.email_address.focus();
 		document.pre_form.email_address.select();	
 		return false;
 	}
	if (document.pre_form.org_country_office.selectedIndex == 0) 
  {
  alert("Please select your Country of Head Office.");
  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("You must choose at least one nature of business.");
    	   return false;
	}
	
		var count1 = 0;
	for (var i=36; i <= 62; i++)
	{
		if (document.pre_form.elements[i].checked)
		{
			++count1;
		}
		
	}	
	if (count1 <= 0)
	{
	   alert("You must choose at least one product handled.");
    	   return false;
	}
	/*
		var count2 = 0;
	for (var i=64; i <= 77; i++)
	{
		if (document.pre_form.elements[i].checked)
		{
			++count2;
		}
		
	}	
	if (count2 > 3)
	{
	   alert("You are able to select maximum of 3 TDC trade publications.");
    	   return false;
	}
	*/
}

function checkOpt(opt){
  if (opt.checked) {
	alert("Choosing not to receive TDC promotional materials via e-mail will not affect any existing subscription to TDC e-newsletters.")	
  }
}


function checkLength (str) {
var j, s;
size = 0;
    for (j = 0; j < str.length; j++)
    {           
        var c = str.charAt(j);    
        var asciisize = c.charCodeAt(0);        
        if (asciisize >= 32 && asciisize <= 130) 
        	size = size + 1;
        else
        	size = size + 2;        
     }
     
     return size;
	
}


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));
}