﻿

var NUMBER_OF_REPETITIONS = 40;
var nRepetitions = 0;
var g_oTimer = null;

function startLongProcess()
{
   divProgressDialog.style.display = "";
   resizeModal();
   window.onresize = resizeModal;
   window.onbeforeunload = showWarning;
   continueLongProcess();
}

function updateProgress(nNewPercent)
{
   divProgressInner.style.width = (parseInt(divProgressOuter.style.width)* nNewPercent / 100)+ "px";
}

function stopLongProcess()
{
   if (g_oTimer != null)
   {
      // Clear the timer so we don't get called back an extra time
      window.clearTimeout(g_oTimer);
      g_oTimer = null;
   }

   // Hide the fake modal DIV
   divModal.style.width = "0px";
   divModal.style.height = "0px";
   divProgressDialog.style.display = "none";

   // Remove our event handlers
   window.onresize = null;
   window.onbeforeunload = null;

   nRepetitions = 0;
}

function continueLongProcess()
{
   if (nRepetitions < NUMBER_OF_REPETITIONS)
   {
      // Set the timeout somewhere between 0 and .25 seconds
      var nTimeoutLength = Math.random() * 100;
      updateProgress(100 * nRepetitions / NUMBER_OF_REPETITIONS);

      g_oTimer = window.setTimeout("continueLongProcess();", nTimeoutLength);
      nRepetitions++;
   }
   else
   {
   	 NUMBER_OF_REPETITIONS = 40;
	 nRepetitions = 0;
	 g_oTimer = null;
      startLongProcess();
   }
}

function showWarning()
{
   //Warn users before they refresh the page or navigate away
   return "Navigating to a different page or refreshing the window could cause you to lose precious data.\n\nAre you*absolutely* certain you want to do this?";
}

function resizeModal()
{
   // Resize the DIV which fakes the modality of the dialog DIV
   divModal.style.width = document.body.scrollWidth;
   divModal.style.height = document.body.scrollHeight;

   // Re-center the dialog DIV
   divProgressDialog.style.left =((document.body.offsetWidth - divProgressDialog.offsetWidth)/2);
   divProgressDialog.style.top=((document.body.offsetHeight - divProgressDialog.offsetHeight)/2);
}

document.write('<DIV STYLE="BORDER: buttonhighlight 2px outset; FONT-SIZE: 8pt; Z-INDEX: 4; FONT-FAMILY: Tahoma; POSITION: absolute; BACKGROUND-COLOR: buttonface; DISPLAY: none; WIDTH: 350px; CURSOR: default" ID="divProgressDialog" onselectstart="window.event.returnValue=false;">');
document.write('	<DIV STYLE="PADDING: 3px; FONT-WEIGHT: bolder; COLOR: captiontext; BORDER-BOTTOM: white 2px groove; BACKGROUND-COLOR: activecaption">'); 
document.write('      天脉网站管理系统政府版'); 
document.write('   </DIV>'); 
document.write('   <DIV STYLE="PADDING: 5px">系统正在处理你的操作，请稍后……</DIV>'); 
document.write('   <DIV STYLE="PADDING: 5px">这可能花费几分钟时间！</DIV>'); 
document.write('   <DIV STYLE="PADDING: 5px">'); 
document.write('         <DIV ID="divProgressOuter" STYLE="BORDER: 1px solid threedshadow; WIDTH: 336px; HEIGHT: 15px">'); 
document.write('            <DIV ID="divProgressInner" STYLE="COLOR: white; TEXT-ALIGN: center; BACKGROUND-COLOR: infobackground; MARGIN: 0px; WIDTH: 0px; HEIGHT: 13px;"></DIV>'); 
document.write('         </DIV>'); 
document.write('   </DIV>'); 
document.write('');
document.write('</DIV>'); 
document.write(''); 
document.write('<DIV ID="divModal"   STYLE="BACKGROUND-COLOR: white; FILTER: alpha(opacity=75); LEFT: 0px; POSITION: absolute; TOP: 0px; Z-INDEX: 3" onclick="window.event.cancelBubble=true; window.event.returnValue=false;"></DIV>'); 
