function updateClassName(obj,newclass,classtoreplace) {
	var modifiedclass = obj.className;
	if ((modifiedclass.indexOf(newclass) == -1) || (newclass === "")) { // new class isn't already a part of the class attribute
		if (classtoreplace.length > 0) { // check if user passed a class name to check for
			var rloc = modifiedclass.indexOf(classtoreplace);
			if (rloc != -1) { // if class attribute contains class name to check for
				modifiedclass = modifiedclass.replace(classtoreplace,newclass);
			} else { // append the new class
				modifiedclass = modifiedclass + " " + newclass;
			}
		} else { // append the new class
			modifiedclass = modifiedclass + " " + newclass;
		}
		if(modifiedclass.charAt(modifiedclass.length-1) == " ") {
			modifiedclass = modifiedclass.substring(0,modifiedclass.length-1);
		}
		obj.setAttribute("class", modifiedclass);
		obj.setAttribute("className", modifiedclass);
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function parseElementId(id) {
	var finalid = "";
	var pos = id.lastIndexOf("__");
	if (pos != -1 && id.length > pos+1) {
		finalid =  id.substr(pos+2);
	}
	finalid = parseInt(finalid,10);
	if (isNaN(finalid)) {
		return "";
	} else {
		return finalid;
	}
}

function clearData(obj) {
	var obj_to_clear = obj;
	if(typeof(obj_to_clear) == "string") {
		obj_to_clear = document.getElementById(obj);
	}
	if(obj_to_clear !== null) {
		var idx = obj_to_clear.childNodes.length;
		for (var i = idx - 1; i >= 0; i--) {
			obj_to_clear.removeChild(obj_to_clear.childNodes[i]);
		}
	}
}

function getScriptName() {
	return location.pathname.slice(0,location.pathname.lastIndexOf("/")+1);
}

function getLinkPath(linkobj) {
	var href = linkobj.getAttribute("href").replace(location.protocol+"//"+location.host,"");
	return href.slice(0,href.lastIndexOf("/")+1);
}