﻿
if(!document.all){Node.prototype.__defineGetter__("xml",_Node_getXML);}
function _Node_getXML(){var objXMLSerializer=new XMLSerializer;var strXML=objXMLSerializer.serializeToString(this);return strXML;}
function xmlDoc_parseIndex(subPath){var index=-1;if(subPath.length>0&&subPath.charAt(subPath.length-1)==']'){var k;for(k=subPath.length-1;k>0;--k){if(subPath.charAt(k-1)=='[')
break;}
index=parseInt(subPath.substr(k,subPath.length-k-1));if(!isNaN(index)){this.parseIndexStripped=subPath.substr(0,k-1);}else if(subPath.charAt(k)!='@'){alert("Invalid index in xpath: "+path);return null;}else{index=-1;}}else{this.parseIndexStripped=subPath;}
return index;}
function xmlDoc_pathMatchInternal(fullPath,partialPath,full){if(fullPath==partialPath)
return true;var fpComponents=fullPath.split("/");var ppComponents=partialPath.split("/");if(full){if(fpComponents.length!=ppComponents.length)
return false;}else{if(fpComponents.length<ppComponents.length)
return false;}
for(var i=0;i<ppComponents.length;++i){var fpi=this.parseIndex(fpComponents[i]);var fp=this.parseIndexStripped;var ppi=this.parseIndex(ppComponents[i]);var pp=this.parseIndexStripped;if(pp!=fp)
return false;if(fpi==-1)fpi=1;if(ppi==-1)ppi=1;if(ppi!=fpi)
return false;}
return true;}
function xmlDoc_pathMatch(path1,path2){return this.pathMatchInternal(path1,path2,true);}
function xmlDoc_partialPathMatch(fullPath,partialPath){return this.pathMatchInternal(fullPath,partialPath,false);}
function xmlDoc_getNodeText(n){var tn=this.selectSingleNode('#text',n);if(tn){return tn.nodeValue;}
return'';}
function xmlDoc_setNodeText(n,txt){var tn=this.selectSingleNode('#text',n);if(tn){tn.nodeValue=txt;}else{tn=n.ownerDocument.createTextNode(txt);n.appendChild(tn);}}
function xmlDoc_getPath(n,parent){var doc=n.ownerDocument;if(!parent)parent=doc;var path='';while(typeof(n)!='undefined'&&n!=null&&n!=parent){if(typeof(n.nodeName)!='undefined'&&n.nodeName!=null){if(path!='')
path='/'+path;var suffix='';if(typeof(n.parentNode)!='undefined'&&n.parentNode!=null){var children=n.parentNode.childNodes;var index=0,found=false,matching=0;for(var i=0;i<children.length;++i){if(n.nodeName==children[i].nodeName){++matching;if(!found)
++index;}
if(children[i]==n){found=true;}}
if(matching>1)
suffix='['+index+']';}
path=n.nodeName+suffix+path;}
n=n.parentNode;}
if(parent==doc)
path='/'+path;return path;}
function xmlDoc_selectSingleNode(path,doc,tryCreate){if(path.length==0)
return null;if(path.charAt(0)=='/'){if((doc!=null)&&(doc.ownerDocument!=null))
doc=doc.ownerDocument;path=path.substr(1,path.length-1);}
if(!doc)doc=this.getDocument();var pathArr=path.split("/");var thisNode=doc;var nodeToSeek,condition;for(var i=0;i<pathArr.length;i++){var subPath=pathArr[i];nodeToSeek=subPath;var condition=null;var re=/([^\[]*)\[([^\]]*)\]/;var conditional=subPath.match(re);if(conditional){nodeToSeek=conditional[1];condition=new Array();if(conditional[2].indexOf("=")>0){var expr=conditional[2].split("=");condition["node-name"]=expr[0];condition["equals"]=expr[1].substr(1,expr[1].length-2);}else{var digitsOnly=/^\d+$/;if(conditional[2].match(digitsOnly)){condition["index"]=parseInt(conditional[2]);}else{condition["node-name"]=conditional[2];}}}
var children;if(nodeToSeek.charAt(0)=="@"){children=thisNode.attributes;}else{children=thisNode.childNodes;}
var matchedNode=null;var matchIndex=0;for(var j=0;j<children.length;j++){if(((children[j].nodeType==1)&&(children[j].nodeName==nodeToSeek))||((children[j].nodeType==2)&&("@"+children[j].nodeName==nodeToSeek))){if(condition){if(condition["index"]&&(++matchIndex==condition["index"])){matchedNode=children[j];break;}
if(condition["node-name"]){var prepend="";var childNodes=children[j].childNodes;if(condition["node-name"].substr(0,1)=="@"){childNodes=children[j].attributes;prepend="@";}
for(var k=0;k<childNodes.length;k++){var n=childNodes[k];if(prepend+n.nodeName==condition["node-name"]){if(((condition["equals"])&&(n.nodeValue==condition["equals"]))||(!condition["equals"])){matchedNode=children[j];break;}}}}}else{matchedNode=children[j];break;}}else if((children[j].nodeType==3)&&(nodeToSeek=="#text")){matchedNode=children[j];break;}}
if(!matchedNode){if(!tryCreate){return null;}
if(nodeToSeek.charAt(0)=="@"){matchedNode=thisNode.ownerDocument.createAttribute(nodeToSeek.substr(1));thisNode.setAttributeNode(matchedNode);}else{matchedNode=thisNode.ownerDocument.createElement(nodeToSeek);thisNode.appendChild(matchedNode);if(condition&&condition["node-name"]&&condition["equals"]&&(condition["node-name"].charAt(0)=="@")){matchedNode.setAttribute(condition["node-name"].substr(1),condition["equals"]);}}}
thisNode=matchedNode;}
return matchedNode;}
function xmlDoc_selectNodes(path,doc){if(path.length==0)
return null;if(path.charAt(0)=='/'){if(doc!=null)
doc=doc.ownerDocument;path=path.substr(1,path.length-1);}
if(!doc)doc=this.getDocument();var pathArr=path.split("/");var found=new Array(doc);for(var i=0;i<pathArr.length;i++){var subPath=pathArr[i];var index=this.parseIndex(subPath);subPath=this.parseIndexStripped;var foundChildren=new Array()
for(var j=0;j<found.length;j++){foundChildren[j]=found[j].childNodes;}
found=new Array();var matchIndex=0;for(var j=0;j<foundChildren.length;j++){for(var k=0;k<foundChildren[j].length;k++){if(((foundChildren[j][k].nodeType==1)&&(subPath=="*"||(foundChildren[j][k].nodeName==subPath)))||((foundChildren[j][k].nodeType==3)&&(subPath=="#text"))){if(index==-1){found[found.length]=foundChildren[j][k];}else if(++matchIndex==index){found[found.length]=foundChildren[j][k];break;}}}}
if(found.length==0){break;}}
return found;}
function xmlDoc_onReadyStateChange(){if((this.req.readyState==4)||(this.req.readyState=="interactive")){var doc=null;if((this.req.id)&&(this.req.id.substr(0,10)=="xml_island")){doc=this.req.XMLDocument;}else if(this.req.status==200){doc=this.req.responseXML;}
this.xmlDocument=doc;if(doc){if(doc.childNodes.length==0){alert("XML Document empty - please ensure that response stream is of MIME type 'text/xml' and that the XML is valid");}else{AS(this.id).onXMLDocLoaded(doc);}}else{if(AS(this.id).onXMLDocFailed){AS(this.id).onXMLDocFailed(this.req.statusText);}else{alert("There was a problem retrieving the XML data:\n"+this.req.statusText);}}}}
function handleReadyStateChange(id){AS(id).onReadyStateChange()}
function xmlDoc_makeHttpRequest(url,postData){var b=this.id;this.readyStateChangeHandler=function(){handleReadyStateChange(b);};if(window.XMLHttpRequest){this.req=new XMLHttpRequest();this.req.onreadystatechange=this.readyStateChangeHandler;this.req.open((postData!=null)?"POST":"GET",url,true);this.req.setRequestHeader('Content-Type','application/text-xml; charset="utf-8"');if(postData!=null){this.req.send(postData);}else{this.req.send(null);}}else if(window.ActiveXObject){try{this.req=new ActiveXObject("Microsoft.XMLHTTP");}catch(err){if(err.number==-2146827859){if(postData!=null){alert(__tr('Your browser security settings do not allow this sort of interactive content.\n\nPlease set \'Script ActiveX controls marked safe for scripting\' to \'Allow\''));return;}
var doc=document.getElementById("xml_island_"+this.id);if(!doc){doc=document.createElement("xml");doc.id="xml_island_"+this.id;document.body.appendChild(doc);}
this.req=doc;this.req.onreadystatechange=this.readyStateChangeHandler;if(!doc.load(url)){alert("Failed to load XML Island");}
return;}}
if(this.req){this.req.onreadystatechange=this.readyStateChangeHandler;this.req.open((postData!=null)?"POST":"GET",url,true);this.req.setRequestHeader('Content-Type','application/text-xml; charset="utf-8"');if(postData!=null){this.req.send(postData);}else{this.req.send(null);}}}}
function xmlDoc_setDocument(doc){this.xmlDocument=doc;}
function xmlDoc_createDocument(string){var xmlDocument;if(window.DOMParser){if(string==undefined){return document.implementation.createDocument("","",null);}
var xmlParser=new DOMParser();return xmlParser.parseFromString(string,'text/xml');}else if(window.ActiveXObject){xmlDocument=new ActiveXObject('Microsoft.XMLDOM');xmlDocument.async=false;xmlDocument.loadXML(string);return xmlDocument;}
throw"Unknown browser Xml implementation";}
function xmlDoc_onXMLDocLoaded(){alert("onXMLDocLoaded not overridden");}
function xmlDoc_getDocument(){return this.xmlDocument;}
function xmlDoc_getXML(node){if(!node)node=this.getDocument();if(node.xml){return node.xml;}
var objXMLSerializer=new XMLSerializer();var strXML=objXMLSerializer.serializeToString(node);return strXML;}
function xmlDoc(id){this.base=AspenScriptlet;this.base(id);this.makeHttpRequest=xmlDoc_makeHttpRequest;this.onReadyStateChange=xmlDoc_onReadyStateChange;this.onXMLDocLoaded=xmlDoc_onXMLDocLoaded;this.selectSingleNode=xmlDoc_selectSingleNode;this.selectNodes=xmlDoc_selectNodes;this.getPath=xmlDoc_getPath;this.createDocument=xmlDoc_createDocument;this.partialPathMatch=xmlDoc_partialPathMatch;this.pathMatch=xmlDoc_pathMatch;this.pathMatchInternal=xmlDoc_pathMatchInternal;this.getDocument=xmlDoc_getDocument;this.getXML=xmlDoc_getXML;this.parseIndex=xmlDoc_parseIndex;this.getNodeText=xmlDoc_getNodeText;this.setNodeText=xmlDoc_setNodeText;this.setDocument=xmlDoc_setDocument;this.xmlDocument=null;}