var IS_IE = (navigator.userAgent.toLowerCase().indexOf("msie") > -1)?true:false;
var XCURSOR_INTERVAL = 100;
var XBUSY_MESSAGE = "Preparing report...";
var XREADY_MESSAGE = "Done.";
var source=null, style=null, dsplsource=null;
var currsource="nocurrsrc";
var xmlfile="NoXMLFile";
var currstyle = "nocurrstyle";
var xslfile = "NoXSLFile";
var currdsplsource = "nocurrdsplsource";
var hdgtext = " ";
var hdg2txt = "";
var grouphdgtext = "<h1>Scheduling Optimizer Reports</h1>";
var printopentxt = "";
printopentxt += "It may take a minute or more for this report to\n";
printopentxt += "display on the screen.";
var optiontxt = " ";
var winObj;
var printWinTitle = "Printer Friendly Report";
function detectxml()
{
var idlist = ["Microsoft.XmlDom",
              "MSXML.DOMDocument",
              "MSXML2.DOMDocument",
              "Msxml2.DOMDocument.3.0",
              "Msxml2.DOMDocument.4.0",
              "Msxml2.DOMDocument.5.0"];
   //determine best msxml progID string to use 
var progID = "";
for (var i=0; i < idlist.length; i++) {
   try {
     var objXML = new ActiveXObject(idlist[i]);
     progID = idlist[i];
   } catch (objException) { 
   }
}
// alert("Open string:"+progID); // debug
if (progID == "") {
var alerttxt = "";
alerttxt += " The Microsoft XML parser is not installed ";
alerttxt += "on your computer! \n\n";
alerttxt += " For more information and to install ";
alerttxt += "this required component, \n";
alerttxt += " go to the following link: \n\n";
alerttxt += " http://www.tabbysoft.com/xml4 \n";
alert(alerttxt);
}
return progID;
}

function bldStdRepXML()
{
//     =========== xml and xsl DOM docmuments =============
       source = getXMLObj();
       source.async = false;
       style = getXMLObj();
       style.async = false;
       dsplsource = getXMLObj();
       dsplsource.async = false;
}

function getXMLObj(rootName)
{
var xmlDoc = null;
if (IS_IE) {  // IE MSXML object create
   var progID = detectxml();
   if (progID != "") {
     try
     {
       xmlDoc=new ActiveXObject(progID);
       xmlDoc.async="false";
       xmlDoc.setProperty("SelectionLanguage", "XPath");
       if (rootName)
          xmlDoc.loadXML("<" + rootName + "/>");
     }
     catch (e) {
        alert("Error: unable to create MSXML DOM object!");
     }
   }
}
else {  // Assume Netscape or Mozilla
  try {
  xmlDoc = document.implementation.createDocument("", rootName, null);
  }
  catch (e) {
    alert("Error: XML DOM object creation failed!");
  }
}
return xmlDoc;
}




function loadSourceXML(xmlFile)
{
   if (xmlFile != currsource) {
      source.load(xmlFile);
      currsource = xmlFile;
   }
}

function loadStyleXSL(xslFile)
{
   if (xslFile != currstyle) {
      style.load(xslFile);
      currstyle = xslFile;
   }
}

// Transform current XML content in dsplsource using current style xslt,
// result in innerhtml of division id passed in parameterlocID
function putRepXML(locID,xmlExt)
{
var repTarget;
// Target document-division based on whether framed or unframed page
if (window != top) {  // framed, target bottom frame from parent
   p=parent;
   b=p.bottom;
   repTarget = b.document.getElementById(locID);
}
else {  // not framed, operate on this document
   repTarget = document.getElementById(locID);
}

// select source xml and style xslt based on 
// whether opened by another window
if (xmlExt) {  // use data from opener
   if (IS_IE) {
     repTarget.innerHTML = opener.dsplsource.transformNode(opener.style);
   }
   else {
      var xslp = new XSLTProcessor();
      xslp.importStylesheet (opener.style);
      repTarget.innerHTML = "";
      repTarget.appendChild(xslp.transformToFragment(opener.dsplsource,document));
   }
}
else { // directly opened window - unframed report or printer friendly page 
   if (IS_IE) {
      repTarget.innerHTML = dsplsource.transformNode(style);
   }
   else {
      var xslp = new XSLTProcessor();
      xslp.importStylesheet (style);
      repTarget.innerHTML = "";
      repTarget.appendChild(xslp.transformToFragment(dsplsource,document));
   }
}
} // end putRepXML

function putRepSource(outPutID, xmlExt)
{
if (xmlfile != currdsplsource || currsource != 'nocurrsrc') {
dsplsource = null;
dsplsource = getXMLObj("DISPLREP");
dsplsource.async = false; // required for netscape
dsplsource.load(xmlfile);
currdsplsource = xmlfile;
}
loadStyleXSL(xslfile);
putRepXML(outPutID, xmlExt);
}  // end putRepSource


