﻿var manualShowUpdateProgressElementName;
var manualShowUpdateProgressDelay = 1000; //default

function ShowUpdateProgress()
{
  var element = document.getElementById(manualShowUpdateProgressElementName);
  if (element != null)
  {
    element.style.display = 'block'    
  }
}

function ShowUpdateProgressOnAsyncTrigger(sender, args)
{
  var splitPanelTriggersItem;
  var hideOthers = true;
  var other;
  var updatePanel;
  var updatePanelDivs;
  
	// see if the postback triggering control is in our array of updateprogress control + triggering controls array:
	for (i in panelTriggers)
	{
	  splitPanelTriggersItem = panelTriggers[i].split(',');
	  
		// note that this line doesn't care about the updateprogress thing in first CSV position
	  if (universalIndexOf(splitPanelTriggersItem, args.get_postBackElement().id, 0) > 0)
	  {
	    manualShowUpdateProgressElementName = splitPanelTriggersItem[0];
	    setTimeout('ShowUpdateProgress()', manualShowUpdateProgressDelay);
	  }
	  else
	  {
	    try
	    {
	      if (overrideHideOthers) // effectively also tests for existence because of try/catch
	      {
	        hideOthers = overrideHideOthers;
	      }
	    }
	    catch(ex) {}

	    if (hideOthers)
	    {			     
	      other = $find(splitPanelTriggersItem[0]);
	      
	      // may not be output to the browser i.e. server-side visible=false (or container similarly set)
	      if (other != null)
	      {
	        updatePanel = other.get_element();
	        // we're hiding the contained element, then showing it on endRequest (not the actual panel element - we're leaving that to RequestManager
          updatePanelDivs = other.get_element().getElementsByTagName('div');
          if (updatePanelDivs.length > 0)
          {
            updatePanelDivs[0].style.display = 'none';
          }
	      }
	    }
	  }
	}
}

function RestoreUpdateProgressesAfterAsyncTrigger(sender, args)
{
  var item;
  var splitPanelTriggersItem;
  var updatePanel;
  var updatePanelDivs;
  var containerElement;

  // ensure setTimeout call does not show panel
  manualShowUpdateProgressElementName = '';
  
	// see if the postback triggering control is in our array of updateprogress control + triggering controls array:
	for (i in panelTriggers)
	{
	  item = panelTriggers[i];
	  splitPanelTriggersItem = item.split(',');
	  
    other = $find(splitPanelTriggersItem[0]);
    // may not be output to the browser i.e. server-side visible=false (or container similarly set)
    if (other != null)
    {
      updatePanelDivs = other.get_element().getElementsByTagName('div');
      if (updatePanelDivs.length > 0)
      {
        manualShowUpdateProgressElementName = '';
        updatePanelDivs[0].style.display = 'block';
      }
    }
	}
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();