
if(!console) {
	try {
		var console = {
			'log':function (){}, 
			'debug':function (){}, 
			'info':function (){}, 
			'warn':function (){}, 
			'error':function (){}, 
			'assert':function (){}, 
			'dir':function (){}, 
			'dirxml':function (){}, 
			'trace':function (){}, 
			'group':function (){}, 
			'groupEnd':function (){}, 
			'groupCollapsed':function (){}, 
			'time':function (){}, 
			'timeEnd':function (){}, 
			'profile':function (){}, 
			'profileEnd':function (){}, 
			'count':function (){}, 
			'clear':function (){}, 
			'notifyFirebug':function (objs, methodName, eventID) {}, 
			'getFirebugElement':function (){ return null; }, 
			'firebug':'not loaded' 
		};
	} catch(e) {};
}

var Scm = {

	test: function(regex, params){
		return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
	},

	contains: function(string, separator){
		return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
	},

	trim: function(){
		return this.replace(/^\s+|\s+$/g, '');
	},

	clean: function(){
		return this.replace(/\s+/g, ' ').trim();
	},

	camelCase: function(){
		return this.replace(/-\D/g, function(match){
			return match.charAt(1).toUpperCase();
		});

	},

	hyphenate: function(){
		return this.replace(/[A-Z]/g, function(match){
			return ('-' + match.charAt(0).toLowerCase());
		});
	},

	capitalize: function(){
		return this.replace(/\b[a-z]/g, function(match){
			return match.toUpperCase();
		});
	},

	escapeRegExp: function(){
		return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
	},

	toInt: function(base){
		return parseInt(this, base || 10);
	},

	toFloat: function(){
		return parseFloat(this);
	},

	isMailAddr : function checkMailAddr() {
		var addr = this.split("@");
		if(addr.length==1 || addr.length>2) return false;
		var dom = addr[1].split(".");
		if(dom.length == 1) return false;
		var domLen = dom.length
		if(domLen>2 && (dom[domLen-1]).length==0) domLen--;
		if(dom[domLen-1].length<2 || dom[domLen-1].length>3) return false;
		for(var i=0;i<domLen;i++) { if(dom[i].length==0) return false; }
		var acc = addr[0].split(".");
		for(i=0;i<acc.length;i++) { if(acc[i].length==0) return false; }
		var okChars = "abcdefghijklmnopqrstuvwxyz";
		okChars += okChars.toUpperCase()+"0123456789-_";
		var testString = acc.join("")+"."+dom.join("");
		if("."==testString) return false;
		i=0;
		while( i<testString.length ) { 
			if('.'==testString.substr(i,1)) {
				okChars = okChars.substr(0,okChars.length-1);
			} else {
				if(okChars.indexOf(testString.substr(i,1))==-1 ) return false;
			}
			i++;
		}
		return true;
	}

};

for( var methodName in Scm ) {
	if( 'undefined' == typeof String.prototype[methodName] ) {
		String.prototype[methodName] = Scm[methodName];
	}
}
delete Scm;

var ElGoodies = {
	
	getDocument: function(){
		return this.ownerDocument;
	},
	
	getWindow: function(){
		return this.getDocument().getWindow?this.getDocument().getWindow():window;
	},

	dispose: function(){
		return this.parentNode.removeChild(this);
	},

	replaces: function(el){
		if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
		el.parentNode.replaceChild(this, el);
		return this;
	},

	hasClass: function(className){
		return this.className.contains(className, ' ');
	},

	addClass: function(className){
		if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
		return this;
	},

	removeClass: function(className){
		this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1').clean();
		return this;
	},

	toggleClass: function(className){
		return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
	},

	getComputedStyle: function(property){
		var result = null;
		if (this.currentStyle){
			result = this.currentStyle[property.camelCase()];
		} else {
			var computed = this.getWindow().getComputedStyle(this, null);
			if (computed) result = computed.getPropertyValue([property.hyphenate()]);
		}
		return result;
	},

	isBody: function() {
		return this.tagName.toLowerCase() == 'body';
	},

	getPosition: function(relative){
		function objectize(el) {
			if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
			return el;
		}
		if (this.isBody()) return {x: 0, y: 0};
		var el = this, position = {x: 0, y: 0};
		while (el){
			position.x += el.offsetLeft;
			position.y += el.offsetTop;
			el = el.offsetParent;
		}
		var rpos = (relative) ? objectize(relative).getPosition() : {x: 0, y: 0};
		return {x: position.x - rpos.x, y: position.y - rpos.y};
	},

	enrich: function(el){
		if(null==el) return;
		if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
		for( var methodName in this ) {
			if('enrich'==methodName) continue;
			if( 'undefined' == typeof el[methodName] || null == typeof el[methodName] ) {
				el[methodName] = this[methodName];
			}
		}
	}
};