﻿/// <reference name="MicrosoftAjax.js"/>
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._postBackSettings.panelID.split("|")[0];
  sendingPanelID = sendingPanelID.replace("$", "_");
  // 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)
      if (inputs[element].type == 'image') {
          inputs[element].src = 'images/search_wait.png';
          inputs[element].disabled = true;
          
      }
}
//  for (element in inputs)

//      if (inputs[element].type == 'submit') {
//          inputs[element].disabled = true;
//          inputs[element].blur();
//      } else if (inputs[element].type == 'text') {
//          inputs[element].readonly = true;
//          inputs[element].blur();
//      } else {
//         inputs[element].disabled = true;
//      }

// }

function EndRequest(sender, args)
{
  // Find the ID of the UpdatePanel raising the partial postback.
  var sendingPanelID = sender._postBackSettings.panelID.split("|")[0];
  sendingPanelID = sendingPanelID.replace("$", "_");
  // 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, enable it.  
  for (element in inputs)
      if (inputs[element].type == 'submit')
          inputs[element].disabled = false;
}
