//
// home.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;

// Add a BookMark
function addBookMark()
{
	if ( window.external ) 
		{
			window.external.AddFavorite( document.location.href,document.title );
		} 
		else 
		{
			alert( "Sorry, your browser doesn't support bookmarking this page...\n\nPlease try pressing Control + D instead" );
		}
}

// 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;
        }  
	//fix up search params
		if( typeof(m_search) != "undefined" && m_search != null )
		{
			var r1			= /name=\"cat\"/g;
			var r2			= /value=\"all\"/g;
			m_search		= m_search.replace ( r1, "name=\"subcat\"" ).replace ( r2, "value=\"\"");;
		}      
    } 
    
}


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/menu.aspx";

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 menuItem( text, href )
{
	this.Text			= text;
	this.Href			= mhFixupLink( href, "&~ck=mn" );
	this.IsSeparator	= false;
	this.IsCaption		= false;
	this.MenuItems		= null;
}

function writeMH( phoneTitle, phoneMsg, phoneTariff, segmentTitle, hasLocale, logoLink, pnmsg )
{
	autoconfig();

	 
}

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\" width=\"2\" height=\"24\" 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\" width=\"4\" height=\"17\" border=\"0\" alt=\"\"></a></td>" );
			document.write( "<td valign=\"middle\"><a href=\"" + href + "\" nowrap=\"1\" class=\"lnk_main_masthead_SE\">" + 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 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 );
}

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()
{
	//chk this
     //document.write( "<td nowrap=\"1\"><div class=\"mhsep\"></div></td>" );
   	document.writeln( "<tr><td nowrap=\"1\" class=\"mhLine\" height=\"1\" width=\"1\"></td></tr>" );
	//document.writeln( "<tr><td bgcolor=\"" + color + "\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" alt=\"\" border=\"0\" width=\"1\" height=\"1\" /></td></tr>" );
}

function writeFooterStart()
{
	var width = ( m_mhFixed ? "728" : "100%" );
	document.write( "<table style=\"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%" );
	//chk this
	document.write( "<table width=\"" + width + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#ededed\">" );
	
	//-- RW: Change to move country selector
	document.writeln( "<tr><td colspan=\"2\" style=\"background-color:#ffffff;border-top: 1px solid #efefef\"><div style=\"width:720px;position:relative;left:178px;padding:0px;\">" + m_localeSelector + "</div></td></tr>" );
	document.write( "<tr><td colspan=\"2\"><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()
{
	/*if( m_search )
	{	
		document.writeln( "<div style=\"width:728px;border-top: 1px solid #efefef;margin-top: 4px\"><div style=\"width:720px;position:relative;left:178px;padding-top:2px;\">" + m_localeSelector + "</div></div>" );
		//document.writeln( "<hr noshade=\"true\" size=\"1\" color=\"#efefef\" />" );		
		//document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"728\"><tr><td>"  + m_localeSelector + "</td></tr></table>");
	}
	else
	{
		document.writeln( "<div style=\"width:728px;border-top: 1px solid #efefef;margin-top: 4px\"><div style=\"border-top:1px solid #efefef;width:720px;\">" + m_localeSelector + "</div></div>" );
	}*/
	
    writeFooterStart();
    writeFooterMid();
  
}

function writeFooterClose()
{
	document.write( "</td><td><table><tr><td valign=\"middle\"><a href=\"#mastheadtop\"><img src=\"" + m_imgPfx + "/images/global/brand/ui/arrow_top.gif\" width=\"7\" height=\"4\" alt=\"\" border=\"0\"></a></td><td style=\"padding-right:6px;\" valign=\"middle\"><a href=\"#mastheadtop\"><span class=\"para\">" + m_gototop + "</span></a></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 writeFooterEnd()
{
	var width	= ( m_mhFixed ? "728" : "100%" );
	
	document.write( "<table width=\"" + width + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#ededed\">" );
	document.write( "<tr><td colspan=\"2\" class=\"bcbg\"><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\" width=\"7\" height=\"4\" alt=\"\" border=\"0\"></td><td style=\"padding-right:6px;\" valign=\"middle\"><a href=\"#mastheadtop\"><span class=\"para\">" + m_gototop + "</span></a></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 writeFooter()
{
	writeFooterStart();
	writeFooterEnd();
}


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 fixup_FragHeight()
{
}

