// JavaScript Document


function checkTraining()
{ 
  var salutation=document.getElementById("salutation");	
  var first_name=document.getElementById("first_name");	
  var surname= document.getElementById('surname');
  var company_name=document.getElementById("company_name");
  var email=document.getElementById("email");
  var telephone=document.getElementById("telephone");	
  var post_code=document.getElementById("post_code");
  var products=document.getElementById("products");
  var training_requirements=document.getElementById("training_requirements");
  var training_location=document.getElementById("training_location");
  var comment=document.getElementById("comment");
 

  salutation.value=salutation.value.replace(/^\s+|\s+$/g,""); 
  first_name.value=first_name.value; 
  surname.value=surname.value.replace(/^\s+|\s+$/g,""); 
  company_name.value=company_name.value.replace(/^\s+|\s+$/g,""); 
  email.value=email.value.replace(/^\s+|\s+$/g,"");
  telephone.value=telephone.value.replace(/^\s+|\s+$/g,"");
  post_code.value=post_code.value.replace(/^\s+|\s+$/g,"");
  products.value=products.value.replace(/^\s+|\s+$/g,"");
  training_requirements.value=training_requirements.value.replace(/^\s+|\s+$/g,"");
  training_location.value=training_location.value.replace(/^\s+|\s+$/g,"");
  comment.value=comment.value.replace(/^\s+|\s+$/g,"");


  document.getElementById("spnSalutation").style.display="none";
  document.getElementById("spnFirstName").style.display="none";
  document.getElementById("spnSurName").style.display="none";
  document.getElementById("spnCompanyName").style.display="none";
  document.getElementById("spnEmail").style.display="none";  
  document.getElementById("spnTelephone").style.display="none";
  document.getElementById("spnPostCode").style.display="none";
  document.getElementById("spnProducts").style.display="none";
  document.getElementById("spnTrainingRequirements").style.display="none";
  document.getElementById("spnTrainingLocation").style.display="none";
  document.getElementById("spnComment").style.display="none";
  
  if(salutation.value=="0"){
	 document.getElementById("spnSalutation").style.display="block";
	 document.getElementById("spnSalutation").innerHTML='Enter a value for salutation';
     salutation.focus();
     return false;
  }
  else if(!hasOnlyAlphaNumericWithSpace("First Name",first_name.value))
  {
     document.getElementById("spnFirstName").style.display="block";
	 document.getElementById("spnFirstName").innerHTML='Enter only alphabets, 0-9 and space for name';
	 first_name.focus();
     return false;
  }
  else if(first_name.value==""){
	 document.getElementById("spnFirstName").style.display="block";
	 document.getElementById("spnFirstName").innerHTML='Enter a value for first name';
     first_name.focus();
     return false;
  }
  else if(!hasOnlyAlphaNumericWithSpace("Surname",surname.value))
  {
     document.getElementById("spnSurName").style.display="block";
	 document.getElementById("spnSurName").innerHTML='Enter only alphabets, 0-9 and underscore for surname';
	 surname.focus();
     return false;
  }
  else if(surname.value==""){
	 document.getElementById("spnSurName").style.display="block";
	 document.getElementById("spnSurName").innerHTML='Enter a value for surname';
     surname.focus();
     return false;
  }
  else if(!hasOnlyAlphaNumericWithSpace("Surname",surname.value))
  {
     document.getElementById("spnSurName").style.display="block";
	 document.getElementById("spnSurName").innerHTML='Enter any character except <,>,^ for surname';
	 surname.focus();
     return false;
  }  
  else if(!hasOnlyAlphaNumericWithSpace("Company",company_name.value))
  {
     document.getElementById("spnCompanyName").style.display="block";
	 document.getElementById("spnCompanyName").innerHTML='Enter only alphabets, 0-9 and underscore for company';
	 company_name.focus();
     return false;
  }
  else if(company_name.value==""){
	 document.getElementById("spnCompanyName").style.display="block";
	 document.getElementById("spnCompanyName").innerHTML='Enter a value for company';
     company_name.focus();
     return false;
  }
  else if(post_code.value==""){
	 document.getElementById("spnPostCode").style.display="block";
	 document.getElementById("spnPostCode").innerHTML='Enter a value for post code';
     post_code.focus();
     return false;
  }
  else if(email.value==""){
	 document.getElementById("spnEmail").style.display="block";
	 document.getElementById("spnEmail").innerHTML='Enter a value for email address';
     email.focus();
     return false;
  }
  else if(!isEmail(email.value))
  {
	 document.getElementById("spnEmail").style.display="block";
	 document.getElementById("spnEmail").innerHTML='Invalid email address';
     email.focus();
     return false;
  } 
  else if(telephone.value==""){
	 document.getElementById("spnTelephone").style.display="block";
	 document.getElementById("spnTelephone").innerHTML='Enter a value for telephone number';
     telephone.focus();
     return false;
  }
  else if(!hasOnlyNumericWithSpace("Telephone",telephone.value))
  {
	 document.getElementById("spnTelephone").style.display="block";
	 document.getElementById("spnTelephone").innerHTML='Invalid telephone number';
     telephone.focus();
     return false;
  } 
  
  else if(!hasOnlyAlphaNumericWithSpace("Post Code",post_code.value))
  {
	 document.getElementById("spnPostCode").style.display="block";
	 document.getElementById("spnPostCode").innerHTML='Invalid post code';
     post_code.focus();
     return false;
  }  
  else if(products.value=="0"){
	 document.getElementById("spnProducts").style.display="block";
	 document.getElementById("spnProducts").innerHTML='Select a value for products';
     products.focus();
     return false;
  }
  else if(training_requirements.value=="0"){
	 document.getElementById("spnTrainingRequirements").style.display="block";
	 document.getElementById("spnTrainingRequirements").innerHTML='Select a value for training requirements';
     training_requirements.focus();
     return false;
  }
  else if(training_location.value=="0"){
	 document.getElementById("spnTrainingLocation").style.display="block";
	 document.getElementById("spnTrainingLocation").innerHTML='Select a value for training requirements';
     training_location.focus();
     return false;
  }
  return true;
}