var netscape = (navigator.appName.toLowerCase().indexOf("netscape") > -1);
var ns4 = ((navigator.appVersion.charAt(0) == '4') && netscape);
var ie4 = (document.all)? true:false;
var gHide = (ns4) ? "hide" : "hidden";
var gShow = (ns4) ? "show" : "visible";

/* This function is designed for collapsable menus.  It should be used when you want to 
   show/hide a div, and then change an image to indicate to the user that the div is visible/hidden.  
   Arguments:
   		imgName - The name of the image to be changed (the "NAME" attribute in the "IMG" tag).
		imgWhenVisible - a file which will be the source of "imgName" if the accompanying menu is visible.
		imgWhenHidden - opposite of above.
		divToShowHide - The "ID" of the "DIV" tag (menu) that will appear/disappear when this function
						is invoked.
		expandCollapseList - a list (separated by commas, for example, "div1,div2,div3") of "DIV" "ID"s
							 that will move up/down by the height of "divIdToShowHide", depending on whether
							 or not "divIdToShowHide" is visible or hidden.  If this parameter is "null" or
							 undefined (i.e. this function is only called with 4 arguments), all the divs 
							 beneath "divIdToShowHide" are moved up or down.
							 .
*/
function ChangeDivImage(imgName, imgWhenVisible, imgWhenHidden, divIdToShowHide, expandCollapseList) {
	var img = document.images[imgName];
	img.src = (IsHidden(divIdToShowHide)) ? imgWhenVisible : imgWhenHidden;
	ExpandCollapse(divIdToShowHide, expandCollapseList);
}

/* There is a major assumption being made in this program -- the browser lists
   divs according to the top to bottom positioning in which they appear.  The goal of this
   function is that when one div changes display state, only the divs located at a 
   lower y-coordinate will move up or down.  To determine whether a div is "lower" than
   another div, we use the browser's ordering.  This is not a foolproof scheme (see the
   notes accompanying this file). */
function ExpandCollapse(id, expandCollapseList) {
	// First show/hide the div object corresponding to "id".
	ToggleDisplayState(id);
	var mainDivObj = GetDivObject(id);
	var height = GetHeight(id); 
	var yInc = (IsHidden(id)) ? -1 * height : height;
	
	var divsToMove;
	var i;
	if (expandCollapseList == null) {
		var divNames = GetDivNames();	
		divsToMove = new Array(divNames.length);
		// Now move all divs beneath "mainDivObj" up or down depending on
		// whether the main div is visible or not.
		var moveLowerDivs = false;
		var ctr = 0;
		for (i=0; i<divNames.length; i++) {
			if (moveLowerDivs) {
				divsToMove[ctr] = divNames[i];
				ctr++;
			}
			
			if (divNames[i] == id)
				moveLowerDivs = true;
		}
	} else {
		divsToMove = (expandCollapseList != '') ? expandCollapseList.split(",") : new Array(0);
		//alert(divsToMove);
	}
			
	for (i=0; i<divsToMove.length; i++) {
		if (divsToMove[i] != null && divsToMove[i] != '') 
			MoveDiv(divsToMove[i], 0, yInc);
	}	
}


function GetDivNames() {
	// Get all the div names on the page.
	var numDivs;
	if (netscape) {
		numDivs = (ns4) ? document.layers.length : document.getElementsByTagName('div').length;
	} else {
		numDivs = document.all.tags('div').length;
	}
	var divNames = new Array(numDivs);
	var i;
	for (i=0; i<numDivs; i++) {
		if (netscape) {
			divNames[i] = (!ns4) ? document.getElementsByTagName('div')[i].id : document.layers[i].id;	
		} else {
			divNames[i] = document.all.tags('div')[i].id;	
		}
	}
	return divNames;
}

function GetHeight(id) {
	var height;
	if (netscape) {
		var div = GetDivObject(id);
		height = (ns4) ? parseInt(div.clip.height) : parseInt(div.height.substring(0, div.height.indexOf("px")));
	} else {
		height = parseInt(document.all[id].style.height);
	}
	return height;
}

function MoveDiv(id, x, y) {
  var obj = GetDivObject(id);
  obj.xpos = parseInt(obj.left) + parseInt(x);
  obj.ypos = parseInt(obj.top) + parseInt(y);
  obj.left = obj.xpos;
  obj.top = obj.ypos;
}
 
function ToggleDisplayState(id) {
	var divObj = GetDivObject(id);
	if (IsHidden(id)) {
	  divObj.visibility = gShow;
	} else {
	  divObj.visibility = gHide;
	}
}

function IsHidden(id) {
	var divObj = GetDivObject(id);
	return divObj.visibility == gHide;
}

function GetDivObject(id) {
  if (netscape) { 
    return (!ns4) ? document.getElementById(id).style : document.layers[id];
  } else {
    return document.all[id].style;
  }
}

function DoIt() {
	var id = "div" + document.forms[0].id.value;
	ExpandCollapse(id);
}