$(document).ready(function() {
  $("#chiefban").click(function() {
    $.get('/inc/chief-form.html', '', function(data, status) {
      $.fancybox(data, {
        'hideOnContentClick'	: false,
        'scrolling'		: 'no',
        'titleShow'		: false,
        'padding'		: 0,
        'centerOnScroll'	: true,
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'showCloseButton'	: false,
        'onComplete'		: function() {
          $("input[name=name]").focus();
          $("#chieform input[type=submit]").click(function() {
            formSubmit();
            return false;
          });
          $("#chieform").bind("submit", function() {
            formSubmit();
            return false;
          });
        }
      });
    });
  });

  function formSubmit() {
    var frm = document.getElementById("chieform");
    if(frm.name.value.match(/^\s*$/) || frm.contact.value.match(/^\s*$/) || frm.message.value.match(/^\s*$/))
    { $("#chieform").find("u:first").show();
      return false;
    }
    var slz = $("#chieform").serialize();
    $("#chieform").find("input").attr("disabled", true);
    $("#chieform textarea").attr("disabled", true);
    $("#chieform").find("u:first").hide();
    $("#chieform").find("i:first").show();
    $.post('/cgi-bin/chief.pl', slz, function(data, status) {
      if(data == "sent")
      { $.fancybox.close();
        return false;
      }
      else
      { $("#chieform").find("input").attr("disabled", false);
        $("#chieform textarea").attr("disabled", false);
        $("#chieform").find("u:first").show();
        $("#chieform").find("i:first").hide();
        return false;
      }
    });
    return false;
  }
});

