// hack for ie - mozilla doesn't need this
ActivateDropdownMenu = function() {

	if (document.all&&document.getElementById) {
	
		// Scan through the unordered list for li's containing ul's.
		var navRoot = document.getElementById("williamsNav");

		if(!navRoot) return false;
		
		Item = new Array(navRoot);
		
		
		// Find all the childrend of the navRoot.
		for(i=0; i < Item.length; i++) {
			for(j=0; j < Item[i].childNodes.length; j++) {
				
				// If the child is an unordered list and the parent is a list item...
				if(Item[i].nodeName == 'LI' && Item[i].childNodes[j].nodeName == 'UL') {
					
					if(i <= navRoot.childNodes.length) { // create first level dropdowns
						Item[i].onmouseover=function() {
							// Make the menu appear
							this.className+=" over";
							// Hide any dropdown menus
							FlipFormVisibility(0);
							
						}
						Item[i].onmouseout=function() {
							// Make the menu disappear
							this.className=this.className.replace(" over", "");
							// Unhide any dropdown menus
							FlipFormVisibility(1);
						}
					
					} else { // or sub level dropdowns
						Item[i].onmouseover=function() {
							// Make the menu appear
							this.className+=" subover";
							// Hide any dropdown menus
							FlipFormVisibility(0);
						}
						Item[i].onmouseout=function() {
							// Make the menu disappear
							this.className=this.className.replace(" subover", "");
							// Unhide any dropdown menus
							FlipFormVisibility(1);
						}
					}
				}// end if
				
				// Add the child to the list of children to investigate if it's a list element.
				if(Item[i].childNodes[j].nodeName == 'LI' || Item[i].childNodes[j].nodeName == 'UL') {
					Item.push(Item[i].childNodes[j]);
				}
				
			} // end for j
		} // end for i
	} 
}


/* ----------------------------------------------------------------------
FlipFormVisibility
This function hides and unhides SELECT form items so that the menu will 
appear properly.  We store the form fields in an array so we don't have 
to scan the whole file every time the function is called.
*/
var FormFields = null;
var LastVisibilitySwitch = 1;

function FlipFormVisibility(visible) {

	// Return if we are not changing from the previous state
	if(LastVisibilitySwitch == visible) { return; }
	else { LastVisibilitySwitch = visible; }
	
	// If we haven't gotten the form fields yet do so.
	if(FormFields == null) {
		FormFields = new Array();
		
		if(document.forms) {
			// Get all the form objects into an array.
			Item = new Array();
			for(i=0; i < document.forms.length; i++) {
				Item.push(document.forms[i]);
			}
			// Find all the childNodes of the form objects.
			for(i=0; i < Item.length; i++) {
				for(j=0; j < Item[i].childNodes.length; j++) {
					Item.push(Item[i].childNodes[j]);
				}
				// If the childNode is a SELECT field, store it.
				if(Item[i].nodeName == 'SELECT') {
					FormFields.push(Item[i]);
				}	
			}
		}	
	}
	
	// Flip all the form fields
	for(i=0; i < FormFields.length; i++) {
		FormFields[i].style.visibility = (visible ? 'visible' : 'hidden');
	}
}

// Run the function on load for IE:
//if(document.all && document.getElementById) {window.onload = ActivateDropdownMenu;}
//window.onload=function(){enableTooltips("williamsContainer");}

// Hack for Skye - checks if the the content menu is populated for a page only, but has no <content-menu.php> file included for the category
function hasPageMenu()
{
	var contentMenu = document.getElementById("menuCurrentPage");
	Item = new Array(contentMenu);
	counter=0; 
	
	// Find all the children of the navRoot.
		for(i=0; i < Item.length; i++) 
			for(j=0; j < Item[i].childNodes.length; j++) 
				if(Item[i].childNodes[j].nodeName == 'LI') counter++;
					
   var contentMenu = document.getElementById("menuCategory");
	Item = new Array(contentMenu);
	
	// Find all the childrend of the navRoot.
		for(i=0; i < Item.length; i++) 
			for(j=0; j < Item[i].childNodes.length; j++) 
				if(Item[i].childNodes[j].nodeName == 'LI') counter++;
					
    //Has two blank <li> items for XML validation in case no extra <li> items are added.
    if(counter>2) return true;
	return false;
}

function showDiv(div)
{
	
	
if (document.getElementById)	var style2 = document.getElementById(div).style;
else if (document.all) var style2 = document.all[div].style;
else if (document.layers) document.layers[div].style;
	
	
style2.visibility="visible";
style2.display="block";
}

function hideDiv(div)
{
		
if (document.getElementById)	var style2 = document.getElementById(div).style;
else if (document.all) var style2 = document.all[div].style;
else if (document.layers) document.layers[div].style;
	
	

}

function showHideDiv(div)
{
	
if (document.getElementById)	var style2 = document.getElementById(div).style;
else if (document.all) var style2 = document.all[div].style;
else if (document.layers) document.layers[div].style;
	
if(style2.display=="" || style2.display=="block") 
{
style2.visibility="hidden";
style2.display="none";	
}

else
{
style2.visibility="visible";
style2.display="block";		
}

	
}


function clearSelect(sel)
{
obj = returnObj(sel);

obj.options[0].selected=true;
}

function clearText(text)
{
obj = returnObj(text);

obj.value="";
}



function backtotop()
{
	document.writeln ("<div class='backtotop'><a href='#top'><img src='../image/top.gif' width=15 height=15 alt='Back to Top'></a></div>");
}


// generic  function to return an id by whatever browser you use 
function returnObj(id )
{
  if (document.getElementById)
        return document.getElementById(id);
	
    else if (document.all)
        return document.all[id];
    else if (document.layers)
        return document.layers[id];
		
		
}

//validation for forms
function confirmDelete()
{
	
}

/* ----------------------------------------------------------------------
ActivateSearchForm
This function shows or hides the search form in the page banner.

taken from Nick's Library Page... thanks Nick :-)
*/
function ActivateSearchForm() {
	// If the form exists...
	if(document && document.getElementById && document.getElementById("searchForm")) {
		
		// If the form field is visible
		if(document.getElementById("searchForm").style.visibility == "visible") {
					
			// If there is text in the form field, submit the form.
			if(document.getElementById("searchField") && 
				document.getElementById("searchField").value != "" && document.getElementById("searchField").value!="Search Williams...") {
				
				document.getElementById("searchForm").submit();
				return false;
			}
			
					
			// Otherwise, hide the form.
			document.getElementById("searchForm").style.visibility = "hidden";
			
			return false;
			
		} 
		// If the form field is hidden
		else {
				// Make the form visible.
			document.getElementById("searchForm").style.visibility = "visible";
			// Put the focus on the form field.
			if(document.getElementById("searchField")) {
				document.getElementById("searchField").focus();
			}
			return false;				
		}
		
	}
	// If the script couldn't find the form, return true and allow the user
	// to proceed to the search page.
	return true;
}


/* For HomePage only */
function setHomePageTopWrapperHeight() {


		if(document.getElementById) {
		   var col1 = document.getElementById("newsColumn1");
		   var col2 = document.getElementById("newsColumn2");
		   var wrapper = document.getElementById("topWrapper");
		}
		else if (document.all){
		var col1 = document.all["newsColumn1"];
		var col2 = document.all["newsColumn2"];
		var wrapper = document.all["topWrapper"];
		}
		else return "";
	    
		//Col1		
		var col1height = col1.offsetHeight;	
	    col1.style.height = col1height+"px";
		if(col1height>=240) wrapper.style.height = col1height+"px";
				
		//Col2		
		var col2height = col2.offsetHeight;	
	    col2.style.height = col2height+"px";
		
		if(col2height > col1height && (col2height>=240)) wrapper.style.height = col2height+"px";
	
}

