//------------------------------------------------------------------------------
// Miscellaneous
//------------------------------------------------------------------------------

var SKIP_IE6		= 6;

function Footer(except) {

  var isIE6 = false;

  if (except == SKIP_IE6)
    var isIE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);

  if (!isIE6) {
    document.write('&nbsp;<br>Copyright &copy; 2005-2010 by <a class="footer" href="mailto:chordian@gmail.com">Chordian</a>. All Rights Reserved.');
    document.write('&nbsp;&nbsp;&nbsp;&nbsp;[<a class="footer" href="/sitemap.htm">Site Map</a>]');
  }

}

function Unhide(divID, imgID) {

  var item = document.getElementById(divID);
  if (item)
    item.className=(item.className=='hidden')?'unhidden':'hidden';
    
  var item = document.getElementById(imgID);
  if (item)
    item.className=(item.className=='plus')?'minus':'plus';

}

//------------------------------------------------------------------------------
// Menu bar for all pages
//------------------------------------------------------------------------------

var MENU_GAMES		= 0;	// These numbers can be changed
var MENU_FILES		= 1;
var MENU_WOW_ENCHANTS	= 2;
var MENU_EQ2_GOODS	= 3;
var MENU_ABOUT		= 4;
var MENU_LOTRO_BARTER	= 5;

var MCOL_BEIGE		= 0;	// These numbers must match the array below
var MCOL_RED		= 1;
var MCOL_GREEN		= 2;
var MCOL_CYAN		= 3;

var mcolor = new Array("beige", "red", "green", "cyan");

function Menu(menuselect, menucolor) {

  // If a color is unspecified (or wrong) choose one randomly
  if (menucolor < 0 || menucolor > 3 || menucolor == undefined)
    menucolor = Math.round(3 * Math.random());
    
  // If a menu is not specified the undefined variable will always
  // fail below, lighting up all menu choices (which is what we want)

  document.write('<div class="menu" style="background:url(images/top1_bump_' + mcolor[menucolor] + '.png);">');
    document.write('<a href="index.htm"><div class="home" alt="" title="Click here to return to the start page"></div></a>');
    document.write('<ul>');

      if (menuselect == MENU_ABOUT)
        document.write('<li class="dim small down_' + mcolor[menucolor] + '_sm">&nbsp;About</li>');
      else
        document.write('<li class="small up_' + mcolor[menucolor] + '_sm"><a href="about.htm">About</a></li>');

      if (menuselect == MENU_FILES)
        document.write('<li class="dim small down_' + mcolor[menucolor] + '_sm">&nbsp;Files</li>');
      else
        document.write('<li class="small up_' + mcolor[menucolor] + '_sm"><a href="files.htm">Files</a></li>');

      if (menuselect == MENU_GAMES)
        document.write('<li class="dim down_' + mcolor[menucolor] + '">&nbsp;PC Games</li>');
      else
        document.write('<li class="up_' + mcolor[menucolor] + '"><a href="games.htm">PC Games</a></li>');

      if (menuselect == MENU_LOTRO_BARTER)
        document.write('<li class="dim down_' + mcolor[menucolor] + '"><img src="images/icon_lotro_dim.gif" style="margin:3px 0 0 7px;"></img>Barterers</li>');
      else
        document.write('<li class="up_' + mcolor[menucolor] + '"><a href="index.htm?tab=2"><img src="images/icon_lotro.gif" style="margin:3px -2px 0 5px;"></img>Barterers</a></li>');

      if (menuselect == MENU_EQ2_GOODS)
        document.write('<li class="dim down_' + mcolor[menucolor] + '"><img src="images/icon_eq2_dim.gif" style="margin:3px -8px 0 14px;"></img>Goods</li>');
      else
        document.write('<li class="up_' + mcolor[menucolor] + '"><a href="index.htm?tab=1"><img src="images/icon_eq2.gif" style="margin:3px -10px 0 12px;"></img>Goods</a></li>');

      if (menuselect == MENU_WOW_ENCHANTS)
        document.write('<li class="dim down_' + mcolor[menucolor] + '"><img src="images/icon_wow_armory_dim.gif" style="margin:3px 0 0 8px;"></img>Enchants</li>');
      else
        document.write('<li class="up_' + mcolor[menucolor] + '"><a href="index.htm?tab=0"><img src="images/icon_wow_armory.gif" style="margin:3px -2px 0 6px;"></img>Enchants</a></li>');

    document.write('</ul>');
  document.write('</div>');
}

//------------------------------------------------------------------------------
// Procedures for generating the rows for file downloads
//------------------------------------------------------------------------------

var FILEREQ_HALFLIFE	= "Requires Half-Life";
var FILEREQ_ADLIB	= "Requires an AdLib sound chip";
var FILEREQ_ADL_SB	= "Requires AdLib and/or Sound Blaster";
var FILEREQ_GUS_SB	= "Requires GUS or Sound Blaster";
var FILEREQ_C64		= "Requires a real C64 or a C64 emulator";

function JchFile(picparams, picture1, picture2, title, ecolor, etext, created, modified, requires, maintext, sizetype, dlurl) {

  // Outer table
  document.write('<table class="file">');
    document.write('<tr>');
      document.write('<td class="file file_left">');

        // Inner table for pictures
        document.write('<table class="fleft">');
          document.write('<tr>');
            document.write('<td class="fleft">');
              if (picparams != false)
		document.write('<a href="show.htm?' + picparams + '" title="Click to zoom">');
              document.write('<img src="/images/' + picture1 + '" class="fpic">');
              if (picparams != false)
                document.write('</a>');
            document.write('</td>');
	    document.write('<td class="fleft">');
              if (picparams != false)
		document.write('<a href="show.htm?' + picparams + '" title="Click to zoom">');
	      document.write('<img src="/images/' + picture2 + '" class="fpic">');
              if (picparams != false)
                document.write('</a>');
	    document.write('</td>');
	  document.write('</tr>');
	document.write('</table>');

      document.write('</td>');
      document.write('<td class="file">');

	// Inner table for main text
	document.write('<table class="fmid">');
	  document.write('<tr>');
	    document.write('<td class="fmid ftitle">');
	      document.write(title);
	    document.write('</td>');
	    document.write('<td class="fmid fextra">');
	      document.write('<font color="' + ecolor + '"><u>&nbsp;</u>&nbsp;&nbsp;&nbsp;&nbsp;<u>&nbsp;</u>&nbsp;');
              document.write('&nbsp;<u>&nbsp;</u>&nbsp;<u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + etext  + '</u></font>');
	    document.write('</td>');
	  document.write('</tr>');
	  document.write('<tr>');
	    document.write('<td class="fmid fdata" colspan="2">');
	      document.write('<span style="float:left;">Created: ' + created + ' &mdash; Last Modified: ' + modified + '</span>');
              document.write('<span style="float:right;" align="Right"><font color="#A06060">' + requires + '</font></span>');
	    document.write('</td>');
	  document.write('</tr>');
	document.write('</table>');
	document.write('<div class="fmain">');
	  document.write(maintext);
	document.write('</div>');

      document.write('</td>');
      document.write('<td class="file file_right" align="right">');

	// Inner table for size and download
	document.write('<table class="fright">');
	  document.write('<tr>');
	    document.write('<td class="fright ftype">');
	      document.write('<div class="ftype">' + sizetype + '</div>');
	      document.write('<a href="' + dlurl + '"><img src="/images/download.png" class="fdownload" alt="Fetch" title="Click to download"></a>');
	    document.write('</td>');
	  document.write('</tr>');
	document.write('</table>');
		    
      document.write('</td>');
    document.write('</tr>');
  document.write('</table>');

}

//------------------------------------------------------------------------------
// Procedures for generating the PC Games table
//------------------------------------------------------------------------------

// Completed Game,Gold,Developer,Genre,Save,Difficulty,Length,Rating,Cheat,Short,SaveGames,Screenshots
// GameTable("Aliens versus Predator 2", "2001", "Monolith", "FPS", "SA", "3", "4", "9", "0", "", false [||] "53", false [||] "1024x768|11|PNG|94")

var rowtype;

function GameTable(titlename, goldyear, developer, genre, savesystem, difficulty, duration, rating, cheat, fileprefix, savegames, screenshots) {

  if (rowtype == 0) {
    rowtype = 1;
    document.write('<tr class="even">'); }
  else {
    rowtype = 0;
    document.write('<tr class="odd">'); }

  // The optional star icon
  document.write('<td class="star">');
  if (rating == "8+" || rating == "9")
    document.write('<img border="0" src="images/icon_silverstar.gif" title="Nice game" alt="">');
  else if (rating == "9+" || rating == "10")
    document.write('<img border="0" src="images/icon_goldstar.gif" title="Great game!" alt="">');
  document.write('</td>');

  // Upper line is title
  document.write('<td class="gametitle">');
  document.write('<b>' + titlename + '</b><br>');

  // Middle line is release year and developer
  document.write('<font class="tiny">' + goldyear);
  document.write(' by ' + developer + '</font><br>');

  // Lower line is genre (unused for now)
  //document.write('<font class="tiny">' + genre');
  document.write('</td>');

  // Column with two thumbnails
  document.write('<td class="thumbnails">');
  if (screenshots != false) {
    document.write('<a href="screenshots.htm" onClick="this.href=&quot;screenshots.htm?' + titlename + '|' + fileprefix + '|' + screenshots + '&quot;" title="Click here for screenshots">');
    document.write('<img class="thumbnails" src="images/games/' + fileprefix.toLowerCase() + '_thumb1.jpg" alt="">');
    document.write('</a>');
    document.write('&nbsp;');
    document.write('<a href="screenshots.htm" onClick="this.href=&quot;screenshots.htm?' + titlename + '|' + fileprefix + '|' + screenshots + '&quot;" title="Click here for screenshots">');
    document.write('<img class="thumbnails" src="images/games/' + fileprefix.toLowerCase() + '_thumb2.jpg" alt="">');
    document.write('</a>');
  }
  document.write('</td>');

  // Save system
  if (rowtype == 0) {
    document.write('<td class="saveodd">'); }
  else {
    document.write('<td class="saveeven">'); }

  switch (savesystem)
  {
    case "SA": {
      document.write('<font color="#336600" title="Save Anywhere">SA</font></td>'); break }
    case "AS": {
      document.write('<font color="#993399" title="Auto Saves">AS</font></td>'); break }
    case "LS": {
      document.write('<font color="#336699" title="Limited Saves">LS</font></td>'); break }
    case "SP": {
      document.write('<font color="#993333" title="Save Points">SP</font></td>'); break }
    case "MS": {
      document.write('<font color="#993333" title="Mission Saves">MS</font></td>'); break }
    case "": {
      document.write('-</td>'); break }
    default: {
      document.write('SAVESYS ERROR ' + savesystem); break }
  }

  // Filler column
  if (rowtype == 0) {
    document.write('<td class="fillodd">'); }
  else {
    document.write('<td class="filleven">'); }
  document.write('</td>');

  // Difficulty
  if (rowtype == 0) {
    document.write('<td class="diffodd">'); }
  else {
    document.write('<td class="diffeven">'); }

  switch (difficulty)
  {
    case "1": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_difficulty1.png" title="Very easy" alt="Very easy"></td><td class="bars">&nbsp;1</td></tr></table></td>'); break }
    case "2": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_difficulty2.png" title="Easy" alt="Easy"></td><td class="bars">&nbsp;2</td></tr></table></td>'); break }
    case "3": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_difficulty3.png" title="Fair" alt="Fair"></td><td class="bars">&nbsp;3</td></tr></table></td>'); break }
    case "4": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_difficulty4.png" title="Hard" alt="Hard"></td><td class="bars">&nbsp;4</td></tr></table></td>'); break }
    case "5": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_difficulty5.png" title="Very hard" alt="Very hard"></td><td class="bars">&nbsp;5</td></tr></table></td>'); break }
    case "": {
      document.write('</td>'); break }
    default: {
      document.write('DIFF ERROR ' + difficulty); break }
  }

  // Duration
  if (rowtype == 0) {
    document.write('<td class="durodd">'); }
  else {
    document.write('<td class="dureven">'); }

  switch (duration)
  {
    case "1": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration1.png" title="Extremely short" alt="Extremely short"></td><td class="bars">&nbsp;1</td></tr></table></td>'); break }
    case "2": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration2.png" title="Very short" alt="Very short"></td><td class="bars">&nbsp;2</td></tr></table></td>'); break }
    case "3": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration3.png" title="Short" alt="Short"></td><td class="bars">&nbsp;3</td></tr></table></td>'); break }
    case "4": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration4.png" title="Slightly short" alt="Slightly short"></td><td class="bars">&nbsp;4</td></tr></table></td>'); break }
    case "5": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration5.png" title="Medium length" alt="Medium length"></td><td class="bars">&nbsp;5</td></tr></table></td>'); break }
    case "6": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration6.png" title="Slightly long" alt="Slightly long"></td><td class="bars">&nbsp;6</td></tr></table></td>'); break }
    case "7": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration7.png" title="Quite long" alt="Quite long"></td><td class="bars">&nbsp;7</td></tr></table></td>'); break }
    case "8": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration8.png" title="Very long" alt="Very long"></td><td class="bars">&nbsp;8</td></tr></table></td>'); break }
    case "9": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_duration9.png" title="Extremely long" alt="Extremely long"></td><td class="bars">&nbsp;9</td></tr></table></td>'); break }
    case "10": {
      document.write('<table class="bars"><tr><td class="bars"><img class="bars" src="images/game_infinity.gif" title="Theoretically infinite" alt="Theoretically infinite"></td></tr></table></td>'); break }
    case "": {
      document.write('</td>'); break }
    default: {
      document.write('DURATION ERROR ' + difficulty); break }
  }

  // Download save games
  if (rowtype == 0) {
    document.write('<td class="dlodd">'); }
  else {
    document.write('<td class="dleven">'); }

  if (savegames != false) {
    document.write('<a href="saves.htm" onClick="this.href=&quot;saves.htm?' + titlename + '|' + fileprefix + '|' + savegames + '&quot;" title="Download save games">');
    document.write('<img class="generic" src="images/icon_floppy.gif" alt="DL">');
    document.write('</a>');
  }

  document.write('</td>');
  document.write('</tr>');

}

//------------------------------------------------------------------------------
// The following procedures by Nicolas - http://www.javascript-page.com
//------------------------------------------------------------------------------

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) 
      break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  if (cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
