var url = window.location.href;
var IDPattern = /\?[.]*ID=([\d]+)/;
var PreviousID = url.match(IDPattern);
var SessionID;
var DateNow = new Date();
var ShowYear = DateNow.getFullYear();

if (DateNow.getMonth() == 11) {
   ShowYear = ShowYear+1;
}

// This function will remove leading and trailing blanks from a string
function trimString (str) {
   str = this != window? this : str;
   return str.replace(/^\\s+/g, '').replace(/\\s+\$/g, '');
}

// Add trimString to the methods for strings
String.prototype.trim = trimString;

if ( typeof(Picture) != "undefined" ) {
	// Set the slideshow speed (in milliseconds)
	var SlideShowSpeed = 3000;
	
	// Set the duration of crossfade (in seconds)
	var CrossFadeDuration = 3;
	
	//var Picture = new Array(); 
	
	//Picture[1]  = OffsetToRoot +'images/Slide01.jpg';
	//Picture[2]  = OffsetToRoot +'images/Slide02.jpg';
	//Picture[3]  = OffsetToRoot +'images/Slide03.jpg';
	//Picture[4]  = OffsetToRoot +'images/Slide04.jpg';
	//Picture[5]  = OffsetToRoot +'images/Slide05.jpg';
	//Picture[6]  = OffsetToRoot +'images/Slide06.jpg';
	
	var tss;
	var iss;
	var jss = 1;
	var pss = Picture.length-1;
	
	var preLoad = new Array();
	for (iss = 1; iss < pss+1; iss++){
	   preLoad[iss] = new Image();
	   preLoad[iss].src = Picture[iss];
	}
	
	function runSlideShow(){
	   if (document.all){
	      document.images.PictureBox.style.filter="blendTrans(duration=2)";
	      document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
	      document.images.PictureBox.filters.blendTrans.Apply();
	   }
	   document.images.PictureBox.src = preLoad[jss].src;
	   if (document.all) document.images.PictureBox.filters.blendTrans.Play();
	   jss = jss + 1;
	   if (jss > (pss)) jss=1;
	   tss = setTimeout('runSlideShow()', SlideShowSpeed);
	}
}

var menu = new Array();

for (var i = 0; i <=28; i++) {
   menu[i] = new Object;
}


var USDF_HOTYMenu = [
   {Caption:   "Program",
    URL:       "HOTY/USDF/2005/USDF-Program.htm",
    ChildMenu: null},
   {Caption:   "2007",
    URL:       "HOTY/IFSHA/2007/IFSHA-HOTY-2007.htm#dressage",
    ChildMenu: null},
   {Caption:   "2006",
    URL:       "HOTY/IFSHA/2006/IFSHA-HOTY-2006.htm#dressage",
    ChildMenu: null},
   {Caption:   "2005",
    URL:       "HOTY/USDF/2005/USDF-2005.htm",
    ChildMenu: null},
   {Caption:   "2004",
    URL:       "HOTY/USDF/2004/USDF-2004.htm",
    ChildMenu: null}
];

var USEF_HOTYMenu = [
   {Caption:   "Program",
    URL:       "HOTY/USEF/2007/USEF-HOTY-2007-Program.htm",
    ChildMenu: null},
   {Caption:   "2006",
    URL:       "HOTY/USEF/2006/USEF-HOTY-2006.php",
    ChildMenu: null},
   {Caption:   "2005",
    URL:       "HOTY/USEF/2005/USEF-HOTY-2005.htm",
    ChildMenu: null}
];

var IFSHA_HOTYMenu = [
   {Caption:   "Program",
    URL:       "HOTY/IFSHA/2009/IFSHA-HOTY-2009-Program.htm",
    ChildMenu: null},
   {Caption:   "Year to Date",
    URL:       "cgi-bin/Office/ShowHOTY.pl?Year=Current",
    ChildMenu: null}
];

var HOTYMenu = [
   {Caption:   "IFSHA",
    URL:       "HOTY/IFSHA/2007/IFSHA-HOTY-2007-Program.htm",
    ChildMenu: IFSHA_HOTYMenu},
   {Caption:   "USEF",
    URL:       "HOTY/USEF/2007/USEF-HOTY.htm",
    ChildMenu: USEF_HOTYMenu},
   {Caption:   "USDF",
    URL:       "HOTY/USDF/2007/USDF-2007.htm",
    ChildMenu: USDF_HOTYMenu},
   {Caption:   "Show Point Chart",
    URL:       "ShowPointChart.htm",
    ChildMenu: null}
];

var CommitteeMenu = [
   {Caption:   "USEF Friesian",
    URL:       "committees/usef.htm",
    ChildMenu: null},
   {Caption:   "Rules",
    URL:       "committees/rules.htm",
    ChildMenu: null},
   {Caption:   "Show",
    URL:       "committees/show.htm",
    ChildMenu: null}
];

var ShowsMenu = new Array();

function CreateShowReference(Year) {
   this.Caption = Year+'';
   this.URL = "cgi-bin/Office/ShowSchedule.pl?ShowYear=" + this.Caption;
   this.ChildMenu = null;
}

for (i = ShowYear; i > ShowYear-5; i--) {
   ShowsMenu.push(new CreateShowReference(i));
}

var ShowMgrMenu = [
   {Caption:   "Show Manager Login",
    URL:       "cgi-bin/ShowMgr/Login.pl",
    ChildMenu: null},
   {Caption:   "USEF Friesian Judges",
    URL:       "USEF_Judges.htm",
    ChildMenu: null}
];

var ResultsMenu = [
//   {Caption:   "2009",
//    URL:       "results/2009/results-2009.htm",
//    ChildMenu: null},
   {Caption:   "2008",
    URL:       "results/2008/results-2008.htm",
    ChildMenu: null},
//   {Caption:   "2007",
//    URL:       "results/2007/results-2007.htm",
//    ChildMenu: null},
   {Caption:   "2006",
    URL:       "results/2006/results-2006.htm",
    ChildMenu: null},
   {Caption:   "2005",
    URL:       "results/2005/results-2005.htm",
    ChildMenu: null},
   {Caption:   "2004",
    URL:       "results/2004/results-2004.htm",
    ChildMenu: null}
];

//var HOTYMenu = [
//   {Caption:   "2006",
//    URL:       "cgi-bin/Office/ShowHOTY.pl?Year=2006",
//    ChildMenu: null},
//   {Caption:   "2005",
//    URL:       "cgi-bin/Office/ShowHOTY.pl?Year=2005",
//    ChildMenu: null},
//   {Caption:   "2004",
//    URL:       "HOTY/2004/HOTY.htm",
//    ChildMenu: null}
//];

var MainMenu = [
   {Caption:   "Home",
    URL:       "index.php",
    ChildMenu: null},
   {Caption:   "Welcome",
    URL:       "welcome.htm",
    ChildMenu: null},
   {Caption:   "News",
    URL:       "news.php",
    ChildMenu: null},
   {Caption:   "Committees",
    URL:       "committees/committees.htm",
    ChildMenu: CommitteeMenu}, 
   {Caption:   "Show Schedule",
    URL:       "cgi-bin/Office/ShowSchedule.pl?ShowYear=2011",
    ChildMenu: ShowsMenu},
   {Caption:   "Show Manager Resources",
    URL:       "ShowMgrResources.htm",
    ChildMenu: ShowMgrMenu},
   {Caption:   "Horse of the Year",
    URL:       "HOTY/Directory.php",
    ChildMenu: HOTYMenu}, 
   {Caption:   "Show Results",
    URL:       "results/2006/results-2006.htm",
    ChildMenu: ResultsMenu},
//   {Caption:   "IFSHA Horse of the Year",
//    URL:       "HOTY/2005/ifsha-2005.htm",
//    ChildMenu: HOTYMenu},
   {Caption:   "Show Rules",
    URL:       "rules_intro.htm",
    ChildMenu: null},
   {Caption:   "FAQs",
    URL:       "faqs.php",
    ChildMenu: null},
   {Caption:   "IFSHA E-News Archive",
    URL:       "http://archive.constantcontact.com/fs050/1102843058003/archive/1102861174485.html",
    ChildMenu: null},
   {Caption:   "IFSHA NewsTime",
    URL:       "Newsletter.php",
    ChildMenu: null},
   {Caption:   "IFSHA Bulletin",
    URL:       "bulletin.php",
    ChildMenu: null},
   {Caption:   "Gift Shop",
    URL:       "http://www.cafeshops.com/ifsha",
    ChildMenu: null}, 
   {Caption:   "Links",
    URL:       "links.htm",
    ChildMenu: null},
   {Caption:   "Forms Library",
    URL:       "FormsLibrary.htm",
    ChildMenu: null},
   {Caption:   "Contacts",
    URL:       "contacts.htm",
    ChildMenu: null},
   {Caption:   "Fees",
    URL:       "Fees.htm",
    ChildMenu: null},
   {Caption:   "Join IFSHA",
    URL:       "cgi-bin/Members/NewMember.pl",
    ChildMenu: null},
   {Caption:   "Member Login",
    URL:       "cgi-bin/Members/Login.pl",
    ChildMenu: null}
];

function InsertImage(imagename, width, height, alttext, name) {
   var s = OffsetToRoot + "images/" + imagename;
//   var s = OffsetToRoot() + "images/" + imagename;

//   document.write("image path = \"" + s + "\"");
   s = "<image";
   if (name != "") {
      s = s + " name=\"" + name + "\"";
   }
   s = s + " src=\"" + OffsetToRoot + "images/" + imagename + "\"";
   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;
   
   if (Link.substr(0, 4).toLowerCase() == "http") {
      s  = Link;
   } else {
      s  = OffsetToRoot + Link;
   }

   return "<a class=\"menu\" href=\"" +
          s +
          "\">" +
          Caption +
          "</a>";
}

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\" align='center'> <font color=white>&nbsp;");
   if (window.TestMachineNote) {
      document.write(TestMachineNote);
   }
   document.write("&nbsp</font></td>");
   document.write("</tr>");
   document.write("<tr>");
   document.write("<td bgcolor=\"#0000C4\">" +
                  InsertImage("SlideShowFill.jpg", "147", "106", "", "PictureBox") +
                  "</td>");
//   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-3.gif", "500", "114", "International Friesian Show Horse Association", ""));
   document.write("</td>");
   document.write("<td  width=\"147\" align=\"left\" valign=\"center\">");
   document.write(InsertImage("ifshalogo.jpg", "131", "133", "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("<span style='font-size: 8pt; text-align: left;'>");
      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("</span>");
      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 style='font-size: 10pt; text-align: left;'>");
      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 ShowCGIFooter(CGI_Name, CGI_Version) {
   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("Generated " + document.lastModified);
   document.write(" by " + CGI_Name + ", version of " +CGI_Version + ".");
   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){
   document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + caption + '</a>');
}


