﻿/// <reference name="MicrosoftAjax.js"/>
var prm = Sys.WebForms.PageRequestManager.getInstance();


Sys.Application.add_init(App_Init);
prm.add_initializeRequest(InitializeRequest);

function InitializeRequest(sender, args) {
  if (prm.get_isInAsyncPostBack())
   {
      args.set_cancel(true);
   }
}

function App_Init()
{
  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
}


function AbortPostBack() 
{
 var prm = Sys.WebForms.PageRequestManager.getInstance();
   if (prm.get_isInAsyncPostBack()) {
          prm.abortPostBack();
    } 
}

function BeginRequest(sender, args)
{
/*
	all wrong...dipstick of the forum...should have replied to him
	...disable the form..so all type of input are disabled.
  // Find the ID of the UpdatePanel raising the partial postback.
  var sendingPanelID = sender._postBackSettings.panelID.split("|")[0];
  
  // 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 == 'submit')
    {
      inputs[element].disabled = true;
      inputs[element].blur();
    }
    }
    */
   // Work around browser behavior of "auto-submitting" simple forms
   var frm = document.getElementById("aspnetForm");
     if (frm) {             
             frm.onsubmit = function() { return false; };
    }

    document.body.style.cursor = 'wait';


    // popuponclick();
    // window.open('../../underConstruction.aspx');


    var ppnl = document.getElementById("ProgressUpdateId");
    // if (prm.get_isInAsyncPostBack()) {
        if (ppnl) {
            document.getElementById("ProgressUpdateId").style.display = 'block'
        }
    // Nifty("div#ProgressUpdateId","big");     
    // }
}

function EndRequest(sender, args)
{
/*
  // Find the ID of the UpdatePanel raising the partial postback.
  var sendingPanelID = sender._postBackSettings.panelID.split("|")[0];
  
  // 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 == 'submit')
      inputs[element].disabled = false;
 */
  // var making double sure.     
  var frm = document.getElementById("aspnetForm");
  if (frm) {
             frm.onsubmit = function() { return true; };
  }
  
  document.body.style.cursor='auto';
  
  
  // closepopup();
   
 //   if (prm.get_isInAsyncPostBack()) {
  var ppnl = document.getElementById("ProgressUpdateId");
    if (ppnl) {
        document.getElementById("ProgressUpdateId").style.display = 'none'
    }
   // }
 
}

function popuponclick() {
    my_window = window.open("", "mywindow", "'height=1,width=1,status=yes,toolbar=no,menubar=no,location=no;visible=no'");
    my_window.document.write('<H1>The Popup Window</H1>');
}

function closepopup() {
    if (false == my_window.closed) {
        my_window.close();
    }
    else {
        alert('Window already closed!');
    }
}



// added here to make it available everywhere
function FindControl(parentControl, strId)
        {
            var returnObject;
            for(i=0;i < parentControl.elements.length; i++)
            {
                if(parentControl.elements[i].id.indexOf(strId) >= 0)
                    returnObject = parentControl.elements[i];
                else if(parentControl.elements[i].hasChildNodes())
                    returnObject = FindControl(parentControl.elements[i],strId);
                
                if(returnObject != null) 
                {   //if object is found return
                    return returnObject;
                }
            }
            return returnObject;
}


