﻿<!--

function getXmlHttp() {
   if(window.XMLHttpRequest) {
      return new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      return new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      alert("Error creating XMLHttpRequest object");
      return null;
   }
}

function getXmlDoc() {
   if(document.implementation && document.implementation.createDocument) {
      return document.implementation.createDocument("", "", null);
   } else if(window.ActiveXObject) {
      return new ActiveXObject("MSXML2.DOMDocument");
   } else {
      alert("Error creating XMLDocument object");
      return null;
   }
}

function getXmlDocFromString(cfxmlstr) {
   var cfxmldoc = getXmlDoc();
   cfxmldoc.async = false;
   if(document.implementation && document.implementation.createDocument) {
      var domParser = new DOMParser(); 
      cfxmldoc = domParser.parseFromString(cfxmlstr,"application/xml");
   } else {
      cfxmldoc.loadXML(cfxmlstr);
   }
   return cfxmldoc;
}

function ajaxLookup(cfpageargs) {
   var cfXML = getXmlHttp();
   cfXML.open("GET", cfpageargs, false);
   cfXML.send("");
   return cfXML.responseXML;
}

function ajaxExecute(cfpageargs) {
   var cfXML = getXmlHttp();
   cfXML.open("GET", cfpageargs, true);
   cfXML.send("");
   return;
}

function ajaxGetValue(cfpageargs) {
   var cfXML = getXmlHttp();
   cfXML.open("GET", cfpageargs, false);
   cfXML.send("");
   if(cfXML.responseText.indexOf("This session has been bumped") >= 0) {
      document.write(cfXML.responseText);
      return null;
   } else {
      return cfXML.responseText;
   }
}

function populateChildOptions(cffld, cfXML) {
   if(cfXML == null || cffld == null || cffld.options == null) {
      alert("crap");
      return;
   }
   var cfnewoplist = selectNodes(cfXML,"/root/records/record");
   for(cfi=0; cfi<cfnewoplist.length; cfi++) {
      var newoption = document.createElement("option");
      newoption.value = getChildNodeValue(cfnewoplist[cfi],"value");
      newoption.innerText = getChildNodeValue(cfnewoplist[cfi],"display");
      newoption.text = getChildNodeValue(cfnewoplist[cfi],"display");
      if(cffld != null && cffld.getAttribute("curval") != null && cffld.getAttribute("curval") == newoption.value) {
         valselected = true;
      }
      cffld.appendChild(newoption);
   }
}

function selectSingleNode(cfxmldoc,cfxpath) {
   if(window.XMLHttpRequest) {
      try {
         cfxresult;
         if(typeof XPathResult == "undefined") {
            cfxresult = cfxmldoc.selectSingleNode(cfxpath);
            return cfxresult.singleNodeValue;
         } else {
            cfxresult = cfxmldoc.evaluate(cfxpath,cfxmldoc,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null);
            return cfxresult.singleNodeValue;
         }
      } catch (e) {
         return cfxmldoc.getElementsByTagName(cfxpath)[0];
      }
   } else {
      return cfxmldoc.selectSingleNode(cfxpath);
   }
}

function selectNodes(cfxmldoc,cfxpath) {
   if(window.XMLHttpRequest) {
      try {
         var cfxresult;
         if(navigator.userAgent.indexOf("MSIE") >= 0) {
            return cfxmldoc.selectNodes(cfxpath);
         } else {
            cfxresult = cfxmldoc.evaluate(cfxpath,cfxmldoc,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE,null);
            var cfnodes = [];
            var cfcnode = cfxresult.iterateNext();
            while(cfcnode) {
              cfnodes[cfnodes.length] = cfcnode;
              cfcnode = cfxresult.iterateNext();
            }
            return cfnodes;
         }
      } catch (e) {
         return cfxmldoc.getElementsByTagName(cfxpath);
      }
   } else {
      return cfxmldoc.selectNodes(cfxpath);
   }
}

function getChildNodeValue(cfxmldoc,cfxpath) {
   if(cfxmldoc == null) {
      return "";
   }
   var cfxcnode = selectSingleNode(cfxmldoc,cfxpath);
   if(cfxcnode == null) {
      return "";
   }
   if(cfxcnode.firstChild) {
      return cfxcnode.firstChild.nodeValue;
   }
   return "";
}

//-->
