// Copyright (c) 2004, Josh Williams, Iowa State University
// Comments:
//   - Adapted from scripts at www.dynamicdrive.com

var base = "http://www.public.iastate.edu/~cucurbitipm/";

function BannerStamp()
{
  document.write('<center><span class="logo"><img src="'+base+'img/TopBanner.jpg" alt="Cucurbit Pest Management"></span></center><br>');
}

function CopyrightStamp()
{
  document.write('<hr><center><span class="copyright">');
  document.write('Design By: Josh Williams, ISU<br>In Collaboration With: Daren Mueller, ISU');
  
  if (location.href.indexOf("homepage.html") != -1 ||
    location.href == "http://www.public.iastate.edu/~cucurbitipm/" ||
    location.href == "http://www.public.iastate.edu/~cucurbitipm")
  {
    document.write('<br>This web site looks best with Internet Explorer. It is under development, so please bear with us.<br>');
    document.write('<a href="http://www.uoguelph.ca/"><img src="img/guelph.gif" alt="University of Guelph"></a>');
    document.write('&nbsp;<a href="http://www.iastate.edu/"><img src="img/ISU.gif" alt="Iowa State University"></a>');
    document.write('&nbsp;<a href="http://www.umn.edu/"><img src="img/UofMinn.gif" alt="University of Minnesota"></a>');
    document.write('&nbsp;<a href="http://welcome.colostate.edu/"><img src="img/CSU.gif" alt="Colorado State University"></a>');
    document.write('&nbsp;<a href="http://www.carleton.edu/"><img src="img/carleton.gif" alt="Carleton College"></a>');
  }
  else
  {
    document.write('<br><a href="http://validator.w3.org/check/referer"><img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a>&nbsp;');
    document.write('<a href="http://www.adobe.com/products/acrobat/readstep2.html"><img border="0" height="31" width="88" src="http://www.adobe.com/images/getacro.gif" ALT="Adobe&reg; Reader&reg;"></a>');
  }
  document.write('</span></center>');
}


///////////////////////////////////////////////////////////////////
// Find out the browser type
var ie4 = (document.all && (navigator.userAgent.indexOf("Opera") == -1));
var ns6 = (document.getElementById && !document.all);
var ns4 = (document.layers);

///////////////////////////////////////////////////////////////////
// Fade a link (in IE).
function doFade(obj)
{
	if(ie4)
	{
    if (obj.filters.blendTrans == null) return;
    
		obj.filters.blendTrans.apply();
		obj.filters.blendTrans.play();
	}
}

///////////////////////////////////////////////////////////////////
// CucurbitipmMenu class                                            //
///////////////////////////////////////////////////////////////////
function CucurbitipmMenuBar(menuBarID, divClass, menuBarClass, tableClass)
{
  this.divClass = divClass;
  this.menuBarClass = menuBarClass;
  this.tableClass = tableClass;
  
  this.AddMenu = AddMenu;
  this.AddMenuItem = AddMenuItem;
  this.Show = Show;
  
  this.menuPlaceHolder = "<!--MENUS--></tr>";
  
  this.HTML  = "<div id='" + menuBarID + "' class='"+ divClass + "'><div class='" + menuBarClass + "'><table class='" + tableClass + "'>";
  this.HTML += this.menuPlaceHolder;
  this.HTML += "</table></div></div>";
  this.HTML += "<!--MENUITEMS-->";
  
  lastMenu = null;
}

///////////////////////////////////////////////////////////////////
// AddMenu function
//    o menuID - The unique identifier of the menu
//    o text   - The text <can be html tag(s)>
//    o newRow - Do you want to start a new row?
//    o href   - The href of the link
//    o title  - The tooltip text.
//
// NOTES:
//  - The first menu ALWAYS starts a row!!!!!
//
function AddMenu(menuID, text, newRow, href, title)
{
  var newMenu = "<!--MENU:" + menuID + "-->";
  
  // The menu already exists!!
  if (this.HTML.indexOf(newMenu) != -1)
  {
    alert(newMenu + " already exists!");
    return;
  }
  
  newMenu += ((newRow)?"</tr><tr>":"") + "<td><div id='" + menuID + "'><a href='" + ((href != null)?href:"#") + "'";
  newMenu += "title='" + ((title != null)?title:text) + "'";
  newMenu += "onmouseover='doFade(this);'";
  newMenu += "onmouseout='doFade(this);'";
  
  // "return false" makes nothing happen when the link is clicked.
  newMenu += "onclick='this.blur();" + (((href == null)||(href == "#"))?"return false;":"") + "'>" + text + "</a></div></td>";
  newMenu += this.menuPlaceHolder;
  
  this.HTML = this.HTML.replace(this.menuPlaceHolder, newMenu);
}

///////////////////////////////////////////////////////////////////
// AddMenuItem function
function AddMenuItem(parentMenuID, menuItemID, href, text, title)
{
  var parentItemHolder = "<!--MENUITEM:" + parentMenuID + "-->";
  var menuItemHolder = "<!--MENUITEM:" + parentMenuID + "_" + menuItemID + "-->";
  
  // The parent menu does not exist!!
  if (this.HTML.indexOf("<!--MENU:" + parentMenuID + "-->") == -1)
  {
    alert('Parent Menu "' + parentMenuID + '" does not exist!');
    return;
  }
  
  // The menu item already exists
  if (this.HTML.indexOf(menuItemHolder) != -1)
  {
    alert(menuItemHolder + " already exists!");
    return;
  }
  
  var newMenuItem = "";
  // This is the first menu item for parentMenuID
  if (this.HTML.indexOf(parentItemHolder) == -1)
  {
    newMenuItem  = "<div id='" + parentMenuID + "_menu' onmouseout='hideAll()' style='background:black;position:absolute; visibility: hidden; z-index:100; top: -300;'";
    newMenuItem += "<div class='" + this.menuBarClass + "'><table class='" + this.tableClass + "'>";
    newMenuItem += parentItemHolder;
    newMenuItem += "</table></div></div>";
    newMenuItem += "<!--MENUITEMS-->";
    
    this.HTML = this.HTML.replace("<!--MENUITEMS-->", newMenuItem);
  }
  
  newMenuItem  = menuItemHolder;
  newMenuItem += "<tr><td><a href='" + href + "'>" + title + "</a></td></tr>";
  newMenuItem += parentItemHolder;
  this.HTML = this.HTML.replace(parentItemHolder, newMenuItem);
}

///////////////////////////////////////////////////////////////////
// Show function
// NOTES:
//  - Should call AFTER ALL ADDITIONS OF MENUS & MENU ITEMS
function Show()
{
  document.writeln(this.HTML);
}