﻿var ErrorHandler = {
    m_strSYSTEM_ERROR: 'Error: please again try later!  If this error continues to occur, please contact customer service with the following information:',

    HandleAjaxError: function (objAjax, objXMLHttpRequest, strTextStatus) {
        if (objXMLHttpRequest.status == 0) return; // Do nothing if the error happens because the user aborted the page loading.

        var strAjaxError = 'SourceURL=' + location.pathname + ',\nTargetURL=' + objAjax.url + ',\nData=' + objAjax.data + ',\nHttpStatus=' + objXMLHttpRequest.status + ',\nResponseText = ' + objXMLHttpRequest.responseText + ',\TextStatus = ' + strTextStatus;
        if (window.location.hostname.substring(0, 3) == "dev") {
            if (typeof (BeanFunBlock) != "undefined" && typeof (BeanFunBlock.ShowMsgBox) == "function") {
                BeanFunBlock.ShowMsgBox(ErrorHandler.m_strSYSTEM_ERROR + '\n\n______________________\n\n' + strAjaxError);
            } else {
                alert(ErrorHandler.m_strSYSTEM_ERROR + '\n\n______________________\n\n' + strAjaxError);
            }
        }
        var strData = 'meth=LogAjaxError&ae=' + encodeURIComponent(strAjaxError);
        $.ajax({
            cache: false,
            data: strData,
            dataType: 'json',
            error: function (objXMLHttpRequest, strTextStatus) {
            },
            success: function (strReturnedData, strTextStatus) {
            },
            type: 'POST',
            url: location.protocol + '//' + location.host + '/generic_handlers/error_handler.ashx'
        });
    }
}
