/**
 *	This file is &copy; 2004 Ikomm
 *
 *	Base functionality for DF
 */

// {{{ function addLoadEvent( func )
/**
 *	Add a new window onload event.
 *	The events are stacked and will be run as they are set on this func.
 */
function addLoadEvent( func ) {
	var oldonload = window.onload;
	if( typeof window.onload != 'function' ) {
		window.onload = func;
	}else{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
// 2}}}

// {{{ getElementByClass( classname )
/**
 *	Similar functionality like getElementById(), but for
 *	class names.
 *
 *	@param classname string Name of the classes you want to retrieve.
 *	@return array Array of tags with "classname" as class
 */
function getElementByClass( classname )
{
	var inc = 0;
	var ret = new Array();
	var alltags = document.all ? document.all : document.getElementsByTagName( "*" );
	for( i = 0; i < alltags.length; i++ )
	{
		if( alltags[i].className == classname )
		{
			ret[inc++] = alltags[i];
		}
	}
	return ret;
} 
// 2}}}

// {{{ function searchSelectedText()
/**
 *	Search the text highlighted in the browser.
 */
function searchSelectedText()
{
	if( document.getElementById )
	{
		var cat = document.getElementById( "topsearchcat" );
	}
	else if( document.all )
	{
		var cat = document.all["topsearchcat"];
	}
	else if( document.layers )
	{
		var cat = document.layers["topsearchcat"];
	}
	var s = "";
	if( window.getSelection )
	{
		s = window.getSelection().toString();
	}
	else if( document.selection && document.selection.createRange )
	{
		var range = document.selection.createRange();
		s = range.text.toString();
	}
	if( s == "" )
	{
		alert( "Merk deler av teksten du vil søke etter først!" );
		return;
	}
	document.location = "/search?s=" + s +"&category=" + cat.options.item(cat.selectedIndex).attributes.getNamedItem( "value" ).value;
}
// }}}
