/////////////////////////////////////////////////////////////////////////////
// Global Variable

strSubMenuOn = '';
strOnID = '0';
mouseOn = 0;


/////////////////////////////////////////////////////////////////////////////
// Navigation Functions

function topNavOn (strID) {
	mouseOn = 1;
	
	if (document.getElementById('subselected'))	document.getElementById('subselected').style.visibility = 'hidden';

	if (strSubMenuOn != '')	document.getElementById(strSubMenuOn).style.visibility = 'hidden';

	if (document.getElementById('sub' + strID)) {
		document.getElementById('sub' + strID).style.visibility = 'visible';
		strSubMenuOn = 'sub' + strID;
	}
	else
		strSubMenuOn = '';

	strOnID = strID
}


function topNavOff () {
	mouseOn = 0;
	setTimeout('checkOff()', 250);
}


function subNavOn () {
	mouseOn = 1;
}


function subNavOff () {
	mouseOn = 0;
	setTimeout('checkOff()', 250);
}


function checkOff () {
	if (!mouseOn) {
		if (document.getElementById('subselected'))	document.getElementById('subselected').style.visibility = 'visible';
		if (strSubMenuOn != '') {
			document.getElementById(strSubMenuOn).style.visibility = 'hidden';
		}
	}
}


/////////////////////////////////////////////////////////////////////////////
// Form String Validation Functions

String.prototype.trim = function() {
	var x = this;

	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}

function textCounter(field, max) {
	if (field.value.length > max) {
	field.value = field.value.substring(0, max);
	alert("Maximum character limit for this field is " + max);
	field.focus();
	return false;
	}
}


/////////////////////////////////////////////////////////////////////////////
// Search Functions

function SearchClick ()
{
	var strTerms = document.getElementById('search_terms').value;
	if (strTerms != '') {
		window.location = '/museum/liberty/site/search_results.asp?terms=' + escape(strTerms);
	}
	else {
		alert('Please enter your search terms');
	}
}

function SearchKeyPress(e, objText)
{
	var strTerms = objText.value;
	if (getKey(e) == 13) {
		StopBubbling(e);
		if (strTerms != '') {
			window.location = '/museum/liberty/site/search_results.asp?terms=' + escape(strTerms);
			return false;
		}
		else {
			alert('Please enter your search terms');
			return false;
		}
	}
	else {
		return true;
	}
}

function getKey(e)
{
	if (window.event) {
		return window.event.keyCode;
	}
	else if (e) {
		return e.which;
	}
	else {
		return null;
	}
}

function StopBubbling(e)
{
	if(window.event && window.event.cancelBubble != null) {
		window.event.cancelBubble = true;
	}
	else if(e && e.stopPropogation) {
		e.stopPropogation();
	}
}	

