﻿// see http://www.gotapi.com/prototypejs

/*This function is used on Ajax functions to handle errors for onFailure and onXYZ
Currently all application exceptions are handled by the global exception handler (in global.asx)
The 550 error is an OLC custom error status to describe a session timeout.  There is code in the 
controlhandler.aspx.cs that checks to see if the session has expired, and if so sets the response
statusCode to 550. 
*/

function onErrorHandler(transport)
{
    switch (transport.status)
    {
            case 500: 
                //This case will never get hit because the 500 exceptions will
                //be handled by the global exception handler, which then redirects the
                //page to a global error back.  So the request is never failed.
                break;
            case 550: 
                document.location = AjaxLinkBuilder.getLoginUrl();
                break
     }
}

// Handle 550 error system wide for all ajax requests.
function ajaxLogoutHandler() {
    // Make sure prototype has been loaded.
    if (null == Ajax) {
        window.setTimeout("ajaxLogoutHandler()", 100);
    }
    else {
        Ajax.Responders.register({
	        onCreate: function(request, transport, json) {
		        request.options.on550 = function() {
			        document.location= AjaxLinkBuilder.getLoginUrl();
		        }
        		
	        }
        });
    }
}
ajaxLogoutHandler();
