jQuery(document).ready(function () {

  /* Close modal */
  jQuery(document.body).click(function () {
    jQuery('.message-box').remove();
  });

  /* Form */
  var v = {
    'contact-name'    : '',
    'contact-email'   : '',
    'contact-message' : ''
  };
  jQuery('#contact-name,#contact-email,#contact-message').focus(f).blur(b).each(function () {
    var e = jQuery(this);
    v[this.id] = jQuery('label[for="' + this.id + '"]').text();
    if (e.val().replace(/\s+/g, '') == '') {
      e.val(v[this.id]);
    }
  });
  function f(e) {
    o = jQuery(this);
    if (o.val() == v[this.id]) {
      o.val('');
    }
  }
  function b(e) {
    o = jQuery(this);
    if (o.val().replace(/\s+/g, '') == '') {
      o.val(v[this.id]);
    } else {
      o.removeClass('error');
    }
  }
  jQuery('form').submit(function () {
    var i = jQuery(this).find('input,textarea');
    i.each(function () {
      var e = jQuery(this);
      if (e.val().replace(/\s+/g, '') == '' || e.val() == v[this.id]) {
        e.addClass('error');
      }
    });
    return !i.is('.error');
  });

});
