//
// 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;

// 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 || ( isOpera && readOperaVer() < 7 ) )
        {
			// Opera 6.x doesn't seem to like the DHTML...
			isDHTML	= false;
        }
    }
}

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 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.getElementsByName )
	{
		return document.getElementsByName(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";
        //alert('test1');
    }
}

// Set the visibility of an object to hidden
function hide(obj)
{
    var theObj = getObject(obj);
    if (theObj)
    {
        theObj.visibility = "hidden";
        //alert('test2');
    }
}

// Set the visibility of an object to hidden
function isVisible(obj)
{
    var theObj = getObject(obj);
    return (theObj) ? ( theObj.visibility == "visible" ) : false;
}

// 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) 
{
	window.open(url,stuff,morestuff).focus();
}

// -------------------------------------------------------------
// 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 );
}

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();
}

//Test Function
function SubmitUrl (url)
{

  //alert('test');
  if (window.document.forms.length > 0)		
  {
	//alert(window.document.forms[0].name);

	if (window.document.forms[0].name == 'configform')
	{
		window.document.configform.action = "RedirectASP.asp?Link=" + escape(url);
		window.document.configform.target="_top";
		window.document.configform.submit();
	}
	else if (window.document.forms[0].name == 'frmDelBlade')
	{
		window.document.frmDelBlade.action = "RedirectASP.asp?Link=" + escape(url);
		window.document.frmDelBlade.target="_top";
		window.document.frmDelBlade.submit();
	}
	else	
	{
		window.location = url;
	}
  }
  else
  {
	window.location = url;
  }
}
//Test Function

// -------------------------------------------------------------
// 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;

function renderMenuStrip()
{
	var menuHeaderID;

	if( isIE6 )
	{
		bodyTag.style.behavior	= "url(#default#clientCaps)";
		m_colorDepth			= bodyTag.colorDepth;
	}
	
	for( var n = 0; n < m_menuBar.length; n++ )
	{
		if( n > 0 )
		{
			document.write( "<td nowrap=\"1\"><img src=\"" + m_imgPfx + "/StoreMenu/global/masthead/menu_sep.gif\" width=\"2\" alt=\"\" /></td>" );
		}
		
		menuHeaderID = m_menuBar[n].Id + "Hdr";

		if( isDHTML )
		{
			document.write( "<td class=\"menuMainItem\"  id=\"" + menuHeaderID + "\" onmouseover=\"showMenu(event, \'" + menuHeaderID + "\', \'" + m_menuBar[n].Id + "\' )\" onclick=\"document.location = \'" + m_menuBar[n].Href + "\'\" align=\"center\" style=\"cursor:hand\" nowrap=\"1\">" );
			document.write( "<a target=_top href=\"" + m_menuBar[n].Href + "\" class=\"menuMainItem\" style=\"text-decoration:none\">&nbsp;&nbsp;" + m_menuBar[n].Text );
			
			if(m_menuArrows )
			{
				document.write("<img src='" + m_imgPfx + "/StoreMenu/global/masthead/mnmenuarrow.gif' height='7' width='15' alt='' border='0' />" );				
			}
			else
			{
				document.write( "&nbsp;&nbsp;" );
			}
			document.write( "</a></td>" );
		}
		else
		{
			document.write( "<td class=\"menuMainItem\" id=\"" + menuHeaderID + "\" align=\"center\" nowrap=\"1\">" );
			document.write( "<a target=_top href=\"" + m_menuBar[n].Href + "\" class=\"menuMainItem\">" + m_menuBar[n].Text + "</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)' summary='Table for the " + menu.Id + "'>" );
	}

	for( var n = 0; n < menu.MenuItems.length; n++)
	{
		var	item = menu.MenuItems[n];
		var test = "";
	
		if( item.IsSeparator )
		{
			document.write( "<tr><td class='menuSep' background='" + m_imgPfx + "/StoreMenu/global/masthead/menu_isep.gif'><img src='" + m_imgPfx + "/StoreMenu/global/general/spacer.gif' height='2' width='1' alt='' /></td></tr>" );
		}
		else if( item.IsCaption )
		{
			document.write( "<tr><td class=''>" + item.Text + "</td></tr>" );
		}
		else if( item.MenuItems )
		{
			//modified 21/12/2003
			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 target=_top href='" + item.Href + "' class='menuItem' style='text-decoration:none'>" + item.Text + "</a></td><td nowrap=\"1\" align='right' valign='middle'><img src='" + m_imgPfx + "/StoreMenu/global/masthead/menuarrow.gif' height='7' width='16' alt='' /></td></tr></table></td></tr>" );
		}
		else
		{
			//document.write("var v =" + item.href + "';");
			//alert(item.Href);
			//document.write("<tr><td nowrap=\"1\" class='" + css + "' onclick=\"document.location = \'" + item.Href + "\'\"><a target=_top  href='" + item.Href + "' class='menuItem' style='text-decoration:none'>" + item.Text + "</a></td></tr>" );
			
			document.write("<tr><td nowrap=\"1\" class='" + css + "' onclick=\"SubmitUrl('" + item.Href + "');\"><a class='menuItem' style='text-decoration:none'>" + item.Text + "</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 )
{
	this.Id				= id;
	this.Text			= text;
	this.Href			= href;
	this.IsSeparator	= false;
	this.IsCaption		= false;
	this.MenuItems		= items;
}

function menuItem( text, href )
{
	this.Text			= text;
	this.Href			= href;
	this.IsSeparator	= false;
	this.IsCaption		= false;
	this.MenuItems		= null;
}

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 showSubMenu( evt, menuID)
{
	
	if( isDHTML )
	{
		evt			= evt ? evt : event;
		
		var top		= -1;
		var left	= m_header.offsetLeft + m_menu.offsetWidth + 3;
		var currentEle;
		
		var newMenu = getRawObject( menuID );

		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 );	//.parentElement;
		m_subMenu		= newMenu;
		
		currentEle		= getHilite( evt );
			
		rowHeight		= ( ( m_menu.offsetHeight ) / ( m_menu.rows.length ) );

	//	left		+= currentEle.offsetLeft;
		top			+= m_menu.offsetTop - 1;
		top			+= currentEle.rowIndex * rowHeight;

		m_subMenu.style.left	= left;
		m_subMenu.style.top		= 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 )
{
	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;
	
	// add the width of the header, and width of extra image.
	//
	top += (m_header.offsetHeight);
				
	m_menu.style.left		= left;
	m_menu.style.top		= top;

	hideSelectCtrl();

	if( !isVisible(m_menu) )
	{
		if( isIE6 && m_menu.filters && m_colorDepth > 8 )
		{
			m_menu.filters.item(0).Apply();
			m_menu.filters.item(1).Apply();
		}
		
		show(m_menu);

		if( isIE6 && 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 );
	}
}

// hide/reset the current menu, but only if we're
// not moving onto the menu itself
//
function resetMenu( evt )
{
	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 ) )
			{
				hideSubMenu();
			}	

			// 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 ) )
			{
				hideSubMenu();

				hide(m_menu);
				m_header.className			= "menuMainItem";

				if( m_hilite )
				{
					m_hilite.className = "";
					m_hilite = null;
				}

				m_header							= null;
				m_menu								= null;
				m_hilite							= null;
				showSelectCtrl();
			}
			// work out what dest highlight
			//
			else if( m_menu || m_subMenu )
			{
				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";
					}
				}
			}

			evt.cancelBubble = true;
		}
	}
}

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_production	= true;
var m_menudef		= "/content/public/menudef.aspx";

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 + "/StoreMenu/global/brand/ui/bg_phonestrip.gif\" align=\"right\" valign=\"middle\">" );
	if( m_printLink )
	{
		//modified 21/12/2003
		document.write( "<a target=_top href=\"" + m_printLink + "\" class=\"mhTextEmph\">" + m_printText + "</a>" );
	}
	
	if( showClose )
	{
		if( m_printLink )
		{
		document.write( "<span class=\"mhTextEmph\">&nbsp;&nbsp;|&nbsp;&nbsp;</span>" );
		}
		//modified 21/12/2003
		document.write( "<a target=_top href=\"#\" onclick=\"window.close()\" class=\"mhTextEmph\">" + m_popClose + "</a>" );
	}

	document.write( "<img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" border=\"0\" width=\"20\" height=\"1\" /></td></tr>" );

	// main section
	document.write( "<tr><td width=\"122\" height=\"44\" bgcolor=\"#0066CC\"><img src=\"" + m_imgPfx + "/StoreMenu/global/brand/ui/logo.gif\" align=\"absmiddle\" border=\"0\" width=\"123\" height=\"28\" /></td></tr>" );
	document.write( "<tr><td bgcolor=\"#004E98\" ><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" /></td></tr>" );

	if( !legacyMode )
	{
		document.write( "<tr><td bgcolor=\"#ffffff\" ><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"5\" /></td></tr>" );
	}
	
	document.write( "</table>" );
}

function writeMH( phoneTitle, phoneMsg, phoneTariff, segmentTitle, hasLocale, logoLink, pnmsg )
{
	autoconfig();

	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;
	}
	
	m_mhFixed	= true;

	if( isDHTML )
	{
		for( var n = 0; n < m_menuBar.length; n++ )
		{
			renderItems( m_menuBar[n], 100 );
		}
	}
	
	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=\"721\" height=\"19\" ><tr><td 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 + "/StoreMenu/global/general/spacer.gif\" border=\"0\" width=\"20\" height=\"1\" /></td></tr></table>" );
	// main section
	if( m_isHome )
	{
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"721\" bgcolor=\"#0066CC\">" );
		document.write( "<tr><td width=\"155\" height=\"44\" valign=\"middle\">" );
		document.write( "<img src=\"" + m_homelogo + "\" align=\"absmiddle\" border=\"0\" />" );
		document.write( "</td><td valign=\"bottom\" nowrap=\"1\">");
		document.write( "<img src=\"" + m_ctryImg + "\" vspace=\"4\">" );

		if ( flag )
		{
			document.write( "&nbsp;<IMG src=\"" + m_imgPfx + "/StoreMenu/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 + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" /></td></tr>" );
		
		document.write( "</table>" );
	}
	else
	{
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"721\" background=\"" + m_imgPfx + "/StoreMenu/global/brand/ui/mnbg.GIF\">" );
		document.write( "<tr><td width=\"1\"><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" height=\"44\" width=\"1\" alt=\"\" border=\"0\" /></td>" );
		document.write( "<td width=\"122\">" );

		if( logoLink )
		{
			//modified 21/12/2003
			document.write( "<a target=_top href=\"" + m_homelink + "\">" );
		}	
		
		document.write( "<img src=\"" + m_imgPfx + "/StoreMenu/global/brand/ui/logo.gif\" align=\"absmiddle\" border=\"0\" width=\"123\" height=\"28\" />" );

		if( logoLink )
		{
			document.write( "</a>" );
		}	
		
		document.write( "</td><td nowrap>" );

		if( flag )
		{
			document.writeln( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td width=\"2\" nowrap><span class=\"mhTitleNew\">" + m_ctryShort + "&nbsp;</span></td><td ><img src=\"" + m_imgPfx + "/StoreMenu/global/masthead/smlflags/" + flag + ".gif\" alt=\"" + m_ctryName + "\" border=\"0\" /></td></tr></table>" );
		}
		else
		{
			document.writeln( "<div class=\"mhTitleNew\">" + m_ctryShort + "</div>" );
		}
		
		if( segmentTitle )
		{
			document.write( "<div class=\"mhTitleNew\">" );
			
			if( m_seglink )
			{
				//modified 21/12/2003
				document.write( "<a target=_top href=\"" + m_seglink + deptcode +"\" class=\"mhTitleLinkNew\">" );
			}		
			
			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></table>" );

		// nav strip - table width changed to 667 12/12/2003
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"721\">" );
		document.write( "<tr><td width=\"721\" bgcolor=\"#006699\" ><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\" width=\"721\" height=\"1\" /></td></tr></table>" );
		
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"721\" height=\"20\">" );
		document.write( "<tr><td bgcolor=\"#0099FF\" background=\"" + m_imgPfx + "/StoreMenu/global/brand/ui/menubg.gif\">" );
		document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"721\"><tr>" );
		renderMenuStrip();
		document.write( "</tr></table></td></tr></table>" );
	}

	// pn strip
	document.writeln( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"721\" bgcolor=\"#cccccc\">" );
	document.write( "<tr><td nowrap=\"1\" bgcolor=\"#cccccc\" height=\"21\">&nbsp;" );

	if( pnmsg )
	{
		document.write( "<span class=\"mhTextPnMsg\">&nbsp;&nbsp;&nbsp;&nbsp;" + pnmsg + "</span>" );
	}
	
	if( m_pnlinks )
	{
		document.write( "</td><td align=\"right\" background=\"" + m_imgPfx + "/StoreMenu/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 + "/StoreMenu/global/masthead/secondary_sep.gif\"></td>" );
			}

			var href = m_pnlinks[n].Href;
			var icon = m_pnlinks[n].Icon;
			
			if( icon )
			{
				//modified 21/12/2003
				document.write( "<td valign=\"middle\"><a target=_top href=\"" + href + "\"><img src=\"" + m_imgPfx + "/StoreMenu/global/brand/icons/" + icon + ".gif\" border=\"0\"  alt=\"\"></a></td>" );
			}
			
			//modified 21/12/2003
			document.write( "<td align=\"left\" valign=\"middle\" nowrap=\"true\"><a target=_top 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=\"721\" bgcolor=\"#e1e1e1\">" );
	document.writeln( "<tr><td bgcolor=\"#666666\"><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\" height=\"1\" /></td></tr>" );

	// mda
	if( m_mda )
	{
		document.writeln( "<tr><td bgcolor=\"#e1e1e1\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">");
		document.writeln( "<tr><td bgcolor=\"#f5f5f5\" valign=\"middle\" height=\"21\" class=\"title_emph\">&nbsp;&nbsp;&nbsp;" + m_mda + "</td></tr>" );
		document.writeln( "<tr><td bgcolor=\"#999999\"><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" /></td></tr>" );
		document.writeln( "</table></td></tr>" );
	}
		
	// breadcrumbs
	if( !m_isHome && !m_isSegHome && m_crumbs )
	{
		renderCrumbs();

		document.writeln( "<tr><td bgcolor=\"#999999\"><IMG src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" /></td></tr>" );
	}
	// changed from height 5 to 0
	if( !legacyMode && !m_isHome )
	{
		document.writeln( "<tr><td bgcolor=\"#ffffff\" ><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"0\" /></td></tr>" );
	}
	
	document.write( "</table>" );
}

function renderCrumbs()
{
	document.writeln( "<tr><td bgcolor=\"#e1e1e1\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">" );
	document.write( "<tr><td bgcolor=\"#f5f5f5\" valign=\"middle\" height=\"21\" class=\"para_small\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + m_backto + ":&nbsp;" );
	
	for( var n = 0; n < m_crumbs.length; n++ )
	{
		if( n > 0 )
		{
			document.write( "&nbsp;>&nbsp;" );
		}

		if( m_crumbs[n].Href )
		{
			//modified 21/12/2003
			document.write( "<a  target=_top class=\"lnk_small\" href=\"" + m_crumbs[n].Href + "\">" + m_crumbs[n].Text + "</a>" );
		}
		else
		{
			document.write( "<span class=\"crumbsel\">" + m_crumbs[n].Text + "</span>" );
		}
	}
			
	document.write( "</td>" );

	if( typeof(m_printableText) == "undefined" )
	{
		m_printableText = m_printText;
	}
	
	if( m_printLink || m_emailLink )
	{
		document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\">" );

		document.write( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>" );

		if( m_emailLink )
		{
			var emailUrl = "javascript:void(document.location.href=" + escape( "'mailto:?subject=" + escape(document.title) + "&body=" + escape( document.location.href ) + "')" );
			
			//modified 21/12/2003
			document.write( "<td valign=\"middle\"><a  target=_top href=\"" + emailUrl + "\"><img src=\"" + m_imgPfx + "/StoreMenu/global/brand/icons/email.gif\" border=\"0\" alt=\"" + m_emailText + "\" /></a></td>" );
			document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\" class=\"para_small\"><a target=_top class=\"lnk_small\" href=\"" + emailUrl + "\">" + m_emailText + "</a></td>" );
		}			

		if( m_printLink )
		{
			if( m_emailLink )
			{
				document.write( "<td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>" );
			}
			
			//modified 21/12/2003
			document.write( "<td valign=\"middle\"><a target=_top href=\"" + m_printLink + "\"><img src=\"" + m_imgPfx + "/StoreMenu/global/brand/icons/print.gif\" border=\"0\" alt=\"" + m_printableText + "\" /></a></td>" );
			document.write( "<td bgcolor=\"#f5f5f5\" align=\"right\" valign=\"middle\" class=\"para_small\"><a target=_top class=\"lnk_small\" href=\"" + m_printLink + "\">" + m_printableText + "</a></td>" );
		}			

		document.write( "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></tr>" );
	}
	
	document.write( "</tr></table></td></tr>" );
}

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 + "/StoreMenu/global/brand/ui/mhlnksep.gif\" alt=\"\"></td>" );
			}
			
			var href = m_searchLinks[n].Href;
			var text = m_searchLinks[n].Text;
				
			//modified 21/12/2003	
			document.write( "<td valign=\"middle\"><a target=_top href=\"" + href + "\"><img src=\"" + m_imgPfx + "/StoreMenu/global/brand/ui/secondary.gif\" border=\"0\" alt=\"\"></a></td>" );
			document.write( "<td valign=\"middle\"><a target=_top href=\"" + href + "\" class=\"lnk_main_masthead\">" + text + "</a></td>" );
		}

		document.write( "<td><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" border=\"0\" width=\"10\" height=\"1\" /></td></tr></table>" );
	}
	else
	{
		document.write( "&nbsp;" );
	}
}

function mhLink( text, href, icon )
{
	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 );
}

function addCrumb( text, href )
{
	if( !m_crumbs )
	{
		m_crumbs = new Array();
	}
	
	m_crumbs[m_crumbs.length] = new mhLink( text, href, null );
}

// -------------------------------------------------------------
// client-side footer
// -------------------------------------------------------------

function writeFooterLine( color )
{
	//alert(color);
	document.writeln( "<tr><td bgcolor=\"" + color + "\" ><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" /></td></tr>" );
}

function writeFooterStart()
{
	var width = 721;
	document.write( "<table width=\"" + width + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#ededed\">" );
	document.write( "<tr><td bgcolor=\"white\"><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"8\" width=\"1\" alt=\"\" /></td></tr>" );

	if( !m_isHome && m_crumbs ) 
	{
		writeFooterLine( "#999999" );
		renderCrumbs();
	}
	
	document.write( "</table>" );
}

function writeFooterMid()
{
	var width	= 721;
	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 + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" alt=\"\" /></td></tr>" );
	document.write( "<tr><td colspan=\"2\" ><img src=\"" + m_imgPfx + "/StoreMenu/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 + "/StoreMenu/global/brand/ui/arrow_top.gif\" 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 + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"5\" width=\"1\" /></td></tr><TR><td colspan=\"2\" bgcolor=\"#cdcdcd\"><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" /></td></tr></table>" );
}

function writeFooterEnd()
{
	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 + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" alt=\"\" /></td></tr>" );
	document.write( "<tr><td colspan=\"2\" ><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"5\" width=\"1\" alt=\"\" /></td></tr><tr><td width=\"" + width + "\" align=\"center\" valign=\"top\">" );
	document.write( m_birdseed );
	document.write( "</td><td><table><tr><td valign=\"middle\"><img src=\"" + m_imgPfx + "/StoreMenu/global/brand/ui/arrow_top.gif\" 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 + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"5\" width=\"1\" /></td></tr><TR><td colspan=\"2\" bgcolor=\"#cdcdcd\"><img src=\"" + m_imgPfx + "/StoreMenu/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" /></td></tr></table>" );
}

function writeFooter()
{
	writeFooterStart();
	writeFooterEnd();
}

// -------------------------------------------------------------
// end of common.js
// -------------------------------------------------------------
