$(document).ready(function() {
  $('<meta http-equiv="Cache-control" content="no-cache">').appendTo('head');
    var form = '<form method="post" action="http://overturehq.com/websiteform/formsubmit" id="enquiry_form">';
  form += '<p><label for="firstname">First name</label></p>';
  form += '<p><input type="text" name="firstname" id="firstname"></p>';
  
  form += '<p><label for="surname">Surname</label></p>';
  form += '<p><input type="text" name="surname" id="surname"></p>';
  
  form += '<p><label for="company">Company</label></p>';
  form += '<p><input type="text" name="company" id="company"></p>';
  
  form += '<p><label for="email">Email address</label></p>';
  form += '<p><input type="text" name="email" id="email"></p>';
  
  form += '<p><label for="phone">Phone</label></p>';
  form += '<p><input type="text" name="phone" id="phone"></p>';
  
  form += '<p><label for="details">What would you like to discuss with us?</label></p>';
  form += '<p><textarea name="details" id="details"></textarea></p>';
  
  form += '<p><label for="source">How did you hear about us?</label></p>';
  form += '<p><select name="source" id="source">';
  
  form += '<option>Please select....</option>';
    form+= '<option value="6">Google</option>';
    form+= '<option value="7">Yahoo</option>';
    form+= '<option value="8">Bing</option>';
    form+= '<option value="9">Other Search Engine</option>';
    form+= '<option value="10">Website Link</option>';
    form+= '<option value="11">Press Advertisement</option>';
    form+= '<option value="12">Email Flyer</option>';
    form+= '<option value="13">Directory</option>';
    form+= '<option value="14">Word of Mouth</option>';
    form+= '<option value="15">Direct Mail</option>';
    form+= '<option value="16">Event</option>';
    form+= '<option value="32">Leaflet or Flyer</option>';
    form += '<option>Other</option>';
  form += '</select></p>';
  
  form += '<div id="other_input" style="display:none">';
  form += '<p><label for="other">Please let us know the details of how you heard of us</label></p>';
  form += '<p><input type="text" name="other" id="other"></p>';
  form += '</div>';
  
  form += '<input type="hidden" name="accountId" value="1">';
  form += '<input type="hidden" name="csrfToken" value="c1696effb2362886807257a4c8aa4ade">';
  form += '<input type="hidden" name="url" value="'+window.location+'">';
  
  form += '<br /><br /><input type="submit" name="submit" value="Send">';
  
  form += '</form>';
  
    
  $('.enquiry_form').append(form);
  
    
  $('#source').change(function() {
    if ($('#source').val() == 'Other') {
      $('#other_input').fadeIn('slow');
    } else {
      if ($('#other_input:visible').length == 1) {
        $('#other').val('');
        $('#other_input').fadeOut('slow');
      }
    }  
  });
  
  $('#enquiry_form').submit(function(e) {
    var error = '';
    if ($('#other_input:visible').length == 1 && $('#other').val() == '') {
      error = 'Please provide us with the details of how you heard about us';
    }
    if ($('#source').val() == 'Please select....') {
      error = 'Please let us know how you heard about us';
    }
    if ($('#details').val() == '') {
      error = 'Please provide the details of what you would like to discuss with us';
    }
    if ($('#phone').val() == '') {
      error = 'Please enter your phone number';
    }
    if ($('#email').val() == '') {
      error = 'Please enter your email address';
    }
    if ($('#surname').val() == '') {
      error = 'Please enter your surname';
    }
    if ($('#firstname').val() == '') {
      error = 'Please enter your firstname';
    }
    
    if (error != '') {
      e.preventDefault();
      alert(error);
    }
    
  });
  });  