function checkField(strng, err_msg) 
{
  var error = "";
  if (strng.length == 0) 
  {
    error = err_msg;
  }
  return error;	  
}//endcheckField

function checkRadio(checkvalue, err_msg) 
{
  var error = "";
  if (!(checkvalue)) 
  {
    error = err_msg;
  }
  return error;
}//endcheckRadio

function checkDropdown(choice, err_msg) {
var error = "";
    if (choice == 0) {
    error = err_msg;
    }    
return error;
}  

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter your Email Address.\n";
return error;
}
if (strng != "") {
   var emailFilter=/^.+@.+\..{2,3}$/;
   if (!(emailFilter.test(strng))) { 
      error = "Please enter a valid Email Address.\n";
    }
   else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
         if (strng.match(illegalChars)) {
          error = "The Email Address contains illegal characters.\n";
     }  
 }
}
return error;    

}

function checkInputForm(theForm) 
{
   var why = "";

//  for (i=0, n=theForm.title.length; i<n; i++)
//  {
//    if (theForm.title[i].checked) 
//    {
//      var titlevalue = theForm.title[i].value;
//      break;
//    } 
//  }
//  why += checkRadio(titlevalue, "Please select your Title.\n");

//  if (titlevalue == "Others")
//  {
//    why += checkField(theForm.title_other.value, "You selected 'Other'. Please enter your Title.\n");
//  }

  why += checkDropdown(theForm.title.selectedIndex, "Please select your Title.\n");
  if (theForm.title.selectedIndex == "Other")
  {
    why += checkField(theForm.title_other.value, "You selected 'Other'. Please enter your Title.\n");
  }
  why += checkField(theForm.lastname.value, "Please enter your Last Name / Surname.\n");
  why += checkField(theForm.firstname.value, "Please enter your First Name(s).\n");
  why += checkField(theForm.jobtitle.value, "Please enter your Job Title.\n");
  why += checkField(theForm.company_name.value, "Please enter your Company Name.\n");

  why += checkField(theForm.company_address_01.value, "Please enter your Address (Line 1).\n");
  why += checkField(theForm.town.value, "Please enter your Town.\n");
  why += checkDropdown(theForm.country.selectedIndex, "Please select your Country.\n");
  why += checkEmail(theForm.email.value);
  why += checkEmail(theForm.email2.value);
  if (theForm.email.value != theForm.email2.value)
  {
    why += "Please enter the same email twice.\n";
  }
  why += checkField(theForm.tel_country_code.value, "Please enter your Telephone Country Code.\n");
  why += checkField(theForm.tel_area_code.value, "Please enter your Telephone Area Code.\n");
  why += checkField(theForm.tel_no.value, "Please enter your Telephone Number.\n");

//////////////////////////////////////////////////////////////////////


  if (why != "") 
  {
    alert(why);
    return false;
  }
  return true;

}//endcheckInputForm


function onlyNumeric(string, theField) 
{
  //if (!string) return false;
  var Chars = "0123456789-";

  for (var i = 0; i < string.length; i++) 
  {
    if (Chars.indexOf(string.charAt(i)) == -1)
    {
      alert("Numeric Only");
      theField.value = "";
      return false;
    }
  }
  return true;
}//endonlyNumeric 

