$(document).ready(function(){
  //Contact Form Widget
  $('#contactFormWidget').submit(function() {
      // assign dynamic div height to footer
      $('form#contactFormWidget .error').remove();
      var hasError = false;
      $('.requiredField').each(function() {
          if($.trim($(this).val()) == '') {
            if(!hasError) {
              var thisid = $(this).attr("id");
              if (thisid == "inputName") {
                  $("#formResponse").html('<div>You forgot to enter your name.</div>');
              } else if (thisid == "inputEmail") {
                  $("#formResponse").html('<div>You forgot to enter your email address.</div>');
              } else if (thisid == "inputCountry") {
                  $("#formResponse").html('<div>You forgot to enter your country.</div>');
              } else if (thisid == "inputMessage") {
                  $("#formResponse").html('<div>You forgot to enter the message.</div>');
              }
              $(this).addClass('inputError');
              hasError = true;
            }
          } else if($(this).hasClass('email')) {
              var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
              if(!emailReg.test($.trim($(this).val()))) {
                  $("#formResponse").html('<div>You entered an invalid email address</div>');
                  $(this).addClass('inputError');
                  hasError = true;
              }
          }
      });
  
      if(!hasError) {
          var formInput = $(this).serialize();
          $.post($('#submitUrl').val(),formInput, function(data){	   
                $("#formResponse").html('<strong>Thanks!</strong> Your email was successfully sent.');
                $('.requiredField').each(function() {
                    $(this).val("");
                });
          });
      }
      return false;
  });
});
