
var objFilesFmErrorHandler = new FilesFmErrorHandler ();

function FilesFmErrorHandler ()
{

    var strLogToken = '98420277d91a6fd61cab95512dcff526';
    var strLogUrl = 'https://files.fm/post_log?token=' + strLogToken;
    
    var intStackNum = 0;
    var objRecentAutoLogs = {};
    var bolCloudflareChallengeDetected = false;
    
    
    function init()
    {
        var fnRuntimeErrorHandler = function ( message_in, filename_in, linenum_in, colnum_in, error_in )
        {
            if ( intStackNum > 1 )
            {
                return false;
            }

            if ( isIgnorableScriptUrl( filename_in ) )
            {
                return false;
            }

            intStackNum++;

            var objError = buildErrorObject( message_in, filename_in, linenum_in, colnum_in, error_in );

            sendAutoLogEntry( { 'Type': 'JS-Runtime-Error', 'Data': objError } );

            intStackNum--;
            return true;         };

        if ( window.addEventListener )
        {
            window.addEventListener( 'error', function ( event )
            {
                if ( event && event.target && event.target !== window && ( event.target.src || event.target.href ) )
                {
                    if ( isThirdPartyNoiseUrl( event.target.src || event.target.href || '' ) )
                    {
                        return;
                    }

                    sendAutoLogEntry( {
                        'Type': 'JS-Resource-Error',
                        'Data': {
                            'message': 'Resource failed to load',
                            'tag': event.target.tagName || null,
                            'url': event.target.src || event.target.href || null,
                            'line': null,
                            'col': null
                        }
                    } );
                    return;
                }

                if ( event && typeof event.message !== 'undefined' )
                {
                    fnRuntimeErrorHandler( event.message, event.filename, event.lineno, event.colno, event.error );
                }
            }, true );
        }
        else
        {
            window.onerror = fnRuntimeErrorHandler;
        }

        if ( window.addEventListener )
        {
            window.addEventListener( 'unhandledrejection', function ( event )
            {
                if ( intStackNum > 1 )
                {
                    return;
                }

                intStackNum++;

                var objReason = event.reason;
                var strMessage = 'Unhandled promise rejection';
                var strStack = null;
                var strName = 'UnhandledRejection';

                if ( objReason && typeof objReason === 'object' )
                {
                    if ( typeof objReason.message !== 'undefined' )
                    {
                        strMessage = reduce( objReason.message, 2 );
                    }
                    if ( typeof objReason.name !== 'undefined' )
                    {
                        strName = reduce( objReason.name );
                    }
                    if ( typeof objReason.stack !== 'undefined' )
                    {
                        strStack = reduce( objReason.stack, 3 );
                    }
                }
                else if ( objReason !== null && typeof objReason !== 'undefined' )
                {
                    strMessage = reduce( String( objReason ), 2 );
                }

                sendAutoLogEntry( {
                    'Type': 'JS-Promise-Rejection',
                    'Data': {
                        'message': strMessage,
                        'name': strName,
                        'stack': strStack,
                        'url': window.location.href,
                        'line': null,
                        'col': null
                    }
                } );

                intStackNum--;
            } );

            window.addEventListener( 'securitypolicyviolation', function ( event )
            {
                if (
                    event
                    && /challenges\.cloudflare\.com/i.test( String( event.originalPolicy || '' ) )
                    && /'nonce-/i.test( String( event.originalPolicy || '' ) )
                )
                {
                    bolCloudflareChallengeDetected = true;
                }

                sendAutoLogEntry( {
                    'Type': 'JS-CSP-Error',
                    'Data': {
                        'message': 'Content Security Policy violation',
                        'blockedURI': event.blockedURI || null,
                        'violatedDirective': event.violatedDirective || null,
                        'effectiveDirective': event.effectiveDirective || null,
                        'disposition': event.disposition || null,
                        'originalPolicy': event.originalPolicy || null,
                        'documentURI': event.documentURI || null,
                        'statusCode': event.statusCode || null,
                        'sourceFile': event.sourceFile || null,
                        'line': event.lineNumber || null,
                        'col': event.columnNumber || null
                    }
                } );
            } );
        }

        instrumentConsoleError();
        
        if ( window.jQuery )
        {
            instrumentJQueryXHR();

            $( document ).ajaxError( function( event, jqXHR, ajaxSettings, thrownError ) {
                if ( jqXHR && jqXHR.__filesFmNativeXHR )
                {
                    jqXHR.__filesFmNativeXHR.__filesFmLoggedByJQuery = true;
                }
                if ( jqXHR && jqXHR.skipGlobalAjaxErrorLog === true )
                {
                    return;
                }
                if ( typeof( jqXHR.skipLogOnCancel ) != 'undefined' && jqXHR.skipLogOnCancel === true )
                {
                    return;
                }
                if ( ajaxSettings && ajaxSettings.url && String( ajaxSettings.url ).indexOf( '/check_progress.php' ) !== -1 )
                {
                    return;
                }
                if ( ajaxSettings && isLogEndpoint( ajaxSettings.url ) )
                {
                    return;
                }

                sendAutoLogEntry( {
                    'Type': 'JS-Ajax-Error',
                    'Data': {
                        'message': 'jQuery ajax error',
                        'status': jqXHR ? jqXHR.status : null,
                        'statusText': jqXHR ? jqXHR.statusText : null,
                        'method': ajaxSettings && ajaxSettings.type ? ajaxSettings.type : null,
                        'url': ajaxSettings && ajaxSettings.url ? ajaxSettings.url : null,
                        'thrownError': thrownError ? String( thrownError ) : null,
                        'requestData': ajaxSettings ? serializeRequestBody( ajaxSettings.data ) : null,
                        'responseText': getXHRResponseText( jqXHR ),
                        'responseHeaders': getXHRResponseHeaders( jqXHR, ajaxSettings && ajaxSettings.url ? ajaxSettings.url : '' )
                    }
                } );
            } );
        }

        instrumentFetch();
        instrumentXMLHttpRequest();
    }

    function sendAutoLogEntry( objLog )
    {
        var strKey = buildClientFingerprint( objLog );
        var intNow = ( new Date() ).getTime();

        if ( objRecentAutoLogs[ strKey ] && intNow - objRecentAutoLogs[ strKey ] < 5000 )
        {
            return;
        }

        objRecentAutoLogs[ strKey ] = intNow;

        var fltSampleRate = getAutoLogSampleRate( objLog );
        if ( ! passesAutoLogSample( strKey, fltSampleRate ) )
        {
            return;
        }
        if ( objLog.Data && typeof objLog.Data === 'object' && fltSampleRate < 1 )
        {
            objLog.Data._sampleRate = fltSampleRate;
        }

        sendLogEntry( objLog );
    }

    function getAutoLogSampleRate( objLog )
    {
        var strType = objLog && objLog.Type ? String( objLog.Type ) : '';
        var objData = objLog && objLog.Data ? objLog.Data : {};
        var strUrl = String( objData.url || objData.blockedURI || '' );
        var strMessage = String( objData.message || '' );
        var strTag = String( objData.tag || '' ).toUpperCase();
        var strPolicy = String( objData.originalPolicy || '' );

        if ( strType === 'JS-Resource-Error' )
        {
            if ( bolCloudflareChallengeDetected )
            {
                return 0.02;
            }
            if ( /^(IMG|VIDEO|AUDIO|SOURCE)$/.test( strTag ) )
            {
                return 0.02;
            }
        }

        if (
            strType === 'JS-CSP-Error'
            && (
                /\/cdn-cgi\/rum|\/post_log|static\.cloudflareinsights\.com/i.test( strUrl )
                || ( /challenges\.cloudflare\.com/i.test( strPolicy ) && /'nonce-/i.test( strPolicy ) )
            )
        )
        {
            return 0.02;
        }

        if (
            strType === 'JS-Console-Error'
            && /error setting cookie `_pk_|registered more than once in "?_paq/i.test( strMessage )
        )
        {
            return 0.05;
        }

        return 1;
    }

    function passesAutoLogSample( strFingerprint, fltSampleRate )
    {
        if ( fltSampleRate >= 1 )
        {
            return true;
        }

        var strValue = strLogToken + '|' + strFingerprint;
        var intHash = 2166136261;
        for ( var i = 0; i < strValue.length; ++i )
        {
            intHash ^= strValue.charCodeAt( i );
            intHash += ( intHash << 1 ) + ( intHash << 4 ) + ( intHash << 7 ) + ( intHash << 8 ) + ( intHash << 24 );
        }

        return ( intHash >>> 0 ) % 10000 < Math.floor( fltSampleRate * 10000 );
    }

    function buildClientFingerprint( objLog )
    {
        var objData = objLog && objLog.Data ? objLog.Data : {};
        return [
            objLog.Type || '',
            objData.message || '',
            objData.url || '',
            objData.line || ''
        ].join( '|' ).replace( /[a-z0-9_-]{18,}/ig, '{id}' );
    }

    function instrumentConsoleError()
    {
        if ( ! window.console || ! console.error || console.error.__filesFmLogged )
        {
            return;
        }

        var fnOriginalConsoleError = console.error;
        var fnLoggedConsoleError = function ()
        {
            var arrArguments = Array.prototype.slice.call( arguments );
            try
            {
                sendAutoLogEntry( {
                    'Type': 'JS-Console-Error',
                    'Data': {
                        'message': arrArguments.length ? String( arrArguments[ 0 ] ) : 'console.error',
                        'arguments': reduce( arrArguments, 3 )
                    }
                } );
            }
            catch ( exConsoleLog )
            {
            }

            return fnOriginalConsoleError.apply( console, arguments );
        };

        fnLoggedConsoleError.__filesFmLogged = true;
        console.error = fnLoggedConsoleError;
    }

    function instrumentJQueryXHR()
    {
        if ( ! window.jQuery || typeof jQuery.ajaxPrefilter !== 'function' || instrumentJQueryXHR.__filesFmInstalled )
        {
            return;
        }

        jQuery.ajaxPrefilter( function( options, originalOptions, jqXHR )
        {
            var fnCreateXHR = options.xhr;

            if ( typeof fnCreateXHR !== 'function' || fnCreateXHR.__filesFmMarksJQueryXHR )
            {
                return;
            }

            options.xhr = function()
            {
                var xhr = fnCreateXHR.apply( this, arguments );
                if ( xhr )
                {
                    xhr.__filesFmHandledByJQuery = true;
                    xhr.__filesFmJQueryXHR = jqXHR;
                    jqXHR.__filesFmNativeXHR = xhr;
                }
                return xhr;
            };
            options.xhr.__filesFmMarksJQueryXHR = true;
        } );

        instrumentJQueryXHR.__filesFmInstalled = true;
    }

    function truncateClientValue( strValue )
    {
        var intLimit = 524288;
        strValue = typeof strValue === 'string' ? strValue : String( strValue || '' );

        if ( strValue.length <= intLimit )
        {
            return strValue;
        }

        return strValue.substring( 0, intLimit ) + '\n[truncated; original characters: ' + strValue.length + ']';
    }

    function isSensitiveRequestKey( strKey )
    {
        return /(^|_)(password|password_confirm|pass|passwd|authorization|cookie|phpsessid|sessid|session_id|access_token|api_key|private_key|user_hash)($|_)/i.test( String( strKey || '' ) );
    }

    function serializeRequestBody( mixBody )
    {
        if ( mixBody === null || typeof mixBody === 'undefined' )
        {
            return null;
        }

        if ( typeof FormData !== 'undefined' && mixBody instanceof FormData )
        {
            var objFormData = {};
            mixBody.forEach( function( mixValue, strKey )
            {
                var mixSafeValue = isSensitiveRequestKey( strKey ) ? '[redacted]' : mixValue;
                if ( typeof File !== 'undefined' && mixValue instanceof File )
                {
                    mixSafeValue = { name: mixValue.name, type: mixValue.type, size: mixValue.size };
                }

                if ( typeof objFormData[ strKey ] === 'undefined' )
                {
                    objFormData[ strKey ] = mixSafeValue;
                }
                else if ( Array.isArray( objFormData[ strKey ] ) )
                {
                    objFormData[ strKey ].push( mixSafeValue );
                }
                else
                {
                    objFormData[ strKey ] = [ objFormData[ strKey ], mixSafeValue ];
                }
            } );
            return objFormData;
        }

        if ( typeof Blob !== 'undefined' && mixBody instanceof Blob )
        {
            return { bodyType: 'Blob', type: mixBody.type || null, size: mixBody.size };
        }

        if ( typeof ArrayBuffer !== 'undefined' && ( mixBody instanceof ArrayBuffer || ArrayBuffer.isView && ArrayBuffer.isView( mixBody ) ) )
        {
            return { bodyType: 'ArrayBuffer', size: mixBody.byteLength || 0 };
        }

        if ( typeof mixBody === 'string' )
        {
            return truncateClientValue( mixBody );
        }

        return reduce( mixBody, 4 );
    }

    function getXHRResponseHeaders( xhr, strRequestUrl )
    {
        if ( ! xhr || typeof xhr.getResponseHeader !== 'function' )
        {
            return null;
        }

        try
        {
            var objHeaders = {
                'content-type': xhr.getResponseHeader( 'Content-Type' ),
                'content-length': xhr.getResponseHeader( 'Content-Length' ),
                'server': xhr.getResponseHeader( 'Server' ),
                'cf-ray': xhr.getResponseHeader( 'CF-Ray' )
            };
            var strDVSRequestId = xhr.getResponseHeader( 'X-DVS-Request-ID' );

            if ( strDVSRequestId || isDVSRequestUrl( strRequestUrl ) )
            {
                objHeaders[ 'x-dvs-request-id' ] = strDVSRequestId;
            }

            return objHeaders;
        }
        catch ( exResponseHeaders )
        {
            return null;
        }
    }

    function getXHRResponseText( xhr )
    {
        try
        {
            return xhr && typeof xhr.responseText === 'string' ? truncateClientValue( xhr.responseText ) : null;
        }
        catch ( exResponseText )
        {
            return null;
        }
    }

    function getFetchResponseHeaders( response, strRequestUrl )
    {
        if ( ! response || ! response.headers )
        {
            return null;
        }

        var objHeaders = {
            'content-type': response.headers.get( 'Content-Type' ),
            'content-length': response.headers.get( 'Content-Length' ),
            'server': response.headers.get( 'Server' ),
            'cf-ray': response.headers.get( 'CF-Ray' )
        };
        var strDVSRequestId = response.headers.get( 'X-DVS-Request-ID' );

        if ( strDVSRequestId || isDVSRequestUrl( strRequestUrl ) )
        {
            objHeaders[ 'x-dvs-request-id' ] = strDVSRequestId;
        }

        return objHeaders;
    }

    function instrumentFetch()
    {
        if ( ! window.fetch || window.fetch.__filesFmLogged )
        {
            return;
        }

        var fnOriginalFetch = window.fetch;
        window.fetch = function ()
        {
            var arrArgs = arguments;
            var strUrl = extractRequestUrl( arrArgs[ 0 ] );
            var strMethod = extractRequestMethod( arrArgs[ 0 ], arrArgs[ 1 ] );
            var mixRequestBody = arrArgs[ 1 ] && typeof arrArgs[ 1 ].body !== 'undefined' ? serializeRequestBody( arrArgs[ 1 ].body ) : null;
            var intStartedAt = Date.now();

            return fnOriginalFetch.apply( this, arrArgs ).then( function ( response )
            {
                if ( response && response.status >= 400 && ! isLogEndpoint( strUrl ) )
                {
                    if ( isThirdPartyNoiseUrl( strUrl ) )
                    {
                        return response;
                    }

                    logFetchResponseFailure( response, strUrl, strMethod, mixRequestBody, intStartedAt );
                }
                return response;
            }, function ( error )
            {
                if ( ! isLogEndpoint( strUrl ) )
                {
                    if ( isThirdPartyNoiseUrl( strUrl ) )
                    {
                        throw error;
                    }

                    sendAutoLogEntry( {
                        'Type': 'JS-Fetch-Error',
                        'Data': {
                            'message': error && error.message ? error.message : 'fetch failed',
                            'name': error && error.name ? error.name : null,
                            'stack': error && error.stack ? reduce( error.stack, 3 ) : null,
                            'method': strMethod,
                            'url': strUrl,
                            'requestData': mixRequestBody,
                            'durationMs': Date.now() - intStartedAt
                        }
                    } );
                }
                throw error;
            } );
        };

        window.fetch.__filesFmLogged = true;
    }

    function logFetchResponseFailure( response, strUrl, strMethod, mixRequestBody, intStartedAt )
    {
        var objBaseData = {
            'message': 'fetch HTTP ' + response.status,
            'status': response.status,
            'statusText': response.statusText,
            'method': strMethod,
            'url': strUrl,
            'requestData': mixRequestBody,
            'durationMs': Date.now() - intStartedAt,
            'responseHeaders': getFetchResponseHeaders( response, strUrl )
        };

        try
        {
            response.clone().text().then( function( strResponseText )
            {
                objBaseData.responseText = truncateClientValue( strResponseText );
                sendAutoLogEntry( { 'Type': 'JS-Fetch-Error', 'Data': objBaseData } );
            }, function()
            {
                sendAutoLogEntry( { 'Type': 'JS-Fetch-Error', 'Data': objBaseData } );
            } );
        }
        catch ( exResponseRead )
        {
            sendAutoLogEntry( { 'Type': 'JS-Fetch-Error', 'Data': objBaseData } );
        }
    }

    function instrumentXMLHttpRequest()
    {
        if ( ! window.XMLHttpRequest || window.XMLHttpRequest.__filesFmLogged )
        {
            return;
        }

        var fnOpen = window.XMLHttpRequest.prototype.open;
        var fnSend = window.XMLHttpRequest.prototype.send;

        window.XMLHttpRequest.prototype.open = function ( method, url )
        {
            this.__filesFmLogMethod = method || 'GET';
            this.__filesFmLogUrl = url || '';
            this.__filesFmLogStartedAt = Date.now();
            return fnOpen.apply( this, arguments );
        };

        window.XMLHttpRequest.prototype.send = function ()
        {
            var xhr = this;
            xhr.__filesFmLogRequestData = serializeRequestBody( arguments.length ? arguments[ 0 ] : null );
            if ( xhr.addEventListener )
            {
                xhr.addEventListener( 'error', function ()
                {
                    logXHRFailure( xhr, 'xhr network error' );
                } );
                xhr.addEventListener( 'timeout', function ()
                {
                    logXHRFailure( xhr, 'xhr timeout' );
                } );
                xhr.addEventListener( 'loadend', function ()
                {
                    if ( xhr.status >= 400 )
                    {
                        logXHRFailure( xhr, 'xhr HTTP ' + xhr.status );
                    }
                } );
            }

            return fnSend.apply( this, arguments );
        };

        window.XMLHttpRequest.__filesFmLogged = true;
    }

    function logXHRFailure( xhr, strMessage )
    {
        var strUrl = xhr.__filesFmLogUrl || '';
        if ( xhr.__filesFmSkipClientLog )
        {
            return;
        }
        if ( xhr.__filesFmLoggedByJQuery )
        {
            return;
        }
        if ( strUrl.indexOf( '/check_progress.php' ) !== -1 )
        {
            return;
        }
        if ( isLogEndpoint( strUrl ) )
        {
            return;
        }
        if ( isThirdPartyNoiseUrl( strUrl ) )
        {
            return;
        }

        sendAutoLogEntry( {
            'Type': 'JS-XHR-Error',
            'Data': {
                'message': strMessage,
                'status': xhr.status || 0,
                'statusText': xhr.statusText || null,
                'method': xhr.__filesFmLogMethod || null,
                'url': strUrl,
                'requestData': xhr.__filesFmLogRequestData || null,
                'responseText': getXHRResponseText( xhr ),
                'responseHeaders': getXHRResponseHeaders( xhr, strUrl ),
                'durationMs': xhr.__filesFmLogStartedAt ? Date.now() - xhr.__filesFmLogStartedAt : null
            }
        } );
    }

    function extractRequestUrl( mixRequest )
    {
        if ( typeof mixRequest === 'string' )
        {
            return mixRequest;
        }
        if ( mixRequest && mixRequest.url )
        {
            return mixRequest.url;
        }

        return '';
    }

    function extractRequestMethod( mixRequest, objOptions )
    {
        if ( objOptions && objOptions.method )
        {
            return objOptions.method;
        }
        if ( mixRequest && mixRequest.method )
        {
            return mixRequest.method;
        }

        return 'GET';
    }

    function isLogEndpoint( strUrl )
    {
        return typeof strUrl === 'string'
            && ( strUrl.indexOf( '/post_log' ) !== -1 || /(^|\/)cdn-cgi\/rum(?:[\/?#]|$)/i.test( strUrl ) );
    }

    function isDVSRequestUrl( strUrl )
    {
        return typeof strUrl === 'string' && /(^|https?:\/\/[^/]+)\/dvs(?:\/|[?#]|$)/i.test( strUrl );
    }

    function isThirdPartyNoiseUrl( strUrl )
    {
        if ( ! strUrl || typeof strUrl !== 'string' )
        {
            return false;
        }

        return /(^https?:)?\/\/([^\/]+\.)?(doubleclick\.net|google-analytics\.com|analytics\.google\.com|googletagmanager\.com|googlesyndication\.com|googleadservices\.com|adtrafficquality\.google|adform\.net|adkernel\.com|setupad\.net|adxpremium\.services|smartadserver\.com|criteo\.com|360yield\.com|hadron\.ad\.gt|4dex\.io|creativecdn\.com|onetag-sys\.com|stpd\.cloud|id5-sync\.com|a-mo\.net)\b/i.test( strUrl )
            || /analytics\.files\.fm\/matomo/i.test( strUrl )
            || /[?&]set_visited_cookie_and_exit=1\b/i.test( strUrl );
    }
    
    var strSendMessageTextWithNextJSError = null;
    
    this.sendLogEntry = sendLogEntry;
    function sendLogEntry ( objLog )
    {
        var objNavigator = null;
        if ( typeof( navigator ) != 'undefined' )
        {
            objNavigator = reduce( navigator );
        }

        var objRuntime = getRuntimeContext();
           
        if ( typeof( strSendMessageTextWithNextJSError ) != 'undefined' && strSendMessageTextWithNextJSError != null )
        {
            objLog[ 'Data' ].included_message = strSendMessageTextWithNextJSError;
            strSendMessageTextWithNextJSError = null;
        }

        if ( objLog[ 'Data' ] && typeof objLog[ 'Data' ] === 'object' )
        {
            objLog[ 'Data' ]._tags = classifyErrorTags( objLog[ 'Data' ] );
        }
        
        var strURL = window.location.href;
        var strLogJSON = safeStringify( objLog[ 'Data' ] );
        var strNavigatorJSON = safeStringify( objNavigator );
        var strRuntimeJSON = safeStringify( objRuntime );
        var strBody = 'Url=' + encodeURIComponent( strURL )
            + '&Type=' + encodeURIComponent( objLog[ 'Type' ] )
            + '&Log=' + encodeURIComponent( strLogJSON )
            + '&Navigator=' + encodeURIComponent( strNavigatorJSON )
            + '&Vars=' + encodeURIComponent( strRuntimeJSON );

        if ( navigator.sendBeacon )
        {
            try
            {
                if ( navigator.sendBeacon( strLogUrl, new Blob( [ strBody ], { type: 'application/x-www-form-urlencoded' } ) ) )
                {
                    return;
                }
            }
            catch ( exBeacon )
            {
            }
        }

        try
        {
            var xhr = new XMLHttpRequest();
            xhr.open( 'POST', strLogUrl, true );
            xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
            xhr.send( strBody );
        }
        catch ( exXHR )
        {
        }
    }

    function safeStringify( mix )
    {
        try
        {
            if ( JSON.decycle )
            {
                return JSON.stringify( JSON.decycle( mix ) );
            }

            return JSON.stringify( mix );
        }
        catch ( ex )
        {
            try
            {
                return JSON.stringify( reduce( mix, 3 ) );
            }
            catch ( exReduce )
            {
                return '{}';
            }
        }
    }
    
    
    this.reduce = reduce;
    function reduce ( mix, intMaxLevel, intCurrentLevel )
    {
        if ( typeof mix == 'undefined' || mix == null )
        {
            return null;
        }
            
        if ( typeof( intMaxLevel ) == 'undefined' || intMaxLevel === null )
        {
            intMaxLevel = 1;
        }
        if ( typeof( intCurrentLevel ) == 'undefined' || intCurrentLevel === null )
        {
            intCurrentLevel = 0;
        }
        
        var ret = mix;
        if ( !( /boolean|number|string/ ).test( typeof mix ) )
        {
            ret = {};
            for ( var key in mix )
            {
                if ( ( /boolean|number|string/ ).test( typeof mix[ key ] ) )
                {
                    ret[ key ] = mix[ key ];
                }
                else if ( intMaxLevel > intCurrentLevel + 1 )
                {
                    ret[ key ] = reduce( mix[ key ], intMaxLevel, intCurrentLevel + 1 );
                }
            }
        }
        return ret;
    }

    function getRuntimeContext()
    {
        var objRuntime = {
            'jquery': null,
            'jquery_ui': null,
            'jquery_migrate': null,
            'ready_state': document.readyState,
            'viewport': window.innerWidth + 'x' + window.innerHeight,
            'path': window.location.pathname,
            'hash': window.location.hash ? window.location.hash.substring( 0, 120 ) : '',
            'language': navigator.language || null,
            'online': typeof navigator.onLine === 'boolean' ? navigator.onLine : null,
            'screen': window.screen ? ( window.screen.width + 'x' + window.screen.height ) : null,
            'pixel_ratio': window.devicePixelRatio || null,
            'referrer': document.referrer ? document.referrer.substring( 0, 500 ) : '',
            'timezone': ( new Date() ).getTimezoneOffset()
        };

        if ( window.jQuery && jQuery.fn )
        {
            objRuntime.jquery = jQuery.fn.jquery || null;

            if ( jQuery.ui && jQuery.ui.version )
            {
                objRuntime.jquery_ui = jQuery.ui.version;
            }

            if ( jQuery.migrateVersion )
            {
                objRuntime.jquery_migrate = jQuery.migrateVersion;
            }
        }

        return objRuntime;
    }

    function classifyErrorTags( objError )
    {
        var arrTags = [];
        var strHaystack = '';

        try
        {
            strHaystack = JSON.stringify( objError ).toLowerCase();
        }
        catch ( ex )
        {
            strHaystack = String( objError.message || '' ).toLowerCase();
        }

        if ( /jquery-\d|jquery\.fn|\/jquery/.test( strHaystack ) )
        {
            arrTags.push( 'jquery' );
        }

        if ( /jquery-ui|jquery\.ui/.test( strHaystack ) )
        {
            arrTags.push( 'jquery-ui' );
        }

        if ( /jquery-migrate|jquery\.migrate/.test( strHaystack ) )
        {
            arrTags.push( 'jquery-migrate' );
        }

        if ( /reading 'value'|\.attr\(['"]value['"]\)/.test( strHaystack ) )
        {
            arrTags.push( 'jq3-attr-value' );
        }

        if ( /is not a function|unrecognized expression|dispatchEvent must be an instance of Event/.test( strHaystack ) )
        {
            arrTags.push( 'jq3-candidate' );
        }

        if ( window.jQuery && jQuery.fn && jQuery.fn.jquery && String( jQuery.fn.jquery ).indexOf( '3.' ) === 0 )
        {
            arrTags.push( 'jquery3-runtime' );
        }

        return arrTags;
    }

    function isIgnorableScriptUrl( strUrl )
    {
        if ( ! strUrl || typeof strUrl !== 'string' )
        {
            return false;
        }

        return /^(chrome-extension|moz-extension|safari-extension|safari-web-extension):/i.test( strUrl );
    }

    function buildErrorObject( message_in, filename_in, linenum_in, colnum_in, error_in )
    {
        var objError = {
            'message': reduce( message_in, 2 ),
            'url': reduce( filename_in ),
            'line': reduce( linenum_in ),
            'col': reduce( colnum_in ),
            'name': null,
            'stack': null
        };

        if ( error_in && typeof error_in === 'object' )
        {
            if ( typeof error_in.name !== 'undefined' )
            {
                objError.name = reduce( error_in.name );
            }
            if ( typeof error_in.stack !== 'undefined' )
            {
                objError.stack = reduce( error_in.stack, 4 );
            }
            if ( objError.message === null && typeof error_in.message !== 'undefined' )
            {
                objError.message = reduce( error_in.message, 2 );
            }
        }

        return objError;
    }
    
    
    init();
    
}
