//
// 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 ) || ( isGecko && navigator.productSub <= 20011022 ) || ( isGecko && navigator.productSub == 20030107 ) )
        {
			// Opera 6.x doesn't seem to like the DHTML...
			// Netscape 6.2 puts the menus in the wrong place...
			// Safari, the menus don't go away... problem in ResetMenu
			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 ) );
}

// -------------------------------------------------------------
// 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 menuItem( text, href )
{
	this.Text			= text;
	this.Href			= href;
	this.IsSeparator	= false;
	this.IsCaption		= false;
	this.MenuItems		= null;
}

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;

	document.writeln( "<a name=\"mastheadtop\"></a>" );
	document.writeln( m_localeSelector );
	
	// 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\" border=\"0\" width=\"20\" height=\"1\" /></td></tr></table>" );

	// main section
	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 + "\" 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 + "/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\" /></td></tr>" );
	
	document.write( "</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 )
	{
		document.write( "<span class=\"mhTextPnMsg\">&nbsp;&nbsp;&nbsp;&nbsp;" + pnmsg + "</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\"></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( "</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\" /></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 + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"1\" /></td></tr>" );
		document.writeln( "</table></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 )
		{
			document.write( "<a 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 ) + "')" );
			
			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\" 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\" class=\"para_small\"><a 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 + "/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\"><a href=\"" + href + "\" class=\"lnk_main_masthead\">" + text + "</a></td>" );
		}

		document.write( "<td><img src=\"" + m_imgPfx + "/images/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 )
{
	document.writeln( "<tr><td bgcolor=\"" + color + "\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\"  height=\"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>" );

	document.write( "</table>" );
}

function writeFooterMid()
{
	var width	= ( m_mhFixed ? "728" : "100%" );
	var sepCol	= "#cccccc";
	
	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\" 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\" border=\"0\" height=\"5\" width=\"1\" /></td></tr><TR><td colspan=\"2\" bgcolor=\"#cdcdcd\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" /></td></tr></table>" );
}

function writeFooterEnd()
{
	var width	= ( m_mhFixed ? "728" : "100%" );
	var sepCol	= "#cccccc";
	
	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\">" );
	document.write( m_birdseed );
	document.write( "</td><td><table><tr><td valign=\"middle\"><img src=\"" + m_imgPfx + "/images/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 + "/images/global/general/spacer.gif\" border=\"0\" height=\"5\" width=\"1\" /></td></tr><TR><td colspan=\"2\" bgcolor=\"#cdcdcd\"><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" border=\"0\" height=\"1\" width=\"1\" /></td></tr></table>" );
}

function writeFooter()
{
	writeFooterStart();
	writeFooterEnd();
}

// -------------------------------------------------------------
// end of common.js
// -------------------------------------------------------------

