var BODY_BGCOLOR            = "#D0FFD0",

    P_WINHEADING_COLOR      = "#FFFFFF",

    A_COLOR                 = "#007020",
    A_SMALL_COLOR           = "#007020",
    A_HIGH_COLOR            = "#FFFFFF",
    A_MSEOVER_COLOR         = "#FFFFFF",
    A_HOVER_COLOR           = "#B0B000",

    FONT_TITLE_COLOR        = "#005005",

    TABLE_OUTLINE_COLOR     = "#007020",
    TABLE_BODY_COLOR        = "#FFFFFF",
    TABLE_HOVER_COLOR       = "#B0B000";

function doStyles(winHandle, theme)
{
    if (winHandle == null)
    {
        winHandle = this;
    }

    if (theme == "BANCHOR")
    {
        BODY_BGCOLOR = "#B00000";
        A_COLOR = "#B00000";
        A_SMALL_COLOR = "#B00000";
        FONT_TITLE_COLOR = "#900000";
        TABLE_OUTLINE_COLOR = "#555555";
    }

    winHandle.document.write(
        "<STYLE TYPE='text/css'>"+
        "body"+
        "  {background-color: " + BODY_BGCOLOR + ";"+
        "   font-family: arial}"+
        "p"+
        "  {font-family: arial;"+
        "   font-size: x-small}"+
        "p.small"+
        "  {font-family: arial;"+
        "   font-size: xx-small}"+
        "p.winHeading"+
        "  {font-family: tahoma;"+
        "   font-size: x-small;"+
        "   font: bold;"+
        "   color: " + P_WINHEADING_COLOR + "}"+
        "font.heading"+
        "  {font-size: medium;}"+
        "a"+
        "  {text-decoration: none;"+
        "   font: bold;"+
        "   color: " + A_COLOR + "}"+
        "a.small"+
        "  {text-decoration: none;"+
        "   font-weight: normal;"+
        "   color: " + A_SMALL_COLOR + "}"+
        "a.high"+
        "  {text-decoration: none;"+
        "   font: bold;"+
        "   color: " + A_HIGH_COLOR + "}"+
        "a:hover"+
        "  {text-decoration: none;"+
        "   color: " + A_HOVER_COLOR + "}"+
        "a.high:hover"+
        "  {text-decoration: none;"+
        "   color: " + A_HIGH_COLOR + "}"+
        "a.mseover:hover"+
        "  {text-decoration: none;"+
        "   color: " + A_MSEOVER_COLOR + "}"+
        "font.title"+
        "  {font-family: arial black;"+
        "   color: " + FONT_TITLE_COLOR + "}"+
        "table.outline"+
        "  {background-color: " + TABLE_OUTLINE_COLOR + "}"+
        "table.body"+
        "  {background-color: " + TABLE_BODY_COLOR + "}"+
        "table.navHigh"+
        "  {font-family: tahoma;"+
        "   font: bold;"+
        "   background-color: " + TABLE_OUTLINE_COLOR + ";"+
        "   width: '100%';"+
        "   text-align: center;"+
        "   color: #FFFFFF;"+
        "   font-size: x-small}"+
        "table.nav"+
        "  {font-family: tahoma;"+
        "   font: bold;"+
        "   background-color: #FFFFFF;"+
        "   width: '100%';"+
        "   text-align: center;"+
        "   color: #007020;"+
        "   font-size: x-small}"+
        "td"+
        "  {font-size: x-small}"+
        "td.nav"+
        "  {font-family: tahoma;"+
        "   font: bold;"+
        "   width: '14%';"+
        "   text-align: center;"+
        "   font-size: x-small}"+
        "td.date"+
        "  {width: '25%';"+
        "   text-align: left;"+
        "   vertical-align: top;"+
        "   font-size: xx-small;"+
        "   color: #777777}"+
        "td.updateText"+
        "  {vertical-align: top;"+
        "   font-size: x-small;}"+
        "</STYLE>");
}

function doStdHeader(title, highlight)
{
    document.write(
        "<BODY TOPMARGIN=0 BOTTOMMARGIN=0 LEFTMARGIN=0 RIGHTMARGIN=0>"+
        "<CENTER>"+

        "<TABLE WIDTH=1003 HEIGHT='100%' BORDER=0 CELLPADDING=0 CELLSPACING=15>"+
        "<TR><TD WIDTH='100%' COLSPAN=2>");

    doTopLogo();
    document.write("</TD></TR><TR><TD WIDTH='100%' COLSPAN=2>");
    doNavbar(highlight);

    document.write(
        "</TD></TR>"+
        "<TR><TD WIDTH='100%' HEIGHT='100%'>");

    startWindow("&nbsp;" + title, "100%", "100%", "LEFT");
    document.write("<P ALIGN=JUSTIFY>");
}

function doStdFooter(highlight)
{
    document.write("<TR><TD VALIGN=BOTTOM ALIGN=CENTER>");
    doCopyright();
    endWindow();
    document.write(
        "<TD WIDTH=250 HEIGHT='100%' VALIGN=TOP>"+

        "<TABLE WIDTH=250 BORDER=0 CELLPADDING=0 CELLSPACING=0>"+
        "<TR><TD WIDTH='100%'>");

// Site Updates Window
    startWindow("Site Updates");
    startUpdatesTable();
    addUpdateEntry(
        "23/5/09",
        "Added a shorter programs page with the most <A CLASS=small HREF='../main/popular.html'>popular / recent releases</A>.")
    addUpdateEntry(
        "20/5/09",
        "Updated <A CLASS=small HREF='../main/about.html'>About Me</A> page.");
    addUpdateEntry(
        "13/5/09",
        "Fixed some links in the Links section below.");
    addUpdateEntry(
        "12/11/08",
        "Updated <A CLASS=small HREF='../main/about.html'>About Me</A> page and fixed some links in the Links section.");
    addUpdateEntry(
        "26/4/07",
        "Updated <A CLASS=small HREF='../main/about.html'>About Me</A> page and updated some of the links in the Links section.");
    endUpdatesTable();
    endWindow();

    doSidebarSpacer();

// Calc File Updates Window
    startWindow("Calc File Updates");
    startUpdatesTable();
    addUpdateEntry(
        "7/6/09",
        "<A CLASS=small HREF='../programs/hangman.html'>Hangman</A><BR>Version 1.00 (TI-83/83+/84+/86)");
    addUpdateEntry(
        "20/5/09",
        "<A CLASS=small HREF='../programs/banchor.html'>Banchor: The Hellspawn</A><BR>Version 1.10 (TI-86)");
    endUpdatesTable();
    endWindow();

    doSidebarSpacer();

// Old News Window
    startWindow("Old News");
    startUpdatesTable();
    addUpdateEntry(
        "23/5/09",
        "<A CLASS=small HREF='../oldnews/2009-05-23.html'>Hangman update</A><BR>I've spent some time on my...");
    addUpdateEntry(
        "20/5/09",
        "<A CLASS=small HREF='../oldnews/2009-05-20.html'>Banchor v1.10 released</A><BR>After 3 years of mulling over it, I...");
    addUpdateEntry(
        "15/5/09",
        "<A CLASS=small HREF='../oldnews/2009-05-15.html'>Centipede v1.11 released</A><BR>I have uploaded a small update...");
    document.write("<TR><TD COLSPAN=2><P CLASS=small ALIGN=CENTER><A CLASS=small HREF='../oldnews/oldnews.html'>All Old News</A>");
    endUpdatesTable();
    endWindow();

    doSidebarSpacer();

// Links Window
    startWindow("Links");
    document.write(
        "<CENTER>"+
        "<A TARGET='_blank' HREF='http://www.ticalc.org'>ticalc.org</A><BR>"+
        "<A TARGET='_blank' HREF='http://www.calcgames.org'>CalcGames.org</A><BR>"+
        "<BR>"+
        "<A TARGET='_blank' HREF='http://www.ocf.berkeley.edu/~pad'>Pat D's Site</A><BR>"+
        "<A TARGET='_blank' HREF='http://www.detachedsolutions.com'>Detached Solutions</A><BR>"+
        "<A TARGET='_blank' HREF='http://www.ticalc.org/archives/files/authors/57/5713.html'>Me @ ticalc.org</A><BR>"+
        "<BR>"+
        "<A TARGET='_blank' HREF='http://education.ti.com'>Texas Instruments</A><BR>"+
        "<BR>"+
        "<A TARGET='_blank' HREF='http://www.myspace.com/jamesvmusic'>Me @ Myspace</A>");
    endWindow();

    doSidebarSpacer();

// Contact Window
    startWindow("Contact Details");
    document.write(
        "<TABLE WIDTH='100%' BORDER=0 CELLPADDING=0 CELLSPACING=2>"+
        "<TR>"+
        "<TD WIDTH='25%'>Email:"+
        "<TD><A HREF='mailto:jamesv82@iprimus.com.au'>jamesv82@iprimus.com.au</A><BR>"+
/*        "<TR>"+
        "<TD>ICQ#:"+
        "<TD>71589304"+
        "<TR>"+
        "<TD>mIRC:"+
        "<TD>James_V&nbsp;&nbsp;(on #tcpa)"+*/
        "</TABLE>");
    endWindow();

    document.write(
        "</TABLE>"+
        "<TR><TD WIDTH='100%' COLSPAN=2>");

    doNavbar(highlight);

    document.write("</TABLE></BODY>");
}


function startNewsItem(title)
{
    startWindow(
        "<FONT CLASS=heading>&nbsp;" + title + "</FONT>",
        null, null, "LEFT");
    document.write("<P ALIGN=JUSTIFY>");
}


function endNewsItem(date)
{
    endWindow(date + "&nbsp;", "RIGHT");
}


function newsUpdate(date, text)
{
    document.write("<TABLE WIDTH='100%' BORDER=0 CELLPADDING=0 CELLSPACING=2>");
    document.write(
        "<TR>"+
        "<TD WIDTH=70 VALIGN=TOP><B>(" + date + ")</B>"+
        "<TD CLASS=updateText><P ALIGN=JUSTIFY>" + text);
    document.write("</TABLE>");
}


function startWindow(title, w, h, a, pad)
{
    var width = "100%";
    var align = "CENTER";
    var padding = 10;

    if (pad != null)
    {
        padding = pad;
    }
    if (w != null)
    {
        width = w;
    }
    if (a != null)
    {
        align = a;
    }
    if (h == null)
    {
        document.write("<TABLE CLASS=outline WIDTH='" + width + "' BORDER=0 CELLPADDING=2 CELLSPACING=0>");
    }
    else
    {
        document.write("<TABLE CLASS=outline WIDTH='" + width + "' HEIGHT='" + h + "' BORDER=0 CELLPADDING=2 CELLSPACING=0>");
    }

    if (title != null)
    {
        document.write(
            "<TR><TD WIDTH='100%' ALIGN=" + align + ">"+
            "<P CLASS=winHeading>" + title);
    }

    document.write(
        "<TR><TD WIDTH='100%' HEIGHT='100%'>"+

        "<TABLE CLASS=body WIDTH='100%' HEIGHT='100%' BORDER=0 CELLPADDING=" + padding + " CELLSPACING=0>"+
        "<TR><TD WIDTH='100%' HEIGHT='100%' VALIGN=TOP>");
}


function endWindow(title, a)
{
    var align="CENTER";

    if (a != null)
    {
        align = a;
    }

    document.write("</TABLE>");

    if (title != null)
    {
        document.write(
            "<TR><TD WIDTH='100%' ALIGN=" + align + ">"+
            "<P CLASS=winHeading>" + title);
    }

    document.write("</TABLE>");
}

function doNavbar(highlight)
{   document.write(
        "<TABLE CLASS=outline WIDTH='100%' BORDER=0 CELLPADDING=0 CELLSPACING=2>"+
        "<TR>");

    addNavbarEntry("News", "../main/news.html", highlight);
    addNavbarEntry("Programs", "../main/programs.html", highlight);
    addNavbarEntry("Add-Ons", "../main/addons.html", highlight);
    addNavbarEntry("Source Code", "../main/source.html", highlight);
    addNavbarEntry("Projects", "../main/projects.html", highlight);
    addNavbarEntry("FAQ", "../main/faq.html", highlight);
    addNavbarEntry("About Me", "../main/about.html", highlight);

    document.write("</TABLE>");
}

function addNavbarEntry(name, url, highlight)
{
    if (name == highlight)
    {
    document.write(
        "<TD CLASS=nav><TABLE CLASS=navHigh BORDER=0 CELLPADDING=3 CELLSPACING=0>"+
        "<TR><TD onMouseOver='cursorPointer(this)' onMouseOut='cursorDefault(this)' onClick='mClick(this)'><A CLASS=high HREF='" + url + "'>" + name + "</A>"+
        "</TABLE>");
    }
    else
    {
    document.write(
        "<TD CLASS=nav><TABLE CLASS=nav BORDER=0 CELLPADDING=3 CELLSPACING=0>"+
        "<TR><TD onMouseOver='mOver(this)' onMouseOut='mOut(this)' onClick='mClick(this)'><A HREF='" + url + "'>" + name + "</A>"+
        "</TABLE>");
    }
}

function doSidebar()
{
}

function doSidebarSpacer()
{
    document.write("<TABLE HEIGHT=15 BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD></TABLE>");
}

function doTopLogo()
{
    startWindow()
    document.write("<CENTER><FONT CLASS=title SIZE=7><B>James V's TI-Calculator Site");
    endWindow()
}

function doCopyright()
{
    document.write(
        "<P CLASS=small>"+
        "This page is best viewed in 1024x768 resolution or higher using <A CLASS=small HREF='http://www.microsoft.com/windows/ie/downloads/default.asp'>Internet Explorer 5</A> or higher.<BR>"+
        "Copyright &copy;2000-2009 James Vernon");
}

function startUpdatesTable()
{
    document.write("<TABLE WIDTH='100%' BORDER=0 CELLPADDING=3 CELLSPACING=0>");
}

function endUpdatesTable()
{
    document.write("</TABLE>");
}

function addUpdateEntry(date, text)
{
    document.write(
        "<TR>"+
        "<TD CLASS=date>(" + date + ")"+
        "<TD><P CLASS=small ALIGN=JUSTIFY>" + text);
}


/////////////////////////////////////////////////
//  showProgramHistory - Make an invisible table with last update and current version info
//
//      update - Last update
//      version - Current version
//
/////////////////////////////////////////////////
function showProgramHistory(update, version)
{
    document.write(
        "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>"+
        "<TR>"+
        "<TD WIDTH=120><B>Last Update:"+
        "<TD>" + update +
        "<TR>"+
        "<TD><B> Current Version:"+
        "<TD>" + version +
        "</TABLE><BR>");
}


/////////////////////////////////////////////////
//  showAddon - Draw a table with addon information
//
//      name = Name of addon
//      comp = Compatibility
//      desc = Description
//      url = Link to download
//      author = Author of addon
/////////////////////////////////////////////////
function showAddon(name, comp, desc, url, author)
{
    startWindow(
        "&nbsp;&nbsp;" + name,
        null,
        null,
        "LEFT");
    document.write("<P ALIGN=JUSTIFY>");
    document.write("<B>Compatibility:&nbsp;&nbsp;&nbsp;</B>" + comp + "<BR>");
    document.write(desc);
    document.write("<CENTER><A HREF='" + url + "'>Download</A>");
    endWindow("by " + author + "&nbsp;&nbsp;", "RIGHT");
}


/////////////////////////////////////////////////
//  showSource - Draw a table with source code information
//
//      name = Name of program
//      desc = Description
//      url = Link to download
//      platforms = Platforms that program is for
/////////////////////////////////////////////////
function showSource(name, desc, url, platforms)
{
    startWindow(
        "&nbsp;&nbsp;" + name,
        null,
        null,
        "LEFT");
    document.write("<P ALIGN=JUSTIFY>");
    document.write(desc);
    document.write("<BR><BR><CENTER><A HREF='" + url + "'>Download</A>");
    endWindow(platforms + "&nbsp;&nbsp;", "RIGHT");
}


/////////////////////////////////////////////////
//  addProgramLink - Draw a table with program image, name, calc types and link to program page
//
//      name = Name of program
//      calcs = Calculators that program runs on
//      image = Image to display
//      size = "SMALL" for 83/83+/84+ image, "LARGE" for 86 size
//      url = URL of program page
/////////////////////////////////////////////////
var numPrograms = 0;

function addProgramLink(name, calcs, image, size, url)
{
    var winSize;

    numPrograms++;
    if ((numPrograms % 2) != 0)
    {
        document.write("<TR>");
    }
    document.write("<TD WIDTH='50%' ALIGN=CENTER>");

    if (size == "SMALL")
    {
        winSize = 98 * 2;
    }
    else
    {
        winSize = 130 * 2;
    }

    startWindow(
        "&nbsp;" + name,
        winSize,
        null,
        "LEFT",
        0);
    document.write("<A HREF='" + url + "'><IMG WIDTH=" + winSize + " BORDER=0 SRC=" + image + "></A><BR>");
    endWindow(
        calcs + "&nbsp;",
        "RIGHT");
}


/////////////////////////////////////////////////
//
//  mOver - Highlight a section of the page that the mouse is over
//
//      tag = Tag of area
//
/////////////////////////////////////////////////
function mOver(tag)
{
    tag.bgColor = TABLE_HOVER_COLOR;
    tag.getElementsByTagName("a")[0].style.color = A_MSEOVER_COLOR;
    cursorPointer(tag);
}


/////////////////////////////////////////////////
//
//  mOut - Unhighlight a section of the page that the mouse has left
//
//      tag = Tag of area
//
/////////////////////////////////////////////////
function mOut(tag)
{
    tag.bgColor = TABLE_BODY_COLOR;
    tag.getElementsByTagName("a")[0].style.color = A_COLOR;
    cursorDefault(tag);
}


/////////////////////////////////////////////////
//
//  mOutWin - Unhighlight a frame that mouse has left
//
//      tag = Tag of frame
//
/////////////////////////////////////////////////
function mOutWin(tag)
{
    tag.bgColor = TABLE_OUTLINE_COLOR;
    cursorDefault(tag);
}


/////////////////////////////////////////////////
//
//  mClick - Redirect window to href of area that mouse has clicked
//
//      tag = Tag of area
//
/////////////////////////////////////////////////
function mClick(tag)
{
    window.location.href = tag.getElementsByTagName("a")[0].href;
}


/////////////////////////////////////////////////
//
//  cursorPointer - Change cursor to hand pointer
//
//      tag = Tag of area to modify style
//
/////////////////////////////////////////////////
function cursorPointer(tag)
{
    tag.style.cursor = "pointer";
}


/////////////////////////////////////////////////
//
//  cursorDefault - Change cursor to default pointer
//
//      tag = Tag of area to modify style
//
/////////////////////////////////////////////////
function cursorDefault(tag)
{
    tag.style.cursor = "default";
}
