//function to find the absolute x coordinate of a DHTML object
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

//function to find the absolute y coordinate of a DHTML object
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//prefix for onmouseover images
var hoversuffix = "_ov";
		
function imagehover( obj, overout, doIt )
{
	if( obj.id == activeMenuItem && doIt != true ) return;
	src = obj.src;
	
	//for toggle check whether obj is hoverd or not
	if( overout == 0 || !overout )
	{
		//hoversuffix not found, then hover item else unhover item
		if( src.indexOf( hoversuffix + "." ) == -1 )
			overout = 1;
		else
			overout = -1;
	}
	
	//unhover
	if( overout < 0 )
	{
		obj.src = src.replace( hoversuffix, "" );
	}
	
	//hover
	else if ( overout > 0 )
	{
		src = src.replace( hoversuffix, "" );
		ext = src.substring( src.lastIndexOf("."), src.length );
		obj.src = src.replace( ext, hoversuffix + ext );
	}
}

function imageSwitcher( obj, newSRC )
{
	if( newSRC == null && obj.oldSRC == null ) return;
	if( newSRC == null )
	{
		obj.src = obj.oldSRC;
	}
	else
	{
		obj.oldSRC	= obj.src;
		obj.src		= newSRC;
	}
	
	return;
}

//preload function for just one image
function preloadImage( src, hover )
{
	//if hover is true, we want to preload the onmouseover image
	if( hover )
	{
		src = src.replace( hoversuffix, "" );
		ext = src.substring( src.lastIndexOf("."), src.length );
		src = src.replace( ext, hoversuffix + ext );
	}
			
	//create imageobject
	tmpImage = new Image( );
	//set preloadprocess handler
	//load image
	tmpImage.src = src;
}

function subhover( row, overout )
{
	//haal tds in row op
	oTd = row.getElementsByTagName( "td" );
	
	//het moeten er drie zijn
	if( oTd.length != 3 ) return;
	
	if( overout > 0 )
		subhover_over( oTd );
	if( overout < 0 )
		subhover_out( oTd );
}

function subhover_over( oTd )
{
	oTd[0].style.backgroundImage	= "url( /images/subnav_bg_left_ov.gif )";
	oTd[1].className				= "submenu_hover";
	oTd[2].style.backgroundImage	= "url( /images/subnav_bg_right_ov.gif )";
}

function subhover_out( oTd )
{
	oTd[0].style.backgroundImage 	= "url( /images/subnav_bg_left.gif )";
	oTd[1].className				= "submenu";
	oTd[2].style.backgroundImage 	= "";
}

function enlargeBlueBarById( id )
{
	//alleen hoofdsubmenu items kunnen de bar verlengen
	if( parseInt( id.replace( "root", "" ) ) < 7 || (parseInt( id.replace( "root", "" ) ) > 12  && parseInt( id.replace( "root", "" ) ) != 295 && parseInt( id.replace( "root", "" ) ) != 260)) return false;
	
	//object ophalen en als het niet bestaat stoppen
	obj = document.getElementById( id );
	if( obj == null ) return;
	
	//positie van object vinden
	minWidth = findPosX( obj );
	
	//currentWidth betalen
	obj = document.getElementById( "submenuLyr" );
	currentWidth = obj.offsetWidth;
	
	if( 150 + parseInt( minWidth ) - parseInt( currentWidth ) > 0 ) enlargeBlueBar( 100 + parseInt( minWidth ) - parseInt( currentWidth ) );
	
	return true;
}

function enlargeBlueBar( newSize )
{
	obj = document.getElementById( "submenuLyr" );
	td = document.createElement( "td" );
	td.style.backgroundColor	= "#161D7C";
	td.style.width				= newSize + "px";
	td.style.height				= "21px";
	td.innerHTML				= "<img src=\"/images/spacer.gif\" alt=\"spacer\" />";
		
	firstElement = obj.getElementsByTagName( "td" );
	obj.insertBefore( td, firstElement[0] );
}

function popup(what, w, h, resize)
{
	if(!w) { w = 500; } 
	if(!h) { h = 400; }
	if(!resize) { resize = "no"; }
	
	var x = (screen.width / 2)-(w / 2);
	var y = (screen.height / 2)-(h / 2);
	var win = window.open(what, '_blank',"toolbar=no,location=no,menubar=no,scrollbars=yes,left=" + x + ",top=" + y + ",width=" + w + ",height=" + h + ",resizable=" + resize + ",status=no");
}

function disable( frm )
{
	//disable all fields in the form
	for( i = 0; i < frm.elements.length; i++ )
	{
		//if the field is an array, then it is a radiobuttonlist
		if( frm.elements[i].length )
			//disable all the radiobuttons
			for( j = 0; j < frm.elements[i].length; j++ )
			{
				//disable
				frm.elements[i][j].disabled = true;
				
				//in MSIE turn the backgroundcolor gray (moz does it automaticly)
				frm.elements[i][j].style.backgroundColor = '#DDDDDD';
			}
		else
		{
			//disable
			frm.elements[i].disabled = true;
			
			//in MSIE turn the backgroundcolor gray (moz does it automaticly)
				if( document.all ) frm.elements[i].style.backgroundColor = '#DDDDDD';
		}
	}
	
	//disable the links inside the form
	anchors = frm.parentNode.getElementsByTagName( "A" );
	
	for( i = 0; i < anchors.length; i++ )
	{
		//make gray
		anchors[i].style.color	= "#CCCCCC";
		//normal cursor
		anchors[i].style.cursor	= "default";
		//onclick do nothin'
		anchors[i].onclick = function( ) { return false;}
	}
}

function neem_optie( id )
{
	url = '/actions/optie_nemen?clusterID=' + id + '&self=' + document.location;
	top.location = url;
}

function show_onrendabeletop( id )
{
	popup( '/popup/help/onrendabeletop?clusterID=' + id, 640, 480 );
}
