// Javascript for Department of Mathematics, University of Denver
// (c) Petr Vojtechovsky, 2008

// displays e-mail address securely

function email( address ) {
    var plainChars =    "abcdefghijklmnopqrstuvwxyz0123456789.@";
    var cipheredChars = "bcdefghijklmnopqrstuvwxyza1234567890*!";
    
    var s = "";
    for (var i=0; i<address.length; i++) {
        s += plainChars.charAt( cipheredChars.indexOf( address.charAt( i ) ) );
    }
    document.write("<a href='mailto:" + s + "'>" + s + "</a>");
}

// random picture selection for main page

function showRandomPicture()
{
    var p = new Array()
    p[0] = 'knots';
    p[1] = 'mandelbrot';
    p[2] = 'klein';
    p[3] = 'platonic';
    p[4] = 'sierpinski';
    p[5] = 'petersen';
    p[6] = 'bifurcation';
    p[7] = 'greeks';
    p[8] = 'before1800';
    p[9] = '18th';
    p[10] = '19th';
    p[11] = '20th';
    p[12] = 'fibonacci';
    p[13] = 'pi';
    p[14] = 'ciphers';
    p[15] = 'conway';
    p[16] = 'euclid';
    p[17] = 'algorizmi';
    p[18] = 'penrose';
    p[19] = 'packings';
    p[20] = 'hyperbolic';
    p[21] = 'hypercubes';
    p[22] = 'riemann_siegel';
    var r = p.length;
    var whichImage = Math.round(Math.random()*(r-1));
    var s = "<img src='images/main_" + p[whichImage] + ".jpg' style='margin-top:10px';/>";
    document.write(s);
}

// GENRATING HTML TO AVOID FRAMES AND MINIMIZE CLUTTER
// ===================================================

function displayUniversityHeader( chapter) {
    var s = "";
    s += "<table cellspacing=0 cellpadding=0 width=100%>";                  // [begin] table that holds the whole page
        s += "<tr height=30 class='universityHeader'>";                            // [begin] row for university header
            s += "<td width=*>&nbsp;</td>";              // reserving space for left margin
            if (chapter=="") {
                s += "<td width=753>";                      // this is the only time the width is specified
            } else {
                s += "<td colspan=2>";
            }
                s += "<form id='header' action='http://search1.du.edu/search' method='get'>";
                s += "<a id='duLogo' href='http://www.du.edu'><img src='images/du_logo_sm.gif'\></a>";
                s += "<span id='globalNav'>";
                s += "<a href='http://www.du.edu/today/' title='News'>News</a>|";
                s += "<a href='http://www.du.edu/calendar' title='Events'>Events</a>|";
                s += "<a href='http://taurus.cair.du.edu/cgi-bin/dirn' title='Directory'>Directory</a>|";
                s += "<a href='http://www.du.edu/az/' title='A-Z'>A-Z</a>";
                s += "<input type='hidden' name='site' value='du_collection' />";
                s += "<input type='hidden' name='client' value='du_frontend' />";
                s += "<input type='hidden' name='proxystylesheet' value='du_frontend' />";
                s += "<input type='hidden' name='output' value='xml_no_dtd' />";
                s += "<input id='searchInput' class='searchinput' type='text' value='Search DU' name='q' size='8' maxlength='255' />";
                s += "<input id='searchBtn' type='submit' name='btnG' value='Go' />";
                s += "</span>";
                s += "</form>";
            s += "</td>";
            s += "<td width=*>&nbsp;</td>";              // reserving space for right margin
        s += "</tr>";                           // [end] row for university header
    document.write( s );
}

function displayMainMenu( chapter ) {
    var s = "";
        s += "<tr class='mainMenu'>";                            // [begin] row with math logo and main menu
            s += "<td></td>";                   // reserving space for left margin
            if (chapter="") {
                s += "<td>";
            } else {
                s += "<td colspan=2>";
            }
                s += "<a href='index.html'>";
                s += "<img id='mathLogo' src='images/logo_math_department.gif'>";
                s += "</a>";
                s += "<span id='mainMenu'>";
                s += "<a href='index.html'><img id='navH' src='images/navHOut.png' onMouseOver=\"navH.src='images/navHOver.png';\" onMouseOut=\"navH.src='images/navHOut.png';\"\></a>";
                s += "<a href='general_information.html'><img id='navPS' src='images/navPSOut.png' onMouseOver=\"navPS.src='images/navPSOver.png';\" onMouseOut=\"navPS.src='images/navPSOut.png';\"\></a>";
                s += "<a href='courses.html'><img id='navDM' src='images/navDMOut.png' onMouseOver=\"navDM.src='images/navDMOver.png';\" onMouseOut=\"navDM.src='images/navDMOut.png';\"\></a>";
                s += "<a href='faculty.html'><img id='navP' src='images/navPOut.png' onMouseOver=\"navP.src='images/navPOver.png';\" onMouseOut=\"navP.src='images/navPOut.png';\"\></a>";
                s += "<a href='preprints.html'><img id='navR' src='images/navROut.png' onMouseOver=\"navR.src='images/navROver.png';\" onMouseOut=\"navR.src='images/navROut.png';\"\></a>";
                s += "<a href='contact_us.html'><img id='navDL' src='images/navDLOut.png' onMouseOver=\"navDL.src='images/navDLOver.png';\" onMouseOut=\"navDL.src='images/navDLOut.png';\"\></a>";                    
                s += "</span>";
            s += "</td>";
            s += "<td></td>";                   // reserving space for right margin
        s += "</tr>";                           // [end] row with math logo and main menu
    document.write( s );
}

function displaySideMenu( chapter, section ) {        
    var s = "";
            s += "<td width=180px valign=top>";                 // the widths of the 2 columns have to add up to the total width
                if ( chapter == "prospective students" ) {
                    s += "<img class='menuImage' src='images/menu_shell.jpg'\>";
                    s += "<div id='leftSidebar'><div id='secondaryNav'><ul>";
                    s += "<li><a href='general_information.html'>General information for students</a></li>";
                    s += "<li><a href='why.html'>Why major in math?</a></li>";
                    s += "<li><a href='aid.html'>Financial aid</a></li>";
                    s += "<li><h3><a href='http://www.du.edu/admission'>Undergrad admission</a></h3>";
                    s += "<a class='indented' href='http://www.du.edu/admission/app.html'>Apply to DU</a>";
                    s += "<a class='indented' href='http://www.du.edu/admission/contact.html'>Request information</a>";
                    s += "<a class='indented' href='http://www.du.edu/admission/visit.html'>Visit DU</a></li>";
                    s += "<li><h3><a href='http://www.du.edu/grad'>Graduate admission</a></h3>";
                    s += "<a class='indented' href='apply/index.html'>Apply to Math at DU</a>";
                    s += "<a class='indented' href='http://www.du.edu/grad/admissions/request-info.html'>Request information</a></li>";
                    s += "</ul></div></div>";
                }
                if ( chapter == "degrees and majors" ) {
                    s += "<img class='menuImage' src='images/menu_platonic.jpg'\>";
                    s += "<div id='leftSidebar'><div id='secondaryNav'><ul>";
                    s += "<li><a href='courses.html'>Catalog of courses</a></li>";
                    s += "<li><a href='schedules.html'>Schedules of courses</a></li>";
                    s += "<li><a href='algebra_placement_test.html'>Algebra placement test</a></li>";
                    s += "<li><a href='matc.html'>MATC requirement</a></li>";
                    s += "<li><a href='minor.html'>Minor in mathematics</a></li>";
                    s += "<li><a href='ba.html'>Bachelor of Arts</a></li>";
                    s += "<li><a href='bs.html'>Bachelor of Science</a></li>";
                    s += "<li><a href='dual.html'>Dual degrees</a></li>";                         
                    s += "<li><a href='ms.html'>Masters degrees</a></li>";
                    s += "<li><a href='phd.html'>PhD in mathematics</a></li>";
                    s += "<li><a href='phdcs.html'>PhD in mathematics and computer science</a></li>";
                    s += "</ul></div></div>";
                }
                if ( chapter == "people" ) {
                    s += "<img class='menuImage' src='images/menu_euclid.jpg'\>";
                    s += "<div id='leftSidebar'><div id='secondaryNav'><ul>";
                    s += "<li><a href='faculty.html'>Faculty</a></li>";
                    s += "<li><a href='staff.html'>Staff</a></li>";
                    s += "<li><a href='graduates.html'>Graduate students</a></li>";
                    s += "<li><a href='undergraduates.html'>Undergraduate students</a></li>";
                    s += "<li><a href='recent_phd_graduates.html'>Recent PhD graduates</a></li>";
                    s += "<li><a href='mailing_groups.html'>Mailing groups</a></li>";
                    s += "<li><a href='photos.html'>Departmental photographs</a></li>";
                    s += "<li><a href='genealogy.html'>Mathematical genealogy of our faculty</a></li>";
                    s +="</ul></div></div>";
                }
                if ( chapter == "research" ) {
                    s += "<img class='menuImage' src='images/menu_klein.jpg'\>";
                    s += "<div id='leftSidebar'><div id='secondaryNav'><ul>";
                    s += "<li><a href='preprints.html'>Preprint series</a></li>";
                    s += "<li><a href='research_areas.html'>Research areas</a></li>";
                    s += "<li><h3><a href='seminars.html'>Seminars</a></h3>";
                    s += "<a class='indented' href='algebra_seminar.html'>Algebra &amp; logic</a>";
                    s += "<a class='indented' href='analysis_seminar.html'>Analysis &amp; dynamics</a>";
                    s += "<a class='indented' href='faculty_seminar.html'>Faculty</a>";
                    s += "<a class='indented' href='graduate_colloquium.html'>Graduate colloquium</a>";
                    s += "<a class='indented' href='student_only_seminar.html'>Student only</a></li>";
                    s += "<li><a href='conferences.html'>Conferences</a></li>";
                    s += "<li><a href='online_resources.html'>Online resources</a></li>";
                    s += "</ul></div></div>";
                }
                if ( chapter == "departmental life" ) {
                    s += "<img class='menuImage' src='images/menu_hypercubes.jpg'\>";
                    s += "<div id='leftSidebar'><div id='secondaryNav'><ul>";
                    s += "<li><a href='contact_us.html'>Contact us</a></li>";
                    s += "<li><a href='newsletter.html'>Newsletter</a></li>";
                    s += "<li><a href='old_news.html'>News from the front page</a></li>";
                    s += "<li><a href='tea.html'>Friday tea</a></li>";
                    s += "</ul></div></div>";
                }
            s += "</td>";   
            s += "<td width=573px valign=top>";            // [begin] cell that holds content
                s += "<h1>" + section + "</h1>";
    document.write( s );
}

function displayHeader ( chapter, section ) {
    // batch function 
    // 'chapter' specifies which side menu should be used
    displayUniversityHeader( chapter );
    displayMainMenu( chapter );
    var s = "";
        s += "<tr>";                            // [begin] row that holds side menu and content
            s += "<td></td>";                   // reserving space for left margin
    document.write( s );
    if ( chapter!="" ) {
        displaySideMenu( chapter, section );
    } else { // main page
            s = "<td>";      // [begin] cell that holds content
        document.write( s );
    }
}

function displayFooter( chapter ) {
    // content has been displayed
    var s = "";
        if (chapter!="") {
                // display update information first
                var defaultDate = "01/02/08";
                var date = document.lastModified;
                if (Date.parse(date) == 0) {
                    date = defaultDate;
                }   
                s += "<br/><span class='update'>Modified on " + date + "</span><br/><br style='line-height=10px'/>";
        }
            s += "</td>";                       // [end] cell that holds content
            s += "<td></td>";                   // reserving space for right margin
        s += "</tr>";                           // [end] row that holds side menu and content 
        s += "<tr class='mathFooter'>";         // [begin] row that holds math footer
            s += "<td></td>"                        // reserving space for left margin
            if (chapter=="") {
                s += "<td align=center>";
            } else {
                s += "<td colspan=2 align=center>";
            }
                s += "<br style='line-height:10px;'/>Department of Mathematics, 2360 S Gaylord St, Denver, Colorado 80208";
                s += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(phone) 303.871.2911&nbsp;&nbsp;&nbsp;&nbsp;(fax) 303.871.3173";
                s += "&nbsp;&nbsp;&nbsp;&nbsp;(email) <a href='mailto:info@math.du.edu'>info@math.du.edu</a><br/>";
                s += "<br style='line-height:10px;'/>";
            s += "</td>";
            s += "<td></td>";                       // reserving space for right margin
        s += "</tr>";                               // [end] row that holds math footer
        s += "<tr class='universityFooter'>";                            // [begin] row that holds DU footer
            s += "<td></td>";                   // reserving space for left margin
            if (chapter=="") {
                s += "<td align=center>";
            } else {
                s += "<td colspan=2 align=center>";
            }
                s += "<br style='line-height:10px;'/><a href='http://www.du.edu/index.html' title='DU.edu'>DU.edu</a>";
                s += " | <a href='http://www.du.edu/resources/contacts.html' title='Contacts &amp; Directions'>Contacts &amp; Directions</a>";
                s += " | <a href='http://www.du.edu/admission/' title='Undergraduate Admission'>Undergraduate Admission</a>";
                s += " | <a href='http://www.du.edu/grad/admissions/apply.html' title='Graduate Admission'>Graduate Admission</a>";
                s += " | <a href='http://www.giving.du.edu/' title='Giving to DU'>Giving to DU</a>";
                s += " | <a href='http://www.du.edu/hr/employment/jobs.html' title='Jobs @ DU'>Jobs @ DU</a>";
                s += " | <a href='http://www.du.edu/today/' title='News'>News</a></li>";
                s += " | <a href='http://www.du.edu/calendar' title='Events'>Events</a>";
                s += " | <a href='http://taurus.cair.du.edu/cgi-bin/dirn' title='Directory'>Directory</a>";
                s += " | <a href='http://www.du.edu/az/' title='A-Z'>A-Z</a>";
                s += " | <a href='http://search1.du.edu/' title='Search'>Search</a>";
                s += "<br/><br/>&copy;2008 University of Denver. All Rights Reserved.";
                s += " <a style='text-decoration: underline;' href='http://www.du.edu/privacy/' title='Privacy Policy'>Privacy</a><br/>";
                s += "The University of Denver is an equal opportunity/affirmative action institution.<br/><br style='line-height:10px;'/>";
            s += "</td>";        
            s += "<td></td>";                   // reserving space for right margin
        s += "</tr>";                           // [end] row that holds footer
    s += "</table>";                            // [end] table that holds the whole page
    document.write( s );
}
