function initEventHandlers()
{
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
}

function asyncBeginRequest(obj) {
    display = obj.style.display;
    obj.style.display = 'none';
    postBackElement = obj;
}

// variable to store the element that caused a Async postback
var postBackElement = null;
var display = '';

// Function to handle the PageLoaded event of the ASP.NET AJAX Async request 
// The element that caused the Async postback is made visible again.
function PageLoaded(sender, args)
{ 
    if(postBackElement != null)
    {
        postBackElement.style.display = display;
    }
}

// Function to handle the EndRequest event of the ASP.NET AJAX Async request that adds item to basket.
// The basket is initialized and opened. It is closed after 3 seconds.
// This event is registered in DetailPage.aspx. 
function EndRequest(sender, args)
{ 
    if(postBackElement != null) {
        basketEndRequest();
        postBackElement = null;
    }
}