/**
 * Global variables to determine IE version
 *
 * These sould be declared very first of all JS because some JS libraries
 * will create the XMLHttpRequest onject for LTE IE6 (which is evil)!!!
 */
CRNA_LTE_IE6 = !window.XMLHttpRequest;

CRNA_GTE_IE7 = !!(window.XMLHttpRequest && window.ActiveXObject);

/**
 * Cross-browser event addition function.
 *
 * param object obj DOM object to add event to
 * param string type type of event (e.g. load, click, etc)
 * param string fn function to call on event
 *
 * return void
 */
function CRNA_addEvent(obj, type, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(type, fn, false);
    }
    else 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['on' + type] = obj['e' + type + fn];
    }
}

/**
 * Finds elements based on class name
 *
 * param DOMNode node a DOMNode returned by getElementById() or 'document' for whole document
 * param string searchClass name of class to search for
 * param string tag name of type of tag to search for or '*' for all tags
 *
 * return array array of DOMElements
 */
function CRNA_getElementsByClass(node, searchClass, tag) {
    var classEls = new Array();

    var els = node.getElementsByTagName(tag);

    var elsLen = els.length;

    var pattern = new RegExp("\\b" + searchClass + "\\b");

    for (var i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classEls[j] = els[i];
            j++;
        }
    }

    return classEls;
}

/*
 * Extend Array object to add inArray() method
 */
Array.prototype.inArray = function (value) {
    var i;

    for (i = 0; i < this.length; i++) {
        if (this[i] === value) {
            return true;
        }
    }

    return false;
};
