﻿if (!Poseidon.Exception) {
    Poseidon.Exception = {};
}

Poseidon.Exception.AjaxExceptionHandler = function (response, callback, scope) {
    var title = "Fejlmeddelelse";

    // Differentiate between special exceptions.
    switch (response.ExceptionType) {
        case "SessionLostException":
            callback = function () {
                var currentDate = new Date();
                var currentURL = document.URL;
                var domainEndPosition = -1;
                if (currentURL.indexOf('//')) {
                    currentURL = currentURL.substring(currentURL.indexOf('//') + 2, currentURL.length);
                }
                if (currentURL.indexOf('/')) {
                    currentURL = currentURL.substring(currentURL.indexOf('/'), currentURL.length);
                }

                window.parent.location = '/Login/login.aspx?url=' + currentURL +
                                         '&time=' + currentDate.getDay() + "-" + currentDate.getMonth() + "-" + currentDate.getYear() +
                                         " " + currentDate.getHours() + "-" + currentDate.getMinutes() + "-" + currentDate.getSeconds();
            }
            break;
        default:
            break;
    }

    Ext.MessageBox.show({
        title: title,
        msg: response.Message,
        buttons: Ext.MessageBox.OK,
        fn: callback || null,
        scope: scope || this,
        icon: Ext.MessageBox.ERROR
    });    
}
