var onFocusStyle = 'style="background-color: #FF0000; border-top: 2px solid #FFCCCC; border-left: 2px solid #FFCCCC; border-bottom: 2px solid #990000; border-right: 2px solid #990000; color: #FFFFFF"';
var directory = [ "mainpage",
                  "introduction",
                  "notes_download",
                  "module",
                  "geomlab",
                  "articles",
                  "fun",
                  "gallery",
                  "resource_sharing",
                  "forum",
                  "links", 
                  ""
                ]
var width;

function makeChineseMainMenu(e_filename) {
    var name = [ "首頁",
                 "編者的話",                  
                 "數學筆記",
                 "教學單元",
                 "幾何實驗室",
                 "數學文章",
                 "數學趣趣地",
                 "數學畫廊",
                 "資源交流區",
                 "講數天地",
                 "網上連結",
	             "English Version"   
               ]
    var link = [ "../mainpage/c_main.htm",
                 "../introduction/c_introduction.htm",
                 "../notes_download/c_notes.htm",
                 "../module/c_module.htm",
                 "../geomlab/c_geomlab.htm",
                 "../articles/c_articles.htm",
                 "../fun/c_comics.htm",
                 "../gallery/c_3d.htm",
                 "../resource_sharing/c_resource_01.htm",
                 "../forum/c_forum.htm",
                 "../links/c_links_01general.htm", 
                 ""
               ]
    var current_directory = String(window.location), c_filename, index;
    index = current_directory.lastIndexOf('/');
    c_filename = current_directory.substring(index + 1, current_directory.length); 			 
    if (e_filename == null) e_filename = "e_" + c_filename.substring(2, c_filename.length);
    link[link.length - 1] = e_filename;
    current_directory = current_directory.substring(0, index);
    index = current_directory.lastIndexOf('/');
    current_directory = current_directory.substring(index + 1, current_directory.length);

    if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5) {
        onFocusStyle = '';
        if (current_directory == directory[0])
            alert('Your browser is ' + navigator.appName + ' ' + navigator.appVersion + '. To have a better view of this site, we suggest you to use Netscape 7.0 or above.');  
    }

    document.writeln('<table border="0" cellpadding="5" cellspacing="0" width="100%" class="main-menu">');
    document.writeln('  <tr align="center"><td colspan="6"><div onclick="javascript:window.location.href=\'http://www.mathdb.org\' "><img border="0" src="../c_banner.gif" alt="數學資料庫"></div></td></tr>');
    document.writeln('  <tr align="center">');
    for (i = 0; i < 6; i++) {
        if (i < 2)
            width = "16%";
        else
            width = "17%";  
        if (current_directory == directory[i])
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '" ' + onFocusStyle + '>' + name[i] + "</a></td>");
        else
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '">' + name[i] + "</a></td>");
    }
    document.writeln('  </tr>');
    document.writeln('  <tr align="center">');
    for (i = 6; i < 12; i++) {
        if (i < 8)
            width = "16%";
        else
            width = "17%";  
        if (current_directory == directory[i])
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '" ' + onFocusStyle + '>' + name[i] + "</a></td>");
        else
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '">' + name[i] + "</a></td>");
    }
    document.writeln('  </tr>');
    document.writeln('</table>');
}

function makeEnglishMainMenu(c_filename) {
    var name = [ "Main",
                 "Our Aim",                  
                 "Math Notes",
                 "Teaching Module",
                 "Geom Lab",
                 "Math Articles",
                 "Math Funland",
                 "Math Gallery",
                 "Resource Sharing",
                 "Math Forum",
                 "Links",
	             "Chinese Version"   
               ]
    var link = [ "../mainpage/e_main.htm",
                 "../introduction/e_introduction.htm",
                 "../notes_download/e_notes.htm",
                 "../module/e_module.htm",
                 "../geomlab/e_geomlab.htm",
                 "../articles/e_articles.htm",
                 "../fun/e_comics.htm",
                 "../gallery/e_3d.htm",
                 "../resource_sharing/e_resource_01.htm",
                 "../forum/e_forum.htm",
                 "../links/e_links_01general.htm",
                 ""
               ]
    var current_directory = String(window.location), e_filename, index;
    index = current_directory.lastIndexOf('/');
    e_filename = current_directory.substring(index + 1, current_directory.length); 			 
    if (c_filename == null) c_filename = "c_" + e_filename.substring(2, e_filename.length);
    link[link.length-1] = c_filename;
    current_directory = current_directory.substring(0, index);
    index = current_directory.lastIndexOf('/');
    current_directory = current_directory.substring(index + 1, current_directory.length);

    if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5) {
        onFocusStyle = '';
        if (current_directory == directory[0])
        alert('Your browser is ' + navigator.appName + ' ' + navigator.appVersion + '. To have a better view of this site, we suggest you to use Netscape 7.0 or above.');  
    }
  
    document.writeln('<table border="0" cellpadding="5" cellspacing="0" width="100%" class="main-menu">');
    document.writeln('  <tr align="center"><td colspan="6"><div onclick="javascript:window.location.href=\'http://eng.mathdb.org\' "><img border="0" src="../e_banner.gif" alt="Mathematical Database"></div></td></tr>');
    document.writeln('  <tr align="center">');
    for (i = 0; i < 6; i++) {
        if (i < 2)
            width = "16%";
        else
            width = "17%";
        if (current_directory == directory[i]) 
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '" ' + onFocusStyle + '>' + name[i] + "</a></td>");
        else
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '">' + name[i] + "</a></td>");
    }
    document.writeln('  </tr>');
    document.writeln('  <tr align="center">');
    for (i = 6; i < 12; i++) {
        if (i < 8)
            width = "16%";
        else
            width = "17%";
        if (current_directory == directory[i]) 
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '" ' + onFocusStyle + '>' + name[i] + "</a></td>");
        else
            document.writeln('    <td width="' + width + '"><a href="' + link[i] + '">' + name[i] + "</a></td>");
    }
    document.writeln('  </tr>');
    document.writeln('</table>');
}

function makeMenu(category, link, noOfColumns) {
    if (noOfColumns == null) noOfColumns = 4;
    var width = String(Math.floor(100 / noOfColumns)) + "%";
    var counter = 1, n = Math.min(category.length, link.length);
    var filename = String(window.location);
    filename = filename.substring(filename.lastIndexOf('/')+1, filename.length);
  
    document.write('<p><table width="100%" cellspacing="5" class="menu">');
    while (counter <= n) {
        document.write('<tr align="center">');
        for (i = 0; i < noOfColumns; i++, counter++) {
            document.write('<td width="' + width + '">');
            if (counter <= n)
                if (filename == link[counter-1])
                    document.write('<a href="' + link[counter-1] + '" style="color: #FF0000; text-decoration: none">' + category[counter-1] + '</a>');
                else
                    document.write('<a href="' + link[counter-1] + '">' + category[counter-1] + '</a>');
            document.write('</td>');
        }
        document.write('</tr>');
    }
    document.write('</table></p>');
}

