/*
Common.js

Provides functionality common to any javascript on
the site.  It must be included in every HTML file
that uses the common functions.
*/

// Alter native objects

Array.prototype.contains = function(object){
    for(var k = 0; k < this.length; k++){
        if(this[k] == object){
            return true;
        }
    }
    
    return false;
}

// Create the Esm namespace.

//if(!Object.prototype.Esm) Object.prototype.Esm = new Object();

var globalVars = new Array();   // to prevent naming conflicts
var Esm = new Object(); // for compatibility with IE6
globalVars.push("Esm");

// Creates one or more namespaces.

Esm.namespace = function(){
    for(var i = 0; i < arguments.length; i++){
        //eval("if(!Object.prototype." + arguments[i] + ") Object.prototype." + arguments[i] + " = new Object()");
        var names = arguments[i].split(".");
        var name = "";
        
        for(var j = 0; j < names.length; j++){
            if(name != ""){
                 name += ".";
            }
            
            name += names[j];
            
            if(!globalVars.contains(name)){
                globalVars.push(name);
                eval(name + " = new Object();");
            }
        }
    }
}

