// JScript File

Sys.Application.add_init(Initialize);
var prm = null;
var originControl;

function Initialize(sender)
{                      
    if(typeof(Sys.WebForms) !== "undefined")            
    {       
        prm = Sys.WebForms.PageRequestManager.getInstance();    
        if (prm)
        {
            prm.add_initializeRequest(InitRequestHandler);                                                                
            prm.add_beginRequest(BeginRequestHandler);    
            prm.add_endRequest(EndRequestHandler);                                    
        }
    }
}

function InitRequestHandler(sender, eventArgs)
{              
   originControl = eventArgs.get_postBackElement().id;
                                                               
   if (prm.get_isInAsyncPostBack())
   {
        alert('A request is currently being processed. Please wait...');
        eventArgs.set_cancel(true);
   }
   else           
   if (originControl == 'btnFind' || originControl == 'btnShow')
   {               
        if (!validate())
        {                                    
            eventArgs.set_cancel(true);            
        }                                      
   }          
}

function BeginRequestHandler(sender, eventArgs)
{           
   setHourglass('wait');   
   document.body.style.cursor = 'wait';
     
   // We hide the entire div to avoid showing the Grid's scrollbars
   if (originControl == 'btnFind' || originControl == 'btnShow')
   {  
      hideDiv('divGrid');
      showDiv('divProgress');
      
      document.getElementById('lblMgsBtm').innerHTML = '';
      document.getElementById('lblInstructions').innerHTML = '';
      
   }   
}

function EndRequestHandler(sender, eventArgs)
{      
   // re-enable date picker after the request   
   hideDiv('divProgress'); 

   if (eventArgs.get_error() != undefined)           
   {
       var errorMessage = eventArgs.get_error().message;
       eventArgs.set_errorHandled(true);
              
       hideDiv('divGrid');
       document.getElementById('lblMgsBtm').innerHTML = 'We are unable to display Court Proceedings at this time.';       
       
       alert('We are unable to display Court Proceedings at this time.\n\nAn error occured with the following information:\n\n' + errorMessage);
   } 
   else      
   {         
       myString = new String(originControl);
                                                           
       if (originControl == 'btnFind' || originControl == 'btnShow' || myString.indexOf('gridNames') >= 0)
       {                                                           
           // Re-displaying the GridView is handled on the server side
           FreezeGridViewHeader('gridNames','WrapperDiv');                                 

           if (originControl == 'btnFind')
           {
               $get('lname').focus();
               $get('lname').click();            
           } 
           else
           if (originControl == 'btnShow')
           {
               $get('TextBox1').focus();
               $get('TextBox1').click();            
           } 
                      
           // If the origin control is the gridNames (sort) the user sorted the columns
           // therefore we set the scrollTop property of the div to 0
           if (originControl == "gridNames")
           {                       
               $get("divWrap").scrollTop = 0;
           }
           else           
           if (myString.indexOf('gridNames') >= 0)
           { 
               // If the origin control is one of the links that opens the case detail
               // window then we set the scrollTop property of the div to the stored value in
               // the hidden input field
               $get("divWrap").scrollTop = $get("hiddenInput").value;
           }           
       }    
      
   }                
   setHourglass('');      
}        


if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded(); 
