﻿Sys.Application.add_init(App_Init);

function App_Init()
{
  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
  //Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
}

function BeginRequest(sender, args)
{
  // Find the ID of the UpdatePanel raising the partial postback.
  var sendingPanelID = sender._updatePanelClientIDs[0];  
  
  if(sendingPanelID){
	  // Using that ID, get a reference to that UpdatePanel's div.
	  var sendingPanel = document.getElementById(sendingPanelID);
	  // Get an array of all the input elements in that div.
	  var inputs = sendingPanel.getElementsByTagName('input');
	  
	  // Loop through the elements and check each one's type.
	  //  if it's a submit type element, disable it.
	  for (element in inputs)
	  try{
		 if ((inputs[element].type == 'submit') || (inputs[element].type == 'checkbox'))
		 {
			inputs[element].disabled = true;
			inputs[element].blur();
		 }
		}catch(e){}
		
	}
}

function EndRequest(sender, args)
{
  // Find the ID of the UpdatePanel raising the partial postback.
  var sendingPanelID = sender._updatePanelClientIDs[0];  
  
  if(sendingPanelID){
		 // Using that ID, get a reference to that UpdatePanel's div.
	  var sendingPanel = document.getElementById(sendingPanelID);
	  
	  // Get an array of all the input elements in that div.
	  var inputs = sendingPanel.getElementsByTagName('input');
	 
	  // Loop through the elements and check each one's type.
	  //  if it's a submit type element, disable it.  
	  for (element in inputs)
	  try{
		 if (inputs[element].type && ((inputs[element].type == 'submit') || (inputs[element].type == 'checkbox')))
			inputs[element].disabled = false;
		}catch(e){}
	}
}

function UpdateCheckedVisibility(chk, div)
{
	$get(div).style.display = chk.checked ? 'block' : 'none';
}

function UpdateCheckedHidden(chk, div)
{
    $get(div).style.display = chk.checked ? 'none' : 'block';
}

function ToggleImages(imageButton)
{
	if(imageButton.AlternateImageUrl == null)
	{
		imageButton.AlternateImageUrl = imageButton.attributes["AlternateImageUrl"].nodeValue;
	}
	
	var swap = imageButton.AlternateImageUrl;
	
	imageButton.AlternateImageUrl = imageButton.src;
	imageButton.src = swap;
	
	return false;
}

function PositionHelp(helpButton)
{
	Cover(helpButton, helpButton.nextSibling);
}

// Move an element directly on top of another element
function Cover(bottom, top) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
}

