
$(document).ready(function(){
    // validation
    $('.wpcf7 form').submit(function(){
      var error_msg = '';
      if ( $('input[name=situation]').length > 0 )
      {
          var situation = $('input[name=situation]:checked').val();
          if ( ! situation )
          {
              error_msg += "Please select one of the options above\n"
          }
          else if ( situation == "other" )
          {
              if ( $('input[name=situation_other]').val() == '' || ! $('input[name=situation_other]').hasClass('cleared_state') )
                error_msg += "Please tell us what you'd like to contact us about\n";
          }
      }
      if ( $('input[name=your-name]').length > 0 )
      {
          if ( $('input[name=your-name]').val() == '' )
              error_msg += "Please enter your name\n";
      }
      if ( $('input[name=your-email]').length > 0 )
      {
          if (  ! $('input[name=your-email]').val().match(/[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]+/i) )
              error_msg += "Please enter a valid email address\n";
      }
      if ( error_msg != '' )
      {
          alert(error_msg);
          form_is_valid = false;
          return false;
      }
      form_is_valid = true;
      return true;
    });
})

if ( typeof wpcf7BeforeSubmit == 'function' )
{
    var wpcf7BeforeSubmit_or = wpcf7BeforeSubmit;
    var form_is_valid = false;
    wpcf7BeforeSubmit = function(formData, jqForm, options)
    {
        if ( form_is_valid )
            return wpcf7BeforeSubmit_or(formData, jqForm, options);
        else
            return false;
    }
}

