<HTML>
<BODY onLoad="test()">
<script src="../jnext/jnext.js"></script>
<script src="../jnext/directory.js"></script>
<script>
var g_strSeparator;
var g_strPath;
var g_strRoot;
var g_dirList = "";

function test()
{
    var strPath;
    var strOS = JNEXT.getosname();
    switch ( strOS )
    {
        case "unix":
        case "darwin":
            g_strRoot = "";
            g_strSep  = "/";
            break;
        
        case "win":
            g_strRoot = "c:";
            g_strSep  = "\\";
            break;
        
        default:
            alert( "unknown system:" + strOS );
            return;
    }
    
    g_dirList = new JNEXT.Directory();
    g_strPath = g_strRoot;
    showDirContent( g_strRoot );
}

function showDirContent( strDir )
{
    if ( strDir == ".." )
    {
        var nSearchFrom = g_strPath.length - 2;
        var nNewLen     = g_strPath.lastIndexOf( g_strSep, nSearchFrom );
        g_strPath       = g_strPath.substr( 0, nNewLen ) + g_strSep;
    }
    else
    {
        g_strPath += strDir + g_strSep;
    }
    
    document.getElementById( "id_CurrPath" ).innerHTML = g_strPath;
    
    var arContent = g_dirList.getDirContent( g_strPath );
    if ( arContent == null )
    {
        alert( "Error getting directory content for " + g_strPath );
        return;
    }
    
    var arDirectories = arContent[0];
    var arFiles       = arContent[1];
    var i;
    
    strHTML = "<table>";

    if ( g_strPath != g_strRoot + g_strSep )
    {
        strHTML += "<tr><td bgcolor='beige'>";
        strHTML += "<a href='javascript:showDirContent(\"..\");'>..</a>";
        strHTML += "</td></tr>";
    }

    arDirectories.sort();
    for ( i=0; i<arDirectories.length; i++)
    {
        var strName = arDirectories[i];
        if ( strName == "." || strName == ".." )
        {
            continue;
        }
        strHTML += "<tr><td bgcolor='beige'>";
        strHTML += "<a href='javascript:showDirContent(\"" + strName + "\");'>" + strName + "</a>";
        strHTML += "</td></tr>";
    }
    strHTML += "</table>";
    document.getElementById( "idDirs" ).innerHTML = strHTML;

    strHTML = "<table>";
    arFiles.sort();
    for ( i=0; i<arFiles.length; i++)
    {
        strHTML += "<tr><td bgcolor='#ededed'>";
        strHTML += arFiles[i];
        strHTML += "</td></tr>";
    }
    strHTML += "</table>";
    document.getElementById( "idFiles" ).innerHTML = strHTML;
}

</script>
<h3>JNEXT Directory test</h3>

<div id="id_CurrPath"></div>
<table>
<tr bgcolor="#ededfd">
    <td width="300">Directories</td><td width="300">Files</td>
</tr>
<tr>
    <td>
        <div id="idDirs" style="position:absolute; height:300px; width:300px;
         background-color:beige; overflow:auto;">
        </div>
     </td>
     <td>
        <div id="idFiles" style="position:absolute; height:300px; width:300px;
         background-color:#ededed; overflow:auto;">
        </div>
     </td>
</tr>
</table>
</BODY>
</HTML>