var archive_years = [2012,2011,2010,2009,2008,2007,2006,2005,2004,2003,2002,2001,1988];

function eadt_years(newStyle, explan)
{
    if (newStyle === undefined || newStyle)
        yrSuffix = '/';
    else
        yrSuffix = '/?new=n';

    document.write('<div class="nav"><p>EADT Archive</p><ul class="eadt-years">');
    document.write('<li><a href="/bridge/eadt/">About</a></li>');

    for (i=0; i<archive_years.length; i++)
        document.write('<li><a href="/bridge/eadt/' + archive_years[i] + yrSuffix + '">' + archive_years[i] + '</a></li>');

    document.write('</ul></div>');

    document.write("<div><p><a class='latest-article' href='/bridge/eadt/latest/'>Latest Article</a></p></div>");

    if (explan === undefined || explan) // omit explanations in top-level indexes
    {
        if (newStyle === undefined || newStyle)
        {
            document.write('<div class="info-text"><p>This is the index of \'new style\' versions. You can read about the enhancements (and possible problems) on the <a href="/bridge/eadt/">main EADT index</a></p><p>You can return to the <a href="./?new=n">old styling</a></p></div>');
        }
        else
        {
            document.write('<div class="info-text"><p>This is the index of \'original style\' versions. Articles are also produced in a more attractive format &ndash; <a href="./">try it now</a>.</p></div>');
        }
    }
}

function returnDocument() {
    var file_name = document.location.href;
    var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
    return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

function ISO2EADT(isoDate)
{
var dateobject = new Date(isoDate.substring(0,4), isoDate.substring(5,7) - 1, isoDate.substring(8,10), 0, 0, 0);
var dtMonth = dateobject.toString().substring(4,7);
var dtDay = dateobject.toString().substring(8,10);

    if (dtDay.substring(0,1) == '0') dtDay = dtDay.substring(1,2); // drop leading zero
    if (dtDay.substring(1,2) == ' ') dtDay = dtDay.substring(0,1); // drop trailing space for IE

    return dtMonth + dtDay;
}

function EADTPrevNextIndex()
{
    var id = 0;

    var fname = returnDocument();

    var aname = fname.substring(0,fname.indexOf(".")); // root of article name

    var suf = (fname.indexOf(".doc.") == -1) ? "" : ".doc"; // suffix for old/new style (actually 'midfix')

    for (i=0; i<articles.length; i++)
    {
        if (ISO2EADT(articles[i][0]) == aname)
            id = i;
    }

    document.write("<p><a href='" + (suf.length > 0 ? ".?new=n" : ".") + "'>Index</a></p>");

    if (id != articles.length - 1)
        document.write("<p><a href='" + ISO2EADT(articles[id+1][0]) + suf + ".htm'>Earlier</a></p>");
    else
        document.write("<p>First in year</p>");

    if (id != 0)
        document.write("<p><a href='" + ISO2EADT(articles[id-1][0]) + suf + ".htm'>Later</a></p>");
    else if (articles[0][0].substring(0,4) != archive_years[0])
        document.write("<p>Last in year</p>");
    else
        document.write("<p class='emphasise-latest'>This is latest</p>");

    if (suf.length > 0)
    {
        document.write("</div>\n<div><p>Try this in the<br><a href='" + ISO2EADT(articles[id][0]) + ".htm'>new style</a></p>");
    }
    else
    {
        document.write("</div>\n<div><p>This page is properly formatted and looks good in modern browsers. If that's not the case for you, revert to the <a href='" + ISO2EADT(articles[id][0]) + ".doc.htm'>old style</a></p>");
    }
    
    document.write("</div>\n<div><p>Bookmark the latest article by right-clicking<br><a class='latest-article' href='/bridge/eadt/latest/'>this link</a>.</p>");
}

function EADTCreateArticleList(newStyle) // newStyle = 'n' or missing
{
    document.write("<ul>\n");
    for (var i=0;i<articles.length;i++)
    {
        var dateobject = new Date(articles[i][0].substring(0,4), articles[i][0].substring(5,7) - 1, articles[i][0].substring(8,10), 0, 0, 0);
        var dtMonth = dateobject.toString().substring(4,7);
        var dtDay = dateobject.toString().substring(8,10);

        if (dtDay.substring(0,1) == '0') dtDay = dtDay.substring(1,2); // drop leading zero
        if (dtDay.substring(1,2) == ' ') dtDay = dtDay.substring(0,1); // drop trailing space for IE

        document.write("<li><a href='" + dtMonth + dtDay + ((newStyle.toLowerCase() == 'n') ? ".doc.htm'>" : ".htm'>") + articles[i][0] + "</a> &ndash; " + articles[i][1] + "</li>\n");
    }
    document.write("</ul>\n");
}

function EADTIndexH2IntroText()
{
    if (GetThisYear() == articles[0][0].substring(0,4))
    {
        document.write("<h2>This Year's EADT Articles</h2>\n<p>I'll get a few more details to help find articles on county matches, local competitions etc. but for the time being, here they are by date - the Saturday on which they appear in the newspaper.</p>");

//        document.write("<p>I'm always on the look out for information about Suffolk players, table tales and interesting or amusing hands. You can email me at " + MailMe() +".</p>");

        document.write("<p>I'm always on the look out for information about Suffolk players, table tales and interesting or amusing hands. You can email me at <script src='/scripts/email/email.js' type='text/javascript'></script>.</p>");

//        document.write("<p>I'm always on the look out for information about Suffolk players, table tales and interesting or amusing hands. You can email me at <span id='mail-address'></span>.</p>");

//        addJavascriptToID("/scripts/email/email.js","mail-address");
//        addJavascriptToTagName("/scripts/email/email.js","head");
//        hiveware_enkoder();
    }
    else
    {
        document.write("<h2>EADT Articles " + articles[0][0].substring(0,4) + "</h2>\n");
    }

    document.title = "Dubious Logic - EADT Articles " + articles[0][0].substring(0,4);
}
