/*******************************************************************************
						Created by GS
*******************************************************************************/

dom = {
	ready : function (func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	},
	
	gebi : function (n) {
		if(!n) return false;
		if(!document.getElementById(n)) return false;
		return document.getElementById(n);
	},
	
	gebc : function (c, t, n) {
		var a = new Array();
		if ( n == null ) n = document;
		if ( t == null ) t = '*';
		var els = n.getElementsByTagName(t);
		var len = els.length;
		var pattern = new RegExp("(^|\\\\s)" + c + "(\\\\s|$)");
		for (i = 0, j = 0; i < len; i++) {
			if (pattern.test(els[i].className)) {
				a[j] = els[i];
				j++;
			}
		}
		return a;
	},
	
	bubbling : function (e) {
		e = this.eie(e); 
		if (!e.cancelBubble) e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		return false;
	},
	
	eie : function (e) {
		if (!e) var e = window.event;
		return e;
	},
	
	bounds : function(o) {
		var left = o.offsetLeft;
		var top = o.offsetTop;

		for (var parent = o.offsetParent; parent; parent = parent.offsetParent) {
			left += parent.offsetLeft;
			top += parent.offsetTop;
		}
		return { left:left, top:top, width:o.offsetWidth, height:o.offsetHeight };
	},
	
	camelize : function (s) {
		return s.replace(/\-(.)/g, function(m, l){return l.toUpperCase()});
	},
	
	clean : function(a) {
		var r = [];
		for ( var i = 0; i < a.length; i++ ) {
			if ( a[i].constructor == String ) {

				if ( !a[i].indexOf("<tr") ) {
					var tr = true;
					a[i] = "<table>" + a[i] + "</table>";
				} else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
					var td = true;
					a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
				}

				var div = document.createElement("div");
				div.innerHTML = a[i];

				if ( tr || td ) {
					div = div.firstChild.firstChild;
					if ( td ) div = div.firstChild;
				}

				for ( var j = 0; j < div.childNodes.length; j++ )
					r[r.length] = div.childNodes[j];
			} else if ( a[i].length && !a[i].nodeType )
				for ( var k = 0; k < a[i].length; k++ )
					r[r.length] = a[i][k];
			else if ( a[i] !== null )
				r[r.length] =
					a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
		}
		return r;
	},
	
	append : function() {
		var a = this.clean(arguments);
		for ( var i = 0; i < a.length; i++ )
			document.body.appendChild( a[i] ); //clone ? a[i].cloneNode(true) : 
	},
	
	etarget : function (e) {
		var o;
		if(e.target) o = e.target;
		else if(e.srcElement) o = e.srcElement;
		if(o.nodeType == 3) o = o.parentNode;
		return o;
	},
	
	ischild : function (s,d) {
		while (s) {
			if (s == d) return true;
			s = s.parentNode;
		}
		return false;
	}
}

