/**
 * Util js object
 * 
 * @version		$Id: util.js 640 2008-03-07 10:54:09Z lucasvanlierop $
 */
var RCSF_Base_Util =
{
	/*
	 * Swaps all the elements of that classname to another one
	 * 
	 * @param	string	oldClassname	old classname	
	 * @param	string	newClassname	new classname
	 * @param	object	oOptions	
	 * 				string	sElementId	optional if only 1 el is supposed to be switched
	 * 				boolean	bReplace	if you want to replace the full classname
	 * TODO: make more use of Prototype?
	 */
	SwapClassName : function (oldClassname, newClassname, oOptions)
	{
		var divs = document.getElementsByClassName(oldClassname)
	
		if(typeof(oOptions) != 'undefined')
		{
			if(oOptions.sElementId)
			{
				// Replaces the full clanname into the new class
				if(oOptions.bReplace == true)
				{
					$(oOptions.sElementId).className = newClassname;
				}
				else
				{
					// get old full classname and then only replace that part
					s_class = $(oOptions.sElementId).className;
					$(oOptions.sElementId).className = s_class.replace(oldClassname,newClassname);
				}
			}		
		}
		else
		{
			for(i=0; i <divs.length;i++)
			{
				divs[i].className = newClassname;
			}
		}
	}
	
	/**
	 * Get the height of a window
	 * 
	 * @author Joep Rongen <joep@rhinocreations.com>
	 * 
	 * TODO: make more use of prototype
	 */	
	,GetWindowHeight : function ()
	{
		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') 
		{
			windowHeight = window.innerHeight;
		}
		else 
		{
			if (document.documentElement && document.documentElement.clientHeight) 
			{
				windowHeight = document.documentElement.clientHeight;
			}
			else 
			{
				if (document.body && document.body.clientHeight) 
				{
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}
	
	
	/**
	 * @author Joep Rongen <joep@rhinocreations.com>
	 *
	 * @return	string	curTime	Current time in hh:mm:ss notation  
	 */
	,GetTime : function ()
	{
		var curDateTime = new Date()
	  	var curHour = curDateTime.getHours()
	  	var curMin = curDateTime.getMinutes()
	  	var curSec = curDateTime.getSeconds()
	  	var curTime = 
	    	((curHour < 10) ? "0" : "") + curHour + ":" 
	    	+ ((curMin < 10) ? "0" : "") + curMin + ":" 
	    	+ ((curSec < 10) ? "0" : "") + curSec 
	  	return curTime;
	}
	
	
	/**
   	 * Removes an element and its child elements
   	 * 
   	 * 
   	 * @param	Object	oEl	Element to remove
   	 */
   	,RemoveElement : function (oEl)
	{
		var a_child_elements = oEl.childElements();
		
		// Remove childs
		for (var i = a_child_elements.length - 1; i > 0; i--)
		{
			//alert(a_child_elements[i].name + ' : ' + a_child_elements[i].id + ' : ' + a_child_elements[i].className);
			RCSF_Base_Util.RemoveElement(a_child_elements[i]);
		}
				
		// Remove element itself
		Element.remove(oEl);
	}	

	
	
	/**
	 * Stores value in object in object recursively
	 * 
	 * @param	Object	oData	Object to store value in
	 * @param	Array	aKey	key(s) location where the value should be stored
	 * @param	mixed	mValue	Value
	 */
	,SetObjectElement : function (oData, aKey, mValue)
	{
		var s_key = aKey.shift();
		if (aKey.length == 0) oData[s_key] = mValue;
		else
		{	
			if (typeof(oData[s_key]) == 'undefined') oData[s_key] = {};
			RCSF_Base_Util.SetObjectElement(oData[s_key], aKey, mValue);
		}
	}	
}
