﻿
window.isFireFox = (navigator.userAgent.indexOf("Firefox") != -1);

//below borrowed from http://forums.asp.net/p/1096908/2083284.aspx

var c = null;
    
///Disable any ajax control we click on at the beginning of the asyncpostback
function BeginRequestHandler(sender, args){
    c = args.get_postBackElement();
    if(c){
        c.disabled=true;
    }
}
///Reenable whatever we clicked on once the async postback is complete.
function EndRequestHandler(sender, args){
    if(c){
        c.disabled=false;
    }
}

function RegisterIntercepts(){
    if(typeof(Sys) != 'undefined' && typeof(Sys.WebForms) != 'undefined' && typeof(Sys.WebForms.PageRequestManager) != 'undefined' && Sys.WebForms.PageRequestManager.getInstance() != null){
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        if(window.isFireFox){     //don't blow up for stupid IE
            window.addEventListener('load',FFOnPageLoad,false);
            //this line is actually for the bottom snippet, but hey.
        }
    }
}
    
//end snippet

// Below taken from : http://blog.graffen.dk/2008/01/03/PageRequestManagerParserErrorExceptionPart2Hack.aspx

if(window.isFireFox)
{
    
    function FFOnPageLoad()
    {
             Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(FFOnBeginRequest);       
    }

    function FFOnBeginRequest(sender, args)
    {
            var delta = args.get_request().get_headers()['X-MicrosoftAjax'];    
            if(delta == 'Delta=true')    
            {
                var body = args.get_request().get_body() + 'X-MicrosoftAjax=' + encodeURIComponent('Delta=true');        
		        args.get_request().set_body(body);    
            }
     }
     
}
//end snippet

//setTimeout("RegisterIntercepts()", 10000);
$onLoad("RegisterIntercepts()");
//timeout is so that the intercepts are only registered once they have something to hold onto
//i.e. once the scriptmanager on the page is loaded. 300 ms is arbitrary, but seems plenty enough.

