﻿
var prm = Sys.WebForms.PageRequestManager.getInstance();
var theCtrlToSetFocus = null;

prm.add_pageLoaded(setFocus);
//prm.add_beginRequest(onBeginRequest);
//prm.add_endRequest(onEndRequest);

//function onBeginRequest(sender, args)
//{
//    showProgressBarAndMask();
//}

//function onEndRequest(sender, args)
//{
//    hideProgressBarAndMask();
//}

function setFocus(sender, args)
{
	if (theCtrlToSetFocus != null && theCtrlToSetFocus.focus) 
	{
		
		theCtrlToSetFocus.focus();
		
		window.setTimeout(function () 
							{
								theCtrlToSetFocus.focus();
								theCtrlToSetFocus = null;
							}, 250);
		
	}
}

//function showProgressBarAndMask()
//{

//    var mask = $get("matte_layer");
//    var progressBar = $get("progress_bar");
//    var main = $get("bodyContent");

//    if (main == null)
//        main = $get("bodyContentApp");

//    if (mask != null && progressBar != null && main != null) {

//        var mainBounds = Sys.UI.DomElement.getBounds(main);

//        if (Sys.Debug.isDebug) Sys.Debug.trace(String.format("main div: W:{0} H:{1} X:{2} Y:{3}", mainBounds.width, mainBounds.height, mainBounds.x, mainBounds.y));


//        mask.style.width = String.format("{0}px", mainBounds.width);
//        mask.style.height = String.format("{0}px", mainBounds.height);

//        mask.style.display = "block";
//        progressBar.style.display = "block";

//        var pbBounds = Sys.UI.DomElement.getBounds(progressBar);

//        if (Sys.Debug.isDebug) Sys.Debug.trace(String.format("pb div: W:{0} H:{1} X:{2} Y:{3}", pbBounds.width, pbBounds.height, pbBounds.x, pbBounds.y));

//        Sys.UI.DomElement.setLocation(mask, mainBounds.x, mainBounds.y);
//        Sys.UI.DomElement.setLocation(progressBar, parseInt(mainBounds.x + (mainBounds.width - pbBounds.width) / 2), parseInt(mainBounds.y + (mainBounds.height - pbBounds.height) / 2));

//        if (Sys.Debug.isDebug) {
//            pbBounds = Sys.UI.DomElement.getBounds(progressBar);
//            Sys.Debug.trace(String.format("pb div: W:{0} H:{1} X:{2} Y:{3}", pbBounds.width, pbBounds.height, pbBounds.x, pbBounds.y));
//        }
//    }
//}


//function hideProgressBarAndMask()
//{
//    var mask = $get("matte_layer");
//	var progressBar = $get("progress_bar");

//	if (mask != null && progressBar != null) {
//	    mask.style.display = "none";
//	    progressBar.style.display = "none";
//	}
//}

/*
$addHandler(window, "resize", function ()
								{
									if (prm.get_isInAsyncPostBack()) showProgressBarAndMask();
								});
*/
