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

function ListItemBuildLink(CurrentFileName, ItemNumber)
{
  var BoilerPlate;
  var LinkCode;
  var ListItem;
  var Target = "";
  
  //ListItems[0] is the List Item Label
  //ListItems[1] is the Alt Text
  //ListItems[2] is the href
  //ListItems[3] is the BText - text displayed before the link
  //ListItems[4] is the AText - text displayed after the link
  //ListItems[5] is the target  
  //ListItems[6] is the Parentfile


  ListItem = ListItems[ItemNumber].split("|");

  if (ListItem[6] != "") 
  {
    if (ListItem[6] != CurrentFileName)
      return "";
  }
  
  if (ListItem[2] == "")
  {
    BoilerPlate = ListItem[3] + '<span class="listlinknot">' +
    ListItem[0] +
    '</span>' +
    ListItem[4];
	
	return BoilerPlate + PrintEOL(CurrentFileName, ItemNumber);  
  }
  
  if (ListItem[5] != "")
  {
    Target = 'Target="' + ListItem[5] + '" ';
  }
  
  if (CurrentFileName != ListItem[2])
  {
    LinkCode = '<a class="listlink" ' + 
	Target +
	'href="' +
    ListItem[2] +
    '" title="' +   
    ListItem[1] +
    '">' +
    ListItem[0] +
    '</a>';
  }
  else
  {
    LinkCode = '<span class="listlabelSmallBlack">' +
    ListItem[0] +
    '</span>';
  }
  
  BoilerPlate = ListItem[3] + LinkCode + ListItem[4];

  return BoilerPlate + PrintEOL(CurrentFileName, ItemNumber); 
}


function PrintEOL(CurrentFileName, ItemNumber)
{
  var ListItem;

  //ListItems[0] is the List Item Label
  //ListItems[1] is the Alt Text
  //ListItems[2] is the href
  //ListItems[3] is the BText - text displayed before the link
  //ListItems[4] is the AText - text displayed after the link
  //ListItems[5] is the target  
  //ListItems[6] is the Parentfile

  ListItem = ListItems[ItemNumber].split("|");

  if (ListItem[6] != "") 
  {
    if (ListItem[6] != CurrentFileName)
      return "";
  }

  var StringToTest = ListItem[0].toLowerCase();

  if (StringToTest.indexOf("<h") > -1)
  {
    return "";
  }

  if (StringToTest.indexOf("<p") > -1)
  {
    return "";
  }

  StringToTest = ListItem[3].toLowerCase();

  if (StringToTest.indexOf("<h") > -1)
  {
    return "";
  }

  if (StringToTest.indexOf("<p") > -1)
  {
    return "";
  }

//if (StringToTest.indexOf("<br") == -1)
//{
//  alert('3 StringToTest.indexOf("<br") <br == -1');
//  return "";
//}

  if (ListItem[4] == "")
  {
    return "<br>";
  }

  StringToTest = ListItem[4].toLowerCase();

  if (StringToTest.indexOf("<br") == -1)
  {
    return "";
  }

  return "<br>";

}


//function ListItemTextAfterLink(CurrentFileName, ItemNumber)
//{
//  var ListItem;
  
//  //ListItems[0] is the List Item Label
//  //ListItems[1] is the Alt Text
//  //ListItems[2] is the href
//  //ListItems[3] is the BText - text displayed before the link
//  //ListItems[4] is the AText - text displayed after the link
//  //ListItems[5] is the target  
//  //ListItems[6] is the Parentfile


//  ListItem = ListItems[ItemNumber].split("|");
//
//  if (ListItem[6] != "") 
//  {
//    if (ListItem[6] != CurrentFileName)
//      return "";
//  }
//
//  return "<br>";
//
//}


function ListLinksWrite()
{
  //CurrentFileName is the name of the current file which is calling the function.
  //ListItems is a an array which contains pairs of entries for each menu option.  
  //ListItems[i] is the List Item Label
  //ListItems[i+1] is the Alt Text
  //ListItems[i+1] is the href
  //ListItems[i+1] is the BText - text displayed before the link
  //ListItems[i+1] is the AText - text displayed after the link
  //ListItems[i+1] is the target  
  //ListItems[i+1] is the Parentfile

  
  var i;
  var ListItemString;
  var CurrentFileName = ListGetCurrentFileName();
  
  document.write("<h2>" + ListHeading + "</h2>");
  
  for (i=0; i < ListItems.length; i++)
  {
	ListItemString = ListItemBuildLink(CurrentFileName, i);
    document.write( ListItemString );

//	if ((ListItemString != "") && (i + 1 < ListItems.length))
//      document.write("<br><hr width='60%'><br>");
////    ListItemString = ListItemTextAfterLink(CurrentFileName, i);
////    document.write( ListItemString );

  }

}


