//
// home.js
//
// -------------------------------------------------------------
// Start Render Masthead
// -------------------------------------------------------------
var m_pnlinks;
var m_mhFixed                                    = false;
var m_mda                                            = 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;
var m_subNavLinksDisplay            = false;
var m_subNavIconsDisplay            = false;
var m_largeFont                                    = false;
var m_supressSubNav                            = false;
var m_stdEmpty                            = "";
var m_stdOffImg;
var m_pageTab                   = null;
var m_activeTab                 = null;
var m_mastheadWidth             = 728;
var m_defaultTabs               = false;
var m_tabNav                    = false;
var m_buyonlineMessage          = null;
var m_subNavLinkWidth           = null;
var m_phoneTitle                = null;
var m_phoneMsg                  = null;
var m_phoneTariff               = null;
var m_tabContentDiv             = null;
var m_timeoutDelay              = null;
var Screen                      = new GetScreen();
var loaded                      = new Array();
var onloadFired                 = false;


function writeMH( phoneTitle, phoneMsg, phoneTariff, segmentTitle, hasLocale, logoLink, pnmsg )
{
    m_phoneTitle            = phoneTitle;
    m_phoneMsg              = phoneMsg;
    m_phoneTariff           = phoneTariff;
    document.writeln ( "<!-- begin masthead -->" );
    //country homepage will have mastheadwidth of 728
    m_mastheadWidth         = 728;
    m_defaultTabs           = m_pageTab == "Auto" ? true : false;

        // Off Dell (external link) Icon
        m_stdOffImg             = "<img src=\"" + m_imgPfx + "/images/global/brand/icons/smextlink.gif\", width=\"16\" height=\"9\" border=\"0\"/>";

        //Browser Compatibility Tests
        autoconfig();

    // If there is a m_suppressPrintLink, then the 'printlink' link should not be displayed in the footer
    if ( typeof(m_suppressPrintLink) != "undefined" )
    {
        m_printLink    = null;
    }

        // Menu Definition Error
        if ( typeof(m_menuBar) == "undefined" )
        {
                if( !m_production  )
                {
                        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;
                }
                return;
        }

        if( m_largeFont )
        {
                m_avgChW = m_avgChW + 2;
        }

        // If it is normal layout the width of the footer will be '728' else if it is popup or print layout, footer width will be 100%.
        m_mhFixed        = true;

    document.writeln( "<a name=\"mastheadtop\"></a>" );
        // Masthead container
        document.write( "<table id=\"masthead\" width=\"" + m_mastheadWidth + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );
           document.write( "<tr><td valign=\"bottom\" rowspan=\"2\">" );

    // Logo
    document.write( "<div class=\"logocontainer\" id=\"logocontainer\">" );

    // 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>" );
    // Mahesha : This is for the applications who uses prior to storm 4.2 dll's.  In vid.xdb file, the logo is set to logo.jpg
    // If we change the image ref in vid.xdb file, it will affect the applications which are not using
    // storm 4.2 or storm 4.3 dlls. If everybody moves to storm 4.2/4.3, then this can be removed.
    if( typeof( m_nothomelogo ) != "undefined" )
        {
                m_nothomelogo        = m_nothomelogo.replace ( "/images/global/brand/ui/logo.gif" , "/images/global/brand/ui/logo43.gif");

                if( logoLink )
                {
                        document.write( "<a class=\"logolink\" href=\"" + m_homelink + "\">" );
                }

        document.write( "<img class=\"logo\" src=\"" + m_nothomelogo + "\" border=\"0\"  width=\"109\" height=\"41\" alt=\"\" />" );

                if( logoLink )
                {
                        document.write( "</a>" );
                }
        }
        document.write( "</div></td><td valign=\"top\" " + ((typeof(m_menuBar) != "undefined" && m_menuBar && m_menuBar.length > 0) ? "colspan=\"2\"" : "") + "><table id=\"pbarstriptable\" width=\"" + (m_mastheadWidth - 109) + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>" );
    //Phone Message
    if( m_buyonlineMessage )
        {
            document.write( "<div class=\"mhTitle_SE\">" );
            document.write( m_buyonlineMessage );
            document.write( "</div>" );
        }
        else
        {
            renderBuyOnline();
    }

        document.write( "</td><td><div style=\"height:20px;\" /></td><td nowrap=\"true\" valign=\"top\">" );
        var ticks = new Date();

    // Language Selector
        // Render languague toggle If the secondary nav bar is not present, otherwise langugage toggler will be duplicate
    if( !( m_pnlinks && m_subNavLinksDisplay &&  ( !m_supressSubNav ) ) && ( typeof( m_langSelectorUrl ) != "undefined") )
    {
        document.write( "<div class=\"lang_selector\">" );
        renderLanguageToggle();
        document.write( "</div>" );
    }

    document.write( "</td></tr></table></td></tr><tr>" );

    // Render Primary Tabs
    if( typeof(m_menuBar) != "undefined" && m_menuBar && m_menuBar.length > 0 )
        {
            document.write( "<td valign=\"bottom\">" );
            // Determine Selected Tab
            if( !isNaN( parseInt( m_pageTab ) ) )
        {
            m_pageTab = parseInt( m_pageTab );
        }
        else
        {
            var noTab = true;
            for( n = 0; n < m_menuBar.length; n++ )
            {
                if( m_pageTab == m_menuBar[n].Text )
                {
                   m_pageTab = n;
                   noTab = false;
                }
            }
            if( m_pageTab == "Auto" )
            {
                var qTab = getQueryVariable( "~tid" );
                if( typeof(qTab) != "undefined" && !isNaN( parseInt( qTab ) ) && qTab < m_menuBar.length )
                {
                    m_pageTab = qTab;
                    noTab = false;
                }
            }
            if( noTab )
            {
                m_pageTab = 0;
            }
        }
        for( n = 0; n < m_menuBar.length; n++ )
        {
            if( m_menuBar[n].IsSelectedTab )
            {
                m_pageTab   = n;
            }
        }
        document.write( "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr>" );
            renderPrimaryTabStrip();
            document.write( "<td width=\"100%\"><div class=\"tabspacer\" /></td>" );
        document.write( "</tr></table></td>" );
    }

    document.write( "<td>" );

        // Search
        if ( typeof( m_supressSearch ) == "undefined" || m_supressSearch == false )
    {
        document.write( "<div class=\"searchcontainer\" id=\"searchcontainer\">")
            if( m_search )
            {
                    document.write( m_search );
        }
            else
            {
                    renderSearchLinks();
            }
            document.write( "</div>" );
        }

        document.write( "</td></tr><tr><td colspan=\"3\">" );

    // Render Secondary Tabs
        var noNav   = "<div class=\"subnavcontainernomenu\" id=\"subnav\" ><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" border=\"0\" alt=\"\" height=\"5\" width=\"1\" /></div>";
        if( typeof(m_menuBar) != "undefined" && m_menuBar && m_menuBar.length > 0 )
        {
            if( typeof(m_menuBar[m_pageTab]) != "undefined" && m_menuBar[m_pageTab].MenuItems.length > 0 && !m_tabNav )
            {
                document.write( "<div class=\"subnavcontainer\" id=\"subnav\">" );
                document.write( renderSecondaryTabStrip( m_menuBar[m_pageTab] ) );
                document.write( "</div>" );
            }
            else
            {
                document.write( noNav );
            }
        }
        else
        {
            document.write( noNav );
        }

        // Render Sub Navigation Link
        if( m_pnlinks && m_subNavLinksDisplay &&  (!m_supressSubNav)  )
        {
                document.write( "<div class=\"secondarynavcontainer\">" );
                renderSubNavLinks();
                document.write( "</div>" );
        }

    // Render MDA Strip
    if( m_mda )
        {
            document.write( "<div class=\"mdabarcontainer\" id=\"mdabar\">" );
        document.write( "<span class=\"mdainfo\">" );
        document.write( m_mda );
        document.write( "</span>" );
        document.write( "</div>" );
    }
    // Render Masthead Bread Crumbs
    //Chk whether home
    document.write( "<div class=\"breadcrumbcontainer\">" );
    renderHomepageCrumbs();
    document.write( "</div>" );

        document.write ( "</td></tr></table>" );
        document.write ( "<a name=\"skipMH\"></a>" );
        document.writeln ( "<!-- end masthead -->" );
}

function renderBuyOnline()
{
    if( m_phoneTitle || m_phoneMsg )
    {
            document.write( "<div class=\"message_buyonline\">" );
            if( m_phoneTitle )
            {
                    document.write( m_phoneTitle );
                    document.write( " " );
            }
            if( m_phoneMsg )
            {
                    document.write( m_phoneMsg );
            }
            if( m_phoneTariff )
        {
            document.write( "<span class=\"mhTextNewTrf\">" + m_phoneTariff + "</span>" );
        }
        document.write( "</div>" );
        }
}
// -------------------------------------------------------------
// End Render Masthead
// -------------------------------------------------------------

// -------------------------------------------------------------
// 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        m_anchorClicked = false;


// 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 )
        {
                        var x = navigator.userAgent.indexOf( "AppleWebKit" );
                        if( x > -1 )
                        {
                                // Tiger and newer versions of Safari ...
                                isDHTML = ( navigator.userAgent.substring( x + 12, x + 15 ) ) > 300;
                        }
                        else
                        {
                                // older versions of 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 ) );
}

// ----------------------------------------------------
// End Browser Sniffer Content
// ----------------------------------------------------



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;
}

// 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);
                }
                else if (isIE4)
                {
                        theObj = document.all(obj);
                }
                else if (isNN4)
                {
                        theObj = seekLayer(document, obj);
                }
    }
    else
    {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

function menuGoto( url )
{
        if ( m_anchorClicked )
        {
                return;
        }
        m_anchorClicked        = true;
        if ( url != null && url.indexOf( "javascript" ) > -1 )
        {
                eval ( url );
        }
        else
        {
                document.location = url;
        }
        if( document.event != null )
        {
                document.event.cancelBubble = true;
        }
        return false;
}

function menuWinOpen( url )
{
        window.open( url );
        return false;
}


// 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;
}


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 GetScreen()
{
        this.Width = screen.width;
        this.Height = screen.height;
        this.AvailableWidth = screen.availWidth;
        this.AvailableHeight = screen.availHeight;
        this.ColorDepth = screen.colorDepth;
}

function fixup_FragHeight()
{
}

function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++)
    {
        var pair = vars[i].split("=");
        if (pair[0] == variable)
        {
            return pair[1];
        }
    }
}


function getYouAreHereHome()
{
    if ( typeof ( m_youAreHere ) != "undefined" )
    {
        return m_youAreHere;
    }
    return "";
}


        function addOnLoad( fn )
        {
            if ( onloadFired )
            {
                return;
            }
            if( window.onload )
            {
                if( window.onload != safeLoad )
                {
                    loaded[0] = window.onload;
                    window.onload = safeLoad;
                    loaded[ 1 ] = fn;
                }
                else
                {
                    loaded[ loaded.length + 1 ] = fn;
                }
        }
            else
            {
                window.onload = fn;
        }
        }

        function safeLoad()
        {
            onloadFired = true;
            for( var i=0;i<loaded.length;i++ )
        {
            if( loaded[i] != undefined )
            {
                    loaded[i]();
                }
        }
        }

        function getXMLHTTPObj()
        {
            var obj = false;
            /*@cc_on @*/
            /*@if (@_jscript_version >= 5)
            try { obj = new ActiveXObject( "Msxml2.XMLHTTP" ); } catch( e ){ try { obj = new ActiveXObject( "Microsoft.XMLHTTP" ); } catch( oc ) { obj = false; } }
            @end @*/
            if( !obj && typeof XMLHttpRequest != "undefined" )
            {
                try
                {
                    obj = new XMLHttpRequest();
            }
            catch(e)
            {
                obj = false;
            }
        }
            if( !obj )
            {
                return undefined;
        }
        return obj;
    }


