/*
 * pleaseWait.js
 *
 * This is used in the baseTemplate. It will load the please wait image and words to the
 * please wait div.
 * Author: Amy Smith Wright Express
 * NOTE: pleaseWait.js requires jquery.js    see include...
 *
 * How to use for Submit:
 *           1. submit button has id="pleaseWaitSubmit"
 *           2. place this div with key for message in same page <div id="pleaseWaitMessage" style="display:none"><bean:message key="please.wait.account.adding"/> </div>
 *           3. key should be key in AplicationResouces.properties with the proper message that will be displayed.
 *
 *
 * Date: 2008-10-09
 */

// default message for please wait.
var gsPleaseWaitMessage = "System Process is being executed. Please Wait.";

function getPleaseWaitMessage(msg) {
  if (!msg) {
    msg = gsPleaseWaitMessage;
  }
  return '<table width="100%" height="100%">' +
         '<tr height="100%">' +
         '<td width="100%" class="bodyTxt"><center><span id="loaderText">' + msg + '</span></center></td>' +
         '</tr>' +
         '<tr height="100%">' +
         '<td width="100%"><center><img src="web/images/please_wait.gif" id="wait"/></center></td>' +
         '</tr>' +
         '</table>';
}

function displayPleaseWaitMsg(msg) {
  // bring user to top of page to see please wait icon and message.
  $("#content_main").fadeOut("slow");
  $("#branding").fadeTo("slow", 0.66);

  $("#please_wait_container").html(getPleaseWaitMessage(msg)).show();
  DistribMain.disableHeader(true);
}

// When form is submitted via javascript the on submit is not invoked the above code
// does not work so this function is to be put in the forms onsubmit and in the
// javascript the onsubmit should be invoked....
function invokePleaseWait() {
  if ($("#pleaseWaitSubmit").size()) {
    var msg = null;
    var pwm = $("#pleaseWaitMessage");
    if (pwm.size()) {
      msg = pwm.text();
    }
    displayPleaseWaitMsg(msg);
  }
  return true;
}
