var url = window.location.href;
var IDPattern = /\?[.]*ID=([\d]+)/;
var PreviousID = url.match(IDPattern);
var SessionID;
var menu = new Array();

for (var i = 0; i <=28; i++) {
   menu[i] = new Object;
}


var CareerMenu = [
   {Caption:   "Software Engineers",
    URL:       "Careers/SEandTL.htm",
    ChildMenu: null},
   {Caption:   "Sales and Business Development",
    URL:       "Careers/SalesAndBD.htm",
    ChildMenu: null}
];

var MainMenu = [
   {Caption:   "Home",
    URL:       "default.htm",
    ChildMenu: null},
   {Caption:   "Welcome",
    URL:       "welcome.htm",
    ChildMenu: null},
   {Caption:   "News",
    URL:       "news.htm",
    ChildMenu: null},
   {Caption:   "Show Schedule",
    URL:       "schedule/schedule.htm",
    ChildMenu: null},
   {Caption:   "Show Results",
    URL:       "results/results.htm",
    ChildMenu: null},
   {Caption:   "Show Rules",
    URL:       "rules/Show_Rules-toc.htm",
    ChildMenu: null},
   {Caption:   "Join IFSHA",
    URL:       "join.htm",
    ChildMenu: null},
   {Caption:   "FAQs",
    URL:       "faqs.htm",
    ChildMenu: null},
   {Caption:   "Links",
    URL:       "links.htm",
    ChildMenu: null},
//   {Caption:   "Careers",
//    URL:       "Careers/Careers.htm",
//    ChildMenu: CareerMenu},
   {Caption:   "Contacts",
    URL:       "contacts.htm",
    ChildMenu: null}
];

function InsertImage(imagename, width, height, alttext) {
   var s = OffsetToRoot + "images/" + imagename;
//   var s = OffsetToRoot() + "images/" + imagename;

//   document.write("image path = \"" + s + "\"");
   s = "<image src=\"" + s + "\"";
   if (width != "") {
      s = s + " width=\"" + width + "\"";
   }

   if (height != "") {
      s = s + " height=\"" + height + "\"";
   }

   if (alttext != "") {
      s = s + " alttext=\"" + alttext + "\"";
   }

   return s + ">";
}

function CurrentMenu(Caption) {
   return "<font face=\"arial\" color=\"#FF0000\"><strong>" +
          Caption +
          "</strong></font>";
}

function TargetMenu(Caption, Link) {
   var s = OffsetToRoot + Link;

   return "<a class=\"menu\" href=\"" +
          s +
          "\">" +
          Caption +
          "</a>";
   return "<span class=\"menu\">" +
          "<a href=\"javascript:gotourl('" +
          s +
          "')\">" +
          Caption +
          "</a></span>";
}

function ShowHeader() {
   document.write("<TABLE border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">");
   document.write("<tr>");
   document.write("<td>");
   document.write(InsertImage("UL_Corner.gif", "147", "20", ""));
   document.write("</td>");
   document.write("<td bgcolor=\"#0000C4\">&nbsp;</td>");
   document.write("</tr>");
   document.write("<tr>");
   document.write("<td bgcolor=\"#0000C4\">&nbsp;</td>");
   document.write("<td>");
   document.write("<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">");
   document.write("<tr>");
   document.write("<td align=\"center\" valign=\"center\">");
   document.write(InsertImage("ifsha-banner-1.gif", "363", "106", "International Friesian Show Horse Association"));
   document.write("</td>");
   document.write("<td  width=\"147\" align=\"left\" valign=\"center\">");
   document.write(InsertImage("ifshalogo.gif", "131", "147", "IFSHA Logo"));
   document.write("</td>");
   document.write("</tr>");
   document.write("</table>");
   document.write("</td>");
   document.write("</tr>");
   document.write("<tr>");
}

function ShowSubMenu(Level, Menu, NowAt) {
   var i;

   document.write("<tr>");
   document.write("<td>");
   document.write("<table border=0>");
   document.write("<tr>");
   document.write("<td>&nbsp;&nbsp;</td>");
   document.write("<td>");
   document.write("<table border=0 class=\"submenu\">");
   for (i=0; i < Menu.length; i++) {
      document.write("<tr>");
      document.write("<td>");
      document.write("<small>");
      if (Menu[i].Caption == NowAt[Level]) {
         document.write(CurrentMenu(NowAt[Level]));
         if (Menu[i].ChildMenu != null) {
            ShowSubMenu(Level+1, Menu[i].ChildMenu, NowAt);
         }
      } else {
         document.write(TargetMenu(Menu[i].Caption, Menu[i].URL));
      }
      document.write("</small>");
      document.write("</td>");
      document.write("</tr>");
   }
   document.write("</table>");
   document.write("</td>");
   document.write("</tr>");
   document.write("</table>");
   document.write("</td>");
   document.write("</tr>");
}

function ShowMenu(NowAtMenu) {
   var NowAt = NowAtMenu.split("/");
   var i;

   document.write("<td width='147' valign='top' align='center' bgcolor='#0000C4'>");
   document.write("<font face='arial' color='FFFFFF'>");
   document.write("<table border='0' width='100%' class='menu' cellspacing='0' cellpadding='3'>");
   for (i=0; i < MainMenu.length; i++) {
      document.write("<tr>");
      document.write("<td>");
      if (MainMenu[i].Caption == NowAt[0]) {
         document.write(CurrentMenu(NowAt[0]));
         if (MainMenu[i].ChildMenu != null) {
            ShowSubMenu(1, MainMenu[i].ChildMenu, NowAt);
         }
      } else {
         document.write(TargetMenu(MainMenu[i].Caption, MainMenu[i].URL));
      }
      document.write("</td>");
      document.write("</tr>");
   }
   document.write("</table>");
   
   document.write("</font>");
   document.write("</td>");
   document.write("<td>");
   
   document.write("<table cellpadding='5'>"); // Open table containing the main text
   document.write("<tr>");
   document.write("<td>");
}

function ShowFooter() {
   var mydate=new Date()
   var year=mydate.getYear()

   if (year < 1000) year+=1900

   document.write("</td>");
   document.write("</tr>");
   document.write("</table>");  // Closes the table containing the main text
   document.write("</td>");
   document.write("</tr>");
   document.write("<tr>");
   document.write("<td>");
   document.write(InsertImage("LL_Corner.gif", "147", "20", ""));
   document.write("</td>");
   document.write("<td bgcolor=\"#0000C4\">&nbsp;</td>");
   document.write("</tr>");
   document.write("<tr>");
   document.write("<td>&nbsp;</td>");
   document.write("<td>");
   document.write("<small>");
   document.write("<small>");
   document.write("<font face=\"Arial\">");
   document.write("<em>");
   document.write("    <H5>");
   document.write("      All contents copyright &copy; 2002-");
   document.write(year);
   document.write("      , International Friesian Show Horse Association. All rights reserved.<BR>");
   document.write("Last Revised: " + document.lastModified);
   document.write("    </H5>");
   document.write("</em>");
   document.write("</font>");
   document.write("</small>");
   document.write("</small>");
   document.write("</td>");
   document.write("</tr>");
   document.write("</table>");
}

function MakeSessionID() {
   var d = new Date();
   return d.valueOf();
}

function gotourl(TargetURL){
   if (TargetURL.substring(0,0) == "#") {
      // It's a same page reference, we shouldn't be here...
	  window.alert("Improper use of gotourl.  Param was " + TargetURL);
   } else {
      if (TargetURL.indexOf("?") == -1) {
         // It's a normal link...
         window.location.href = TargetURL + "?ID=" + SessionID;
      } else {
         // It already has parameters (perhaps a CGI)...
         window.location.href = TargetURL + "&ID=" + SessionID;
      }
   }
}

if (PreviousID) {
   SessionID = PreviousID[1];
} else {
   SessionID = MakeSessionID();
}

function newWin(url,name,rs,sc,mn,tl,lo,wd,hi) {
   openWindow = window.open(url,name,'resizable='+rs+',scrollbars='+sc+',menubar='+mn+',toolbar='+tl+',location='+lo+',width='+wd+',height='+hi);
}

function open_window(url) {
email = window.open(url,"eMail","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=yes,width=640,height=480");
}

function MakeEmail(user, domain, suffix, caption){
   if (caption == '') {
      caption = user + '@' + domain + '.' + suffix
   }
   document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + caption + '</a>');
}

