﻿
// If menutxt is defined and not
// empty, write it to the document
///////////////////////////////////////
if((menutxt) && (menutxt != ''))
{
  document.write(menutxt);
}

var targetYear = null;

function showedition(edition, subject, style)
{
    if (static_version)
    {
        var type;
        if (subject == 'literary')
        {
            type = "-L";
        }
        else if (subject == 'philological')
        {
            type = "-P";
        }
        else
        {
            type = "-X";
        }
        window.location.href = "/" + edition + "/" + edition + type + ".html";
        return;
    }
    // load the xslt file

    try
    {
        // Internet Explorer version
        var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
        xmlDoc.async = false;
        xmlDoc.resolveExternals = true;
        xmlDoc.setProperty("ProhibitDTD", false);
        xmlDoc.load(edition + "/" + edition + ".xml");
        var xslt = new ActiveXObject("Msxml2.XSLTemplate.3.0");
        var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
        var xslProc;
        xslDoc.async = false;
        xslDoc.resolveExternals = true;
        xslDoc.setProperty("ProhibitDTD", false);
        if (style)
        {
            xslDoc.load(edition + "/" + edition + ".xsl");
        }
        else
        {
            xslDoc.load("ds2-L.xsl");
        }
        xslt.stylesheet = xslDoc;
        xslProc = xslt.createProcessor();
        xslProc.input = xmlDoc;
        xslProc.addParameter("edition", edition);
        xslProc.addParameter("editionType", subject);
        xslProc.transform();
        document.getElementById("thetext").innerHTML = xslProc.output;
    }
    catch(e)
    {
        try
        {
            var loadCount = 0;

            function onload() {
              if (++loadCount < 2)
              {
                return;
              }
              processor.importStylesheet(xslDoc);
              processor.setParameter("", "edition", edition);
              processor.setParameter("", "editionType", subject);
              var doc = processor.transformToFragment(xmlDoc,document);
              document.getElementById("thetext").innerHTML = "";
              document.getElementById("thetext").appendChild(doc);
            }

            var processor = new XSLTProcessor();

            var xslDoc = document.implementation.createDocument("", "xslDoc", null);
            // onload handler
            xslDoc.addEventListener("load", onload, false);
            if (style)
            {
                xslDoc.load(edition + "/" + edition + ".xsl");
            }
            else
            {
                xslDoc.load("ds2-L.xsl");
            }

            var xmlDoc = document.implementation.createDocument("", "xmlDoc", null);
            xmlDoc.addEventListener("load", onload, false);
            xmlDoc.load(edition + "/" + edition + ".xml");
        }
        catch(e)
        {
          alert("Unable to do xml/xsl processing: " + e.name + ", " + e.message);
        }
    }
}

function showfile(url) 
{ 
    if (static_version)
    {
        if (targetYear != null)
        {
            window.location.href = url + "#" + targetYear;
        }
        else
        {
            window.location.href = url;
        }
        return;
    }

    if (window.XMLHttpRequest)
    { // Non-IE browsers 
      req = new XMLHttpRequest(); 
      req.onreadystatechange = targetDiv; 
      try
      { 
        req.open("GET", url, true); 
      }
      catch (e)
      { 
        alert(e); 
      } 
      req.send(null); 
    }
    else if (window.ActiveXObject)
    { // IE 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
      if (req)
      { 
        req.onreadystatechange = targetDiv; 
        req.open("GET", url, true); 
        req.send(); 

      } 
    } 
} 

function targetDiv()
{ 
    if (req.readyState == 4) 
    { // Complete 
          if (req.status == 200) 
          { // OK response 
              document.getElementById("thetext").innerHTML = req.responseText;
              if (targetYear != null)
              {
                  location.hash = targetYear;
                  targetYear = null;
              }
          } 
          else 
          { 
            alert("Problem: " + req.statusText); 
          } 
    } 
} 

function gotoYear(year, manuscript)
{
    var file = "/" + manuscript + "/" + manuscript + "-L.html";
    targetYear = year;
    showfile(file);
}