// Ajax exception handler
Ext.Ajax.on('requestexception', function(conn, response) {		
    if (response.status == 408) { // Expired
        Sight.util.showError('Your session has expired;...','Invalid Session');
    } else if (response.status == 403) {
        Sight.util.showError('The server has received the request, but refused to handle it','Invalid Request');
    } else if (response.status == 404) {
        Sight.util.showError('Page not found','Invalid Request');
    } else {
        Sight.util.showError("Contact your administrator: " +
            "Status: " + response.status + ", Message: " + response.statusText, 'Error');
    }
});
Ext.Ajax.on('loadexception', function (proxy, options, response, error) {
    if (response.status == 408) { // Expired
        Sight.util.showError('Your session has expired;...','Invalid Session');
    } else {
        var object = Ext.util.JSON.decode(response.responseText);
        var errorMessage = "Error while loading data";
        if (object.success) {
            errorMessage = "Invalid data format. " +
            "Contact your administrator: " + response.responseText;
        } else {
           for (var i=0;i<object.errors.length; i++ ){
                errorMessage+="<br/>"+object.errors[i];
            }
            errorMessage+="<br/>"+object.message;
        }
        Sight.util.showError(errorMessage, 'Error');
    }
});
