// Menu function
function fz_toggle_menu( button, menu_id )
{
	// Restore all buttons
	var cont = document.getElementById( "fz_framework_menu" );
	// Loop uls
	for( i=0; i<cont.childNodes.length; i++ )
	{
		var tmp_elem = cont.childNodes[i];
		if( tmp_elem.nodeType != 1 )
			continue;
		// Loop lis
		for( j=0; j<tmp_elem.childNodes.length; j++ )
			if( tmp_elem.childNodes[j].nodeType == 1 )
				tmp_elem.childNodes[j].className = "";
	}
	
	// Set button as active
	button.className = "active";
	
	// Hide all submenus
	var cont = document.getElementById( "fz_framework_submenu" );
	for( i=0; i<cont.childNodes.length; i++ )
		if( cont.childNodes[i].nodeType == 1 )
			cont.childNodes[i].style.display = "none";
	
	// Show requested menu
	document.getElementById( menu_id ).style.display = "block";
}

// Clear search bar
function fz_clear_search( element )
{
	if( element.value == "Sök på FZ" )
		element.value = "";
}

// Clear login bar
function fz_clear_login( element )
{
	element.style.backgroundImage = "none";
}
function fz_restore_login( element )
{
	if( element.value.length == 0 )
		element.style.backgroundImage = "";	
}

// Ad loading function
function loadAd( element, element_to_hide )
{
	// Move element and display it
	var adloader = $( "adloader_" + element );
	adloader.style.display = "block";

	if( !helios_multiadDebug ){
		$( element ).appendChild( adloader );
		// Remove our calling scripts
		var remove = $( "adloader_" + element + "_script1" );
		remove.parentNode.removeChild( remove );
		var remove = $( "adloader_" + element + "_script2" );
		remove.parentNode.removeChild( remove );

		// If loader element contains nothing but text, hide it
		var loader_is_empty = true;
		for( var i=0; i<adloader.childNodes.length; i++ )
			if( adloader.childNodes[i].nodeType != Node.TEXT_NODE && adloader.childNodes[i].className != "admarker" )
				loader_is_empty = false;
		if( loader_is_empty )
		{
			adloader.parentNode.style.display = "none";

			// Hide separate element if requested
			if( null != element_to_hide && $( element_to_hide ).style )
				$( element_to_hide ).style.display = "none";
		}
	}
}

function increaseFontSize( name, defaultSize )
{
	var p = document.getElementsByName( name );
	for( i = 0; i < p.length; i++ )
	{
		if( p[i].style.fontSize )
			var s = parseInt( p[i].style.fontSize.replace( "px", "" ) );
		else
			var s = defaultSize;

		if( s < 24 )
			p[i].style.fontSize = ( s + 1 ) + "px"
	}
}

function decreaseFontSize( name, defaultSize )
{
	var p = document.getElementsByName( name );
	for( i = 0; i < p.length; i++ )
	{
		if( p[i].style.fontSize )
			var s = parseInt( p[i].style.fontSize.replace( "px", "" ) );
		else
			var s = defaultSize;

		if( s > 8 )
			p[i].style.fontSize = ( s - 1 ) + "px"
	}
}

function expandbox( elem )
{
	var tmp = elem;
	if( tmp.id == 'moreinfo_fanin' )
	{
		new Effect.Morph(tmp,{ style:'max-height:100px; color:#ccc', duration:1 });
		tmp.id = 'moreinfo_fanout';
		tmp.title = 'Klicka för att expandera';
	}
	else
	{
		new Effect.Morph(tmp,{ style:'max-height:10000px; color:#585768', duration:1 });
		new Effect.Highlight(tmp,{ startColor:'#ffffcc', duration:0.5 });
		tmp.id = 'moreinfo_fanin';
		tmp.title = 'Klicka för att återställa';
	}
}

function selectAll( id )
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}