if(!mapness){
	var mapness = {};
}

var DOMcache = {
	get: function(NodeName){
		if(DOMcache[NodeName] == undefined){
			DOMcache[NodeName] = $(NodeName);
		}
		return DOMcache[NodeName];
	}
};
	
jQuery.fn.delegate = function(eventType, rules) {
  return this.bind(eventType, function(e) {
    var target = $(e.target);
    for(var selector in rules)
      if(target.is(selector)) 
        return rules[selector].apply(this, arguments)
  })
}

String.prototype.entityify = function () {
    //return this.replace(/&/g, "&amp;").replace(/</g,"&lt;").replace(/>/g, "&gt;");
		
	// my own stuff to eliminate JS events 
	return this.replace(/onabort/gi, "illegal").replace(/onblur/gi, "illegal").replace(/onchange/gi, "illegal").replace(/onclick/gi, "illegal").replace(/ondblclick/gi, "illegal").replace(/onerror/gi, "illegal").replace(/onfocus/gi, "illegal").replace(/onkeydown/gi, "illegal").replace(/onkeypress/gi, "illegal").replace(/onkeyup/gi, "illegal").replace(/onload/gi, "illegal").replace(/onmouse/gi, "illegal").replace(/onreset/gi, "illegal").replace(/onresize/gi, "illegal").replace(/onselect/gi, "illegal").replace(/onsubmit/gi, "illegal").replace(/onunload/gi, "illegal");
};

String.prototype.quote = function () {
    var c, i, l = this.length, o = '"';
    for (i = 0; i < l; i += 1) {
        c = this.charAt(i);
        if (c >= ' ') {
            if (c === '\\' || c === '"') {
                o += '\\';
            }
            o += c;
        } else {
            switch (c) {
            case '\b':
                o += '\\b';
                break;
            case '\f':
                o += '\\f';
                break;
            case '\n':
                o += '\\n';
                break;
            case '\r':
                o += '\\r';
                break;
            case '\t':
                o += '\\t';
                break;
            default:
                c = c.charCodeAt();
                o += '\\u00' + Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }
        }
    }
    return o + '"';
};

function addslashes(str) {
	str=str.replace(/\'/g,'&#39;');
	str=str.replace(/\"/g,'&#34;');
	return str;
};

function gethash() {
	return location.hash.replace(/^.*#/, ''); 
};


mapness.util = {
	stopEventBubbling:function(e){
              //console.debug('bubblling ',e);
		if(!e){
			var e = window.event;
		} 
		e.cancelBubble = true;
		if(e.stopPropagation){
			e.stopPropagation();
		} 
	},
	
	addslashes : function(str) {
		str=str.replace(/\'/g,'&#39;');
		str=str.replace(/\"/g,'&#34;');
		return str;
	},
	nl2br : function( text ) {
		return text.replace(/\n/g, '<br/>');
	},

	br2nl : function( text ){
		return text.replace(/<br\/>/g, "\n");
	},
	
	submitEnterIE: function(){
		//see http://www.thefutureoftheweb.com/blog/submit-a-form-in-ie-with-enter
		if (jQuery.browser.msie) {
			$('input').keydown(function(e){
				if (e.keyCode == 13) {
					$(this).parents('form').submit();
					return false;
				}
			});
		}
	},
	
	getEventTarget:function(e){
		var targ;
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) targ = targ.parentNode; 
		return targ;
	},
	
	limitText: function(limitField, limitNum) {
	    if (limitField.value.length > limitNum) {
	        limitField.value = limitField.value.substring(0, limitNum);
	    } 
	}

}
