// Common function to open a please wait info dialog. To use this on an individual page you must 
// include this .js file and also include the prototype.js file.
// Call the initPleaseWait() function somewhere in your page, e.g. <script>initPleaseWait();</script>
// Call the openPleaseWait() function in your event handler just prior to submitting the page, this will
// typically be done in the form's onsubmit handlere.g. onsubmit="return doValidation() && openPleaseWait();"
var pleaseWaitHtml;

// Forces preload of the please wait/loading content and it's images. server is the server part of the url
// to the loading.html.  For example http://www.suncountry.com.  If this is for a travel agent page,
// pass in isTravelAgent as true.  purchaserEmail is optional and if supplied will cause the extra 
// "may take some time" purchase text to be displayed with the purchaser's email address.
function initPleaseWait(protocol, host, isTravelAgent, purchaserEmail) {

  server = protocol+host;
  var url;
  if (isTravelAgent) url = server+'/resources/loadingMsg_ta.html';
  else url = server+'/resources/loadingMsg.html';
  if (purchaserEmail!=null) url = url + '?showMsg='+purchaserEmail;
  pleaseWaitHtml = "<iframe id='please_wait_iframe' frameborder='0' scrolling='no' src='"+url+"' width='0' height='0' />";
  $('please_wait_div').innerHTML=pleaseWaitHtml;
  $('please_wait_div').style.visibility = 'visible';
}

// The function that the page has to call to display the please wait content, assuming the div `please_wait_div`
// exists in the doc. Assumes the main content to be hidden is in 'body_div'.
function openPleaseWait(message) {
  $('body_div').style.display = 'none';
  $('please_wait_div').style.left = '0px';
  $('please_wait_div').style.top = '0px';
  var width=1000;
  var height=600;
  if (document.body.offsetWidth&&document.body.offsetWidth>width) {
    width=document.body.offsetWidth;
  }
  if (document.body.offsetHeight&&document.body.offsetHeight>height) {
    height=document.body.offsetHeight;
  }
  $('please_wait_iframe').width=width;
  $('please_wait_iframe').height=height;
  // IE does not animate the image unless we "touch" the image a little later (200 is milliseconds)
  // As contentWindow is not W3C DOM check for it
  if ( document.getElementById("please_wait_iframe").contentWindow ) {
    if (message!=null) {
        try {
              document.getElementById("please_wait_iframe").contentWindow.document.getElementById('loadingMessage').innerHTML=message;
        } catch (err) {}
    }
    setTimeout('try{document.getElementById("please_wait_iframe").contentWindow.document.images["img_loading"].src="/images/Loading_ani.gif"}catch(err){}', 200);
  }
  return true;
}
