// Master init function for window.onload
window.onload = init;

// Master variables.
var formedited = 0;
var checkformchange = 1;
var showformbox = 1;

function init() {
	setupActions();
	// initialize the other modules' javascript
	if (window.init_arlstats)
		init_arlstats();
	if (window.init_digiqual)
		init_digiqual();
	if (window.init_emetrics)
		init_emetrics();
	if (window.init_interactive)
		init_interactive();
	if (window.init_libqual)
		init_libqual();
	if (window.init_mines)
		init_mines();
	if (window.init_sails)
		init_sails();
}

// General Functions
function makeANumber(a) {
	var thisNumber = a.value.replace(/[^\d.-]/g,'');
	thisNumber = thisNumber.replace(/(.)-/g,'$1'); // Replace all but a starting "-"
	return thisNumber;
}

// DOM
function getElem(elem) {
    if (document.getElementById) {
        if (typeof elem == "string") {
            elem = document.getElementById(elem);
            if (elem===null) throw 'cannot get element: element does not exist';
        } else if (typeof elem != "object") {
            throw 'cannot get element: invalid datatype';
        }
    } else throw 'cannot get element: unsupported DOM';
    return elem;
}

function hasClass(elem, className) {
    return getElem(elem).className.split(' ').has(className);
}

function getElementsByClass(className, tagName, parentNode) {
    parentNode = !isUndefined(parentNode)? getElem(parentNode) : document;
    if (isUndefined(tagName)) tagName = '*';
    return filter(parentNode.getElementsByTagName(tagName),
        function(elem) { return hasClass(elem, className) });
}

// MISC CLEANING-AFTER-MICROSOFT STUFF
function isUndefined(v) {
    var undef;
    return v===undef;
}