var original_contents_height;

function CLayer(id, bSwitch, parent)
{
   this.m_id = id;
   this.m_bSwitch = bSwitch;
   this.m_parent = parent;
}

var Layers = new Array;

function switch_layer()
{
   var args = switch_layer.arguments;
   var index;
   var layer = 0;

   // Is this layer in our array 
   for(index = 0; index < Layers.length; index++)
   {
      if(Layers[index].m_id == args[0])
      {
         layer = Layers[index];
         break;
      }
   }

   if(0 == layer)
   {
      layer = new CLayer(args[0],'hide',args[1]);
      Layers[index] = layer;
   }

   Layers[index].m_bSwitch =
   Layers[index].m_bSwitch=='hide'?'show':'hide';

   MM_showHideLayers(Layers[index].m_id,'',Layers[index].m_bSwitch)

   // if we are closing down the main index, close everything down
   if(index == 0 && Layers[index].m_bSwitch == 'hide')
   {
      var i;
      for(i = 1;i < Layers.length; i++)
      {
      Layers[i].m_bSwitch = 'hide'

      MM_showHideLayers(Layers[i].m_id,'',Layers[i].m_bSwitch)
      }
   }

   // when opening a new layer, close down all other layers with thesame parent
   if(Layers[index].m_bSwitch == 'show')
   {
      var j;
      for(j = 1;j < Layers.length; j++)
      {
         // compare parents, but don't close the newly opened layer
         if(Layers[j].m_parent == Layers[index].m_parent && j != index)
         { 
            Layers[j].m_bSwitch = 'hide';

            MM_showHideLayers(Layers[j].m_id,'',Layers[j].m_bSwitch)
         }
      }
   }
}

function MM_findObj(n, d) { //v3.ppk
   var p,i,x;  if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length)
   {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; if(!(x=d[n])&&d.getElementById)
x=d.getElementById(n);
   for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
   return x;}


function MM_showHideLayers()
{ //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
if ((obj=MM_findObj(args[i]))!=null)
{
v=args[i+2];	
    if (obj.style)
{
obj=obj.style;
v=(v=='show')?'visible':(v='hide')?'hidden':v;
}
    obj.visibility=v;
}

}

function change_text(id, text1, text2)
{
	var obj = MM_findObj(id);
		
	obj.innerText = obj.innerText == text1 ? text2:text1;
}
function MoveFooterToFoot(bReload)
{
	var browserName=navigator.appName; 
	if (browserName=="Netscape")
	    MoveFooterToFoot_Netscape(bReload);
	else
	    MoveFooterToFoot_IE(bReload);
}

function MoveFooterToFoot_IE(bReload)
{
	// get the page divs
	var header_div = MM_findObj("header_id");
	var left_div = MM_findObj("page_left_id");
	var contents_div = MM_findObj("contents_id");
	var right_div = MM_findObj("page_right_id");
//	var footer_div = MM_findObj("footer_id");
    var menu_div = MM_findObj("menu_id");
	
	// get the page height
	var page_height;
	page_height = document.body.offsetHeight;
	
	// get the div heights
    var menu_height = menu_div.offsetHeight;
    var left_height = left_div.offsetHeight;
	var contents_height = contents_div.offsetHeight;
	var right_height = right_div.offsetHeight;
	var header_height = header_div.offsetHeight;
	var footer_height = 0;//footer_div.offsetHeight;
	
	// ############## Do the vertical alignment #################
	// Find the maximum height of the left, right and contents divs
	// (remember the right and contents divs have the menu added)
	//var max_height;
	max_height = max(left_height, contents_height+menu_height);
	max_height = max(max_height, right_height+menu_height);
	
	if(bReload==true)
		original_contents_height = max_height;
	else
		max_height = min(original_contents_height, max_height);
	
	// Resize left, right and contents divs to fill the page height less the header and footer
	var fill_height;
	fill_height = max(page_height - header_height - footer_height, max_height);

    // the contents already has the menu, so reduce it's fill height (and the right div's too)
    var content_fill_height = fill_height - menu_height;
	// fill the page
	left_div.style.height = fill_height + "px";
	contents_div.style.height = content_fill_height + "px";
	right_div.style.height = content_fill_height + "px";
}


function MoveFooterToFoot_Netscape(bReload)
{
	// get the page divs
	var header_div = document.getElementById("header_id");
	var left_div = document.getElementById("page_left_id");
	var contents_div = document.getElementById("contents_id");
	var right_div = document.getElementById("page_right_id");
    var menu_div = document.getElementById("menu_id");
	
	// get the page height
	var page_height;
	page_height = document.body.clientHeight;
	
	// get the div heights
    var menu_height = menu_div.clientHeight;
    var left_height = left_div.clientHeight;
	var contents_height = contents_div.clientHeight;
	var right_height = right_div.clientHeight;
	var header_height = header_div.clientHeight;
	var footer_height = 0;
	
	// ############## Do the vertical alignment #################
	// Find the maximum height of the left, right and contents divs
	// (remember the right and contents divs have the menu added)
	//var max_height;
	max_height = max(left_height+8, contents_height+menu_height);
	max_height = max(max_height, right_height+menu_height);
	
	if(bReload==true)
		original_contents_height = max_height;
	else
		max_height = min(original_contents_height, max_height);
	
	// Resize left, right and contents divs to fill the page height less the header and footer
	var fill_height;
	fill_height = max(page_height - header_height - footer_height, max_height);

    // the contents already has the menu, so reduce it's fill height (and the right div's too)
    var content_fill_height = fill_height - menu_height;
	// fill the page
	left_div.style.height = fill_height + 8 + "px";
	contents_div.style.height = content_fill_height + "px";
	right_div.style.height = content_fill_height + "px";
}


function get_ScreenPosY(id)
{
	var elmnt = MM_findObj(id);
	var r=elmnt.getBoundingClientRect();
	return r.top;
}

function max()
{
	var args = max.arguments;
	if(args[0] > args[1])
	{
		return args[0];
	}
	else
	{
		return args[1];
	}
}

function min()
{
	var args = min.arguments;
	if(args[0] < args[1])
	{
		return args[0];
	}
	else
	{
		return args[1];
	}
}

function change_link(new_id)
{
	// close the open link
	MM_findObj(open_link_id).style.borderBottom = "";
	
	// open the new link
	MM_findObj(new_id).style.borderBottom = "solid black 1px";
	
	open_link_id = new_id;
}
