﻿var bPleaseWaitAllowed = true;
function PleaseWait(bAuto){
	if(bPleaseWaitAllowed){
		var bShow = true;
		
		if(!bAuto){
			if (typeof(Page_ClientValidate) == 'function') {
				bShow = true;
				try{
					bShow = ValidatorOnSubmit();//Page_ClientValidate();
				}catch(e){}
			}
		}
		if(bShow){
			PleaseWait_Show();
			
			//Set the time out to clear the screen
			window.setTimeout("PleaseWait_Hide();", 30000);
		}
	}
}

function PleaseWait_Hide(){
	var tblPleaseWait = document.getElementById('tblPleaseWait');
	if(tblPleaseWait != null){
		tblPleaseWait.style.visibility = "hidden";
		var coordsPleaseWait = new Coordinates(tblPleaseWait);
		coordsPleaseWait.showOverLappedDropDowns()
	}			
	
	HideBlocker();
	
	window.status = "Done.";
}

function PleaseWait_Show(){

	var tblPleaseWait = document.getElementById('tblPleaseWait');
	
	if(tblPleaseWait != null){
		// Setup the please wait sign	
		var iTotalWidth = document.body.clientWidth; //window.screen.availWidth;
		var iTotalHeight = document.body.clientHeight; //window.screen.availHeight;
			
		// Determine the halfway points(center)
		var iHalfWidth=iTotalWidth/2;
		var iHalfHeight=iTotalHeight/2;
		
		// Determine top and left positions of the Please wait box
		var iLeftPos = iHalfWidth-(tblPleaseWait.width/2);
		var iTopPos = iHalfHeight-(tblPleaseWait.height/2)
		
		tblPleaseWait.style.posLeft = iLeftPos;
		tblPleaseWait.style.posTop = iTopPos;
		
		// Hide the overlapped dropdowns
		var coordsPleaseWait = new Coordinates(tblPleaseWait);
		coordsPleaseWait.hideOverLappedDropDowns();
		tblPleaseWait.style.visibility = "visible";
		tblPleaseWait.style.zindex = 2200;
		
		this.ShowBlocker();
	}
	
	window.status = "Please wait while the page loads.....";
}

function ShowBlocker(){
	//Let's create a div to block all screen input
	var oDivBlocker = document.getElementById('dvBlocker');
	if(oDivBlocker == null){
		iHeight = document.body.scrollHeight+20;
		oDivBlocker = document.createElement("<DIV id=dvBlocker style='margin:0px;Z-INDEX: 2100; WIDTH: " + document.body.scrollWidth + "px; POSITION: absolute; LEFT:0px; TOP: 0px; HEIGHT: " + iHeight + "px;'></DIV>");
	}
	
	oDivBlocker.style.visibility = "visible";
	oDivBlocker.style.backgroundColor = "#000000";
	oDivBlocker.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=25)";
	document.body.insertBefore(oDivBlocker);
	var coordsBlocker = new Coordinates(oDivBlocker);
	coordsBlocker.hideOverLappedDropDowns();
}

function HideBlocker(){
	var oDivBlocker = document.getElementById('dvBlocker');
	if(oDivBlocker != null){
		oDivBlocker.style.visibility = "hidden";
		var coordsBlocker = new Coordinates(oDivBlocker);
		coordsBlocker.showOverLappedDropDowns();
	}
}