function commonCheck() {
  return top.typeID == "Menu" ||
         top.typeID == "Login"  ||
         top.typeID == "SystemSelection" ||
         !top.opener ||
         top.opener.parent.typeID == "Menu";
}

function pageHeading(systemData, control) {
  if (commonCheck() ||
      top.typeID == "Entry") {

    if (typeof(control) == "undefined") {
      control = "v";
    }

    if (control == "v") {
      writeLogo(systemData);
      writeName(systemData, true);
      writeUser(systemData);
    } else {
      content += '<TABLE WIDTH="100%">\n';
      content += '<TR><TD WIDTH="12%">';
      content += '<IMG ALT="Logo" SRC="' + systemData[3] + '">';
      content += '<\/TD><TD CLASS="cpHeader" VALIGN="top">';
      content += systemData[6] + '<BR>';
      content += systemData[7].charAt(0).toUpperCase() + systemData[7].substring(1, systemData[7].length).toLowerCase() + '<\/TD><\/TR>';
      content += '<TR><TD COLSPAN="2"><HR><\/TD><\/TR>';
      content += '<\/TABLE>\n';
      document.write(content);
    }
  }
}

function pageFooting(systemData, control) {
  if (commonCheck() ||
      top.typeID == "Detail" ||
      top.typeID == "Search") {

    var sCopyright = "Copyright &copy; 1999&mdash;" + new Date().getUTCFullYear();
    var sCompName = "Eloquent Systems Inc."
    var sCompURL = "http://www.eloquent-systems.com/";
    var sCompany = "<a tabindex=\"-1\" href=\"" + sCompURL + "\" target=\"_blank\">" + sCompName + "</a>";
    var sURLLink = "<a tabindex=\"-1\" href=\"" + sCompURL + "\" target=\"_blank\">" + sCompURL + "</a>";

    if (typeof(control) == "undefined") {
      control = "v";
    }

    var content = "";
    if (control == "v") {
      content += "<hr />";
      content += systemData[4] + "<br />";
      content += systemData[5] + "<br />";
      content += sCopyright + "<br />";
      content += sCompany + "<br />";
      content += "License " + systemData[8] + "<br />";
      content += "Licensee " + systemData[9] + "<br />";
    } else if (control == "s") {
      content += "<hr />";
      content += "<div style=\"float:left;\">";
      content += "<a href=\"javascript:print();\">" + txt_ptp + "</a>";
      content += "</div>";
      content += "<div class=\"cpFooter\" style=\"text-align:right;\">";
      content += "Powered by " + systemData[4] + "<br />";
      content += sURLLink;
      content += "</div>";
    } else {
      content += "<table style=\"width:100%;\">";
      content += "<tr><td><hr /></td></tr>";
      content += "<tr><td class=\"cpFooter\">";
      content += systemData[4] + " / " + systemData[5] + "<br />";
      content += sCopyright + " " + sCompany + "<br />";
      content += "Licence " + systemData[8] + "/ Licensee " + systemData[9] + "<br />";
      content += "</td></tr></table>";
    }
    document.write(content);
  }
}

function simpleHeaderWithTitle(systemData) {
  document.write("<td style=\"width:50%; vertical-align:bottom;\">");
  writeLogo(systemData);
  writeName(systemData);
  document.write("</td>");
}

function simpleHeader(systemData) {
  document.write("<td style=\"width:50%; vertical-align:bottom;\">");
  writeLogo(systemData);
  document.write("</td>");
}

function simpleHeader2(systemData) {
  writeLogo(systemData);
  writeName(systemData);
}

function writeLogo(systemData) {
  var logoLink = getLogoLink();
  if (logoLink.length != 0) {
    document.write("<a target=\"_blank\" href=\"" + logoLink + "\" id=\"logoLink\">");
  }
  document.write("<img alt=\"Logo\" src=\"" + systemData[3] + "\" id=\"applicationLogo\" style=\"border-style:none;\" />");
  if (logoLink.length != 0) {
    document.write("</a>");
  }
}

function writeName(systemData, nobr) {
  document.write("<div id=\"applicationName\">" + systemData[6] + "</div>");
  if (!nobr) {
    document.write("<br />");
  }
}

function writeUser(systemData) {
  document.write(systemData[7].charAt(0).toUpperCase() + systemData[7].substring(1, systemData[7].length).toLowerCase());
}

function getLogoLink() {
  var current = top;
  try {
    while (current.opener) {
      if (current.sLogoLink) {
        break;
      }
      current = current.opener.top;
    }
    if (!current.sLogoLink) {
      return "";
    }
  } catch (exception) {
    return "";
  }
  return current.sLogoLink;
}
