
// scripts for Quick Poll functions in FORTUNE Panels site

$(document).ready(function() {

   // if js is enabled, jquery will insert a hidden input element in the QP form
   $("#qpform").prepend('<input type="hidden" name="j" value="1" />');

   $("#qpsubmit").click(function(){
   
      var FormData = $("#qpform").formSerialize();
   
      // now, we want to actually send the form details over to QPSave.asp
      $.ajax({
         type: "POST", 
         url: "/inc/qp/qpsave.asp", 
         data: FormData, 
         beforeSend: function() {
            // remove any saves messages that may be hanging around
            $("#qpform p.msg").remove();
            $("#qpform p.error").remove();
            // disable all input controls in the form while saving
            $("#qpform :input").attr("disabled", 'true');
            $("#qpform").fadeTo("normal", .1);
         }, //beforesend
         complete: function() {
            //alert('test');
         }, //complete
         success: function(msg) {
            //alert(msg);
            $("#qpform").fadeTo("normal", 1, function() {
               if (msg.indexOf('ERROR') == -1) {
                  $("#qpform").empty();
                  $("#qpform").append("<p class='msg'>Saved.</p>");  
                  $("#qpform").append(msg);
               } //if
               else {
                  $("#qpform").fadeTo("normal", 1, function() {
                     $("#qpform").prepend("<p class='error'>" + msg + "</p>");  
                     $("#qpform :input").attr("disabled", '');
                  });
               } // else
            }); // fadeto
         } // success  
      }); //ajax
      return false;
   }); // click
   
}); // document ready