//This is for the jump menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}






//This prints the default email address (kf@usa)
function PrintEmail()
{
  document.write('<a href="mailto:');
  document.write('k');
  document.write('u');
  document.write('n');
  document.write('g');
  document.write('f');
  document.write('u');
  document.write('@');
  document.write('u');
  document.write('s');
  document.write('a');
  document.write('.');
  document.write('c');
  document.write('o');
  document.write('m');
  document.write('">');
  document.write('k');
  document.write('u');
  document.write('n');
  document.write('g');
  document.write('f');
  document.write('u');
  document.write('@');
  document.write('u');
  document.write('s');
  document.write('a');
  document.write('.');
  document.write('c');
  document.write('o');
  document.write('m');
  document.write('</a>');
}

//Example: WriteNamedEmailLink("John Smith", "johnsmith", "gmail.com")
function WriteNamedEmailLink(linkText, emailAddressName, emailAddressDomain)
{
    document.write("<a class=\"email\" href=\"mailto:" + emailAddressName + "@" + emailAddressDomain + "\">" + linkText + "</a>");
}

//Example: WriteEmailLink("johnsmith", "gmail.com")
function WriteEmailLink(emailAddressName, emailAddressDomain)
{
    document.write("<a class=\"email\" href=\"mailto:" + emailAddressName + "@" + emailAddressDomain + "\">" + emailAddressName + "@" + emailAddressDomain + "</a>");
}

function JWindow(loc, wid, hei) {
  window.open(loc, "ICMACNewWindow" + Math.round(Math.random()*1000), "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=" + wid + ",height=" + hei);
}

function CountdownDays() {
  var tournamentDateString = "May 22, 2009";

  var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

  var todayDateObj = new Date();
  var todayYear = todayDateObj.getYear();
  var todayMonth = todayDateObj.getMonth();
  var todayDate = todayDateObj.getDate();
  var todayString = months[todayMonth] + " " + todayDate + ", " + todayYear;

  var daysRemaining = (Math.round((Date.parse(tournamentDateString)-Date.parse(todayString))/(24*60*60*1000))*1);
//  daysRemaining = (Date.parse(tournamentDateString)-Date.parse(todayString))/(1000*60*60*24);

  return daysRemaining;
}


//HOME LANGUAGE MENU
////////////////////

function ChangeHomeLanguage(inputLanguage)
{
    var languages = new Array();
    var language;
    var letterID;

    //Define the list of languages
    languages.push("en", "fr", "ru", "ro", "es", "jp", "it", "cns", "cnt", "ge", "hu", "gr", "pt");

    //Loop through all language possibilities
    for (languageIndex in languages)
    {
        //Create a shortcut to the current language name
        language = languages[languageIndex];

        //Create a shortcut to the current letter element ID
        letterID = "HomeLetter_" + language;

        //Check if the current language is the same as the one clicked; render the letter visible
        if (language == inputLanguage)
        {
            //Try different methods of rendering the object visible, depending on the user's browser
            if (document.layers)
            {
                document.layers[letterID].display = "block";
            }
            if (document.all)
            {
                document.all[letterID].style.display = "block";
            }
            if (document.getElementById)
            {
                document.getElementById(letterID).style.display = "block";
            }
        }
        //Else it is not the same; render the corresponding letter invisible
        else
        {
            //Try different methods of rendering the object visible, depending on the user's browser

            if (document.layers)
            {
                if (document.layers[letterID])
                {
                    document.layers[letterID].display = "none";
                }
            }
            if (document.all)
            {
                if (document.all[letterID])
                {
                    document.all[letterID].style.display = "none";
                }
            }
            if (document.getElementById)
            {
                if (document.getElementById(letterID))
                {
                    document.getElementById(letterID).style.display = "none";
                }
            }
        }
    }
}

//NEXT TOURNAMENT SIGN
//////////////////////

function DaysBetweenDates(earlierDateString, laterDateString)
{
    return (Math.round((Date.parse(laterDateString)-Date.parse(earlierDateString))/(24*60*60*1000))*1);
}

function ShowNextTournaments(fromSubdir)
{
    //This signifies that all tournaments take three days
    var tournamentLength = 3;
    
    //Accept the optional parameter
    if (fromSubdir == undefined)
    {
        fromSubdir = false;
    }
    
    //This is prepended to the paths of the images; it may be changed if we are rendering a page from a subdirectory
    var pathPrefix = "";
    if (fromSubdir)
    {
        pathPrefix = "../";
    }
    
    //These are the months used in describing dates, according to this programming language
    var monthStrings = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    //These are the starting dates of the tournaments, in order, with dates described according to this programming language
    var tournamentDateStrings = new Array("May 22, 2009",
                                          "Aug 7, 2009",
                                          "Oct 9, 2009",
                                          "Dec 4, 2009",
                                          "Jan 22, 2010",
                                          "Feb 26, 2010",
                                          "Mar 26, 2010",
                                          "Apr 23, 2010",
                                          "May 28, 2010");
    
    //These are the city codes (lowercase/simplified versions of city names) of the tournaments, in chronological order.
    //The first ones may be out-of-date; that would not cause an error. Tournaments should only appear in this list if
    //they have dates.
    var tournamentCityCodes = new Array("orlando",
                                        "vegas",
                                        "dc",
                                        "nassau",
                                        "sandiego",
                                        "sanjose",
                                        "dallas",
                                        "pisa",
                                        "orlando");
    
    //These will be used in processing today's date and comparing it with the tournaments' dates
    var todayDateObj = new Date();
    var todayString = monthStrings[todayDateObj.getMonth()] + " " + todayDateObj.getDate() + ", " + ((todayDateObj.getYear() % 100) + 2000);

    //These represent the next and next-next tournaments via indices into the above arrays
    var nextTournamentIndex = 0;
    var nextNextTournamentIndex = 0;
    for (var i = 0; i < tournamentDateStrings.length; i++)
    {
        var daysUntilTemp = DaysBetweenDates(todayString, tournamentDateStrings[i]);

        //If this tournament started two days ago or starts later, this is the first tournament of interest
        if (daysUntilTemp >= (-1)*tournamentLength + 1)
        {
            nextTournamentIndex = i;
            nextNextTournamentIndex = i + 1;
            break;
        }
    }
    
    //These represent the dates until the next tournament and the next-next tournament
    var daysUntilNext = DaysBetweenDates(todayString, tournamentDateStrings[nextTournamentIndex]);
    var daysUntilNextNext = DaysBetweenDates(todayString, tournamentDateStrings[nextNextTournamentIndex]);
    
    var daysUntilNextString = "";
    if (daysUntilNext <= 0)
    {
        daysUntilNextString = "000";
    }
    else if (daysUntilNext < 10)
    {
        daysUntilNextString = "00" + daysUntilNext;
    }
    else if (daysUntilNext < 100)
    {
        daysUntilNextString = "0" + daysUntilNext;
    }
    else
    {
        daysUntilNextString = "" + daysUntilNext;
    }

    var daysUntilNextNextString = "";
    if (daysUntilNextNext <= 0)
    {
        daysUntilNextNextString = "000";
    }
    else if (daysUntilNextNext < 10)
    {
        daysUntilNextNextString = "00" + daysUntilNextNext;
    }
    else if (daysUntilNextNext < 100)
    {
        daysUntilNextNextString = "0" + daysUntilNextNext;
    }
    else
    {
        daysUntilNextNextString = "" + daysUntilNextNext;
    }
    
    //Finally, print the tournament sign
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_top.gif\" />");
    document.write("<a href=\"" + pathPrefix + "next_tournament.htm\" title=\"Upcoming Kung Fu Tournament\" rel=\"nofollow\">");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_city1_city_" + tournamentCityCodes[nextTournamentIndex] + ".gif\" />");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_city1_days_" + daysUntilNextString + ".gif\" />");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_city1_dates_" + tournamentCityCodes[nextTournamentIndex] + ".gif\" />");
    document.write("</a>");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_middle.gif\" />");
    document.write("<a href=\"" + pathPrefix + "next_next_tournament.htm\" title=\"Upcoming Kung Fu Tournament\" rel=\"nofollow\">");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_city2_city_" + tournamentCityCodes[nextNextTournamentIndex] + ".gif\" />");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_city2_days_" + daysUntilNextNextString + ".gif\" />");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_city2_dates_" + tournamentCityCodes[nextNextTournamentIndex] + ".gif\" />");
    document.write("</a>");
    document.write("<img src=\"" + pathPrefix + "images/next_sign/next_sign_bottom.gif\" />");
}

function ShowUpcomingTournamentsBanner(fromSubdir)
{
    //This signifies that all tournaments take three days
    var tournamentLength = 3;
    
    //Accept the optional parameter
    if (fromSubdir == undefined)
    {
        fromSubdir = true;
    }
    
    //This is prepended to the paths of the images; it may be changed if we are rendering a page from a subdirectory
    var pathPrefix = "";
    if (fromSubdir)
    {
        pathPrefix = "../";
    }
    
    //These are the months used in describing dates, according to this programming language
    var monthStrings = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    //These are the starting dates of the tournaments, in order, with dates described according to this programming language
    var tournamentDateStrings = new Array("May 22, 2009",
                                          "Aug 7, 2009",
                                          "Oct 9, 2009",
                                          "Dec 4, 2009",
                                          "Jan 22, 2010",
                                          "Feb 26, 2010",
                                          "Mar 26, 2010",
                                          "Apr 23, 2010",
                                          "May 28, 2010");
    
    //These are the date ranges of the tournaments, in order, as they will be displayed
    var tournamentDateRangeStrings = new Array("May 22-24, 2009",
                                               "August 7-9, 2009",
                                               "October 9-11, 2009",
                                               "December 4-6, 2009",
                                               "January 22-24, 2010",
                                               "February 26-28, 2010",
                                               "March 26-28, 2010",
                                               "April 23-25, 2010",
                                               "May 28-30, 2010");
    
    //These are the city codes (lowercase/simplified versions of city names) of the tournaments, in chronological order.
    //The first ones may be out-of-date; that would not cause an error. Tournaments should only appear in this list if
    //they have dates.
    var tournamentCityCodes = new Array("orlando",
                                        "vegas",
                                        "dc",
                                        "nassau",
                                        "sandiego",
                                        "sanjose",
                                        "dallas",
                                        "pisa",
                                        "orlando");
    
    //These are the locations as they will be displayed, in chronological order.
    //The first ones may be out-of-date; that would not cause an error. Tournaments should only appear in this list if
    //they have dates.
    var tournamentLocationStrings = new Array("Orlando, FL",
                                              "Las Vegas, NV",
                                              "Washington, D.C.",
                                              "Nassau, Bahamas",
                                              "San Diego, CA",
                                              "San José, Costa Rica",
                                              "Dallas, TX",
                                              "Pisa, Italy",
                                              "Orlando, FL");
    
    //These are the names of the tournaments as they will be appear in mouse-over link information, in chronological order.
    //The first ones may be out-of-date; that would not cause an error. Tournaments should only appear in this list if
    //they have dates.
    var tournamentNameStrings = new Array("The International Chinese Martial Arts Championship",
                                          "The Las Vegas Chinese Martial Arts Championship",
                                          "The Washington, D.C. Chinese Martial Arts Championship",
                                          "The Nassau International Chinese Martial Arts Championship",
                                          "The San Diego Chinese Martial Arts Championship",
                                          "The San José International Chinese Martial Arts Championship",
                                          "The Dallas Chinese Martial Arts Championship",
                                          "The Pisa International Chinese Martial Arts Championship",
                                          "The International Chinese Martial Arts Championship");
    
    //These will be used in processing today's date and comparing it with the tournaments' dates
    var todayDateObj = new Date();
    var todayString = monthStrings[todayDateObj.getMonth()] + " " + todayDateObj.getDate() + ", " + ((todayDateObj.getYear() % 100) + 2000);

    //This represents the next tournament via its index into the above arrays
    var nextTournamentIndex = 0;
    for (var i = 0; i < tournamentDateStrings.length; i++)
    {
        var daysUntilTemp = DaysBetweenDates(todayString, tournamentDateStrings[i]);

        //If this tournament started two days ago or starts later, this is the first tournament of interest
        if (daysUntilTemp >= (-1)*tournamentLength + 1)
        {
            nextTournamentIndex = i;
            break;
        }
    }

    //Print the start of the Upcoming Tournaments banner
    document.write("    <div id=\"UpcomingTournamentsFooter\">\n");
    document.write("      <hr class=\"separator\" />\n");
    document.write("      <div class=\"title\">Upcoming Tournaments:</div>\n");
    document.write("      <table class=\"tournaments\">\n");
    document.write("        <tr>\n");

    //Print four upcoming tournaments
	for (var i = 1; i <= 4; i++)
    {
        //Store the index of the tournament currently being printed
        var thisTournamentIndex = nextTournamentIndex + i - 1;

        //Print opening tag(s) for this tournament
        document.write("          <td>\n");

        //Print opening tag(s) for the city name
        document.write("            <div class=\"city\">\n");

        //If this tournament is not the one currently being browsed, wrap its location in a link
        if (fromSubdir != tournamentCityCodes[thisTournamentIndex])
        {
            document.write("<a href=\"" + pathPrefix + tournamentCityCodes[thisTournamentIndex] + "/index.htm\" title=\"" + tournamentNameStrings[thisTournamentIndex] + "\">");
        }

        //Print the location name
        document.write(tournamentLocationStrings[thisTournamentIndex]);

        //Close off the link if it was generated above
        if (fromSubdir != tournamentCityCodes[thisTournamentIndex])
        {
            document.write("</a>");
        }

        //Print closing tag(s) for the city name
        document.write("            </div>\n");

        //Print date range for this tournament
        document.write("            <div class=\"dates\">" + tournamentDateRangeStrings[thisTournamentIndex] + "</div>\n");

        //Print closing tag(s) for this tournament
        document.write("          </td>\n");
    }

    //Print the end of the Upcoming Tournaments banner
    document.write("        </tr>\n");
    document.write("      </table>\n");
    document.write("    </div>\n");
}

function ShowNextTournamentsSubdir()
{
    ShowNextTournaments(true);
}

function RatingsFooter(resultsOnPage)
{
}
