// The following line contains the delay (in milliseconds) before the "Please wait ..." message appears.
var MnPleaseWaitDelay = 300;

function getStyleSheetIndex(strBackGroundStyle)
{
	var astrRules;

	// If the browser supports the W3C DOM way, use cssRules.
	if (document.styleSheets[0].cssRules) {
		astrRules = document.styleSheets[0].cssRules;
	}
	// If it supports the Microsoft way, use rules.
	else if (document.styleSheets[0].rules) {
		astrRules = document.styleSheets[0].rules
	}
	for (var i = 0; i < astrRules.length; i++) {
		if (astrRules[i].selectorText == strBackGroundStyle) {
			return i;
		}
	}

	return false;
}

function getBGroundColor(strBackGroundStyle)
{
	var bkgColor;
	var bkgColorIndex = getStyleSheetIndex(strBackGroundStyle);

   if (bkgColorIndex != -1) {
	   // If the browser supports the W3C DOM way, use cssRules.
	   if (document.styleSheets[0].cssRules) {
		   bkgColor = document.styleSheets[0].cssRules[bkgColorIndex].style.backgroundColor;
	   }
	   // If it supports the Microsoft way, use rules.
	   else if (document.styleSheets[0].rules) {
		   bkgColor = document.styleSheets[0].rules[bkgColorIndex].style.backgroundColor;
	   }
	}

	return bkgColor;
}

function resizeCover()
{
	var cover = document.getElementById("cover");
	var clHeaderArea = document.getElementById("HeaderArea");
	var nOffSetTop = 40;
		
	if (clHeaderArea != null) nOffSetTop += clHeaderArea.offsetHeight;
	
   cover.style.top = nOffSetTop;
   if (G_dIEVersion) {
	   cover.style.left = Math.max(document.body.clientWidth/2 - 50, 0);
   }
   else {
	   cover.style.left = Math.max(window.innerWidth/2 - 50, 0);
   }  
}

// ---------------------------------------------------------------------------- 
// This routine displays a "please wait" message to the end user.
// ----------------------------------------------------------------------------  
function pleaseWait()
{
	var cover = document.getElementById("cover");
	var sTxt;

   hideObjectElements();
	cover.style.zIndex=100;	
	sTxt = "<TABLE class='PleaseWaitTable' >";
	sTxt +=	"<TR><TD>" + resPleaseWait + "</TD></TR>";
	sTxt += "</TABLE>";
	
	cover.innerHTML = sTxt;
	cover.style.visibility = "visible";
	document.aspnetForm.TimerId.value = 0;
	resizeCover();
}

// ----------------------------------------------------------------------------    
function executeWait(object)
{
   zeroScrollPosition();
   OnCancelOptions();
	if (document.aspnetForm.TimerId.value != 0) {
		clearTimeout(document.aspnetForm.TimerId.value);
		document.aspnetForm.TimerId.value = 0;
	}
	document.aspnetForm.TimerId.value = setTimeout("pleaseWait();", MnPleaseWaitDelay);
   document.aspnetForm.ReloadForm.value = true;
   M_bFormSubmitted = true;
	object.submit();
}
