// DIV (layer) manipulation routines, cross browser compatible from NS4 upwards.
// following code by RichardH@uk.CUTTHIS.Shopcreator.com, based on code by:
// Federico Sasso (federicosasso@techCUTTHISnologist.com) from comp.lang.javascript newsgroup.
// Also some code modified from http://www.dansteinman.com/dynduo/ (DivWrite)

// NOTE: content of div variables under Opera are returned IN UPPER CASE. Therefore, 
// Best to say things like mydiv.style.visibility.toLowerCase();
//
// TIP: To get divs to work under Netscape 4, define the div like this:
// <div id="name_of_div" style="position:absolute;visibility:hidden;">  (change visibility to "visible" to show).
//
// TIP: Mozilla (Netscape 6+) is case sensitive with Div names - took me ages to realise this was
//      why some code wasn't working under mozilla but fine under everything else!

// This script contains the following functions:
// ------------------------------------------------------------------------------------------------
// GetDiv("name_of_div")  -  returns the div object that you specify via name, so use like:
//       myDiv = GetDiv("name_of_div");
//       myDiv.Style.Visibility = 'hidden';
//
// IsVisible("name_of_div") - returns true or false based on wether given layer is visible or not.
//
// ShowDiv("name_of_div") - Makes the given Div visible on the page.
//
// HideDiv("name_of_div") - Hides the given Div on the page.
//
// DivWrite(DivId,nestref,text) - Use instead of InnerHTML attribute on layers - this one works with netscape4. pass the Div's id, if its within another div, 
//                                pass the parent div as nextref, and the content as "text".
// ------------------------------------------------------------------------------------------------
// that is all.

function GetDiv(aDiv) // pass it a div name, returns the div object, in a cross-browser compatible stylee
{
  if (document.getElementById) // IE5+, NS6+, Opera5+, Gecko/Mozilla,W3C DOM compliant browsers
  {
    return document.getElementById(aDiv);
  } 
  else if (document.all)   // IE4 etc
  {
    return document.all[aDiv];
  }  
  else if (document.layers) // NS4
  {
    return document.layers[aDiv];
  }
  else
  {
  	return null;
  }
}

function GetImg(aImg) // pass it a div name, returns the div object, in a cross-browser compatible stylee
{
  if (document.getElementById) // IE5+, NS6+, Opera5+, Gecko/Mozilla,W3C DOM compliant browsers
  {
    return document.getElementById(aImg);
  } 
  else if (document.all)   // IE4 etc
  {
    return document.all[aImg];
  }  
  else if (document.images) // NS4
  {
    for(y=0; y < document.images.length; y++)
	{
	   if ( document.images[y].name == aImg)
	   {

         return document.images[y];
		}
	}
	return null;
  }
  else
  {
  	return null;
  }
}

function IsVisible(aDiv,Floaty) //returns a boolean
{
  var el;
  var vis=false;

  if (document.getElementById) // IE5+, NS6+, Opera5+, Gecko/Mozilla,W3C DOM compliant browsers
  {
    el = document.getElementById(aDiv);
	if ( Floaty )
	{
   	 	if (el.style.visibility.toLowerCase() == 'visible')
   	     	vis=true;
	}
	else
	{
	   	 if (el.style.display.toLowerCase() == 'block')
   	     	vis=true;
	}
  }  //Opera5 returns the attribute in uppercase => .toLowerCase() return vis;
  else if (document.all)   // IE4 does not implement getElementById()
  {
    el = document.all[aDiv];
	if ( Floaty )
	{
   	 	if (el.style.visibility.toLowerCase() == 'visible')
   	     	vis=true;
	}
	else
	{
	   	 if (el.style.display.toLowerCase() == '')
   	     	vis=true;
	}
  }  //Opera5 returns the attribute in uppercase => .toLowerCase()
  else if (document.layers) // NS4
  {
    el = document.layers[aDiv];
    if (el.visibility == 'show')
        vis=true;
  }
  return vis;
  
}


// Show/Hide functions

function ShowDiv(aDiv,Floaty)
{
  var el;

  if (document.getElementById ) // IE5+, NS6+, Opera5+, Gecko/Mozilla, W3C DOM compliant browsers
  {
    el = document.getElementById(aDiv);

	if ( Floaty)
	   	 el.style.visibility = 'visible';
	else
		el.style.display = 'block';
  }
  else if (document.all)   // IE4 does not implement getElementById()
  {
    el = document.all[aDiv];
		if ( Floaty)
    		el.style.visibility = 'visible';
		else
			el.style.display = '';
  }
  else if (document.layers) // NS4
  {
    el = document.layers[aDiv];
    el.visibility = 'show';
  }


}

function HideDiv(aDiv,Floaty)
{
  var el;
  if (document.getElementById ) // IE5+, NS6+, Opera5+, Gecko/Mozilla, W3C DOM compliant browsers
  {
    el = document.getElementById(aDiv);
	if ( Floaty)
	    el.style.visibility = 'hidden';
	else
		el.style.display = 'none';

  }
  else if (document.all)   // IE4 does not implement getElementById()
  {
    el = document.all[aDiv];
	if ( Floaty)
 	  el.style.visibility = 'hidden';
	else
	  el.style.display = 'none';
  }
  else if (document.layers) // NS4
  {
    el = document.layers[aDiv];
    el.visibility = 'hide';
  }
}

// NOTE: nestref is when the div is nested within another div.
function DivWrite(DivId,nestref,text) 
{
    if(document.all && document.all[DivId].innerHTML)
	  document.all[DivId].innerHTML = text;
	else if (window.netscape && !document.getElementById && parseFloat(navigator.appVersion)>=4)
	{

		var lyr = (nestref)? eval('document.'+nestref+'.document.'+DivId+'.document') : document.layers[DivId].document
		lyr.open()
		lyr.write(text)
		lyr.close()
	}
}

// added by Nick Johns 2005-08-11
function ToggleDiv(aDiv,Floaty)
{
  var el;
 
  if(IsVisible(aDiv,Floaty))
    return HideDiv(aDiv,Floaty);
  else
  	return ShowDiv(aDiv,Floaty);
}
