// Validation of the ClaimNow form

function validate_required(field) {
  if ($F(field) == null || $F(field) == "") {
    return false;
  } else {
    return true;
  }
}

function validate_email(field)
{
  with (field)
  { 
    if (value==null || value=="")
    {
      alert("An email address must be provided.");
      return false;      
    }
    else if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)==false)
    {
      alert("You must provide a valid email address, e.g. joe@bloggs.co.uk");
      return false;      
    }
    else
    {
      return true;
    }
  }
}

function validate_form(thisform) {
  
  var valid = true;
  
  thisform.select('input', 'select', 'textarea').each(function(field) {
    if (!validate_required(field) && field.type != "image") {
      field.focus();
      valid = false;
    }
  });
  
  if (!valid) {
    alert("You must supply information for all fields");
    return false;
  }  

  var email_address = thisform.select('input[name="enquiry[email_address]"]')[0];
  if (!validate_email(email_address)) {
    email_address.focus();
    return false;
  }
}


// Select box population for claim form on homepage
function populateDropDown(selection){
  var injuryArray = new Array();
  injuryArray[injuryArray.length] = ['RTA', 'Accidents at Work', 'Sports Injury', 'Injuries in Public Places', 'Trips Slips and Falls', 'Catastrophic Injuries', 'Pollutants And Hazardous Substances', 'Other'];
  injuryArray[injuryArray.length] = ['VWF', 'Mesothelioma', 'Miners Claims', 'Asbestosis', 'Noise Induced Hearing Loss', 'Fatal Accidents', 'Other'];
  injuryArray[injuryArray.length] = ['Missold Payment Protection', 'Bank Charge Recovery', 'Credit Card Recovery', 'Other'];
  injuryArray[injuryArray.length] = ['Clinical Negligence', 'Professional Negligence', 'Holiday illness and accidents', 'Dog Bites', 'Food Poisoning', 'Sexual or Physical Abuse', 'Defective Products', 'Other'];

  if (injuryArray[selection])
  {
    var optionsArray = new Array();
    var optionString = new String;
    optionsArray = injuryArray[selection]
    for(i=0;i< optionsArray.length;i++)
    {
      optionString += "<option>" + optionsArray[i] + "</option>" ;
    }

    $("InjuryTypeContainer").innerHTML = '<select name="enquiry[injury_type]">' + optionString + "</select>";

  }
    

}
// Activate styles in IE6 using selectors that are not supported by IE6 (e.g. child selectors, attribute selectors etc.)
function activateIeStyles() {
  $(document.body).select('input[type=text]', 'input[type=password]').each(function(el) {
    el.addClassName('ie_text')
  })
  
  $(document.body).select('*:first-child').each(function(el) {
    el.addClassName('ie_first_child')
  })
}

// Jump to onclick function
function jumpTo(part)
    { 
      window.location.hash= "#" + part; 
    }
