/* esiscript.js - misc. javascript functions for eng-software.com */

/* Top Menu Functions */

// This function is required for IE (no support of li:hover).
// Displays submenu when parent menu is highlighted.
startList = function() {
	if (document.all&&document.getElementById) {
		var navRoot = document.getElementById("nav");
		if( navRoot ) {
			var nodeList = navRoot.getElementsByTagName( "LI" ) ;
			if( nodeList ) {
				for (i = 0; i < nodeList.length; i++) {
					node = nodeList.item( i ) ;
					if ( node.nodeName == "LI" ) {
						node.onmouseover = function() { this.className+=" over"; }
						node.onmouseout = function() { this.className=this.className.replace(" over", ""); }
					}
				}
			}
		}
	}
}

/* attach function to onload event for the page */
if( window && window.attachEvent ) {
	window.attachEvent("onload", startList);
}

/* Side Nav Functions */

// Displays arrow when mouse is over side nav element.
function displayArrow( arrowId ) {
	if( document.getElementById ) {
		var arrowSpan = document.getElementById( arrowId ) ;
		arrowSpan.style.visibility = "visible" ;
	}
}

// Hides arrow when mouse moves off of the side nav element.
function hideArrow( arrowId ) {
	if( document.getElementById ) {
		var arrowSpan = document.getElementById( arrowId ) ;
		arrowSpan.style.visibility = "hidden" ;	}
}

/* General Helper Functions */

// Opens a new window with the parameters below as options for the standard javascript 
// window.open function.
function NewWindow(mypage, myname, w, h, scrollbars, toolbar, location, status, menubar, resizable)
{
	//var winl = (screen.width - w) / 0 ;
	//var wint = (screen.height - h) / 0 ;
	var winl = 0 ;
	var wint = 0 ;

	winprops =	'height='+h+
				',width='+w+
				',top='+wint+
				',left='+winl+
				',scrollbars='+scrollbars+
				',toolbar='+toolbar+
				',location='+location+
				',status='+status+
				',menubar='+menubar+
				',resizable='+resizable

	win = window.open(mypage, myname, winprops)

	if (parseInt(navigator.appVersion) >= 4)
	{
		win.focus();
	}
}

// Expand "display: none" content to be visible (display: block).
// The image you click on (assumes an image) must be of
// name expand_name where name is the name of the container
// that is hidden (display: none).  This function also hides the 
// image once it is done with expansion.
function expandContent( imgName ) {
	var hiddenName = imgName.replace( "expand_", "" ) ;
	if (document.getElementById) {
		var hiddenElement = document.getElementById( hiddenName ) ;
		var imgElement = document.getElementById( imgName ) ;
		if( hiddenElement.style && imgElement.style ) {
			hiddenElement.style.display = 'block' ;
			imgElement.style.display = 'none' ;
		}
	}
}

// Generic redirect to page to url.
function redirectToPage( url ) {
	document.location.href = url ;
}

function refresh( ) {
	window.location.href = window.location.href ;
}

function submitOnEnter( button ) {
	if( typeof( event ) != 'undefined' && button )
	{
		var key_enter = 13; // 13 = Enter
		if ( key_enter == event.keyCode )
		{
			event.keyCode = 0;
			button.click( );
			return false; // always return false so that caller can suppress event from submitting twice.
		}
	}
	return true; // event was not reached - do whatever processing is supposed to be done.
}