/*
COPYRIGHT 2003 BY ED/iT INC
JULY 7, 2003
VERSION 1.0

 &nbsp;> could be added to show submenus
*/

window.name = "currentwindow";
var MenuActiveLevel1 = 0;  //main menu
var MenuActiveLevel2 = 0;  //level1 menu
var MenuCount = 5;
var MenuSpace = 630/5;
var Lpos = 0;
var Loffset = 9;
var Tpos = 170;
var CellHeight = 20; //for fontsize 10 pt only
var menutime = setTimeout('doTime()',3000);
var CellACTIVE = false;
var i = 0;
var j = 0;
var astring = "";
var ShowInfo = false;

/* DESIGN THE MENUS */

MenuMain = new Array("Home", "Invitations and Accessory Papers","Wordings","Getting Them Printed", "Important Resources");
MenuMainLinks = new Array("main.htm",0,0,0,0);

i = 0;
var MMcount = MenuMain.length;

document.writeln('<TABLE WIDTH="630" BORDER="1" CELLPADDING="1" CELLSPACING="0" CLASS="TableMain"><TR>')
 while (i < MMcount)
 {
  if (MenuMainLinks[i] == 0)
  {
   //document.writeln('<TD WIDTH="126" ONMOUSEMOVE="OnMouseOverMain(this,'+(i+1)+')" ONMOUSEOUT="OnMouseOutMain(this)"><B>'+MenuMain[i]+'</B></TD>')
   document.writeln('<TD WIDTH="126" ONMOUSEMOVE="OnMouseOverMain(this,'+(i+1)+')" ONMOUSEOUT="OnMouseOutMain(this,'+(i+1)+')"><P CLASS="MenuCell"><B>'+MenuMain[i]+'</B></P></TD>')
  }
  else
  {
   //document.writeln('<TD WIDTH="126" ONMOUSEMOVE="OnMouseOverMain(this,'+(i+1)+')" ONMOUSEOUT="OnMouseOutMain(this)"><A HREF="'+MenuMainLinks[i]+'">'+MenuMain[i]+'</A></TD>')
   document.writeln('<TD WIDTH="126" ONMOUSEMOVE="OnMouseOverMain(this,'+(i+1)+')" ONMOUSEOUT="OnMouseOutMain(this,'+(i+1)+')" ONCLICK="OnClickMainCell(this,'+(i+1)+')"><P CLASS="MenuCellLink"><B>'+MenuMain[i]+'</B></P></TD>')
  }
  ++i;
 }
document.writeln('</TR></TABLE>')

//BUILD THE LEVEL1 MENUS FOR EACH OF THE MAIN MENU TOPICS
//COUNT AND PLACEMENT OF L1 MUST AGREE WITH MAIN
MenuLevel1 = new Array();
MenuLevel1Links = new Array();

MenuLevel1[1] = Array("1 Level1 1","1 Level1 2","1 Level1 3","1 Level1 4");
MenuLevel1Links[1] = Array(0,0,0,0);
MenuLevel1[2] = Array("The Basics","Envelopes & Addressing","Etiquette","Your Guest List","History & Traditions");
MenuLevel1Links[2] = Array("m1_ep.htm","m1_ea.htm","m1_et.htm","m1_gl.htm","m1_eh.htm");
MenuLevel1[3] = Array("Introduction and Primer","Index to Wordings for all Occasions");
MenuLevel1Links[3] = Array("m1_ew.htm","w_index.htm");
MenuLevel1[4] = Array("Commercial Printers","Mail Order Printers","Print Your Own","Paper Stock","Terminology","Costs");
MenuLevel1Links[4] = Array("m2_cp.htm","m2_mp.htm","m2_py.htm","m2_ps.htm","m2_pt.htm","m2_cs.htm");
MenuLevel1[5] = Array("Printers","Paper Stock","Software","Calligraphers","Product Reviews","Professionals","Related Web Sites","Magazines","Marriage Statistics");
MenuLevel1Links[5] = Array("m3_ip.asp","m3_iv.asp","m3_is.asp","m3_ic.asp","m3_pr.htm","m3_wc.asp","m3_ws.asp","m3_bm.asp","m3_ms.htm");

// BUILD THE LEVEL2 MENUS FOR EACH OF THE LEVEL1 TOPICS
// COUNT AND PLACEMENT OF L2 MUST AGREE WITH EACH L1
// NOTE THAT ALL THE LEVEL2 MENUS REQUIRE LINKS
// NOTE THAT THERE ARE NO LEVEL2 MENUS WHERE A LEVEL1 MENU HAS A LINK
MenuLevel2 = new Array();
MenuLevel2Links = new Array();

//IN ABOVE EXAMPLE THERE ARE FOUR L1 AND EACH REQUIRES A LEVEL2
MenuLevel2[11] = Array("11 Level2 1");
MenuLevel2Links[11] = Array("blank2.htm");
MenuLevel2[12] = Array("12 Level2 1");
MenuLevel2Links[12] = Array("blank.htm");
MenuLevel2[13] = Array("13 Level2 1");
MenuLevel2Links[13] = Array("blank.htm");
MenuLevel2[14] = Array("14 Level2 1");
MenuLevel2Links[14] = Array("blank.htm");

MenuLevel2[21] = Array("21");
MenuLevel2Links[21] = Array("blank21.htm");
MenuLevel2[22] = Array("22");
MenuLevel2Links[22] = Array("blank22.htm");
MenuLevel2[23] = Array("23");
MenuLevel2Links[23] = Array("blank23.htm");
MenuLevel2[24] = Array("24");
MenuLevel2Links[24] = Array("blank24.htm");
MenuLevel2[25] = Array("25");
MenuLevel2Links[25] = Array("blank25.htm");

MenuLevel2[31] = Array("31 Level2 1");
MenuLevel2Links[31] = Array("blank1.htm");
MenuLevel2[32] = Array("32 Level2 1");
MenuLevel2Links[32] = Array("blank1.htm");
MenuLevel2[33] = Array("33 Level2 1");
MenuLevel2Links[33] = Array("blank1.htm");
MenuLevel2[34] = Array("34 Level2 1");
MenuLevel2Links[34] = Array("blank1.htm");
MenuLevel2[35] = Array("35 Level2 1");
MenuLevel2Links[35] = Array("blank1.htm");
MenuLevel2[36] = Array("36 Level2 1");
MenuLevel2Links[36] = Array("blank1.htm");

MenuLevel2[41] = Array("41 Level2 1");
MenuLevel2Links[41] = Array("blank.htm");
MenuLevel2[42] = Array("42 Level2 1");
MenuLevel2Links[42] = Array("blank.htm");
MenuLevel2[43] = Array("43 Level2 1");
MenuLevel2Links[43] = Array("blank.htm");
MenuLevel2[44] = Array("44 Level2 1");
MenuLevel2Links[44] = Array("blank.htm");

MenuLevel2[51] = Array("51 Level2 1");
MenuLevel2Links[51] = Array("blank.htm");
MenuLevel2[52] = Array("52 Level2 1");
MenuLevel2Links[52] = Array("blank.htm");
MenuLevel2[53] = Array("53 Level2 1");
MenuLevel2Links[53] = Array("blank.htm");
MenuLevel2[54] = Array("54 Level2 1");
MenuLevel2Links[54] = Array("blank.htm");
MenuLevel2[55] = Array("54 Level2 1");
MenuLevel2Links[55] = Array("blank.htm");

/*debug
i = 0;
j=1;
while (j < 5)
{
 document.writeln('j='+j)
 i=0;
 while (i < MenuLevel2[40+j].length)
 {
 document.writeln(i + ">" + MenuLevel2[40+j][i])
 ++i
 }
++j
}
*/

//WRITE THE LEVEL1 MENUS
var i = 0;
var ML1count = 0;
var j = 1;
//alert("MMcount"+MMcount);
 while (i < MMcount)
 {
  if (MenuMainLinks[i] == 0)
  //then there is no link item on the main menu so build a level 1 menu
  {
    //alert("write level1 menu for main menu > "+i+" whose style ID is > ML1_"+(i+1));
    //write a level1 menu
    document.writeln('<DIV CLASS="Menu1" STYLE="position: absolute; display: none;" ID="ML1_'+(i+1)+'">')
    document.writeln('<TABLE CELLPADDING="1" CELLSPACING="0" RULES="ROWS">')
    ML1count =  MenuLevel1[i+1].length;
    //alert("MAIN>"+i+" for Level1 has a Level1 count of "+ML1count);
    j = 0;
    while (j < ML1count)
    {
      if (MenuLevel1Links[i+1][j] == 0)
      {//alert("zero"+MenuLevel1[j]);
        document.writeln('<TR><TD ONMOUSEMOVE="OnMouseOverCell(this, '+(j+1)+')" ONMOUSEOUT="OnMouseOutCell(this, '+(j+1)+')"><P CLASS="MenuCell"><B>'+MenuLevel1[i+1][j]+'</B></P></TD></TR>')
      }
      else
      {//alert("nonzero"+MenuLevel1[j]);
        document.writeln('<TR><TD ONMOUSEMOVE="OnMouseOverCell(this, '+(j+1)+')" ONMOUSEOUT="OnMouseOutCell(this, '+(j+1)+')" ONCLICK="OnClickCell(this,'+(i+1)+','+(j+1)+')"><P CLASS="MenuCellLink"><B>'+MenuLevel1[i+1][j]+'</B></P></TD></TR>')
      }
    //alert("bumpj"+j);
    ++j
    }
    document.writeln('</TABLE></DIV>')
    //alert("end of table");
    //try getting the table width after it is created
    //alert(i+1);
    //var idvar = "ML1_"+(i+1);
    //alert(idvar);
    //var avar = document.getElementById(idvar);
    //alert("ID="+avar);
    //var wtable = avar.getAttribute("WIDTH");
    //alert("width " + wtable);*/
    //alert("avar width "+avar.width);
    //var stables = document.body.getElementsByTagName("TABLE");
    //var wtable = stables[i].getAttribute("WIDTH");
    //alert(stables + " " + wtable);
    //alert("ID="+avar);
  }
  ++i
 }

//WRITE THE LEVEL2 MENUS AND SKIP ANY LEVEL1 MENUS WITH A LINK
//you need the mainmenu count and each level1 menu count
i = 1;
var ML2count = 0;
var k = 0;
var nvar = 0;
 while (i < (MMcount+1))
 {
  //alert("DOING LEVEL 2 FOR MAIN>"+ i + " of count " + MMcount + "MainMenuLinks[i-1]="+MenuMainLinks[i-1]);
  if (MenuMainLinks[i-1] == 0)
  {
     //then there is no link item on the main menu so there is a level 1 menu
     //so get the level1 menu count (for each main menu)
     ML1count = MenuLevel1[i].length;
     //alert("ML1count>"+ML1count);
     j = 1;
     while (j < (ML1count+1))
     {
       //alert("WRITE LEVEL2 menu for MAIN> "+i+" with style ID is > ML2_"+ (i*10 + j));
       //write a level2 menu if there is no link on the level 1 menu
       if (MenuLevel1Links[i][j-1] == 0)
       {
         document.writeln('<DIV CLASS="Menu2" STYLE="position: absolute; display: none;" ID="ML2_'+(i*10 + j)+'">')
         //fixed width
         //document.writeln('<TABLE WIDTH="130" CELLPADDING="1" CELLSPACING="0" RULES="ROWS" CELLSPACING="0" ONMOUSEOUT="OnMouseOutSubTable(this)" ONMOUSEMOVE="OnMouseMoveSubTable(this)">')
         //variable width
         document.writeln('<TABLE CELLPADDING="1" CELLSPACING="0" RULES="ROWS" CELLSPACING="0" ONMOUSEOUT="OnMouseOutSubTable(this)" ONMOUSEMOVE="OnMouseMoveSubTable(this)">')
         k = i*10 + j;
         ML2count =  MenuLevel2[k].length
         //alert("MAIN>"+i+" for Level2 has a Level1 count of "+ML2count);
         //alert("WRITING ML2_"+(i*10 + j)+" FOR " +ML2count+ " CELLS");
         k = 1;
         while (k < ML2count+1)
         { //alert("writingJK"+j+k+" <"+(i*10 + j)+" > "+MenuLevel2[i*10 + j][k-1]);
           nvar = (i*10) + j;
           document.writeln('<TR><TD ONMOUSEMOVE="OnMouseOverSubCell(this)" ONMOUSEOUT="OnMouseOutSubCell(this)" ONCLICK="OnClickSubCell(this,'+nvar+','+k+')"><P CLASS="MenuCellLink"><B>'+MenuLevel2[i*10 + j][k-1]+'</B></P></TD></TR>')
           ++k
         }
         document.writeln('</TABLE></DIV>')
       }
       ++j;
     }
  }
  ++i
 }
//END INITIALIZATION

//FUNCTION ROUTINES

//following function used in invitationsetc only
function ShowInfoDO(ilevel,iwhich,ishow)
{ //alert("I"+ilevel+"W"+iwhich+"S"+ishow);
  //alert("string>"+astring);
  var istring = "a";
  istring = "INFO" + (ilevel) + (iwhich);
  if (document.getElementById(istring) != null)
   {
    if (ishow == 1)
    {
     document.getElementById(istring).style.display = "";
    }
    else
    { 
    document.getElementById(istring).style.display = "none";
    }
   }
return;
}

function OnMouseOverMain( el, ivar )
{ el.style.color = "red";//alert("mom"+ivar);
  MenuActiveLevel1 = ivar;
  MenuActiveLevel2 = 0;
  if (ShowInfo == true)
   ShowInfoDO(0,ivar,1);
  CellACTIVE = true;
  clearTimeout(menutime);
  Lpos = Loffset + MenuSpace * (ivar - 1);
  //hide all level1 menus
  i = 0;
  while (i < MenuMainLinks.length)
  {
    astring = "ML1_" + (i+1);
    //alert("string="+astring+" "+document.getElementById(astring));
    if (document.getElementById(astring) != null)
     {
     document.getElementById(astring).style.display = "none";
     }
    //hide all level2 menus
    j = 0;
    while (j < MenuLevel1[i+1].length)
    {
      astring = "ML2_" + (i+1) + (j+1);
      if (document.getElementById(astring) != null)
      {
       document.getElementById(astring).style.display = "none";
      }
      ++j;
    }
    ++i;
  }
  //show level 1 menu
    astring = "ML1_" + MenuActiveLevel1;
    //alert("show level1 menu>"+ MenuActiveLevel1);
    //ML1_4.style.display="";
    if (document.getElementById(astring) != null)
     {
      document.getElementById(astring).style.left = Lpos;
      document.getElementById(astring).style.top = Tpos;
      document.getElementById(astring).style.display = "";
     }
    else
     {
      el.style.color = "white";
      el.style.textDecoration = "underline";
      el.style.cursor = "hand";
     }

return;
}

function OnMouseOutMain( el, ivar )
{ el.style.color = "";
  if (ShowInfo == true)
   ShowInfoDO(0,ivar,0);
  el.style.textDecoration = "none";
   //MenuActiveLevel2 = 0;
   //MenuActiveLevel1 = 0;
   CellACTIVE = false;
   menutime = setTimeout('doTime()', 3000);
return;
}

function OnClickMainCell( el, ivar )
{
 el.style.color = "blue";
 //alert("Main clicked "+ivar+" cellclicked>link>"+MenuMainLinks[ivar-1]);
 window.open(MenuMainLinks[ivar-1], "currentwindow");
return;
}

function OnMouseOverCell( el, ivar )
{ el.style.color = "red";
  if (ShowInfo == true)
   ShowInfoDO(MenuActiveLevel1,ivar,1);
  CellACTIVE = true;
  clearTimeout(menutime);
  MenuActiveLevel2 = ivar;
  //clear all level2 menus for this level1 menu
    //hide level2 menus
    j = 0;
    while (j < MenuLevel1[MenuActiveLevel1].length)
    {
      astring = "ML2_" + (MenuActiveLevel1) + (j+1);
      if (document.getElementById(astring) != null)
      {
       document.getElementById(astring).style.display = "none";
      }
      ++j;
    }
    //show the level2 menu for the selected level1 cell but only if not a link cell
    astring = "ML2_" + MenuActiveLevel1 + MenuActiveLevel2;
    if (document.getElementById(astring) != null)
    {
     document.getElementById(astring).style.left = Lpos + 131;
     document.getElementById(astring).style.top = Tpos + (CellHeight / 2) + (MenuActiveLevel2 - 1) * CellHeight;
     document.getElementById(astring).style.display = "";
    }
    else
    {el.style.color = "white";
     el.style.textDecoration = "underline";
     el.style.cursor = "hand";
    }
return;
}

function OnMouseOutCell( el, ivar )
{ el.style.color = "";
  if (ShowInfo == true)
   ShowInfoDO(MenuActiveLevel1,ivar,0);
  el.style.textDecoration = "none";
  CellACTIVE = false;
  menutime = setTimeout('doTime()', 3000);
return;
}

function OnClickCell( el, var1, var2 )
{
 //el.style.color = "blue";
 //alert("M"+var1+"C"+var2+" cellclicked>link>"+MenuLevel1Links[var1][var2-1]);
 window.open(MenuLevel1Links[var1][var2-1], "currentwindow");
return;
}

function OnMouseOverSubCell( el )
{ el.style.color = "white";
  el.style.textDecoration = "underline";
  el.style.cursor = "hand";
  CellACTIVE = true;
  clearTimeout(menutime);
return;
}

function OnMouseOutSubCell( el )
{ el.style.color = "";
  el.style.textDecoration = "none";
  CellACTIVE = false;
  menutime = setTimeout('doTime()', 3000);
return;
}

function OnMouseOutSubTable( el )
{
 //CellACTIVE == false;
 //menutime = setTimeout('doTime()', 3000);
return;
}

function OnMouseMoveSubTable( el )
{
 //CellACTIVE = true;
 //clearTimeout(menutime);
return;
}

function OnClickSubCell( el, var1, var2 )
{
 //alert("A>"+var1+"B>"+var2+"<subcellclicked>"+(var1*10+var2)+"<link>"+MenuLevel2Links[var1][var2-1]);
 window.open(MenuLevel2Links[var1][var2-1], "currentwindow");
return;
}

function doTime()
{
if (CellACTIVE == false)
  //hide all level1 menus
  i = 0;
  while (i < MenuMainLinks.length)
  {
    astring = "ML1_" + (i+1);
    //alert("string="+astring+" "+document.getElementById(astring));
    if (document.getElementById(astring) != null)
     {
     document.getElementById(astring).style.display = "none";
     }
    //hide all level2 menus
    j = 0;
    while (j < MenuLevel1[i+1].length)
    {
      astring = "ML2_" + (i+1) + (j+1);
      if (document.getElementById(astring) != null)
      {
       document.getElementById(astring).style.display = "none";
      }
      ++j;
    }
    ++i;
  }
  return;
}

// END FUNCTIONS

//document.writeln('</HEAD>')
//document.writeln('<BODY>')
