// $Id: util.js 775 2008-09-04 16:02:17Z ashapiro $

function getObj(name){ // returns an element
  if(document.getElementById) this.obj = document.getElementById(name);
  else if(document.all) this.obj = document.all[name];
  return this.obj;
}
function getElementsByClass(val){ // returns an array of elements
	var all = document.all || document.getElementsByTagName('*');
	var arr = [];
	for(var k = 0; k < all.length; k++)	if(all[k].className == val) arr[arr.length] = all[k];
	return arr;
}
function getElementsByClass2(val, root){ // returns an array of elements
	var all = root.all || root.getElementsByTagName('*');
	var arr = [];
	for(var k = 0; k < all.length; k++)	if(all[k].className == val) arr[arr.length] = all[k];
	return arr;
}
function getElementsByAttrib(node, val){ // returns an array of elements
	var elems = node.getElementsByTagName('*');
	var retval = [];
	for(var i = 0; i < elems.length; i++){
		if(elems[i].getAttribute(val)) retval[retval.length] = elems[i];
	}
	return retval;
}
function realPreviousSibling(node){ // returns previous sibling node
	while(node.previousSibling.nodeType != 1) node = node.previousSibling;
	return node.previousSibling;
}
function realParentNode(node){ // returns parent  node
	while(node.parentNode.nodeType != 1) node = node.parentNode;
	return node.parentNode;
}
function getChildNodes(thisObj){ // returns an array of element child nodes
	var arr = new Array();
	for(var loop = 0; loop < thisObj.childNodes.length; loop++)
		if (thisObj.childNodes[loop].nodeType == 1)	arr[arr.length++] = thisObj.childNodes[loop];
	return arr;
}
function xSwapNode(n1, n2){ // swap two elements in the DOM
	var temp = n2.parentNode;
	var n2 = n1.parentNode.replaceChild(n2, n1);
	var n1 = temp.appendChild(n1);
	temp = null;
	return true;
}

function addEvent(el, type, f, capture){ // Attach events to elements i.e. addEvent(window, 'load', function, false);
	if(el.addEventListener){ el.addEventListener(type, f, capture); return true; }
	else if(el.attachEvent){ var o = el.attachEvent('on' + type, f); return o; }
	else{ el['on' + type] = f; }
}

function leftTrim(s){ // trims off whitespaces on the left of a string
	while (s.substring(0,1) == ' ') s = s.substring(1, s.length); return s;
}
function rightTrim(s){ // trims off whitespaces on the right of a string
	while (s.substring(s.length,s.length-1) == ' ') s = s.substring(0, s.length-1); return s;
}

function getE(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; // defeat Safari bug
		
	return targ;
}
//----------------------------[ Ads post-loading]---------------------------------------------------//

