﻿var _main;
var _updateProgress;
var _updateProgressBackground;

$(document).ready(function () {
	// **************************************************
	//alert('Page Load ()!');
	// **************************************************

	// **************************************************
	// Register for our events
	var oPageRequestManager =
		Sys.WebForms.PageRequestManager.getInstance();

	oPageRequestManager.add_endRequest(endRequest);
	oPageRequestManager.add_beginRequest(beginRequest);
	// **************************************************

	// **************************************************
	// Get the DTMain
	_main = $get('divMain');
	// **************************************************

	// **************************************************
	// Get the UpdateProgress
	_updateProgress = $get('UpdateProgress');
	// **************************************************

	// **************************************************
	// Get the UpdateProgressBackground
	_updateProgressBackground = $get('UpdateProgressBackground');
	// **************************************************

	// **************************************************
	// Make them invisible
	_updateProgress.style.display = 'none';
	_updateProgressBackground.style.display = 'none';
	// **************************************************

	// **************************************************
	var oToolTip = $("<div id='myToolTip'>");
	$("body").append(oToolTip);
	// **************************************************

	// **************************************************
	SetToolTip();
	SetTableRows();
	// **************************************************
});

function beginRequest(sender, args) {
	// **************************************************
	//alert('Begin Request!');
	// **************************************************

	// **************************************************
	// Make them visible
	_updateProgress.style.display = '';
	_updateProgressBackground.style.display = '';
	// **************************************************

	// **************************************************
	// Get the bounds of both the main and the progress div
	var MainBounds = Sys.UI.DomElement.getBounds(_main);
	var UpdateProgressBounds = Sys.UI.DomElement.getBounds(_updateProgress);
	// **************************************************

	// **************************************************
	// Get center of the main
	var x = MainBounds.x +
			Math.round(MainBounds.width / 2) -
			Math.round(UpdateProgressBounds.width / 2);

	var y = MainBounds.y +
			Math.round(MainBounds.height / 2) -
			Math.round(UpdateProgressBounds.height / 2);
	// **************************************************

	// **************************************************
	// Set the dimensions of the background div to the same as the main
	_updateProgressBackground.style.width = MainBounds.width + 'px';
	_updateProgressBackground.style.height = MainBounds.height + 'px';
	// **************************************************

	// **************************************************
	// Set the progress element to this position
	Sys.UI.DomElement.setLocation(_updateProgress, x, y);
	// **************************************************

	// **************************************************
	// Place the div over the main
	Sys.UI.DomElement.setLocation(_updateProgressBackground, MainBounds.x, MainBounds.y);
	// **************************************************
}

function endRequest(sender, args) {
	// **************************************************
	// Make them invisible
	_updateProgress.style.display = 'none';
	_updateProgressBackground.style.display = 'none';
	// **************************************************

	// **************************************************
	SetToolTip();
	SetTableRows();
	// **************************************************

	// **************************************************
	//alert('End Request!');
	// **************************************************
}

