//
// Home
//

// -------------------------------------------------------------
// Browsers
// -------------------------------------------------------------

// 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 
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 ) )
        {
			
			isDHTML	= false;
        }  
	//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 ) );
}


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		= "menu.htm";

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();

	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.write( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"728\" height=\"19\" ><tr>" );
 	
	if( m_mda )
	{
			document.write( "<td width=\"365\" align=\"left\" valign=\"bottom\"  style=\"padding-left:8px; padding-top:0px; padding-bottom:3px;padding-right:8px\">" );
			document.write( "<span class=\"mhTextNewMda\">" );
			document.write( m_mda );
			document.write( "</span>" );
			document.write( "</td>" );
	}	
	
	document.write( "<td align=\"right\" valign=\"bottom\" style=\"padding-bottom:3px;padding-right:4px;\" >" );
	if( phoneTitle || phoneMsg )
	{
		document.write( "<span class=\"mhTextNewPnMsg\">" );
		
		if( phoneTitle )
		{
			document.write( phoneTitle );
			document.write( " " );
		}

		if( phoneMsg )
		{
			document.write( phoneMsg );
		}
			
		document.write( "</span>" );
	}
	
	if( phoneTariff )
	{
		document.write( "<span class=\"mhTextNewTrf\"> " + phoneTariff + "</span>" );
	}	
	
	document.writeln( "</td></tr></table>" );

	
	
	if( m_pnlinks )
	{
		document.writeln( "<table class=\"bcbg\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">" );
		document.write( "<tr>");
		document.write( "<td align=\"right\" style=\"padding-right:3px\"><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/separador.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/" + 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( "</tr></table>" );
		document.write( "</tr></table>" );	
		
		
	 document.writeln( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"728\">" );
	 document.writeln( "<tr class=\"mhLine\"><td><img src=\"" + m_imgPfx + "/images/spacer.gif\" alt=\"\" border=\"0\" height=\"1\" width=\"1\"/></td></tr>" );	
	 document.write( "</table>" ); 		

	}
	 
}

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/middle.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/primer.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/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 );
}

