/////////////////////////////////////////////////////////////////////////////////
//
// Gtools: a library of trivial client side scripting stuff
//
// Version:          0.1
// Copyright:        2004 GVE

// Local windows path
// DOCROOT = 'C:/ISIS Website/Mirror/2004/';
// NLROOT = 'C:/ISIS Website/Mirror/2004/nl/';
// ENROOT = 'C:/ISIS Website/Mirror/2004/en/';

// server path
 DOCROOT = "/2004/";
 NLROOT = "/2004/nl/";
 ENROOT = "/2004/en/";

// unix
//DOCROOT = "/home/www/Mirror/2004/";
//NLROOT = "/home/www/Mirror/2004/nl/";
//ENROOT = "/home/www/Mirror/2004/en/";

/////////////////////////////////////////////////////////////////////////////////

function getEnv()
{
	// kludge to get some browser info
	// FIXMEEEEE
	MOZZ=(!document.all&&document.getElementById);
	IE=document.all;
	IE4=document.body&&document.body.clientHeight;
	//IE 6+ in 'standards compliant mode'
	IE6=document.documentElement&&document.documentElement.clientWidth;
}

//
// Do not allow page to open without frame

function openFrameset( lang, name )
{
   if( parent.location.href == self.location.href )
	{
   	if( lang == 'NL' )
		{
	  		 window.location.replace(NLROOT+name);
		}
		else if( lang == 'EN' )
		{
	   	window.location.replace(ENROOT+name);
		}
	}
}

function openProjectWin( lang, url )
{
	lang == 'NL' ? path = NLROOT: path = ENROOT;
	p = window.open( path+"projects/frameset.html" );
   openProjectFrame( url );
}

function openProjectFrame( url )
{
	//alert(document.addEventListener);
	if( document.readyState != null ) // IE/Opera
	{
	   if( p.document.readyState==null ) // mmm, nothing works yet
	   {
	      setTimeout( "openProjectFrame('"+url+"')", 100 );
	      return;
	   }
		else if( p.document.readyState == 'complete' || p.document.readyState == 'interactive' )
		{
		   if(p.top.frames==null) return; // user closed window?
		   else p.top.frames[3].location.assign( url );
		}
		else setTimeout( "openProjectFrame('"+url+"')", 100 );
	}
	else if( document.addEventListener!=null )
	{
	   if( p.top.frames[3] != null )
	   {
	      p.top.frames[3].location.href = url;
	   }
		else setTimeout( "openProjectFrame('"+url+"')", 100 );
	}
	else p.onload = p.top.frames[3].location.assign( url );
}

// Find frame by framename.
function GetFrameByName( Name )
{
 	// loop frames, assuming single array
 	var fr, i, j;
	for( i = 0; i < top.frames.length; i++ )
	{
	 	if( top.frames[i].name == Name)
		{
		  	 fr = top.frames[i];
			 return fr;
		}
	}
	return 0;
}

function SetInnerHTML( frame, id, txt )
{
 	var fr = GetFrameByName( frame );
 	if( document.readyState != null )
 	{
 	   if( fr.document.readyState == 'complete' || fr.document.readyState == 'interactive' )
      {
         if(fr.document.getElementById( id )!=null) fr.document.getElementById(id).innerHTML = txt;
      }
 	   else
      {
         fr.onreadystatechange = 'SetInnerHTML('+frame+','+id+','+txt+')';
      }
 	}
	else if (document.addEventListener!=null)
	{
		if(fr.document.getElementById( id )!=null)
		{
			fr.document.getElementById(id).innerHTML = txt;
		}
		else fr.document.addEventListener("load", "eval(fr.document.getElementById('"+id+"').innerHTML = '"+txt+"')",false);
	}
	else fr.document.onload = "eval(fr.document.getElementById('"+id+"').innerHTML = '"+txt+"')";
}

// does NOT affect history
function change_frame( frame, url )
{
  var fr = GetFrameByName( frame );
  if(fr!=0) fr.location=url;
}

// *deletes history entry*
function replaceURL( frame, url )
{
 	if( frame != window.name )
	{
 	 	var fr = GetFrameByName( frame );
 	 	if(fr!=0) fr.location.replace( url );
	}
}

function setTitle( title )
{
 	top.document.title=title;
}

// the usual stuff
function showObject( id )
{
	document.getElementById( id ).style.visibility='visible';
}

function hideObject( id )
{
	document.getElementById( id ).style.visibility='hidden';
}

// a little more unusual stuff
function showObjectInFrame( frame, id )
{
	fr = GetFrameByName( frame );
	if( document.readyState != null )
	{
		if( fr.document.readyState == 'complete' || fr.document.readyState == 'interactive' )
		{
			if(fr.document.getElementById( id )!=null) fr.document.getElementById( id ).style.visibility='visible';
		}
		else fr.onreadystatechange = 'showObjectInFrame('+frame+','+id+')';
	}
   else if(document.addEventListener!=null)
	{
		if(fr.document.getElementById( id )!=null)
		{
			fr.document.getElementById( id ).style.visibility='visible';
		}
		else fr.document.addEventListener("load", "eval( fr.document.getElementById('"+id+"').style.visibility='visible')",false);
	}
	else fr.document.onload = "eval( fr.document.getElementById('"+id+"').style.visibility='visible')";
}

function hideObjectInFrame( frame, id )
{
	fr = GetFrameByName( frame );
	if( document.readyState != null )
	{
		if( fr.document.readyState == 'complete' || fr.document.readyState == 'interactive' )
		{
		   if(fr.document.getElementById( id )!=null) fr.document.getElementById( id ).style.visibility='hidden';
		}
		else fr.onreadystatechange = 'hideObjectInFrame('+frame+','+id+')';
	}
   else if(document.addEventListener!=null)
	{
		if(fr.document.getElementById( id )!=null)
		{
			fr.document.getElementById( id ).style.visibility='hidden';
		}
		else fr.document.addEventListener("load", eval( "fr.document.getElementById('"+id+"').style.visibility='hidden'"),false);
	}
	else fr.document.getElementById( id ).style.visibility='hidden';
}

function SetObjVertPos( ob )
{
	document.getElementById(ob).style.visibility = "hidden";
	H = xClientHeight();
	h = xHeight(ob);
	if( H%2 != 0 ) H++;
	if( h%2 != 0 ) h++;
	document.getElementById(ob).style.top = (H/2) - (h/2);
	document.getElementById(ob).style.visibility = "visible";
}

function getWindowHeight()
{
  H = 0;
  if( typeof( window.innerHeight ) == 'number' )
  {
  		H = window.innerHeight;
  }
  else if( document.documentElement && document.documentElement.clientHeight )
  {
  		H = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight )
  {
      H = document.body.clientHeight;
  }
  return H;
}

function getWindowWidth()
{
  W = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
  		W = window.innerWidth;
  }
  else if( document.documentElement && document.documentElement.clientWidth )
  {
  		W = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth )
  {
      W = document.body.clientWidth;
  }
  return W;
}

// begin menu stuff
function setMenuColor( id, color )
{
	document.getElementById( id ).style.color = color;
}

function setMenuFontWeight( id, weight )
{
	document.getElementById( id ).style.fontWeight = weight;
}

function setMenuFontStyle( id, style )
{
	document.getElementById( id ).style.fontStyle = style;
}

function setMenuFont( id, font )
{
	document.getElementById( id ).style.font = font;
}

function setMenuTextDeco( id, style )
{
	document.getElementById( id ).style.textDecoration = style;
}

function onMenuMouseOver( id1, id2 )
{
	setMenuFontWeight( id1, 'bold' );
	setMenuColor( id1, '#FFFFFF' );
	if( id2 != '' )
	{
		document.getElementById( id2 ).src = NLROOT+'projects/mnbt_act.gif';
	}
}

function onMenuMouseOut( id1, id2 )
{
	setMenuFontWeight( id1, 'normal' );
	setMenuColor( id1, '#E5E5E5' );
	if( id2 != '' )
	{
		document.getElementById( id2 ).src = NLROOT+'projects/mnbt.gif';
	}
}

function onClickProjectMenu( id1, id2 )
{
	onMenuMouseOut( top.curItem1, top.curItem2 );
	top.curItem1 = id1;
	top.curItem2 = id2;
	onMenuMouseOver( top.curItem1, top.curItem2 );
	document.getElementById(id1).style.cursor = 'normal'
}

function onProjectMenuMouseOver( id1, id2 )
{
   if(top.curItem1 != id1)
   {
	  setMenuTextDeco( id1, 'underline' );
	  document.getElementById(id2).style.cursor = 'pointer';
   }
   else
   {
   	  document.getElementById(id1).style.cursor = 'normal';
   	  document.getElementById(id2).style.cursor = 'normal';
   }
}

function onProjectMenuMouseOut( id1, id2 )
{
	setMenuTextDeco( id1, 'none' );
	document.getElementById(id2).style.cursor = 'normal';
}
// end menu stuff

