
/* (c) josh 2006 */
function showDiv(divId, otherActions) {
	var divElement = document.getElementById(divId);
	divElement.style.display = "";
	divElement.style.visibility = "visible";
	if (otherActions !== null) {
		executeOtherActions(otherActions);
	}
}
function hideDiv(divId, otherActions) {
	var divElement = document.getElementById(divId);
	divElement.style.display = "none";
	divElement.style.visiblity = "hidden";
	if (otherActions !== null) {
		executeOtherActions(otherActions);
	}
}
function toggleDiv(divId, otherActions, eitherActions) {
	var divElement = document.getElementById(divId);
	if (divElement.style.display === "none") {
		divElement.style.display = "";
		executeOtherActions(otherActions);
	} else {
		divElement.style.display = "none";
		executeOtherActions(eitherActions);
	}
}
function executeOtherActions(otherActions) {
	for (var i = 0; i < otherActions.length; i++) {
		eval(otherActions[i]);
	}
}
function addEventBubble(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on" + evType, fn);
			return r;
		} else {
			return false;
		}
	}
}
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on" + evType, fn);
			return r;
		} else {
			return false;
		}
	}
}

function removeEvent(obj, evtype, fn) {
	if (obj.removeEventListener) {
		obj.removeEventListener(evType, fn, true);
		return true;
	} else {
		if (obj.detachEvent) {
			var r = obj.detachEvent("on" + evType, fn);
			return r;
		} else {
			return false;
		}
	}
}
function removeEventbubble(obj, evType, fn) {
	if (obj.removeEventListener) {
		obj.removeEventListener(evType, fn, false);
		return true;
	} else {
		if (obj.detachEvent) {
			var r = obj.detachEvent("on" + evType, fn);
			return r;
		} else {
			return false;
		}
	}
}

function stopBubble(e) 
{ 
	// check for W3C Compliance
	if(e&&e.stopPropagation) 
	{ 
		e.stopPropagation();
	} 
	else
	{ 
		//seems like we're dealing with IE
		window.event.cancelBubble=true;
	} 
}

function domFunction(f, a)
{
	//initialise the counter
	var n = 0;
	
	//start the timer
	var t = setInterval(function()
	{
		//continue flag indicates whether to continue to the next iteration
		//assume that we are going unless specified otherwise
		var c = true;

		//increase the counter
		n++;
	
		//if DOM methods are supported, and the body element exists
		//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] 
		//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			//set the continue flag to false
			//because other things being equal, we're not going to continue
			c = false;

			//but ... if the arguments object is there
			if(typeof a == 'object')
			{
				//iterate through the object
				for(var i in a)
				{
					//if its value is "id" and the element with the given ID doesn't exist 
					//or its value is "tag" and the specified collection has no members
					if
					(
						(a[i] == 'id' && document.getElementById(i) == null)
						||
						(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
					) 
					{ 
						//set the continue flag back to true
						//because a specific element or collection doesn't exist
						c = true; 

						//no need to finish this loop
						break; 
					}
				}
			}

			//if we're not continuing
			//we can call the argument function and clear the timer
			if(!c) { f(); clearInterval(t); }
		}
		
		//if the timer has reached 60 (so timeout after 15 seconds)
		//in practise, I've never seen this take longer than 7 iterations [in kde 3 
		//in second place was IE6, which takes 2 or 3 iterations roughly 5% of the time]
		if(n >= 60)
		{
			//clear the timer
			clearInterval(t);
		}
		
	}, 250);
};

function stopDefault( e ) 
{ 
	//Prevent the default browseraction(W3C) 
	if ( e && e.preventDefault ) 
		e.preventDefault(); 
	//A shortcut for stoping the browser action in IE 
	else 
		window.event.returnValue=false; 
	return false; 
} 

