﻿/* http://ejohn.org/projects/flexible-javascript-events/ */
function addEvent(obj, type, fn) {
    if (obj.attachEvent) {
        obj['e' + type + fn] = fn;
        obj[type + fn] = function() { obj['e' + type + fn](window.event); }
        obj.attachEvent('on' + type, obj[type + fn]);
    } else
        obj.addEventListener(type, fn, false);
}
function removeEvent(obj, type, fn) {
    if (obj.detachEvent) {
        obj.detachEvent('on' + type, obj[type + fn]);
        obj[type + fn] = null;
    } else
        obj.removeEventListener(type, fn, false);
}
function PreloadImage(url) {
    if (url != null && url.length > 0) {
        if (document.preloadedImages == null) document.preloadedImages = new Array();
        var count = document.preloadedImages.length;
        if (count > 0) {
            for (var i = 0; i < count; i++) {
                if (document.preloadedImages[i].src == url) return;
            }
        }
        document.preloadedImages[count] = new Image();
        document.preloadedImages[count].src = url;
    }
}
function JsonParse(text) {
    var value =
            !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
            text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
            eval('(' + text + ')');
    return value;
}
function GetAjaxClient() {
    var ajaxClient;
    try {
        ajaxClient = new XMLHttpRequest();
    }
    catch (e) {
        try {
            ajaxClient = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                ajaxClient = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                ajaxClient = null;
            }
        }
    }
    return ajaxClient;
}
function OnImageError(image) {
    var spacerPath = document.imgSpacer;
    if (image.src.indexOf(spacerPath) < 0) {
        var appHost = (document.appHost) ? document.appHost : '';
        var spacer = 'http://' + appHost + spacerPath;
        image.src = spacer;
    }
}
