var thisSubmitIsBinaryWrite = false;
var busyBackgroundElement = null;
var busyBackgroundTimerId = null;

function ShowBusyBackground(backgroundImageUrl)
{
   var newBackgroundElement = document.createElement("DIV");
   newBackgroundElement.style.zIndex = 32767;
   newBackgroundElement.style.position = "absolute";         
   newBackgroundElement.style.cursor = "wait";
   newBackgroundElement.style.width = "100%";
   newBackgroundElement.style.backgroundImage = "url(" + backgroundImageUrl + ")";
   newBackgroundElement.style.top = "0px";
   newBackgroundElement.style.left = "0px";
   if(typeof(document.all) != "undefined")
   {
      // IE browser
      newBackgroundElement.style.height = ((document.body.clientHeight > window.screen.height) ? document.body.clientHeight : window.screen.height) + "px";
   }
   else
   {
      // DOM browser
      newBackgroundElement.style.height = ((document.height > window.screen.height) ? document.height : window.screen.height) + "px";
   }
   document.body.insertBefore(newBackgroundElement, document.body.firstChild);
   busyBackgroundElement = newBackgroundElement;
   
   if(thisSubmitIsBinaryWrite)
   {
      thisSubmitIsBinaryWrite = false;
      // set an interval to check for the binary write being complete
      // (so we can hide the busy background when it's done)
      busyBackgroundTimerId = setInterval("ClearBusyBackgroundIfDoneLoading()", 500);
   }
}

function ClearBusyBackgroundIfDoneLoading()
{
   if(busyBackgroundElement != null)
   {
      // NOTE: document.readyState only works in IE, so other browsers we'll just hide the busy background
      // immediately, instead of waiting for document.readyState to be complete...
      if(typeof(document.readyState) == "undefined" || document.readyState == "complete" || document.readyState == 4)
      {
         busyBackgroundElement.style.display = "none";
         if(busyBackgroundTimerId != null)
         {
            clearInterval(busyBackgroundTimerId);
         }
      }
   }
}