<% @codepage="65001"  @LANGUAGE="JScript" %> 
<!-- #include file "locals.inc" -->
<% 
    var PP = "";

    function GetSubPath( sSubName )
    {
        try
        {
            var subMap = Server.CreateObject( "MSXML2.DOMDocument" );
            subMap.async = false;
            var tmpArray = new Array();
            if( subMap.load( Server.MapPath( SubMapPath ) ) )
            {
                var tmpVal = subMap.nodeFromID( sSubName );
                if( tmpVal )
                {
                    tmpVal = tmpVal.attributes.getNamedItem( "pth" ).nodeValue;
                }
                else // In case we forgot the DTD 
                {
                    tmpVal = subMap.documentElement.selectSingleNode( "//.[@url = '" + sSubName + "']" ).attributes.getNamedItem( "pth" ).nodeValue; 
                }
            }
        }
        catch(e)
        {
            //////////////////////////////////// 
            // DEBUG:: 
            // Response.Write( e.description ); 
            //////////////////////////////////// 
            tmpVal = RootTocToken;
        }
        tmpArray = tmpVal.split( "-" );
        return( tmpArray );

    }

    function GetPathFromURL( sURL )
    {
        try
        {
            var mapXML = Server.CreateObject( "MSXML2.DOMDocument" );
            sURL = Server.MapPath( sURL );
            var file = sURL.replace( /\\[^\\]*$/i , "\\map.xml" )
            if( mapXML.load( file ) )
            {
                var sTmp = FormatFileName( sURL.replace( /.*\\([^\\]*$)/gi , "$1" ) );
                var oTmp = mapXML.nodeFromID( sTmp );
                if( oTmp )
                {
                    sTmp = oTmp.attributes.getNamedItem( "pth" ).nodeValue;
                }
                else
                {
                    // In case we've forgotten to include the DTD 
                    if( oTmp = mapXML.selectSingleNode( "/MsdnTocMap/L[@url $ieq$ '" + sTmp + "']" ) ) 
                    {
                        return oTmp.attributes.getNamedItem( "pth" ).nodeValue;
                    }
                    else
                    {
                        return RootTocToken;
                    }
                }
                return sTmp;
            }
            else
            {
                ////////////////////////////////////////// 
                // mapXML did not parse, why? 
                ////////////////////////////////////////// 
                // DEBUG:: 
                 Response.Write(file + " : " + mapXML.parseError.reason);
                ////////////////////////////////////////// 
            }
            return RootTocToken;
        }
        catch(e)
        {
            //////////////////////////////////// 
            // DEBUG:: 
            // Response.Write( e.description ); 
            //////////////////////////////////// 
            return RootTocToken;
        }
    }


    function FormatFileName( sFileName )
    {
        if( "string" == typeof( sFileName ) )
        {
            sFileName = unescape( sFileName );
            // Remove anything that's not a word character, period, dash, underscore or colon (required for ID attributes) 
            sFileName = sFileName.replace( /[^\w\.-_:]/gi , "" );
            // It also can't start with a number 
            if ( sFileName.match( /^[\.\d]/i ) ) sFileName = "f" + sFileName;
            return sFileName;
        }
    }



    function RemoveChildren( oNode )
    {
        try
        {
            oNode = oNode.cloneNode( false );
            return oNode;
        }
        catch(e)
        {
            return oNode;
        }
    }


    function GetAttribValue( oNode, sAttribute )
    {
        var tmpNode;
        if( oNode && ( tmpNode = oNode.attributes.getNamedItem( sAttribute ) ) )
        {
            return tmpNode.nodeValue;
        }
        else
        {
            return false;
        }
    }


    /////////////////////////////////////////////////////// 
    // Initialization, grab the data out of the QueryString 
    /////////////////////////////////////////////////////// 
    var curPath = String( Request.QueryString( "tocPath" ) );
    if( "undefined" == curPath )
    {
        sURL = String( Request.QueryString( "URL" ) );
        if( "undefined" != sURL )
        {
            var idx = sURL.lastIndexOf( "?" )
            if( idx != -1 ) sURL = sURL.substring( idx+5 );
        }
        else
        {
            //sURL = DefaultTopic; 
        }
        curPath = GetPathFromURL( sURL );

    }

    var sCurChunk = "";

    curPath = curPath.split( "-" );

    var masterTOC = Server.CreateObject( "MSXML2.DOMDocument" );
    masterTOC.load( Server.MapPath( sCurChunk = RootDir ) );
    masterTOC = masterTOC.documentElement;
    var tmpNode = Server.CreateObject( "MSXML2.DOMDocument" );
    var val = "";

    try
    {
        for ( i = 0; i < curPath.length; i++ )
        {
            if( !isNaN( Number( curPath[i] ) ) )
            {
                if( masterTOC.childNodes.item( curPath[i] ).attributes.getNamedItem( "nodeType" ).text == "collection" )
                {
                    tmpNode = masterTOC.childNodes.item(curPath[i]);
                    var tmpCollection = Server.CreateObject( "MSXML2.DOMDocument" );
                    tmpCollection.load( PP = Server.MapPath( sCurChunk = GetAttribValue( tmpNode , "prePartum" ) ) );
                    masterTOC.replaceChild( tmpCollection.documentElement, tmpNode);
                    tmpNode = tmpCollection;
                    tmpCollection = null;
                }

                if( masterTOC.childNodes.item( curPath[i] ) )
                {
                    masterTOC = masterTOC.childNodes.item( curPath[i] );
                }
                else
                {
                    break;
                }

                if( i < curPath.length - 1 )
                {
                    masterTOC.setAttribute( "state" , "open" );
                    for ( j = 0; j < masterTOC.childNodes.length; j++ )
                    {
                        tmpNode = masterTOC.childNodes.item( j );
                        if( "node" == ( val = GetAttribValue( tmpNode , "nodeType" ) ) && j != curPath[i+1] )
                        {
                            masterTOC.replaceChild( tmpNode.cloneNode( "false" ) , tmpNode );
                            tmpNode = masterTOC.childNodes.item( j );
                            tmpNode.setAttribute( "nodeType" , "collection" );
                            tmpNode.setAttribute( "prePartum" , sCurChunk );
                        }
                    }
                }
                else
                {
                    masterTOC.setAttribute( "state" , "sel" );
                }
            }
            else if( curPath[i] != RootTocToken )
            {
                curPath = GetSubPath( curPath[i] ).concat( curPath.slice( i + 1 ) );
                i = 0;
            }
        }
    }
    catch(e)
    {
        var masterTOC = Server.CreateObject( "MSXML2.DOMDocument" );
        masterTOC.load( Server.MapPath( sCurChunk = RootDir ) );
        masterTOC = masterTOC.documentElement;
    }

    masterTOC = masterTOC.ownerDocument;
    var styleFile = Server.MapPath( "tocDown.xsl" );
    var style = Server.CreateObject( "MSXML2.DOMDocument" );
    style.load( styleFile );
    style.async = false;

    var content = masterTOC.transformNode( style );

%> 

<HTML DIR="<%= L_strBiDiMode_HTMLText %>">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<META NAME="Robots" CONTENT="noindex">
<SCRIPT LANGUAGE="JavaScript">

var L_LoadingMsg_HTMLText = "<%= L_LoadingMsg_HTMLText %>";

function NoOp()
{
    return;
}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" TYPE="text/javascript" SRC="toc.js"></SCRIPT>
<LINK REL="stylesheet" TYPE="text/css" HREF="toc.css" />

</HEAD>
<BODY TOPMARGIN="0" LEFTMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0" BGCOLOR="#ffffff" TEXT="#000000">
<NOBR>
<DIV STYLE="text-align:center;background-color:336699;color:ivory;padding:3px 10PX;" ONCLICK="location = 'toc.asp?url=' + top.fraTopic.location.pathname;">sync toc</div> 
<%= content %> 
</NOBR>
<IFRAME HEIGHT="0" WIDTH="0" SRC="" NAME="hiddenframe"></IFRAME>

</BODY>
</HTML>