function GetRoot()
{
  return location.protocol + "//" + location.hostname;
}

function BuildPageHeader()
{
  var root = GetRoot();
  var BoilerPlate = 
  '<a name="TopOfPage"></a>' + 
  '<table width=100% border="0" cellspacing="0" cellpadding="0">' + 
  '<tr>' + 
    '<td height=135 width=135 valign="top" align="left" valign=center background="' + root + '/homepagegraphics/gradiant135x135.gif" style="background-repeat: none;background-color: #000;"><a href="' + root + '" title="Back to MFRI home page"><img src="' + root + '/homepagegraphics/mfrilogogradiant135x135.gif" border=0></a></td>' + 
      '<td background="' + root + '/homepagegraphics/gradiant615x135.gif"  style="background-repeat: none; background-color: #fdfd99;">' + 
      '<span style="font-size: ' +
	  PageHeadingSize + 
	  '; color: #ff0; font-weight: normal; font-style: normal; font-family: ' + 
	  "'Bookman Old Style, serif'" +
	  '; vertical-align: bottom; text-align: left;">&nbsp;' + 
	  PageHeading + 
	  '</span><br>' + 
      '<span style="' +
	  'margin-left: 65px; margin-top: -20px; font-size: 110%; color: #000; font-weight: bold; font-style: italic; font-family: ' + 
	  "'Trebuchet MS, Verdana, sans-serif'" +
	  '; vertical-align: bottom; text-align: left;' + 
	  '">Maryland Fire and Rescue Institute, University of Maryland</span>' + 
    '</td>' +
  '</tr>';
  
  return BoilerPlate;
}

function BuildPageFooter()
{
  var root = GetRoot();
  var BoilerPlate = '<tr >' + 
   '<td height=40  style="background-color: #fff; text-align: right;">'  + 
   '<hr width="60%"><br><a class="email" href="#TopOfPage" title="Click to go to Top of Page">Top</a>' +
    '<hr width="40%" color="#000">'  +
    '<a class="menulink" href="' + root + '" title="Back to MFRI home page" >Home</a>'  +
    '</td>'  +
   '<td align="right" style="background-color: #fff;">' + 
	'<table  border=0 cellpadding=0 cellspacing=0>' + 
	  '<tr>' + 
		'<td valign=bottom align=right  style="background-color: #fff;">' + 
		'<a class="dark-link" href="mailto:webmaster@mfri.org" title="Click to Send Email to Webmaster">Contact the MFRI Webmaster</a><br>' + 
		'<span style="background-color: #fff; font-size: smaller">&copy; Copyright 2003 by Maryland Fire and Rescue Institute, All Rights Reserved.</span>' + 
		'<td><a href="http://www.umd.edu" title="Click to View the University of Maryland" style="padding-right: 20px;"><img border=0 src="' + root + '/homepagegraphics/umprimarysm.gif" title="Click To Go To The University of Maryland" ></a></td>' + 
	  '</tr>' + 
	  '</table>' + 
   ' </td>' + 
  '</tr>' +
  '</table>';
  
  return BoilerPlate;
}

function GetCurrentFileName()
{
  var PathName = location.pathname.replace(/\\/gi, "/");
  var PathNameParts = PathName.split("/");
  
 return PathNameParts[PathNameParts.length - 1];
}

function BuildMenuLink(CurrentFileName, ItemNumber)
{
  var BoilerPlate;
  var MenuItem;
  var Target = "";
  
  MenuItem = MenuLinks[ItemNumber].split("|");

  if (MenuItem[4] != "") 
  {
    if (MenuItem[4] != CurrentFileName)
      return "";
  }
  
  if (MenuItem[2] == "")
  {
    BoilerPlate = '<span class="menulinknot">' +
    MenuItem[0] +
    '</span>';
	
	return BoilerPlate; 
  }
  
  if (MenuItem[3] != "")
  {
    Target = 'Target="' + MenuItem[3] + '" ';
  }
  
  if (CurrentFileName != MenuItem[2])
  {
    BoilerPlate = '<a class="menulink" ' + 
	Target +
	'href="' +
    MenuItem[2] +
    '" title="' +   
    MenuItem[1] +
    '">' +
    MenuItem[0] +
    '</a>';
  }
  else
  {
    BoilerPlate = '<span class="menulabelSmallBlack">' +
    MenuItem[0] +
    '</span>';
  }
  
  return BoilerPlate; 
}

function BuildEmailLink()
{
  var BoilerPlate;


   if (PageEmailLink == "")
   {
     BoilerPlate = "";
	 return BoilerPlate;
   }

   if (PageEmailName != "")
   {
     PageEmailName = "<br>" + PageEmailName;
   }

   if (PageEmailDescription != "")
   {
     PageEmailDescription = "to " + PageEmailName;
   }
  
  BoilerPlate = '<span class="emaillabel" >Questions?<br>Email:' + 
  PageEmailName +
  '</span><br>' +
  '<a class="email" href="mailto:' +
  PageEmailLink +
  '" title="Send Email ' +   
  PageEmailDescription +
  '">' +
  PageEmailLink +
  '</a>';
  
  return BoilerPlate; 
}

function WriteMenu()
{
  //CurrentFileName is the name of the current file which is calling the function.
  //MenuLinks is a an array which contains pairs of entries for each menu option.  
  //MenuLinks[i] is the link
  //MenuLinks[i+1] is the label
  
  var i;
  var MenuItemString;
  var CurrentFileName = GetCurrentFileName();
  
  document.write(BuildEmailLink() + "<br><br>");
  
  for (i=0; i < MenuLinks.length; i++)
  {
	MenuItemString = BuildMenuLink(CurrentFileName, i);
    document.write(MenuItemString);

	if ((MenuItemString != "") && (i + 1 < MenuLinks.length))
      document.write("<br><hr width='60%'><br>");

  }

}

function WritePage()
{
  
  document.write(BuildPageHeader());
  document.write('<tr >');
  document.write('<td width=135  style="background-color: #fff;" valign="top" align="right">');
  WriteMenu();	
  document.write('</td>');  
  document.write('<td style="background-color: #fff; padding-left: 8px;" valign="top" >');
  document.write(PageContent);
  document.write('</td>');  
  document.write('</tr >');
  document.write(BuildPageFooter());
  
  document.close();
}

function CheckUncheckAll (ControllerName, CheckBoxGroupName)
{
  var CBCheckAll = document.getElementsByName(ControllerName);		
  var CBCheckBoxes = document.getElementsByName(CheckBoxGroupName);

  var CurrentCheckAllState = CBCheckAll[0].checked;	
	
  if (CBCheckBoxes.length > 0)	
  {

    for (i = 0; i < CBCheckBoxes.length; i++)
    {
	  CBCheckBoxes[i].checked = ! CurrentCheckAllState; // CBCheckAll[0].checked ;
    }	
  }
  else
  {	
    CBCheckBoxes.checked = ! CurrentCheckAllState; // CBCheckAll[0].checked ;
  }
}

function IfCheckedHide(CheckBoxName, WidgetToHideName)
{
  if (0 == WidgetToHideName.length)
  {
    return;	
  }	

  if ($(CheckBoxName).is(":checked") == true) {
    $(WidgetToHideName).fadeOut("fast");	
  }
  else
  {
    $(WidgetToHideName).fadeIn("fast");	
  }

  return;
}

function IfNotEmptyHide(EditFieldName, WidgetToHideName)
{
  if (0 == WidgetToHideName.length)
  {
    return;	
  }	

  if ($(EditFieldName).val().length > 0) {
    $(WidgetToHideName).fadeIn("fast");	
  }
  else
  {
    $(WidgetToHideName).fadeOut("fast");	
  }

  return;
}

function IfListBoxMatchHide(ListBoxName, ValueToMatch, WidgetToHideName)
{
  if (0 == WidgetToHideName.length)
  {
    return;	
  }	

  if ($(ListBoxName).val() == ValueToMatch) {
    $(WidgetToHideName).fadeIn("fast");	
  }
  else
  {
    $(WidgetToHideName).fadeOut("fast");	
  }

  return;
}
function HideWidgetsIfCheckBoxChecked(CheckBoxName, WidgetNameList)
{

  if (0 == WidgetNameList.length)
  {
    return;	
  }	

  var WidgetNames = WidgetNameList.split(",");

  var i;

  for (i=0; i < WidgetNames.length; i++)
  {
    IfCheckedHide(CheckBoxName, WidgetNames[i]);  
  }

  return;	
}

function HideWidgetsIfTextFieldNotEmpty(EditFieldName, WidgetNameList)
{

  if (0 == WidgetNameList.length)
  {
    return;	
  }	

  var WidgetNames = WidgetNameList.split(",");

  var i;

  for (i=0; i < WidgetNames.length; i++)
  {
    IfNotEmptyHide(EditFieldName, WidgetNames[i]);  
  }

  return;	
}

function HideWidgetsOnListBoxValue(ListBoxName, ValueToMatch, WidgetNameList)
{

  if (0 == WidgetNameList.length)
  {
    return;	
  }	

  if (0 == ValueToMatch.length)
  {
    return;	
  }	

  var WidgetNames = WidgetNameList.split(",");

  var i;

  for (i=0; i < WidgetNames.length; i++)
  {
    IfListBoxMatchHide(ListBoxName, ValueToMatch, WidgetNames[i]);
  }

  return;	
}



