/**
 * @author fernando
 */


function log(msg, force){
    try {
        console.log(msg);
    } 
    catch (e) {
        if (force) 
            alert(msg);
    }
}

function augment(receivingClass, givingClass) {
	for (methodName in givingClass.prototype) {
		if (!receivingClass.prototype[methodName]) {
			try{
				receivingClass.prototype[methodName] = givingClass.prototype[methodName];
			}
			catch(e){}
		}
	}
}

function getIdFromHash(hash){
	if(hash)
	 return hash.substring(hash.indexOf('#')+1);
	 else
	 	return null;
}

Array.prototype.intersect = function(){
    if (!arguments.length) 
        return [];
    var a1 = this;
    var a = a2 = null;
    var n = 0;
    while (n < arguments.length) {
        a = [];
        a2 = arguments[n];
        var l = a1.length;
        var l2 = a2.length;
        for (var i = 0; i < l; i++) {
            for (var j = 0; j < l2; j++) {
                if (a1[i] === a2[j]) 
                    a.push(a1[i]);
            }
        }
        a1 = a;
        n++;
    }
    return a.unique();
};

Array.prototype.contains = function(obj){
    for (var i = 0; i < this.length; i++) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
};



function escapeId(id){
	if(!id || typeof(id)=="undefined" || id.indexOf("\\:")>=0 || id.indexOf("\\/")>=0)
		return id;
	
	return id.replace("/", "\\/").replace(":", "\\:");
}

