﻿// Using ModalPopupExtender with UpdateProgress - http://mattberseth.com/blog/2007/07/modalpopup_as_an_ajax_progress.html

//  register for our events
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);    

function beginRequest(sender, args)
{
	var mdlPopup = $find('mdlPopup');
	if (mdlPopup != null)
	{
		mdlPopup.show();
	}
}

function endRequest(sender, args) 
{
	var mdlPopup = $find('mdlPopup');
	if (mdlPopup != null)
	{
		mdlPopup.hide();
	}			
}

// Using ESC key with ModalPopupExtender - http://mattberseth.com/blog/2007/08/how_to_dismiss_a_modalpopup_us.html
function pageLoad(sender, args)
{
	if(!args.get_isPartialLoad())
	{
		//  add our handler to the document's
		//  keydown event
		$addHandler(document, "keydown", onKeyDown);
	}
}

function onKeyDown(e)
{
	if (e != null)
	{
		if (e.keyCode == Sys.UI.Key.esc)
		{
			// if the key pressed is the escape key, dismiss the dialog
			var mdlPopup = $find('mdlPopup');
			if (mdlPopup != null)
			{
				mdlPopup.hide();
			}
		}
	}
} 