//
// common.js
//

// -------------------------------------------------------------
// cross-browser helper functions
// -------------------------------------------------------------

// Global variables
var isCSS 			= false;
var isW3C 			= false;
var isIE4 			= false;
var isNN4 			= false;
var isIE6 			= false;
var isGecko 		= false;
var isOpera 		= false;
var isDHTML 		= false;
var suppressMenus	= false;
var legacyMode		= false;
var timerID			= null;
var subtimerID		= null;
var resetmain		= null;
var resetsub		= null;
var	resetmenu		= null;
var tempEvent		= null;
var lastPopup		= null;
var resetTime		= 500;

// initialize upon load to let all browsers establish content objects
function autoconfig()
{
    if(document && document.images)
    {
        isCSS		= (document.body && document.body.style) ? true : false;
        isW3C		= (isCSS && document.getElementById) ? true : false;
        isIE4		= (isCSS && document.all && readIEVer() >= 4.0) ? true : false;
        isNN4		= (document.layers) ? true : false;
        isGecko		= (isCSS && navigator && navigator.product && navigator.product == "Gecko");
        isOpera		= (isCSS && navigator.userAgent.indexOf( "Opera") != -1 );
		isIE6CSS	= (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isIE6		= ( isIE6CSS && readIEVer() >= 6.0 );
        isDHTML		= isCSS && ( isIE4 || isGecko || isOpera );

        if( suppressMenus )
        {
			// Netscape 6.2 puts the menus in the wrong place...
			// Safari, the menus don't go away... problem in ResetMenu
			isDHTML	= false;
        }
        else if( isOpera && readOperaVer() < 7 )
        {
			// Opera 6.x doesn't seem to like the DHTML...
			isDHTML	= false;
        }
		else if( isGecko && navigator.productSub <= 20011022 )
        {
			// Netscape 6.2 puts the menus in the wrong place...
			isDHTML	= false;
        }
		else if( isGecko && navigator.productSub == 20030107 )
        {
			// Safari, the menus don't go away... problem in ResetMenu
			isDHTML	= false;
        }
		var bwcv=  getCookie( "bandwidth" );
		var bw	= Bandwidth();
		if ( !(bwcv) || (bw && bwcv && bwcv.indexOf ( bw ) > -1 ))
		{
			SetCookie ( "bandwidth" , bw );
		}
		
    }
}

function readIEVer()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}

function BandWidthRedir (  url )
{
	var		bWidth	= Bandwidth();
	if ( bWidth == "Modem" ) 
	{
		document.location.href = url ;
	}
}
function readOperaVer()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "Opera" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 6 ) );
}

// Seek nested NN4 layer from string name
function seekLayer(doc, name)
{
    var theObj;
    for (var i = 0; i < doc.layers.length; i++)
    {
        if (doc.layers[i].name == name)
		{
            theObj = doc.layers[i];
            break;
        }

        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0)
		{
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

function parentNode(elem)
{
	if( elem.parentElement )
	{
		return elem.parentElement;
	}
	
	if( elem.parentNode )
	{
		return elem.parentNode;
	}

	return null;
}

function contains(lookWhere,lookFor)
{
	if( lookWhere == null || lookFor == null )
	{
		return false;
	}
	
/*	if( lookWhere.contains )
	{
		return lookWhere.contains( lookFor );
	}
	else	*/
	{
		var parent = parentNode( lookFor );
		
		while( parent )
		{
			if( parent == lookWhere )
			{
				return true;
			}
			
			parent = parentNode( parent );
		}
	}
	
	return false;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj)
{
    var theObj;
    if (typeof obj == "string")
    {
        if (isW3C)
		{
			theObj = document.getElementById(obj);

			if( !theObj )
			{
				theObj = document.getElementByName(obj);
			}
		}
		else if (isIE4)
		{
			theObj = document.all(obj);
		}
		else if (isNN4)
		{
			theObj = seekLayer(document, obj);
		}
    } 
    else
    {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj)
{
    var theObj = getRawObject(obj);
    if (theObj && isCSS)
    {
        theObj = theObj.style;
    }
    return theObj;
}

function getObjectsByTag(tag)
{
	if( document.getElementsByTagName )
	{
		return document.getElementsByTagName(tag);
	}
	else if( document.all )
	{
		return document.all.tags(tag);
	}

	return null;
}

// get the element an event refers to
function eventToElement( evt )
{
	var elem = null;
	
	if( evt.target )
	{
		elem = evt.target;
	}
	else if( evt.toElement )
	{
		elem = evt.toElement;
	}
	
	if( elem && elem.nodeName == "#text" )
	{
		elem = elem.parentNode;
	}
	
	return elem;
}

// Set the visibility of an object to visible
function show(obj)
{
    var theObj = getObject(obj);
    if (theObj)
    {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj)
{
    var theObj = getObject(obj);
    if (theObj)
    {
        theObj.visibility = "hidden";
    }
}

// Set the visibility of an object to hidden
function isVisible(obj)
{
    var theObj = getObject(obj);
    return (theObj) ? ( theObj.visibility == "visible" ) : false;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) 
{
    var theObj = getObject(obj);
    if (theObj) 
    {
        if (isCSS) 
        {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = x + units;
            theObj.top = y + units;
        }
        else if (isNN4) 
        {
            theObj.moveTo(x,y)
        }
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj) 
{
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView)
    {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    }
    else if (elem.currentStyle)
    {
        result = elem.currentStyle.left;
    }
    else if (elem.style)
    {
        result = elem.style.left;
    }
    else if (isNN4)
    {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj) 
{
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView)
    {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    }
    else if (elem.currentStyle)
    {
        result = elem.currentStyle.top;
    }
    else if (elem.style)
    {
        result = elem.style.top;
    }
    else if (isNN4)
    {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj) 
{
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth)
    {
        result = elem.offsetWidth;
    }
    else if (elem.clip && elem.clip.width)
    {
        result = elem.clip.width;
    }
    else if (elem.style && elem.style.pixelWidth)
    {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj) 
{
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight)
    {
        result = elem.offsetHeight;
    }
    else if (elem.clip && elem.clip.height)
    {
        result = elem.clip.height;
    }
    else if (elem.style && elem.style.pixelHeight)
    {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// Return the available content width space in browser window
function getInsideWindowWidth() 
{
    if (window.innerWidth)
    {
        return window.innerWidth;
    }
    else if ( isIE6CSS )
    {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    }
    else if (document.body && document.body.clientWidth)
    {
        return document.body.clientWidth;
    }
    return 0;
}

// Return the available content height space in browser window
function getInsideWindowHeight() 
{
    if( window.innerHeight )
    {
        return window.innerHeight;
    }
    else if( isIE6CSS )
    {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight
    }
    else if (document.body && document.body.clientHeight)
    {
        return document.body.clientHeight;
    }
    return 0;
}

// Open a popup window
function winopen(url,stuff,morestuff) 
{
	var popwin = window.open(url,stuff,morestuff);
	
	// you may get "undefined" if a popup blocker did its thing...
	if( typeof(popwin) != "undefined" && popwin )
	{
		popwin.focus();
	}
	
	lastPopup = popwin;
}

// -------------------------------------------------------------
// cookie handling functions
// -------------------------------------------------------------

function getCookie(NameOfCookie) 
{
	if (document.cookie.length > 0) 
	{
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) 
		{
			begin += NameOfCookie.length + 1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) 
			{
				end = document.cookie.length;
			}
			return unescape( document.cookie.substring(begin, end)); 
		} 
	}

	return ""; 
}

function SetCookie (NameOfCookie , value) 
{	
	document.cookie	= NameOfCookie + "=" + escape( value );
}

// Auto Submit the form if valid
function AutoSubmit ( frm )
{
	var		cookieVal	= getCookie ( "autosubmit" );
	if ( cookieVal == document.location )
	{
		var 	submitForm	= window.confirm ( "Resubmit form?");
		if ( submitForm	)
		{
			frm.submit();
			return;
		}
		else
		{
			return;
		}	
		
	}
	SetCookie( "autosubmit" , document.location );
	frm.submit();
}

// Auto Submit Form if Valid/Create Form Freq Popup Window
function AutoSubmit2 ( frm, url, freq )
{
	var oldAction = frm.action;
	frm.action = url;
	var		cookieVal	= getCookie ( "autosubmit" );
	if ( cookieVal == document.location )
	{
		var 	submitForm	= window.confirm ( "Resubmit form?");
		if ( submitForm	)
		{
			if( freq == "true" )
			{
				frm.target = "FreqFormPopup";
				var x = window.open( url, "FreqFormPopup", "width=600, height=400, location=yes, menubar=yes, status=yes, toolbar=yes, scrollbars=yes, resizable=yes" );
			}
			frm.submit();
			frm.target = "_self";
			frm.action = oldAction;
			return;
		}
		else
		{
			return;
		}	
	}
	SetCookie( "autosubmit" , document.location );
	if( freq == "true" )
	{
		frm.target = "FreqFormPopup";
		var x = window.open( url, "FreqFormPopup", "width=600, height=400, location=yes, menubar=yes, status=yes, toolbar=yes, scrollbars=yes, resizable=yes" );
	}
	frm.submit();
	frm.target = "_self";
	frm.action = oldAction;
}

// Dynamic Forms Single Choice Skip Level
function singlechoiceskiplevel( formInput )
{
	if( typeof(formInput) != "undefined" )
	{
		var i = 0;
		while ( i < formInput.length )
		{
			if( formInput[i].value != null && formInput[i].value != "")
			{
				if( document.getElementById(formInput[i].value) != null )
				{
					if( formInput[i].selected || formInput[i].checked )
					{
						document.getElementById(formInput[i].value).style.display = "inline";
					}
					else
					{
						document.getElementById(formInput[i].value).style.display = "none";
					}
				}
			}
			i++;
		}
	}
}

// -------------------------------------------------------------
// menu builder functions
// -------------------------------------------------------------

var m_header		= null;
var m_menu			= null;
var m_subMenu		= null;
var m_subMenuEvtCtl	= null;
var m_hilite		= null;
var m_colorDepth	= 0;
var m_menuArrows	= true;
var m_stdTarget		= " target=\"_blank\"";
var m_stdEmpty		= "";
var m_stdOffImg;

function renderMenuStripSep()
{
	document.write( "<td nowrap=\"1\"><img src=\"" + m_imgPfx + "/images/menu_sep.gif\" width=\"2\" alt=\"\" /></td>" );
}

function menuGoto( url )
{
	hideMenus();
	if ( url != null && url.indexOf( "javascript" ) > -1 )
	{
		eval ( url );
	}
	else
	{
		document.location = url;
	}
	if( event != null )
	{
		event.cancelBubble = true;
	}
	
	return false;
}

function menuWinOpen( url )
{
	hideMenus();
	
	window.open( url );
	
	return false;
}

function renderMenuStrip()
{
	var menuHeaderID;

	if( isIE6 )
	{
		bodyTag.style.behavior	= "url(#default#clientCaps)";
		m_colorDepth			= bodyTag.colorDepth;
	}

	spacing = "&nbsp;&nbsp;";
	if( m_menuBar.length < 4 )
	{
		spacing += spacing;
	}

	var presep = ( m_menuBar.length <= 3 );

	if( presep )
	{
		document.write( "<td class=\"menuMainItem\" nowrap=\"1\">&nbsp;</td>" );
	}
	
	for( n = 0; n < m_menuBar.length; n++ )
	{
		if( n > 0 )
		{
			renderMenuStripSep();
		}
		
		menuHeaderID = m_menuBar[n].Id + "Hdr";

		if( isDHTML )
		{
			document.write( "<td class=\"menuMainItem\"  id=\"" + menuHeaderID + "\" onmouseover=\"showMenu(event, \'" + menuHeaderID + "\', \'" + m_menuBar[n].Id + "\' )\" onmouseout=\"resetMenu(event)\" onclick=\"" );
			
			if( m_menuBar[n].TargetHtml )
			{
				document.write( "return menuWinOpen( \'" + m_menuBar[n].Href + "\' )" );
			}
			else
			{
				document.write( "return menuGoto( \'" + m_menuBar[n].Href + "\' )" );
			}

			document.write( "\" align=\"center\" style=\"cursor:hand\" nowrap=\"1\">" );
			document.write( "<a href=\"" + m_menuBar[n].Href + "\" class=\"menuMainItem\" style=\"text-decoration:none\"" + this.TargetHtml + ">" + spacing + m_menuBar[n].Text );
			
			if( m_menuBar[n].Offjosephacademy )
			{
				document.write( m_stdOffImg );
			}
			
			if( m_menuArrows )
			{
				document.write( "<img src='" + m_imgPfx + "/images/mnmenuarrow.gif' height='7' width='15' alt='' border='0' />" );
				
				if( presep )
				{
					document.write( spacing );
				}
			}
			else
			{
				document.write( spacing );
			}
			
			document.write( "</a></td>" );
		}
		else
		{
			document.write( "<td class=\"menuMainItem\" id=\"" + menuHeaderID + "\" align=\"center\" nowrap=\"1\">" );
			document.write( "<a href=\"" + m_menuBar[n].Href + "\" class=\"menuMainItem\"" + this.TargetHtml + ">" + m_menuBar[n].Text );
			
			if( m_menuBar[n].Offjosephacademy )
			{
				document.write( m_stdOffImg );
			}
			
			document.write( "</a></td>" );
		}
	}
}

function renderItems( menu, z )
{
	renderSubItems( menu, z, "menuItem" );
}

function renderSubItems( menu, z, css )
{
	if( css == "menuItem" )
	{
		document.write( "<table border='0' bgcolor='#CCCCCC' class='menu' width='175' id='" + menu.Id + "' cellspacing='0' cellpadding='3'  style='position:absolute;top:0;left:0;z-index:" + z + ";visibility:hidden' onmouseout='resetMenu(event)' summary='Table for the " + menu.Id + "'>" );
	}
	else
	{
		document.write( "<table border='0' bgcolor='#CCCCCC' class='submenu' width='189' id='" + menu.Id + "' cellspacing='0' cellpadding='3' style='position:absolute;top:0;left:0;z-index:" + z + ";visibility:hidden' onmouseout='resetMenu(event)' onmouseover='clearReset()' summary='Table for the " + menu.Id + "'>" );
	}

	for( var n = 0; n < menu.MenuItems.length; n++ )
	{
		var	item = menu.MenuItems[n];
	
		if( item.IsSeparator )
		{
			document.write( "<tr><td class=\"menuSep\" background=\"" + m_imgPfx + "/images/global/masthead/menu_isep.gif\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" height=\"2\" width=\"1\" alt=\"\" /></td></tr>" );
		}
		else if( item.IsCaption )
		{
			if( n > 0 )
			{
				document.write( "<tr><td class=\"menuSep\" background=\"" + m_imgPfx + "/images/global/masthead/menu_isep.gif\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" height=\"2\" width=\"1\" alt=\"\" /></td></tr>" );
			}
			
			document.write( "<tr><td class=\"menuCaption\"><center><i>" + item.Text + "</i></center></td></tr>" );
			document.write( "<tr><td class=\"menuSep\" background=\"" + m_imgPfx + "/images/global/masthead/menu_isep.gif\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" height=\"2\" width=\"1\" alt=\"\" /></td></tr>" );
		}
		else if( item.MenuItems )
		{
			document.write( "<tr><td nowrap=\"1\" class=\"" + css + "\" onmouseover=\"showSubMenu(event, '" + item.Id + "')\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"subContainer\"><tr><td nowrap=\"1\"><a href=\"" + item.Href + "\" class=\"menuItem\" style=\"text-decoration:none\"" + item.TargetHtml + ">" + item.Text + "</a></td><td nowrap=\"1\" align=\"right\" valign=\"middle\"><img src=\"" + m_imgPfx + "/images/global/masthead/menuarrow.gif\" height=\"7\" width=\"16\" alt=\"\" /></td></tr></table></td></tr>" );
		}
		else
		{
			document.write( "<tr><td nowrap=\"1\" class=\"" + css + "\" onmouseover=\"showSubMenu(event, null )\" onclick=\"" );
			
			if( item.TargetHtml )
			{
				document.write( "return menuWinOpen( \'" + item.Href + "\' )" );
			}
			else
			{
				document.write( "return menuGoto( \'" + item.Href + "\' )" );
			}
			
			document.write( "\"><a href=\"" + item.Href + "\" class=\"menuItem\" style=\"text-decoration:none\"" + item.TargetHtml + ">" + item.Text );
			
			if( item.Offjosephacademy )
			{
				document.write( m_stdOffImg );
			}
			
			document.write( "</a></td></tr>" );
		}
	}
	
	document.write( "</table>" );

	for( var n = 0; n < menu.MenuItems.length; n++ )
	{
		var	item = menu.MenuItems[n];
		
		if( item.MenuItems )
		{
			renderSubItems( item, z + 1, "menuSubItem" );
		}
	}
}

function menuRef( id, text, href, items, target )
{
	this.Id				= id;
	this.Text			= text;
	this.Href			= mhFixupLink( href, "&~ck=mn" );
	this.IsSeparator	= false;
	this.IsCaption		= false;
	this.MenuItems		= items;

	this.Offjosephacademy		= false;
	this.TargetHtml		= m_stdEmpty;

	if( ( typeof(target) != "undefined" ) && target )
	{
		this.Offjosephacademy	= ( target == "offjosephacademy" );
		this.TargetHtml	= " target=\"" + target + "\"";
	}
}

function menuItem( text, href, target )
{
	this.Text			= text;
	this.Href			= mhFixupLink( href, "&~ck=mn" );
	this.IsSeparator	= false;
	this.IsCaption		= false;
	this.MenuItems		= null;

	this.Offjosephacademy		= false;
	this.TargetHtml		= m_stdEmpty;

	if( ( typeof(target) != "undefined" ) && target )
	{
		this.Offjosephacademy	= ( target == "offjosephacademy" );
		this.TargetHtml	= " target=\"" + target + "\"";
	}
}

function menuCaption( text )
{
	this.Text			= text;
	this.Href			= null;
	this.IsSeparator	= false;
	this.IsCaption		= true;
	this.MenuItems		= null;
}

function menuSep()
{
	this.IsSeparator	= true;
	this.IsCaption		= false;
}

// -------------------------------------------------------------
// menu display/hiding functions
// -------------------------------------------------------------

function clearReset()
{
	if( resetsub )
	{
		clearTimeout( resetsub );
		resetsub = null;
	}
	if( resetmain )
	{
		clearTimeout( resetmain );
		resetmain = null;
	}
	if( resetmenu )
	{
		clearTimeout( resetmenu );
		resetmenu = null;
	}
}

function showSubMenu( evt, menuID )
{
	if( resetmenu )
	{
		clearTimeout( resetmenu );
		resetmenu = null;		
	}
	if( !isIE6 )
	{
		clearTimeout( resetsub );
		resetsub = null;
	}
	
	if( menuID != null )
	{
		if( resetsub && isIE6 )
		{
			if( resetmain )
			{
				clearTimeout( resetmain );
				resetmain = null;
			}
			tempEvent = document.createEventObject( evt );
			resetmain = setTimeout( "showSubMenuDelay( " + menuID + " )", resetTime );
		}
		else
		{
			showSubMenuNow( evt, menuID );
		}
	}
	else
	{
		if( isIE6 && resetsub )
		{
			if( resetmain )
			{
				clearTimeout( resetmain );
				resetmain = null;
			}
			tempEvent = document.createEventObject( evt );
			resetmain = setTimeout( "setHiliteDelay()", resetTime );
		}
	}
}

function showSubMenuDelay( menuID )
{
	showSubMenuNow( tempEvent, menuID );
	setHilite( tempEvent );
}

function showSubMenuNow( evt, menuID )
{
	if( isDHTML )
	{	
		evt			= evt ? evt : event;
		
		var top		= -1;
		var left;
		var currentEle;

		var newMenu = getRawObject( menuID );

		if( m_menu.id == m_menuBar[m_menuBar.length - 1].Id )
		{
			left =  m_header.offsetLeft + m_header.offsetWidth - m_menu.offsetWidth - newMenu.offsetWidth + 5 + document.body.offsetLeft;
		}
		else
		{
			left = m_header.offsetLeft + m_menu.offsetWidth + 3;
		}
		if( subtimerID )
		{
			if( newMenu && newMenu == m_subMenu )
			{
				return;
			}		
		
			clearTimeout( subtimerID );
			subtimerID = null;
		}
	
		if( m_subMenu != null)
		{
			if( m_subMenu == newMenu )
			{
				evt.cancelBubble = true;
				return;
			}
			
			if( isVisible(m_subMenu) )
			{
				hideSubMenu();
			}
		}
		
		if( m_hilite )
		{
			m_hilite.className = "";
			m_hilite = null;
		}
		
		m_subMenuEvtCtl = eventToElement( evt );
		m_subMenu		= newMenu;
		
		currentEle		= getHilite( evt );
			
		rowHeight		= ( ( m_menu.offsetHeight ) / ( m_menu.rows.length ) );

		top			+= m_menu.offsetTop - 1;
		if( currentEle )
		{
			top			+= currentEle.rowIndex * rowHeight;
		}
		shiftTo( m_subMenu, left, top );
	
		if( !isVisible(m_subMenu) )
		{
			subtimerID = setTimeout( "showSubMenuTimed()", 100 );
		}
				
		evt.cancelBubble = true;
	}
}

function showSubMenuTimed()
{
	if( m_subMenu == null )
	{
		return;
	}

	if( isIE6 && m_subMenu.filters && m_colorDepth > 8 )
	{
		m_subMenu.filters.item(0).Apply();
		m_subMenu.filters.item(1).Apply();
	}

	show(m_subMenu);

	if( isIE6 && m_subMenu.filters && m_colorDepth > 8 )
	{
		m_subMenu.filters.item(0).Play();
		m_subMenu.filters.item(1).Play();
	}
}

// defines/shows the current header and menu
//
function showMenu( evt, menuHeaderID, menuID )
{	
	clearReset();
	if( isDHTML )
	{
		evt = evt ? evt : event;

		if( timerID )
		{
			clearTimeout( timerID );
			timerID = null;
		}

		if( subtimerID )
		{
			clearTimeout( subtimerID );
			subtimerID = null;
		}

		timerID = setTimeout( "showMenuTimed( '" + menuHeaderID + "', '" + menuID + "')", 200 );

		evt.cancelBubble = true;
	}
}

function showMenuTimed( menuHeaderID, menuID )
{
	var top		= 0;
	var left	= 0;
	var currentEle;

	var newMenu = getRawObject( menuID );

	if(m_header != null && m_menu != null && m_menu != newMenu)
	{
		if( isVisible(m_menu) )
		{
			hideMenu();
			showSelectCtrl();
		}
	}

	m_header			= getRawObject( menuHeaderID );
	m_menu				= newMenu;
	m_header.className	= "menuMainItemSel";
	
	currentEle	= m_header;
		
	// work out the position of the header and its parent elements
	//
	while( currentEle && currentEle.tagName.toLowerCase() != 'body' )
	{
		top			+= currentEle.offsetTop;
		left		+= currentEle.offsetLeft;
		currentEle	 = currentEle.offsetParent;
	}

	top			+= currentEle.offsetTop;
	left		+= currentEle.offsetLeft;
	
	if( menuHeaderID == ( m_menuBar[m_menuBar.length - 1].Id + "Hdr" ) )
	{
		left += m_header.offsetWidth - m_menu.offsetWidth;
	}
	
	// add the width of the header, and width of extra image.
	//
	top += (m_header.offsetHeight);
				
	shiftTo( m_menu, left, top );

	hideSelectCtrl();

	if( !isVisible(m_menu) )
	{
		if( isIE6 && typeof(m_menu.filters) != "undefined" && m_menu.filters && m_colorDepth > 8 )
		{
			m_menu.filters.item(0).Apply();
			m_menu.filters.item(1).Apply();
		}
		
		show(m_menu);

		if( isIE6 && typeof(m_menu.filters) != "undefined" && m_menu.filters && m_colorDepth > 8 )
		{
			m_menu.filters.item(0).Play();
			m_menu.filters.item(1).Play();
		}
	}
}

// Hide the current menu
//
function hideMenu()
{
	if( isDHTML && m_menu )
	{
		hideSubMenu();

		hide(m_menu);
		m_header.className			= "menuMainItem";
		m_menu						= null;
	}
}

function hideSubMenu()
{
	if( isDHTML && m_subMenu )
	{
		hide(m_subMenu);
		m_subMenuEvtCtl				= null;
		m_subMenu					= null;

		clearHilite( m_menu );
	}
	if( resetsub )
	{
		clearTimeout( resetsub );
		resetsub = null;
	}
}

function hideMenus()
{
	if( timerID )
	{
		clearTimeout( timerID );
		timerID = null;
	}
	
	hideMenu();
}

// hide/reset the current menu, but only if we're
// not moving onto the menu itself
//
function resetMenu( evt )
{
	if( !resetsub )
	{
		if( isDHTML )
		{
			evt = evt ? evt : event;

			if( timerID )
			{
				clearTimeout( timerID );
				timerID = null;
			}

			if( m_header != null && m_menu != null )
			{
				var	dest		= eventToElement( evt );
				
				var notSubMenu	= ( m_subMenu != dest && !contains( m_subMenu, dest ) );
				
				// hide the submenu if necessary
				//
				if( m_subMenu && m_subMenuEvtCtl && notSubMenu && m_subMenuEvtCtl != dest && !contains( m_subMenuEvtCtl, dest ) && m_subMenu != dest && !contains( m_subMenu, dest ) )
				{
					if( !resetsub )
					{
						resetsub = setTimeout( "hideSubMenu()", resetTime );
					}	
				}
				
				// proceed if we're not moving onto a menu item
				//
				if( ( !m_subMenu || notSubMenu ) && dest && m_header != dest && !contains( m_header, dest ) && m_menu != dest && !contains( m_menu, dest ) )
				{
					if( !resetsub )
					{
						resetsub = setTimeout( "hideSubMenu()", resetTime );
					}	
					if( !resetmenu )
					{
						resetmenu = setTimeout( "hideMenus()", resetTime);
					}
					m_header.className			= "menuMainItem";

					if( m_hilite )
					{
						m_hilite.className = "";
						m_hilite = null;
					}

					if( !resetsub && !resetmenu )
					{
						m_header							= null;
						m_menu								= null;
						m_hilite							= null;
					}	
					showSelectCtrl();
				}
				// work out what dest highlight
				//
				else if( m_menu || m_subMenu )
				{
					setHilite( evt );
				}

				evt.cancelBubble = true;
			}
		}
	}
}

function setHiliteDelay()
{
	if( typeof(tempEvent) != "undefined" )
	{
		setHilite( tempEvent );
	}
}

function setHilite ( evt )
{
	var hilite = getHilite( evt );
					
	if( hilite )
	{
		if( m_hilite && ( !m_subMenu || contains( m_subMenu, m_hilite ) ) )
		{
			m_hilite.className = "menuSubItem";
			m_hilite = null;
		}

		var content = hilite.innerHTML;
		
		if( content.indexOf( "menuSubItem" ) > 0 )
		{
			m_hilite = hilite;
			m_hilite.className = "menuSubSelRow";
		}
		else if( content.indexOf( "menuItem" ) > 0 )
		{
			m_hilite = hilite;
			m_hilite.className = "menuSelRow";
		}
	}
}

function clearHilite( table )
{
	var	cell, row, count, ix;
	
	count = table.rows.length;
	
	for( ix = 0; ix < count; ix++ )
	{
		table.rows[ix].className = "";
	}
}

function getHilite( evt )
{
	evt			= evt ? evt : event;
	
	var hilite	= null;
	var	to		= eventToElement( evt );
	
	if( to && ( m_menu && contains( m_menu, to ) ) || ( m_subMenu && contains( m_subMenu, to ) ) )
	{
		hilite = to;
		
		while( hilite && hilite.tagName.toLowerCase() != "tr" )
		{
			hilite = parentNode( hilite );
		}
		
		if( hilite )
		{
			var menuTable = parentNode( parentNode( hilite ) );
			
			if( menuTable && menuTable.className && menuTable.className == "subContainer" )
			{
				var container = parentNode( menuTable );
				
				if( container.tagName.toLowerCase() == "td" )
				{
					hilite = parentNode( container );
				}
			}
		}
	}
	
	return hilite;
}

// -------------------------------------------------------------
// HTML workarounds
// -------------------------------------------------------------

// Show SELECT controls (dropdown lists) when menu is hidden
//
function showSelectCtrl()
{
	var obj;
	var tags = getObjectsByTag("select");
	
	for( var i = 0; i <tags.length; i++ )
	{
		obj = tags[i];
		if(obj && obj.offsetParent)
		{
			show(obj);
		}
	}

/*	tags = getObjectsByTag("object");
	
	for( var i = 0; i <tags.length; i++ )
	{
		obj = tags[i];
		if(obj && obj.offsetParent)
		{
			show(obj);
		}
	}	*/
}

// Hide SELECT controls (dropdown lists), otherwise the Select will
// appear on top of the menu (HTML workaround)
//
function hideSelectCtrl()
{
	hideCtrl( getObjectsByTag("select") );
//	hideCtrl( getObjectsByTag("object") );
}

function hideCtrl( tags )
{
	var obj;
	var currentEle;
	var menuHeight;
	var timeout;
	var top			= 0;
	var left		= 0;
	
	for( var i = 0; i < tags.length; i++ )
	{
		obj			= tags[i];
		currentEle	= obj;
	
		while( currentEle && currentEle.tagName.toLowerCase() != 'body' )
		{
			top			+= currentEle.offsetTop;
			left		+= currentEle.offsetLeft;
			currentEle	 = currentEle.offsetParent;
		}

		if(m_menu != null)
		{
			menuHeight = ( m_menu.offsetTop + m_menu.offsetHeight );
			
			if( top < menuHeight )
			{
				if((left < (m_menu.offsetLeft + m_menu.offsetWidth)) && (left + obj.offsetWidth > m_menu.offsetLeft)) 
				{
					hide(obj);
				}
			}
		}

		top		= 0;
		left	= 0;
	}
}

// -------------------------------------------------------------
// client-side masthead
// -------------------------------------------------------------

var m_pnlinks;
var m_crumbs;
var m_mhFixed		= false;
var m_isHome		= false;
var m_isSegHome		= false;
var m_mda			= null;
var m_printLink		= null;
var m_emailLink		= false;
var m_helpLink		= null;
var m_production	= true;
var m_menudef		= "/content/public/menu.aspx";
var m_avgChW		= 6;
var m_crumbRegEx1	= /<.*>/g;
var m_crumbRegEx2	= /&nbsp;/g;
var m_crumbRegEx3	= /&~ck=bt/g;

function writeMHPop()
{
	
	autoconfig();

	writeMHPopInternal( true );
}

function writeMHFlat()
{
	autoconfig();

	writeMHPopInternal( false );
}

function writeMHPopInternal( showClose )
{
	document.writeln( "<a name=\"mastheadtop\"></a>" );

	// top strip
	document.write( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td height=\"19\" bgcolor=\"#8C8C8C\" background=\"" + m_imgPfx + "/images/global/brand/ui/bg_phonestrip.gif\" align=\"right\" valign=\"middle\">" );

	if( m_printLink )
	{
		document.write( "<a href=\"" + m_printLink + "\" class=\"mhTextEmph\">" + m_printText + "</a>" );
	}
	
	if( showClose )
	{
		if( m_printLink )
		{
		document.write( "<span class=\"mhTextEmph\">&nbsp;&nbsp;|&nbsp;&nbsp;</span>" );
		}
		
		document.write( "<a href=\"#\" onclick=\"window.close()\" class=\"mhTextEmph\">" + m_popClose + "</a>" );
	}

	document.write( "<img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" width=\"20\" height=\"1\" /></td></tr>" );

	// main section
	document.write( "<tr><td width=\"122\" height=\"44\" bgcolor=\"#0066CC\"><img src=\"" + m_imgPfx + "/images/global/brand/ui/logo.gif\" alt=\"\" align=\"absmiddle\" border=\"0\" width=\"123\" height=\"28\" /></td></tr>" );
	document.write( "<tr><td bgcolor=\"#004E98\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" width=\"1\"/></td></tr>" );

	if( !legacyMode )
	{
		document.write( "<tr><td bgcolor=\"#ffffff\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"5\" width=\"1\"/></td></tr>" );
	}
	
	document.write( "</table>" );
}

function writeMH( phoneTitle, phoneMsg, phoneTariff, segmentTitle, hasLocale, logoLink, pnmsg )
{
	document.writeln ( "<!-- begin masthead -->");
	autoconfig();

	if ( typeof(m_suppressPrintLink) != "undefined" )
	{
		m_printLink	= null;
	}
	
	if( !m_production && typeof(m_menuBar) == "undefined" )
	{
		document.write( "<div class=\"para\" style=\"color:red; font-weight:bold\">There is a problem with the menu definition. " );
		document.write( "<a href=\"" + m_menudef + "\">Click here to view</a></div>" );
		
		return;
	}

//	document.write( "<xmp>" );
	
	m_mhFixed	= true;
//	m_mda = null;

	m_stdOffImg = "<img src=\"" + m_imgPfx + "/images/global/brand/icons/smextlink.gif\", width=\"16\" height=\"9\" border=\"0\"/>";

	if( isDHTML )
	{
		for( var n = 0; n < m_menuBar.length; n++ )
		{
			renderItems( m_menuBar[n], 100 );
		}
	}
	
	if( typeof(m_printableText) == "undefined" )
	{
		m_printableText = m_printText;
	}
	
	if( typeof(m_helpText) == "undefined" )
	{
		m_helpText = "Help";
	}

	if( document.body )
	{
		document.body.onmouseover	= resetMenu;
		document.body.onmouseout	= resetMenu;
	}
	else
	{
		var bodytags = getObjectsByTag( "body" );
		
		if( bodytags && bodytags.length > 0 )
		{
			bodytags[0].onmouseover	= resetMenu;
			bodytags[0].onmouseout	= resetMenu;
		}
	}
	
	document.writeln( "<a name=\"mastheadtop\"></a>" );
	
	if( m_isHome || hasLocale )
	{
		document.writeln( m_isHome ? m_localeSelector : m_localeSelectLite );
	}
	
	// phone strip
	document.write( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"728\" height=\"19\" bgcolor=\"#8C8C8C\"><tr><td background=\"" + m_imgPfx + "/images/global/brand/ui/bg_phonestrip.gif\" align=\"right\" valign=\"middle\">" );

	if( phoneTitle || phoneMsg )
	{
		document.write( "<span class=\"mhTextEmph\">" );
		
		if( phoneTitle )
		{
			document.write( phoneTitle );
			document.write( " " );
		}

		if( phoneMsg )
		{
			document.write( phoneMsg );
		}
			
		document.write( "</span>" );
	}
	
	if( phoneTariff )
	{
		document.write( "<span class=\"mhTextTrf\"> " + phoneTariff + "</span>" );
	}	
	
	document.writeln( "<img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" width=\"20\" height=\"1\" /></td></tr></table>" );

	// main section
	if( m_isHome )
	{
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\" bgcolor=\"#0066CC\">" );
		document.write( "<tr><td width=\"155\" height=\"44\" valign=\"middle\">" );
		document.write( "<img src=\"" + m_homelogo + "\" alt=\"\" align=\"absmiddle\" border=\"0\" />" );
		document.write( "</td><td valign=\"bottom\" nowrap=\"1\">");
		document.write( "<img src=\"" + m_ctryImg + "\" alt=\"" + m_ctryShort + "\" vspace=\"4\">" );

		if ( flag )
		{
			document.write( "&nbsp;<img src=\"" + m_imgPfx + "/images/global/masthead/smlflags/" + flag  + ".gif\"  alt=\"" + m_ctryShort + "\" border=\"0\" vspace=\"9\" />");
		}

		document.write( "</td><td align=\"right\" valign=\"middle\" nowrap=\"1\">");

		renderSearchLinks();
		
		document.write( "</tr>" );
		document.write( "<tr><td colspan=\"3\" bgcolor=\"#004E98\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" width=\"1\"/></td></tr>" );
		
		document.write( "</table>" );
	}
	else
	{
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\" bgcolor=\"#0066CC\">" );
		document.write( "<tr><td width=\"1\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" height=\"44\" width=\"1\" alt=\"\" border=\"0\" /></td>" );
		document.write( "<td width=\"122\">" );

		// Skip Navigation Link
		document.write( "<a href=\"#skipMH\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"Skip to main content\" border=\"0\" width=\"1\" height=\"1\" /></a>" );
		
		if( logoLink )
		{
			document.write( "<a href=\"" + m_homelink + "\">" );
		}	
		
		document.write( "<img src=\"" + m_imgPfx + "/images/global/brand/ui/logo.gif\" alt=\"\" align=\"absmiddle\" border=\"0\" width=\"123\" height=\"28\" />" );
		
		if( logoLink )
		{
			document.write( "</a>" );
		}	
		
		if(typeof(m_mhTheme) != "undefined")
		{
			if( m_mhTheme != null && m_mhTheme.length>0 )
			{
				document.write( "</td><td width=\"62%\" style=\"background-image: url(" + m_mhTheme + ");background-repeat: no-repeat;background-position:right;\">" );
			}
			else
			{
				document.write( "</td><td width=\"62%\">" );
			}
		}
		else
		{
			document.write( "</td><td width=\"62%\">" );
		}
		
		
		if( flag )
		{
			document.writeln( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td width=\"2\" nowrap=\"1\"><span class=\"mhTitle\">" + m_ctryShort + "&nbsp;</span></td><td><img src=\"" + m_imgPfx + "/images/global/masthead/smlflags/" + flag + ".gif\" alt=\"" + m_ctryName + "\" border=\"0\" /></td></tr></table>" );
		}
		else
		{
			document.writeln( "<div class=\"mhTitle\">" + m_ctryShort + "</div>" );
		}
		
		if( segmentTitle )
		{
			document.write( "<div  class=\"mhTitle\">" );
			
			if( m_seglink )
			{
				document.write( "<a href=\"" + m_seglink + "\" class=\"mhTitleLink\">" );
			}		
			
			document.write( segmentTitle );

			if( m_seglink )
			{
				document.write( "</a>" );
			}
						 
			document.write( "</div></td>" );
		}

		if( m_search )
		{
			document.write( "<td align=\"right\" valign=\"bottom\" width=\"100%\">" );
			document.write( m_search );
		}
		else
		{
			document.write( "<td align=\"right\" valign=\"middle\" width=\"100%\">" );
			renderSearchLinks();
		}

		document.write( "</td><td>&nbsp;</td></tr>" );

		// nav strip
		if( typeof(m_menuBar) != "undefined" && m_menuBar && m_menuBar.length > 0 )
		{
			document.write( "</table><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">" );
			document.write( "<tr><td width=\"728\" bgcolor=\"#006699\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" width=\"728\" height=\"1\" /></td></tr></table>" );
			
			document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\" height=\"24\">" );
			
			if( m_menuBar.length < 4 )
			{
				document.write( "<tr><td bgcolor=\"#0099FF\" background=\"" + m_imgPfx + "/images/global/brand/ui/pn_bg.gif\" align=\"right\">" );
				document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>" );
				renderMenuStripSep();
			}
			else
			{
				document.write( "<tr><td bgcolor=\"#0099FF\" background=\"" + m_imgPfx + "/images/global/brand/ui/pn_bg.gif\">" );
				document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\"><tr>" );
			}
			
			renderMenuStrip();
			document.write( "</tr></table></td></tr></table>" );
		}
		else
		{
			document.write( "<tr><td bgcolor=\"#004E98\" colspan=\"5\"><img src=\"" );
			document.write( m_imgPfx );
			document.write( "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" height=\"1\" width=\"1\" /></td></tr></table>" );
		}
	}

	// pn strip
	document.writeln( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\" bgcolor=\"#e1e1e1\">" );
	document.write( "<tr><td background=\"" + m_imgPfx + "/images/global/brand/ui/pn_shader.gif\" nowrap=\"1\" height=\"21\">&nbsp;" );

	if( pnmsg )
	{
		var plusExp	= /\+/g;
		document.write( "<span class=\"mhTextPnMsg\" id=\"pnmsg\" name=\"pnmsg\">&nbsp;&nbsp;&nbsp;&nbsp;" + pnmsg.replace ( plusExp ," " )   + "</span>" );
	}
	
	if( m_pnlinks )
	{
		document.write( "</td><td align=\"right\" background=\"" + m_imgPfx + "/images/global/brand/ui/pn_shader.gif\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"21\"><tr>" );
		
		for( var n = 0; n < m_pnlinks.length; n++ )
		{
			if( n > 0 )
			{
				document.write( "<td><img src=\"" + m_imgPfx + "/images/global/masthead/secondary_sep.gif\" alt=\"\"></td>" );
			}

			var href = m_pnlinks[n].Href;
			var icon = m_pnlinks[n].Icon;
			
			if( icon )
			{
				document.write( "<td valign=\"middle\"><a href=\"" + href + "\"><img src=\"" + m_imgPfx + "/images/global/brand/icons/" + icon + ".gif\" border=\"0\"  alt=\"\"></a></td>" );
			}
			
			document.write( "<td align=\"left\" valign=\"middle\" nowrap=\"true\"><a class=\"lnk_iconic\" href=\"" + href + "\">" + m_pnlinks[n].Text + "</a></td>" );
		}

		document.write( "<td>&nbsp;</td></tr></table>" );
	}
	
//	document.write( "</table>" );	return;
	
	document.write( "</td></tr></table>" );
	
	document.writeln( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\" bgcolor=\"#e1e1e1\">" );
	document.writeln( "<tr><td bgcolor=\"#666666\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" height=\"1\" width=\"1\" /></td></tr>" );

	// mda
	if( m_mda )
	{
		document.write( "<tr><td bgcolor=\"#e1e1e1\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">");
		//document.write( "<tr><td bgcolor=\"#f5f5f5\" valign=\"middle\" height=\"29\" class=\"title_emph\" style=\"padding-bottom:1px; padding-top:0px; padding-right:10px\">&nbsp;&nbsp;&nbsp;" + m_mda + "</td>" );
		// Changed to conform to new MDA spec - using inline style to avoid changing css (John Tipton)
		document.write( "<tr><td bgcolor=\"#f5f5f5\" valign=\"middle\" height=\"28\" style=\"font-size:10pt;font-weight:bold\" style=\"padding-bottom:0px; padding-top:3px; padding-right:10px\">&nbsp;&nbsp;&nbsp;" + m_mda + "</td>" );

		renderPrintEmailLinks();

		document.write( "</tr>" );
		document.write( "<tr><td bgcolor=\"#999999\"" );

		if( m_printLink || m_emailLink || m_helpLink )
		{
			document.write( " colspan=\"2\"" );
		}		
		
		document.write( "><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" width=\"1\" /></td>" );
		document.write( "</tr></table></td></tr>" );
	}
	
	// Skip Navigation Bookmark
	document.write( "<tr><td><a name=\"skipMH\" ></a></td></tr>" );
		
	// breadcrumbs
	if( !m_isHome && !m_isSegHome && m_crumbs )
	{
		renderCrumbs( false );

		document.writeln( "<tr><td bgcolor=\"#999999\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" width=\"1\" /></td></tr>" );
	}

	if( !legacyMode && !m_isHome )
	{
		document.writeln( "<tr><td bgcolor=\"#ffffff\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"5\" width=\"1\" /></td></tr>" );
	}
	
	document.write( "</table>" );

	document.writeln ( "<!-- end masthead -->");
//	document.write( "</xmp>" );
}

function renderCrumbs( forFooter )
{
	document.write( "<tr><td bgcolor=\"#e1e1e1\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">" );
	document.write( "<tr><td bgcolor=\"#f5f5f5\" valign=\"middle\" height=\"23\" class=\"para_crumb\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + m_backto + ":&nbsp;" );

	var totalw = 710 - ( m_backto.length * m_avgChW );
	
	if( forFooter || !m_mda )
	{
		if( m_printLink )
		{
			totalw -= 20 + ( m_printableText.length * m_avgChW );
		}
		
		if( m_emailLink )
		{
			totalw -= 20 + ( m_emailText.length * m_avgChW );
		}
		
		if( m_helpLink )
		{
			totalw -= 20 + ( m_helpText.length * m_avgChW );
		}
	}

	for( var n = 0; n < 2; n++ )
	{
		if( n >= m_crumbs.length )
		{
			break;
		}
		
		if( n > 0 )
		{
			document.write( "&nbsp;&gt;&nbsp;" );
			totalw -= 16;
		}
		
		href = m_crumbs[n].Href;
		
		if( href )
		{
			if( forFooter )
			{
				href = href.replace( m_crumbRegEx3, "&~ck=bb" );
			}
			
			document.write( "<a class=\"lnk_crumb\" href=\"" + href + "\">" + m_crumbs[n].Text + "</a>" );
		}
		else
		{
			document.write( "<span class=\"crumbsel\">" + m_crumbs[n].Text + "</span>" );
		}
		
		totalw -= crumbWidth( m_crumbs[n].Text );
	}

	var trail = "";

	for( var n = m_crumbs.length - 1; n >= 2; n-- )
	{
		totalw -= crumbWidth( m_crumbs[n].Text ) + 16;
		
		if( totalw < 0 )
		{
			break;
		}

		href = m_crumbs[n].Href;
		
		if( href )
		{
			if( forFooter )
			{
				href = href.replace( m_crumbRegEx3, "&~ck=bb" );
			}

			trail = "&nbsp;>&nbsp;<a class=\"lnk_crumb\" href=\"" + href + "\">" + m_crumbs[n].Text + "</a>" + trail;
		}
		else
		{
			trail = "&nbsp;>&nbsp;<span class=\"crumbsel\">" + m_crumbs[n].Text + "</span>" + trail;
		}
	}
	
	if( trail.length > 0 )
	{
		if( totalw < 0 )
		{
			document.write( "&nbsp;&gt;&nbsp;<span class=\"crumbsel\">...</span>" );
		}
		
		document.write( trail );
	}
			
	document.write( "</td>" );

	if( !m_mda )
	{
		renderPrintEmailLinks();
	}
	
	document.write( "</tr></table></td></tr>" );
}

function crumbWidth( crumb )
{
	var text = crumb.replace( m_crumbRegEx1, "" );
	text = text.replace( m_crumbRegEx2, " " );
	
	var hasUnicode = false;
	
	for( n = 0; n < text.length; n++ )
	{
		if( text.charCodeAt( n ) > 0x1000 )
		{
			hasUnicode = true;
			break;
		}
	}
	
	if( hasUnicode )
	{
		return text.length * m_avgChW;
	}
	else
	{
		return text.length * 6;
	}
}

function renderPrintEmailLinks()
{
	if( m_printLink || m_emailLink || m_helpLink )
	{
		//document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\">" );
		// added the padding to match the MDA (John Tipton)
		document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\" style=\"padding-top:4px\">" );

		document.write( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>" );

		if( m_emailLink )
		{
			var m_emailsubject = document.title;
			if( typeof(m_emailSubject) != "undefined" && m_emailSubject != null && m_emailSubject.length > 0 )
			{
				m_emailsubject = m_emailSubject;
			}
			
			var emailUrl = "javascript:void(document.location.href=" + "'mailto:?subject=" + m_emailsubject + "&body=" +  document.location.href.replace(/%26/g,'%2526').replace(/&/g,'%2526') + "')" ;

			document.write( "<td valign=\"middle\"><a href=\"" + emailUrl + "\"><img src=\"" + m_imgPfx + "/images/global/brand/icons/email.gif\" border=\"0\" alt=\"" + m_emailText + "\" /></a></td>" );
			document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\" nowrap=\"1\" class=\"para_small\"><a class=\"lnk_small\" href=\"" + emailUrl + "\">" + m_emailText + "</a></td>" );
		}			

		if( m_printLink )
		{
			if( m_emailLink )
			{
				document.write( "<td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>" );
			}

			document.write( "<td valign=\"middle\"><a href=\"" + m_printLink + "\"><img src=\"" + m_imgPfx + "/images/global/brand/icons/print.gif\" border=\"0\" alt=\"" + m_printableText + "\" /></a></td>" );
			document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\" nowrap=\"1\" class=\"para_small\"><a class=\"lnk_small\" href=\"" + m_printLink + "\">" + m_printableText + "</a></td>" );
		}			

		if( m_helpLink )
		{
			if( m_emailLink )
			{
				document.write( "<td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>" );
			}

			document.write( "<td valign=\"middle\"><a href=\"" + m_helpLink + "\"><img src=\"" + m_imgPfx + "/images/global/brand/icons/help.gif\" border=\"0\" alt=\"" + m_helpText + "\" /></a></td>" );
			document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\" nowrap=\"1\" class=\"para_small\"><a class=\"lnk_small\" href=\"" + m_helpLink + "\">" + m_helpText + "</a></td>" );
		}			

		document.write( "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></td>" );
	}
}

function renderSearchLinks()
{
	if( m_searchLinks )
	{
		document.write( "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\"><tr>" );
		
		for( var n = 0; n < m_searchLinks.length; n++ )
		{
			if( n > 0 )
			{
				document.write( "<td valign=\"middle\"><img src=\"" + m_imgPfx + "/images/global/brand/ui/mhlnksep.gif\" alt=\"\"></td>" );
			}
			
			var href = m_searchLinks[n].Href;
			var text = m_searchLinks[n].Text;

			document.write( "<td valign=\"middle\"><a href=\"" + href + "\"><img src=\"" + m_imgPfx + "/images/global/brand/ui/secondary.gif\" border=\"0\" alt=\"\"></a></td>" );
			document.write( "<td valign=\"middle\" nowrap=\"1\"><a href=\"" + href + "\" class=\"lnk_main_masthead\">" + text + "</a></td>" );
		}

		document.write( "<td><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" width=\"10\" height=\"1\" width=\"1\" /></td></tr></table>" );
	}
	else
	{
		document.write( "&nbsp;" );
	}
}

function mhFixupLink( href, extra )
{
	if( typeof(extra) == "undefined" )
	{
		extra = "&~ck=mn";
	}
	
	if( href )
	{
		var anchor		= null;
		var anchorix	= href.indexOf( "#" );
		
		if( anchorix != -1 )
		{
			anchor		= href.substr( anchorix );
			href		= href.substr( 0, anchorix );
		}
		
		if( href.indexOf( "?" ) == -1 )
		{
			extra = "?" + extra.substr( 1 );
		}

		if( href.toLowerCase().indexOf( "javascript:" ) == -1 )
		{
			href += extra;
		}
		else
		{
			start = href.indexOf( "?" );
			
			if( start != -1 )
			{
				ix = href.indexOf( "\'", start );
				
				if( ix == -1 )
				{
					ix = href.indexOf( "\\", start );

					if( ix == -1 )
					{
						ix = href.indexOf( "\"", start );
					}
				}
				
				if( ix != -1 )
				{
					href = href.substr( 0, ix ) + extra + href.substr( ix );
				}
			}
		}
		
		if( anchor )
		{
			href += anchor;
		}
	}
	
	return href;
}

function mhLink( text, href, icon, extra )
{
	href = mhFixupLink( href, extra );

	this.Text			= text;
	this.Href			= href;
	this.Icon			= icon;
}

function addPnLink( text, href, icon )
{
	if( !m_pnlinks )
	{
		m_pnlinks = new Array();
	}
	
	m_pnlinks[m_pnlinks.length] = new mhLink( text, href, icon, "&~ck=pn" );
}

function addCrumb( text, href )
{
	if( !m_crumbs )
	{
		m_crumbs = new Array();
	}
	
	m_crumbs[m_crumbs.length] = new mhLink( text, href, null, "&~ck=bt" );
}

// -------------------------------------------------------------
// client-side footer
// -------------------------------------------------------------

function writeFooterLine( color )
{
	document.writeln( "<tr><td bgcolor=\"" + color + "\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" width=\"1\" /></td></tr>" );
}

function writeFooterStart()
{
	var width = ( m_mhFixed ? "728" : "100%" );
	document.write( "<table width=\"" + width + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#ededed\">" );
	document.write( "<tr><td bgcolor=\"white\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" border=\"0\" height=\"8\" width=\"1\" alt=\"\" /></td></tr>" );
	
	if(typeof(m_pageTheme) != "undefined")
	{
		if( m_pageTheme != null && m_pageTheme.length>0 )
		{
			document.write( "<tr><td bgcolor=\"white\"><img src=\"" )
			document.write( m_pageTheme );
			document.write(	"\" border=\"0\" alt=\"\" /></td></tr>" );
		}
	}
	
	if( !m_isHome && m_crumbs ) 
	{
		writeFooterLine( "#999999" );
		renderCrumbs( true );
	}
	
	document.write( "</table>" );
}

function writeFooterMid()
{
	var width	= ( m_mhFixed ? "728" : "100%" );
	var sepCol	= "#cccccc";
	
	if( !m_isHome && m_crumbs )
	{
		sepCol = "#999999";
	}
	
	document.write( "<table width=\"" + width + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#ededed\">" );
	document.write( "<tr><td colspan=\"2\" bgcolor=\"" + sepCol + "\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" alt=\"\" /></td></tr>" );
	document.write( "<tr><td colspan=\"2\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" border=\"0\" height=\"5\" width=\"1\" alt=\"\" /></td></tr><tr><td width=\"" + width + "\" align=\"center\" valign=\"top\">" );
}

function writeFooterBegin()
{
	writeFooterStart();
	writeFooterMid();
}

function writeFooterClose()
{
	document.write( "</td><td><table><tr><td valign=\"middle\"><img src=\"" + m_imgPfx + "/images/global/brand/ui/arrow_top.gif\" alt=\"\" border=\"0\"></td><td valign=\"middle\"><a href=\"#mastheadtop\"><span class=\"para\">" + m_gototop + "</span></a>&nbsp;&nbsp;</td></tr></table></td></tr><TR><td colspan=\"2\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" height=\"5\" width=\"1\" /></td></tr><TR><td colspan=\"2\" bgcolor=\"#cdcdcd\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" height=\"1\" width=\"1\" /></td></tr></table>" );
}

function StripCookieValue ( inVal , removeVal )
{
	if ( !inVal || inVal.length == 0 || !removeVal || removeVal.length == 0 )
	{
		return inVal;
	}
	var idx			= 0;
	var ampIdx		= 0;
	var semiIdx		= 0;
	var len			= 0;
	var repString	= "";
	idx				= inVal.indexOf ( removeVal );
	
	if ( idx > - 1)
	{
		
		ampIdx		= inVal.indexOf (  "&" , idx );
		semiIdx		= inVal.indexOf (  ";" , idx);
		len			= ampIdx ;
		
		
		if ( len == -1 )
		{
			len		= semiIdx; 
		}
		else if ( semiIdx != -1 && semiIdx < len )
		{
			len		= semiIdx;
		}
		
		
		if ( len > -1 )
		{
			
			repString	= inVal.substring( idx , len  );
		}
		else
		{
			repString	= inVal.substr( idx );
		}
		
		
		return inVal.replace (  repString , "" ).replace("&&" , "&" ) ;
		
	}
	return inVal;
}
function RemoveName()
{
	
	var cookie		= getCookie ( "StormPCookie" )
	
	
	if ( cookie && cookie.length > 0 )
	{
		cookie= StripCookieValue( cookie , "fstn" );
		cookie	= StripCookieValue( cookie , "lstn");
		document.cookie	= "StormPCookie=" + cookie  + ";domain=.josephacademy.com";
		
	}
	
	cookie			= getCookie ( "lwp" );
	if ( cookie && cookie.length > 0 )
	{
	
		cookie = StripCookieValue( cookie , "fstn" );
		cookie	= StripCookieValue( cookie , "lstn");
		cookie	= StripCookieValue ( cookie , "fn" );
		document.cookie	= "lwp=" + cookie+ ";domain=.josephacademy.org";
		
	}
}

function Bandwidth()
{
	if( readIEVer() < 5.0 || isOpera || navigator.appVersion.toLowerCase().indexOf("win") == -1 )
	{
		return "NA";
	}
	
	document.body.addBehavior ("#default#clientCaps");
	
	if ( typeof( document.body.connectionType) != "undefined"  ) 
	{
		if ( document.body.connectionType == "modem" )
		{
			return "Modem";
		}
		return "Lan";
	}

}

function FlashLibrary(){
	var t = this;
	var activeX = false;
	t.ieAutoInstall = true;
	t.hasVersion = function(ver){
		t.swf = false;
		if(!ver) ver = 0;
		var n = navigator;
		if(n.plugins && n.plugins.length > 0){
			var m,tp,d,v;
			m = n.mimeTypes;
			tp = 'application/x-shockwave-flash';
			if(m && m[tp] && m[tp].enabledPlugin && m[tp].enabledPlugin.description){
				d = m[tp].enabledPlugin.description;
				v = d.charAt(d.indexOf('.')-1);
				t.swf = (v >= ver) ? true : false;
			}
		}else if(n.appVersion.indexOf("Mac") == -1 && window.execScript){
			for(var i=ver; i<=7&&i!=1&&t.swf!=true; i++){
				execScript('on error resume next: flash.swf=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash'+((i==0)?'':'.'+i)+'"))','VBScript');
			}
			activeX = true;
		}else{
			t.swf = false;
		}
		return t.swf;
	}
	t.getPluginTag = function(swfFile,width,height,bgcolor,ver,altFormat,params){
		
		var s = '';
		var win = (navigator.appVersion.toLowerCase().indexOf("win")!=-1);
		var ie = (navigator.appName=="Microsoft Internet Explorer");
		if(t.hasVersion(ver) && swfFile || win && ie && swfFile && t.ieAutoInstall){
			var additionalParams = '';
			
			var		qPos	= swfFile.indexOf ( "?" )		
	
			if ( qPos > -1 && qPos + 1 < swfFile.length && ver == 6 )
			{
				var	ta			= 'FlashVars';
				var v 			= swfFile.substring ( qPos + 1 );
				swfFile			= swfFile.substring ( 0 , qPos );
				additionalParams += (activeX)?'\t<param name="' + ta + '" value="' + v + '" />\n': ' '+ ta + '="' + v + '"';
			}
			
			if(activeX){
				s = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,21,0" width="'+width+'" height="'+height+'">\n';
				s += '\t<param name="movie" value="'+swfFile+'" />\n';
				s += '\t<param name="quality" value="high" />\n';
				s += '\t<param name="menu" value="false" />\n';
				s += '\t<param name="wmode" value="opaque" />\n';
				s += '\t<param name="bgcolor" value="'+bgcolor+'" />\n';
				s += additionalParams;
				s += altFormat;
				s += '</object>\n\n';
				return s;
			}else{
				s = '<embed src="'+swfFile+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" wmode="opaque" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'"'+additionalParams+'></embed>\n';
				return s;
			}
		}else{
			return altFormat;
		}
	}
}


// -------------------------------------------------------------
// end of common.js
// -------------------------------------------------------------
