// function titleBar(txt, alignment, barcolor)
// Displays a blue title bar
// txt = Text string
// alignment - "RIGHT" or "CENTER", default is "LEFT"
// barcolor (optional) - Color code "#FFFFFF", default is Blue (#0000FF)

function titleBar(txt, alignment, barcolor) {
   if (barcolor != null)
      document.write('<table width=710><tr bgcolor=' + barcolor + '>');
   else
      document.write('<table width=710><tr bgcolor=0000ff>');
   if (alignment == 'RIGHT') document.write('<td align=right>')
      else if (alignment == 'CENTER') document.write('<td align=center>')
      else document.write('<td align=left>');
   document.write('<font color=#ffffff><b>');
   document.write(txt);
   document.write('</b></font></td></tr></table>');
}

// function IEBrowserVersion()
// Returns Internet Explorer browser version number

function IEBrowserVersion() {
   version=0
   if (navigator.appVersion.indexOf("MSIE")!=-1) {
      temp=navigator.appVersion.split("MSIE")
      version=parseFloat(temp[1])
   }
   return(version)
}

// function initPage()
// Draws logo bar and menu on top of each page

function initPage() {

   if ((navigator.appName == "Netscape") && (parseFloat(navigator.appVersion)<5.0)) {
      menuspacing = 100; // Replace the '50' in the last menu line to variable 'menuspacing'
      document.write('<table width=905 cellpadding=4 cellspacing=4><tr>');
      document.write('<td width=200></td><td>');
      document.write('<img src="http://www.mah-jong.org/graphics/mjtitlebar.gif" alt="www.mah-jong.org">');
      document.write('</td></tr></table>');
      document.write('<table width=907 cellspacing=0 cellpadding=0>');
      document.write('<tr align=left valign=top><td width=175></td><td width=730 bgcolor=000066>');
      document.write('<img src="http://www.mah-jong.org/graphics/blank.gif" height=7>');
      document.write('</td></tr></table>');
      document.write('<table width=905 cellpadding=4><tr valign=top><td width=195></td><td width=710 bgcolor=ffffcc>');
   } else {
      menuspacing = 50; // replace the '50' in the last menu line to variable 'menuspacing'
      document.write('<table width=905 cellpadding=4 cellspacing=4><tr>');
      document.write('<td width=200></td><td>');
      document.write('<img src="http://www.mah-jong.org/graphics/mjtitlebar.gif">');
      document.write('</td></tr></table>');
      document.write('<table width=907 cellspacing=0 cellpadding=0>');
      document.write('<tr align=left valign=top><td width=168></td><td bgcolor=#000066>');
      document.write('<img src="http://www.mah-jong.org/graphics/blank.gif" height=7>');
      document.write('</td></tr></table>');
      document.write('<table width=905 cellpadding=4><tr valign=top><td width=175></td><td bgcolor=#ffffcc>');
   }

   stm_bm(["menu69d8",400,"","blank.gif",0,"","",0,0,250,275,1000,1,0,0,""],this);
   stm_bp("p0",[0,4,0,0,0,3,20,7,100,"",-2,"",-2,50,0,0,"#fffff7","#fffff7","",3,0,0,"#000000"]);
   stm_ai("p0i0",[0,"Home     ","","",-1,-1,0,"http://www.mah-jong.org","_self","","","http://www.mah-jong.org/graphics/tile-we.gif","http://www.mah-jong.org/graphics/tile-we.gif",20,23,0,"","",0,0,0,0,1,"#ffcc66",0,"#33cc66",0,"","",3,3,0,0,"#fffff7","#000000","#000000","#000000","bold 8pt Verdana","bold 8pt Verdana",0,0]);
   stm_aix("p0i1","p0i0",[0,"World Series of MJ  ","","",-1,-1,0,"","_self","","","http://www.mah-jong.org/graphics/tile-ws.gif","http://www.mah-jong.org/graphics/tile-ws.gif",20,23,0,"http://www.mah-jong.org/scripts/arrow_r.gif","http://www.mah-jong.org/scripts/arrow_r.gif",7,7]);
   stm_bpx("p1","p0",[1,4,0,0,0,3,20,0,100,"",-2,"",-2,50,0,0,"#fffff7","#ffffcc"]);
   stm_aix("p1i0","p0i0",[0,"News and Updates","","",-1,-1,0,"http://www.mah-jong.org/wsomj-news.html","_self","","","http://www.mah-jong.org/graphics/tile-1c.gif","http://www.mah-jong.org/graphics/tile-1c.gif"]);
   stm_aix("p1i1","p0i0",[0,"WSoMJ XI Statistics","","",-1,-1,0,"http://www.mah-jong.org/wsomj11-statistics.asp","_self","","","http://www.mah-jong.org/graphics/tile-2c.gif","http://www.mah-jong.org/graphics/tile-2c.gif"]);
   stm_aix("p1i2","p0i0",[0,"WSoMJ X Statistics","","",-1,-1,0,"http://www.mah-jong.org/wsomj10-statistics.asp","_self","","","http://www.mah-jong.org/graphics/tile-3c.gif","http://www.mah-jong.org/graphics/tile-3c.gif"]);
   stm_aix("p1i3","p0i0",[0,"Tournament Rules      ","","",-1,-1,0,"http://www.mah-jong.org/wsomj-rules.html","_self","","","http://www.mah-jong.org/graphics/tile-4c.gif","http://www.mah-jong.org/graphics/tile-4c.gif"]);
   stm_aix("p1i4","p0i0",[0,"Hall of Champions","","",-1,-1,0,"http://www.mah-jong.org/wsomj-champions.html","_self","","","http://www.mah-jong.org/graphics/tile-5c.gif","http://www.mah-jong.org/graphics/tile-5c.gif"]);
   stm_ep();
   stm_aix("p0i2","p0i1",[0,"How to Play Mah-Jong   ","","",-1,-1,0,"","_self","","","http://www.mah-jong.org/graphics/tile-ww.gif","http://www.mah-jong.org/graphics/tile-ww.gif"]);
   stm_bpx("p2","p1",[]);
   stm_aix("p2i0","p0i0",[0,"Rules                                 ","","",-1,-1,0,"http://www.mah-jong.org/pages/rules/setup.html","_self","","","http://www.mah-jong.org/graphics/tile-1m.gif","http://www.mah-jong.org/graphics/tile-1m.gif"]);
   stm_aix("p2i1","p0i0",[0,"Strategy","","",-1,-1,0,"http://www.mah-jong.org/pages/strategy/strategy.html","_self","","","http://www.mah-jong.org/graphics/tile-2m.gif","http://www.mah-jong.org/graphics/tile-2m.gif"]);
   stm_ep();
   stm_aix("p0i3","p0i0",[0,"Forum    ","","",-1,-1,0,"http://www.mah-jong.org/cgi-bin/discus/discus.cgi","_self","","","http://www.mah-jong.org/graphics/tile-wn.gif","http://www.mah-jong.org/graphics/tile-wn.gif"]);
   stm_aix("p0i4","p0i0",[0,"Old Website    ","","",-1,-1,0,"http://www.mah-jong.org/oldsite","_blank","","Launch the old mah-jong.org site in a new window.","http://www.mah-jong.org/graphics/tile-dr.gif","http://www.mah-jong.org/graphics/tile-dr.gif",20,23,0,"","",0,0,0,0,1,"#ffcc66",0,"#33cccc"]);
   stm_ai("p0i5",[6,50,"#ffcc66","http://www.mah-jong.org/scripts/blank.gif",menuspacing,29,0]);
   stm_ep();
   stm_em();

// Note: The last stm_ai() entry should have the third to last parameter number changed to the
//       variable 'menuspacing'

   document.write('</td></tr></table>');
   document.write('<table border=0><tr width=905><td width=175></td><td width=730>');
   initTiles();
}

// function initTiles()
// Initializes array of Mah-Jong tile images used throughout the website

function initTiles() {
   TileArray = new Array(42)
   BigTileArray = new Array(42)
   TileArrayDescription = new Array(42)
   graphicsPath = "http://www.mah-jong.org/graphics/"
   bigGraphicsPath = "http://www.mah-jong.org/graphics/bigtiles/"

   TileArray[ 1] = graphicsPath + "tile-rf1.gif"
   TileArray[ 2] = graphicsPath + "tile-rf2.gif"
   TileArray[ 3] = graphicsPath + "tile-rf3.gif"
   TileArray[ 4] = graphicsPath + "tile-rf4.gif"
   TileArray[ 5] = graphicsPath + "tile-bf1.gif"
   TileArray[ 6] = graphicsPath + "tile-bf2.gif"
   TileArray[ 7] = graphicsPath + "tile-bf3.gif"
   TileArray[ 8] = graphicsPath + "tile-bf4.gif"
   TileArray[ 9] = graphicsPath + "tile-we.gif"
   TileArray[10] = graphicsPath + "tile-ws.gif"
   TileArray[11] = graphicsPath + "tile-ww.gif"
   TileArray[12] = graphicsPath + "tile-wn.gif"
   TileArray[13] = graphicsPath + "tile-db.gif"
   TileArray[14] = graphicsPath + "tile-dg.gif"
   TileArray[15] = graphicsPath + "tile-dr.gif"
   TileArray[16] = graphicsPath + "tile-1m.gif"  // 16-24 Maan Ji
   TileArray[17] = graphicsPath + "tile-2m.gif"  // 25-33 Tung Ji
   TileArray[18] = graphicsPath + "tile-3m.gif"  // 34-42 Soek Ji
   TileArray[19] = graphicsPath + "tile-4m.gif"
   TileArray[20] = graphicsPath + "tile-5m.gif"
   TileArray[21] = graphicsPath + "tile-6m.gif"
   TileArray[22] = graphicsPath + "tile-7m.gif"
   TileArray[23] = graphicsPath + "tile-8m.gif"
   TileArray[24] = graphicsPath + "tile-9m.gif"
   TileArray[25] = graphicsPath + "tile-1c.gif"
   TileArray[26] = graphicsPath + "tile-2c.gif"
   TileArray[27] = graphicsPath + "tile-3c.gif"
   TileArray[28] = graphicsPath + "tile-4c.gif"
   TileArray[29] = graphicsPath + "tile-5c.gif"
   TileArray[30] = graphicsPath + "tile-6c.gif"
   TileArray[31] = graphicsPath + "tile-7c.gif"
   TileArray[32] = graphicsPath + "tile-8c.gif"
   TileArray[33] = graphicsPath + "tile-9c.gif"
   TileArray[34] = graphicsPath + "tile-1s.gif"
   TileArray[35] = graphicsPath + "tile-2s.gif"
   TileArray[36] = graphicsPath + "tile-3s.gif"
   TileArray[37] = graphicsPath + "tile-4s.gif"
   TileArray[38] = graphicsPath + "tile-5s.gif"
   TileArray[39] = graphicsPath + "tile-6s.gif"
   TileArray[40] = graphicsPath + "tile-7s.gif"
   TileArray[41] = graphicsPath + "tile-8s.gif"
   TileArray[42] = graphicsPath + "tile-9s.gif"

   BigTileArray[ 1] = bigGraphicsPath + "tile-rf1.gif"
   BigTileArray[ 2] = bigGraphicsPath + "tile-rf2.gif"
   BigTileArray[ 3] = bigGraphicsPath + "tile-rf3.gif"
   BigTileArray[ 4] = bigGraphicsPath + "tile-rf4.gif"
   BigTileArray[ 5] = bigGraphicsPath + "tile-bf1.gif"
   BigTileArray[ 6] = bigGraphicsPath + "tile-bf2.gif"
   BigTileArray[ 7] = bigGraphicsPath + "tile-bf3.gif"
   BigTileArray[ 8] = bigGraphicsPath + "tile-bf4.gif"
   BigTileArray[ 9] = bigGraphicsPath + "tile-we.gif"
   BigTileArray[10] = bigGraphicsPath + "tile-ws.gif"
   BigTileArray[11] = bigGraphicsPath + "tile-ww.gif"
   BigTileArray[12] = bigGraphicsPath + "tile-wn.gif"
   BigTileArray[13] = bigGraphicsPath + "tile-db.gif"
   BigTileArray[14] = bigGraphicsPath + "tile-dg.gif"
   BigTileArray[15] = bigGraphicsPath + "tile-dr.gif"
   BigTileArray[16] = bigGraphicsPath + "tile-1m.gif"  // 16-24 Maan Ji
   BigTileArray[17] = bigGraphicsPath + "tile-2m.gif"  // 25-33 Tung Ji
   BigTileArray[18] = bigGraphicsPath + "tile-3m.gif"  // 34-42 Soek Ji
   BigTileArray[19] = bigGraphicsPath + "tile-4m.gif"
   BigTileArray[20] = bigGraphicsPath + "tile-5m.gif"
   BigTileArray[21] = bigGraphicsPath + "tile-6m.gif"
   BigTileArray[22] = bigGraphicsPath + "tile-7m.gif"
   BigTileArray[23] = bigGraphicsPath + "tile-8m.gif"
   BigTileArray[24] = bigGraphicsPath + "tile-9m.gif"
   BigTileArray[25] = bigGraphicsPath + "tile-1c.gif"
   BigTileArray[26] = bigGraphicsPath + "tile-2c.gif"
   BigTileArray[27] = bigGraphicsPath + "tile-3c.gif"
   BigTileArray[28] = bigGraphicsPath + "tile-4c.gif"
   BigTileArray[29] = bigGraphicsPath + "tile-5c.gif"
   BigTileArray[30] = bigGraphicsPath + "tile-6c.gif"
   BigTileArray[31] = bigGraphicsPath + "tile-7c.gif"
   BigTileArray[32] = bigGraphicsPath + "tile-8c.gif"
   BigTileArray[33] = bigGraphicsPath + "tile-9c.gif"
   BigTileArray[34] = bigGraphicsPath + "tile-1s.gif"
   BigTileArray[35] = bigGraphicsPath + "tile-2s.gif"
   BigTileArray[36] = bigGraphicsPath + "tile-3s.gif"
   BigTileArray[37] = bigGraphicsPath + "tile-4s.gif"
   BigTileArray[38] = bigGraphicsPath + "tile-5s.gif"
   BigTileArray[39] = bigGraphicsPath + "tile-6s.gif"
   BigTileArray[40] = bigGraphicsPath + "tile-7s.gif"
   BigTileArray[41] = bigGraphicsPath + "tile-8s.gif"
   BigTileArray[42] = bigGraphicsPath + "tile-9s.gif"

   TileArrayDescription[ 1] = "Red Flower 1"
   TileArrayDescription[ 2] = "Red Flower 2"
   TileArrayDescription[ 3] = "Red Flower 3"
   TileArrayDescription[ 4] = "Red Flower 4"
   TileArrayDescription[ 5] = "Blue Flower 1"
   TileArrayDescription[ 6] = "Blue Flower 2"
   TileArrayDescription[ 7] = "Blue Flower 3"
   TileArrayDescription[ 8] = "Blue Flower 4"
   TileArrayDescription[ 9] = "East Wind"
   TileArrayDescription[10] = "South Wind"
   TileArrayDescription[11] = "West Wind"
   TileArrayDescription[12] = "North Wind"
   TileArrayDescription[13] = "White Dragon"
   TileArrayDescription[14] = "Green Dragon"
   TileArrayDescription[15] = "Red Dragon"
   TileArrayDescription[16] = "Ten Thousand"
   TileArrayDescription[17] = "Twenty Thousand"
   TileArrayDescription[18] = "Thirty Thousand"
   TileArrayDescription[19] = "Forty Thousand"
   TileArrayDescription[20] = "Fifty Thousand"
   TileArrayDescription[21] = "Sixty Thousand"
   TileArrayDescription[22] = "Seventy Thousand"
   TileArrayDescription[23] = "Eighty Thousand"
   TileArrayDescription[24] = "Ninety Thousand"
   TileArrayDescription[25] = "One Circle"
   TileArrayDescription[26] = "Two Circles"
   TileArrayDescription[27] = "Three Circles"
   TileArrayDescription[28] = "Four Circles"
   TileArrayDescription[29] = "Five Circles"
   TileArrayDescription[30] = "Six Circles"
   TileArrayDescription[31] = "Seven Circles"
   TileArrayDescription[32] = "Eight Circles"
   TileArrayDescription[33] = "Nine Circles"
   TileArrayDescription[34] = "One Bamboo Stick"
   TileArrayDescription[35] = "Two Bamboo Sticks"
   TileArrayDescription[36] = "Three Bamboo Sticks"
   TileArrayDescription[37] = "Four Bamboo Sticks"
   TileArrayDescription[38] = "Five Bamboo Sticks"
   TileArrayDescription[39] = "Six Bamboo Sticks"
   TileArrayDescription[40] = "Seven Bamboo Sticks"
   TileArrayDescription[41] = "Eight Bamboo Sticks"
   TileArrayDescription[42] = "Nine Bamboo Sticks"
}

// function postPage()
// Closes off table portion of each page

function postPage() {
   document.writeln('</td></tr></table>')
}

// function displayHand()
// Displays mah-jong hand
// First argument is the hand title
// All additional arguments are tiles that make up the hand

function displayHand() {
   args = displayHand.arguments.length
   for (count=0; count<args; ++count) {
      if (displayHand.arguments[count] == " ") {
         document.write("&nbsp;")
      } else {
         document.write("<img src='"+TileArray[displayHand.arguments[count]]+"' alt='"+TileArrayDescription[displayHand.arguments[count]]+"' border=0>")
      }
   }
   document.write("<br>")
}

function displayBigHand() {
   args = displayBigHand.arguments.length
   for (count=0; count<args; ++count) {
      if (displayBigHand.arguments[count] == " ") {
         document.write("&nbsp;")
      } else {
         document.write("<img src='"+BigTileArray[displayBigHand.arguments[count]]+"' alt='"+TileArrayDescription[displayBigHand.arguments[count]]+"' border=0>")
      }
   }
   document.write("<br>")
}

function displayHandName() {
   args = displayHandName.arguments.length
   document.write ("<h1>" + displayHandName.arguments[0] + "&nbsp;&nbsp;")
   for (count=1; count<args; ++count) {
      document.write("<img src='http://www.mah-jong.org/graphics/chinesephrases/" + displayHandName.arguments[count] + "'>");
   }
   document.write("</h1>");
}

// function drawRulesMenu()
// Displays Rules Left-Side Menu

function drawRulesMenu() {
   cQuote = '"';
   
   document.write("<table class='rowover' striped=true border=1 cellpadding=1 cellspacing=0 width=170>");
   document.write("<thead><th>Mah-Jong Rules</th></thead>");
   if ((navigator.appName == "Netscape" && (parseInt(navigator.appVersion) >= 5)) || (navigator.appName == "Microsoft Internet Explorer")) {
      document.write("<tr bgcolor=ffff33 class='menurow'><td style='cursor:pointer; cursor:hand;' onClick=" + cQuote + "javascript:document.location.href='http://www.mah-jong.org/pages/rules/setup.html'" + cQuote + ">Setup</td></tr>");
      document.write("<tr bgcolor=ffff33 class='menurow'><td style='cursor:pointer; cursor:hand;' onClick=" + cQuote + "javascript:document.location.href='http://www.mah-jong.org/pages/rules/objective.html'" + cQuote + ">Objective</td></tr>");
      document.write("<tr bgcolor=ffff33 class='menurow'><td style='cursor:pointer; cursor:hand;' onClick=" + cQuote + "javascript:document.location.href='http://www.mah-jong.org/pages/rules/rules.html'" + cQuote + ">Rules</td></tr>");
      document.write("<tr bgcolor=ffff33 class='menurow'><td style='cursor:pointer; cursor:hand;' onClick=" + cQuote + "javascript:document.location.href='http://www.mah-jong.org/pages/rules/scoring.html'" + cQuote + ">Scoring</td></tr>");
      document.write("<tr bgcolor=ffff33 class='menurow'><td style='cursor:pointer; cursor:hand;' onClick=" + cQuote + "javascript:document.location.href='http://www.mah-jong.org/pages/rules/specialhands.html'" + cQuote + ">Special Hands</td></tr>");
      document.write("<tr bgcolor=ffff33 class='menurow'><td style='cursor:pointer; Cursor:hand;' onClick=" + cQuote + "javascript:document.location.href='http://www.mah-jong.org/pages/rules/glossary.asp'" + cQuote + ">Glossary</td></tr>");
   } else {
      document.write("<tr bgcolor=ffff33><td><a class='menurow' href='http://www.mah-jong.org/pages/rules/setup.html'>Setup</a></td></tr>");
      document.write("<tr bgcolor=ffff33><td><a class='menurow' href='http://www.mah-jong.org/pages/rules/objective.html'>Objective</a></td></tr>");
      document.write("<tr bgcolor=ffff33><td><a class='menurow' href='http://www.mah-jong.org/pages/rules/rules.html'>Rules</a></td></tr>");
      document.write("<tr bgcolor=ffff33><td><a class='menurow' href='http://www.mah-jong.org/pages/rules/scoring.html'>Scoring</a></td></tr>");
      document.write("<tr bgcolor=ffff33><td><a class='menurow' href='http://www.mah-jong.org/pages/rules/specialhands.html'>Special Hands</a></td></tr>");
      document.write("<tr bgcolor=ffff33><td><a class='menurow' href='http://www.mah-jong.org/pages/rules/glossary.asp'>Glossary</a></td></tr>");
   }
   document.write("</table>");
}
