// site.js
//

var ver = parseInt(navigator.appVersion);
var ns5 = ((navigator.appName.indexOf("Netscape") != -1) && (ver >= 5));
var ns4 = ((navigator.appName.indexOf("Netscape") != -1) && (ver >= 4 && ver < 5));
var isMac = (navigator.appVersion.indexOf ("Mac") != -1) ? true : false;

// /ir/AnnualReports.aspx windows
function report_window(url) {
	if(navigator.userAgent.indexOf("MSIE") == -1) {
        newwindow = window.open(url,'report','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=710,height=550');
        newwindow.focus();
     } else {
        window.open(url,'report','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=710,height=550');
     }
}

function displayWindow(url, width, height) {
	var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',scrollbars=yes,status=no,toolbar=no,directories=no,menubar=no,location=no,resizable' );
	Win.opener.name = "opener";
}

// find an object by ID
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		header_09_over = newImage("/images/header/header_09-over.gif");
		header_10_over = newImage("/images/header/header_10-over.gif");
		header_13_over = newImage("/images/header/header_13-over.gif");
		header_14_over = newImage("/images/header/header_14-over.gif");
		header_15_over = newImage("/images/header/header_15-over.gif");
		header_16_over = newImage("/images/header/header_16-over.gif");
		header_17_over = newImage("/images/header/header_17-over.gif");
		header_18_over = newImage("/images/header/header_18-over.gif");
		preloadFlag = true;
	}
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*
	Fetches the path portion of a URL, e.g.
				
		input = http://localhost/about.us/board.of.trustees/trustee.profiles.shtml
		output = http://localhost/about.us/board.of.trustees/

*/
function getPathFromURL( url ) {

	return url.substr( 0, url.lastIndexOf( "/" )+1 );
}


/*
	Fetches the path portion of a URL, e.g.
				
		input = http://localhost/about.us/board.of.trustees/trustee.profiles.shtml
		output = http://localhost/about.us/board.of.trustees/

*/
function getStripParamFromURL( url ) {

	if( url.substr( 0, url.lastIndexOf( "?" ) ) != '' )
		return url.substr( 0, url.lastIndexOf( "?" ) );
	else
		return url;
}

/*
	The following is an override variable for the highlightMenuLink() function. To force
	 a menu item to be highlighted, set 'highlightMenuLinkOverride' equal to the EXACT
	 URL specified in the menu's <a href=> tag, e.g.:
	 
	 <script language='javascript'>highlightMenuLinkOverride = 'http://localhost/about.us/board.of.trustees/index.shtml';</script>
		
	 This SHOULD NOT BE DONE HERE -- place the override command anywhere in an editable region.
*/
var highlightMenuLinkOverride = null;

/*
	This function highlights a menu item using three different methods:
	
		1) If highlightMenuLinkOverride has been set to the exact URL (see above), this is used.
		2) An exact URL match is attempted (index pages MUST be named 'index.shtml')
		3) A directory name match is attempted
*/
function highlightMenuLink() {

	// make an alternate 'document.URL' that contains the default page name 'index.shtml'
	//  to make URL matching easier
	if( document.URL.lastIndexOf( '/' ) == document.URL.length-1 ) {
		var documentURL = document.URL.toLowerCase() + 'default.aspx';
	} else {
		var documentURL = document.URL.toLowerCase();
	}

	//
	// Pass #1: check for the override
	//
	if( highlightMenuLinkOverride != null ) {

		// loop through the links in the document
		for( var i=document.links.length-1; i >= 0; i-- ) {
			if( highlightMenuLinkOverride.toLowerCase() == document.links[i].href.toLowerCase() ) {
				document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
				break;
			}
		}				
		return;
	}

	//
	// Pass #2: loop through the links in the document, looking for an EXACT match
	//
	
	// strip the parameters
	docUrl = getStripParamFromURL( documentURL ).toLowerCase();
	
	for( var i = 0; i < document.links.length; i++ ) {
		
		// is this a 'menuLink' class link?
		if( document.links[i].className == 'mmhide_secondaryNav' ) {
		
			// if the end of the href ends in a '#', skip it -- it's probably a test link that goes nowhere
			if( document.links[i].href.lastIndexOf( '#' ) == document.links[i].href.length-1 )
				continue;
		
			// append 'default.aspx' if the <a href=> ends in '/'
			if( document.links[i].href.lastIndexOf( '/' ) == document.links[i].href.length-1 ) {
				if( docUrl.toLowerCase() == document.links[i].href.toLowerCase() + 'default.aspx' ) {
					document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
					return;			
				}
			// otherwise, just compare em'			
			} else {
				if( docUrl.toLowerCase() == document.links[i].href.toLowerCase() ) {
					document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
					return;			
				}
			}
		}
	}
	
	//
	// Pass #3: if an exact match was not found, loop through and look for a directory match
	//
	
		// fetch the directory only
	docUrl = getPathFromURL( documentURL ).toLowerCase();

	for( var i=document.links.length-1; i >= 0; i-- ) {
		
		// if the end of the href ends in a '#', skip it -- it's probably a test link that goes nowhere
		if( document.links[i].href.lastIndexOf( '#' ) == document.links[i].href.length-1 )
				continue;
		
		// is this a 'menuLink' class link?
		if( document.links[i].className == 'mmhide_secondaryNav' ) {
						
			s = getPathFromURL( document.links[i].href ).toLowerCase();		// strip the file
		
			if( s == docUrl.substr( 0, s.length ) ) {						// a match?			
				document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
				return;
			}
		}
	}
}

