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.titleothers.value, "You selected 'Others'. Please enter your Title.\n");
  }

  why += checkField(theForm.firstname.value, "Please enter your First Name.\n");
  why += checkField(theForm.lastname.value, "Please enter your Surname.\n");
  why += checkField(theForm.jobtitle.value, "Please enter your Job Title.\n");
  why += checkField(theForm.company.value, "Please enter your Company.\n");
  why += checkField(theForm.address1.value, "Please enter your Address (Line 1).\n");
  why += checkField(theForm.address2.value, "Please enter your Address (Line 2).\n");
  why += checkField(theForm.postalcode.value, "Please enter your Postal code.\n");
  why += checkDropdown(theForm.country.selectedIndex, "Please select your Country.\n");
  why += checkField(theForm.telephone.value, "Please select your Telephone Number.\n");
  why += checkEmail(theForm.email.value);
  why += checkField(theForm.businesssectorothers.value, "Please enter your Business Sector.\n");

  var product_checked=false; 
  if(theForm.new01.checked) 
  {
      product_checked = true;
  }
  if(theForm.new02.checked) 
  {
      product_checked = true;
  }
  if(theForm.new03.checked) 
  {
      product_checked = true;
  }
  if(theForm.new04.checked) 
  {
      product_checked = true;
  }
  if(theForm.retread01.checked) 
  {
      product_checked = true;
  }
  if(theForm.retread02.checked) 
  {
      product_checked = true;
  }
  if(theForm.retread03.checked) 
  {
      product_checked = true;
  }
  if(theForm.retread04.checked) 
  {
      product_checked = true;
  }
  if(theForm.casings01.checked) 
  {
      product_checked = true;
  }
  if(theForm.wheels01.checked) 
  {
      product_checked = true;
  }
  if(theForm.tubes01.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd01.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd02.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd03.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd04.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd05.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd06.checked) 
  {
      product_checked = true;
  }
  if(theForm.equipprd07.checked) 
  {
      product_checked = true;
  }
//  if(theForm.equipprd08.checked) 
//  {
//      product_checked = true;
//  }
  if(theForm.equipprd09.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair01.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair02.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair03.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair04.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair05.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair06.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair07.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair08.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair09.checked) 
  {
      product_checked = true;
  }
  if(theForm.equiprepair10.checked) 
  {
      product_checked = true;
  }
  if(theForm.tyredisposal01.checked) 
  {
      product_checked = true;
  }
  if(theForm.tyredisposal02.checked) 
  {
      product_checked = true;
  }
  if(theForm.tyredisposal03.checked) 
  {
      product_checked = true;
  }
  if(theForm.tyredisposal04.checked) 
  {
      product_checked = true;
  }
  if(theForm.computertech01.checked) 
  {
      product_checked = true;
  }
 if(theForm.trainingcourses01.checked) 
  {
      product_checked = true;
  } 
  if(theForm.productothersval.checked) 
  {
      product_checked = true;
  }

  if (!product_checked)
  {
    why += "Please select at least one product that you are interested in.\n";
  } 
  if (theForm.productothersval.checked)
  {
    why += checkField(theForm.productothers.value, "You selected 'Others'. Please enter the product that you are most interested in.\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 

