﻿/* 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 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) {
    image.Src = document.imgSpacer;
}
function GlobalLoad() {
    if (document.imgSpinner != null) {
        PreloadImage(document.imgSpinner);
    }
    if (document.imgSpinnerWhite != null) {
        PreloadImage(document.imgSpinnerWhite);
    }
    if (document.imgSpacer != null) {
        PreloadImage(document.imgSpacer);
    }
}
addEvent(window, 'load', GlobalLoad);