
/*
standard scripts
	
©2009 Copyright HMH, Inc.   thinkhmh.com
Do not sell or transfer without the expressed written consent of HMH.
This message must remain intact wherever/however this file is used.
*/

var GLOBALS = {
    addElement: function(parent, type, params) {
        var newElem = document.createElement(type);
        if (params) for (key in params) { newElem.setAttribute(key, params[key]); if (key == "class") newElem.setAttribute("className", params[key]); }
        if (parent) parent.appendChild(newElem);
        return newElem;
    },
    addOnload: function(func) {
        if (document.getElementById && (window.addEventListener || window.attachEvent) && GLOBALS.isFunction(func)) {
            var prev = window.onload;
            if (!GLOBALS.isFunction(window.onload)) {
                window.onload = func;
            }
            else {
                window.onload = function() { prev(); func(); };
            }
        }
    },
    isFunction: function(o) {
        return (o != null && typeof (o) == "function");
    },
    removeElement: function(elem) {
        if (typeof elem == 'string') elem = HMH.getById(elem);
        try {
            elem.parentNode.removeChild(elem);
        } catch (err) {
            alert(elem.id + ":" + err);
        }
    }

};

/*
renamed standard $ to be more compatible with scriptaculous and jquery
*/
var HMH = {
    getByClass: function(str, node, tag) {
        var classEls = new Array();
        var elements;
        node = !node ? document : node;
        elements = !tag ? node.all || node.getElementsByTagName('*') : node.getElementsByTagName(tag);
        var pattern = new RegExp('(^|\\s)' + str + '(\\s|$)');
        for (counter = 0, found = 0; counter < elements.length; counter++) {
            if (pattern.test(elements[counter].className)) {
                classEls[found] = elements[counter];
                found++;
            }
        }
        return classEls;
    },
    getById: function() {
        var elements = new Array();
        for (var counter = 0; counter < arguments.length; counter++) {
            var arg = arguments[counter];
            if (typeof arg == 'string') arg = document.getElementById(arg);
            if (arguments.length == 1) return arg;
            elements.push(arg);
        }
        return elements;
    },
    getByTag: function(str, node) {
        if (node == null) node = document;
        return node.getElementsByTagName(str);
    },
    getStyle: function(elem, style) {
        if (!document.getElementById) return;
        var value = 0;
        try {
            if (document.defaultView)
                value = document.defaultView.getComputedStyle(elem, "").getPropertyValue(style);
            else if (elem.currentStyle) {
                value = elem.currentStyle[style];
            }
        }
        catch (e) {
            value = elem.style[style];
        }
        return value;
    }
};

//