function ajaxfunction()
{
  var ajaxrequest;

  try
  {
    ajaxrequest = new XMLHttpRequest();
  }
  catch (e)
  {
    try
    {
      ajaxrequest = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e)
    {
      try
      {
        ajaxrequest = new ActiveXObject('Microsoft.XMLHTTP');
      }
      catch (e)
      {
        alert('Browser does not support HTTP requests');
        
        return false;
      }
    }

  }
  
  return ajaxrequest;
}

function showcity(county)
{
  htmlrequest1 = ajaxfunction();

  if (htmlrequest1 == null)
  {
    alert ('Browser does not support HTTP requests');
    return;
  }
  
  var url = 'showcity.php';
  var params = 'county=' + county;
  
  htmlrequest1.open('POST', url, true);
  htmlrequest1.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  htmlrequest1.setRequestHeader('Content-length', params.length);
  htmlrequest1.setRequestHeader('Connection', 'close');
  htmlrequest1.onreadystatechange = statechanged1;
  htmlrequest1.send(params);
}

function statechanged1()
{
  if (htmlrequest1.readyState == 4)
  {
    if (document.getElementById('showcity'))
      document.getElementById('showcity').innerHTML = htmlrequest1.responseText;
  }
}

function checkserv(aId)
{
  if (document.getElementById(aId + 'check').checked == true)
    checkByParent(aId, true)
  else
    checkByParent(aId, false)
}

function checkByParent(aId, aChecked) 
{
  var collection = document.getElementById(aId).getElementsByTagName('INPUT');
  
  for (var x = 0; x < collection.length; x++) 
  {
    if (collection[x].type.toUpperCase()=='CHECKBOX')
      collection[x].checked = aChecked;
  }
}

function checkhour(aId, cVal)
{
  if (document.getElementById(aId + 'check').checked == true)
    checkByValue('hourtable', cVal, true)
  else
    checkByValue('hourtable', cVal, false)
}

function checkByValue(aId, cVal, aChecked) 
{
  var collection = document.getElementById(aId).getElementsByTagName('INPUT');
  
  for (var x = 0; x < collection.length; x++) 
  {
    if (collection[x].type.toUpperCase()=='CHECKBOX')
    {
      if (collection[x].value.match(cVal))
        collection[x].checked = aChecked;
    }
  }
}

function checkformapp()
{
  var errors = "";

  if (document.getElementById('surname').value == '')
    errors += "- You must enter your surname\n";

  if (document.getElementById('forename').value == '')
    errors += "- You must enter your forename\n";

  if (document.getElementById('title').value == '')
    errors += "- You must enter your title\n";

  if (document.getElementById('dob').value == '')
    errors += "- You must enter your date of birth\n";

  if (document.getElementById('address').value == '')
    errors += "- You must enter your address\n";

  if (document.getElementById('postcode1').value == '')
    errors += "- You must enter the beginning of your postcode\n";

  if (document.getElementById('postcode2').value == '')
    errors += "- You must enter the ending of your postcode\n";

  if (document.getElementById('mobile').value == '')
    errors += "- You must enter your mobile number\n";

  if (document.getElementById('email').value == '')
    errors += "- You must enter your email address\n";

  if (document.getElementById('nationality').value == '')
    errors += "- You must enter your nationality\n";

  if (document.getElementById('languages').value == '')
    errors += "- You must enter your languages\n";

  if (document.getElementById('passportnumber').value == '')
    errors += "- You must enter your passport number\n";

  if (document.getElementById('decname').value == '')
    errors += "- You must enter your name in the declaration agreement\n";

  if (document.getElementById('confname').value == '')
    errors += "- You must enter your name in the confidentiality agreement\n";
    
  if (errors == '')
  {  
    return true;
  }
  else
  {
    errors = "The following errors have occurred:\n\n" + errors + "\nPlease fill in these boxes and submit the application again.";
    
    alert(errors);
    
    return false;
  }    
}

function cllogin()
{
  var errors = "";

  if (document.getElementById('emaill').value == '')
    errors += "- You must enter your email\n";

  if (document.getElementById('passwordl').value == '')
    errors += "- You must enter your password\n";
    
  if (errors == '')
  {  
    return true;
  }
  else
  {
    errors = "The following errors have occurred:\n\n" + errors + "\nPlease fill in these boxes and try logging in again.";
    
    alert(errors);
    
    return false;
  }    
}

function clregister()
{
  var errors = "";

  if (document.getElementById('fullname').value == '')
    errors += "- You must enter your full name\n";

  if (document.getElementById('emailr').value == '')
    errors += "- You must enter your email\n";
    
  if (document.getElementById('passwordr').value == '')
    errors += "- You must enter your password\n";

  if (document.getElementById('phone').value == '')
    errors += "- You must enter your phone number\n";

  if (document.getElementById('address').value == '')
    errors += "- You must enter your address\n";

  if (document.getElementById('postcode').value == '')
    errors += "- You must enter your postcode\n";

  if (document.getElementById('agree').checked == false)
    errors += "- You must tick the box to agree to our TOS\n";
    
  if (errors == '')
  {  
    return true;
  }
  else
  {
    errors = "The following errors have occurred:\n\n" + errors + "\nPlease fill in these boxes and try registering in again.";
    
    alert(errors);
    
    return false;
  }    
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function clpay()
{
  var errors = "";

  if (document.getElementById('bookhourspn').value == '' || !IsNumeric(document.getElementById('bookhourspn').value) || document.getElementById('bookhourspn').value < 2.5)
    errors += "- The amount of hours to book must be at least 2.5 hours\n";

  if (document.getElementById('fullnamepn').value == '')
    errors += "- You must enter your full name\n";

  if (document.getElementById('phonepn').value == '')
    errors += "- You must enter your phone number\n";

  if (document.getElementById('addresspn').value == '')
    errors += "- You must enter your address\n";

  if (document.getElementById('postcodepn').value == '')
    errors += "- You must enter your postcode\n";
    
  if (errors == '')
  {  
    return true;
  }
  else
  {
    errors = "The following errors have occurred:\n\n" + errors + "\nPlease fill in these boxes and try booking again.";
    
    alert(errors);
    
    return false;
  }    
}