function jxte(xml_url,xml_str,xml_obj,debug_level)
{
var bool=false;
this.load_from_url=xml_load_from_url;
this.load_from_string=xml_load_from_string;
this.load_from_object=xml_load_from_object;
this.initialise=xml_initialise;
this.initialise_child_node=xml_initialise_child_node;
this.refresh=xml_refresh;
this.get_elements_by_tag_name=xml_get_elements_by_tag_name;
this.update_node=xml_update_node;
this.insert_node=xml_insert_node;
this.delete_node=xml_delete_node;
this.delete_node_by_id=xml_delete_node_by_id;
this.delete_nodes_by_tag_name=xml_delete_nodes_by_tag_name;
this.delete_nodes_by_attribute=xml_delete_nodes_by_attribute;
this.get_nodes_by_attribute=xml_get_nodes_by_attribute;
this.get_node_value=xml_get_node_value;
this.get_child_node_value=xml_get_child_node_value;
this.get_child_node_attribute=xml_get_child_node_attribute;
this.set_child_node_attribute=xml_set_child_node_attribute;
this.get_attribute=xml_get_attribute;
this.set_attribute=xml_set_attribute;
this.delete_attribute=xml_delete_attribute;
this.get_all_attributes=xml_get_all_attributes;
this.set_all_attributes=xml_set_all_attributes;
this.delete_all_attributes=xml_delete_all_attributes;
this.inspect_internals=xml_inspect_internals;
this.inspect_wrapper=xml_inspect_wrapper;
this.expand_xsl_includes=xml_expand_xsl_includes;
this.render_with_xsl=xml_render_with_xsl;
this.render_with_xsl_to_str=xml_render_with_xsl_to_str;
this.render_with_xsl_to_div=xml_render_with_xsl_to_div;
this.load_xsl_contents=xml_load_xsl_contents;
this.load_url_contents=xml_load_url_contents;
this.is_text_node=xml_is_text_node;
this.debug=xml_debug;
this.debug_values=xml_debug_values;
this.set_debug_level=xml_set_debug_level;
this.wrapped_check=xml_wrapped_check;
this.firstChild=false;
this.lastChild=false;
this.xml_obj=false;
this.ie_xml_obj=false;
this.parent_xml_obj=false;
this.debug_level=0;
this.child_nodes=false;
this.position=-1;
this.tag_name=false;
this.node_name=false;
this.node_type=false;
this.xsl_cache=new Object();
this.xsl_cache_enabled=true;
this.wrapped=false;
if(typeof(debug_level)!='undefined')
this.set_debug_level(debug_level);
if(typeof(xml_url)!='undefined'||typeof(xml_str)!='undefined'||typeof(xml_obj)!='undefined')
{
if(xml_url) 
{
bool=this.load_from_url(xml_url,true);
if(!bool)throw "Unable to load XML from URL "+xml_url;
}
else if(xml_str) 
{
bool=this.load_from_string(xml_str,true);
if(!bool)throw "Unable to load XML from string "+xml_str;
}
else if(xml_obj) 
{
bool=this.load_from_object(xml_obj,true);
if(!bool)throw "Unable to load XML from object";
}
}
}
function check_wrapped()
{
if(!this.wrapped)
{
this.initialise();
}
}
function xml_set_debug_level(debug_level)
{
this.debug_level=debug_level;
if(this.debug_level>4)
alert('jxte: debug enabled');
}
function xml_refresh(rebuild_child_nodes_only)
{
this.initialise(rebuild_child_nodes_only);
}
function xml_initialise(recurse)
{
recurse=(typeof(recurse)!='undefined'?recurse:true);
var i=0;
var cn=0;
var xo=false;
var co=false;
if(this.xml_obj)
{
if(!this.wrapped)
{
xo=this.xml_obj;
this.tag_name=(typeof(xo.tagName)!='undefined'?xo.tagName:'');
this.node_type=xo.nodeType;
this.node_name=(typeof(xo.nodeName)!='undefined'?xo.nodeName:this.tag_name);
if(recurse)
{
try
{
this.child_nodes=new Array();
cn=xo.childNodes.length;
for(i=0;i<cn;i++)
{
this.initialise_child_node(xo.childNodes[i],i);
}
i=this.child_nodes.length;
if(i>0)
{
this.firstChild=this.child_nodes[0];
this.lastChild=this.child_nodes[(i-1)];
}
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_initialise: failure parsing XML: '+err_obj.description);
throw(err_obj);
}
}
this.wrapped=true;
}
}
else
{
var err_str='xml_initialise: XML object has not been loaded: no actions possible';
throw err_str;
}
}
function xml_wrapped_check()
{
if(!this.wrapped)
{
this.initialise();
this.wrapped=true;
}
}
function xml_initialise_child_node(child_node,position)
{
var co=new jxte();
var pxo=false;
try
{
if(this.parent_xml_obj!=false)
pxo=this.parent_xml_obj;
else
pxo=this.xml_obj;
}
catch(eo)
{
pxo=false;
}
co.load_from_object(child_node,pxo,this.ie_xml_obj);
co.position=position;
this.child_nodes.push(co);
return co;
}
function xml_get_attribute(a_name,default_value)
{
var err_obj=false;
var str='';
try
{
if(!this.is_text_node())
{
str=this.xml_obj.getAttribute(a_name);
if(str==null&&typeof(default_value)!=undefined)
str=default_value;
}
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_get_attribute: problem extracting attribute ' 
+a_name+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
return str;
}
function xml_get_all_attributes()
{
var err_obj=false;
var i=0;
var a_node=false;
var a_list=new Object();
try
{
for(i=0;i<this.xml_obj.attributes.length;i++)
{
a_node=this.xml_obj.attributes[i];
a_list[a_node.nodeName]=a_node.nodeValue;
}
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_get_all_attributes: problem reading attributes ' 
+i+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
return a_list;
}
function xml_set_attribute(a_name,a_value)
{
var err_obj=false;
try
{
this.xml_obj.setAttribute(a_name,a_value);
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_set_attribute: problem setting attribute ' 
+a_name+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
}
function xml_delete_attribute(a_name)
{
var xo=this.xml_obj;
var err_obj=false;
try
{
xo.removeAttribute(a_name);
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_delete_attribute: problem removing attribute ' 
+a_name+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
}
function xml_delete_all_attributes()
{
var xo=this.xml_obj;
var err_obj=false;
var i=0;
var a_node=false;
try
{
for(i=0;i<xo.attributes.length;i++)
{
a_node=xo.attributes[i];
xo.removeAttributeNode(a_node);
}
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_delete_all_attributes: problem removing attribute ' 
+i+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
}
function xml_set_all_attributes(attributes_hash,delete_existing)
{
var xo=this.xml_obj;
var err_obj=false;
var a_name='';
var a_value='';
if(delete_existing)
{
try
{
this.delete_all_attributes();
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_set_all_attributes: problem removing existing attributes ' 
+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
}
try
{
for(a_name in attributes_hash)
{
a_value=attributes_hash[a_name];
this.set_attribute(a_name,a_value);
}
}
catch(err_obj)
{
if(this.debug_level>4)
alert('xml_set_all_attributes: problem setting attribute ' 
+a_name+'/'+a_value+' for xml object '+this.node_name+'\n'+err_obj.description);
throw err_obj;
}
}
function xml_is_text_node(include_comments)
{
var retval=false;
switch(this.node_type)
{
case 3:
case 4:
retval=true;
break;
case 8:
if(include_comments)
retval=true;
break;
default:
retval=false;
}
return retval;
}
function xml_load_from_url(xml_url,suppress_warnings)
{
var err_obj=false;
var t_req=false;
var t_list=false;
var t_xml_obj=false;
var bool=true;
this.xml_obj=false;
this.ie_xml_obj=false;
if(typeof(ActiveXObject)!='undefined')
{
try
{
t_xml_obj=new ActiveXObject("Microsoft.XMLDOM");
t_xml_obj.async=false;
t_xml_obj.load(xml_url);
if(this.debug_level>4)
alert('xml_load_from_url: IE path used: remapped XML parent node');
this.ie_xml_obj=t_xml_obj;
this.xml_obj=t_xml_obj.documentElement;
}
catch(err_obj)
{
if(!suppress_warnings)
{
if(this.debug_level>4)
alert('xml_load_from_url: IE path failed: '+err_obj.description);
throw(err_obj);
}
bool=false;
}
}
else
{
try
{
t_req=new XMLHttpRequest();
t_req.open("GET",xml_url,false);
t_req.send(null);
this.xml_obj=t_req.responseXML.documentElement;
}
catch(err_obj)
{
if(!suppress_warnings)
{
if(this.debug_level>4)
alert('xml_load_from_url: Unable to load XML file '+xml_url+':\n'+
err_obj.description+'\nThis may be a local security issue?');
throw(err_obj);
}
bool=false;
}
}
if(this.xml_obj)
{
this.initialise();
if(this.node_name=='parsererror')
{
if(!suppress_warnings)
{
alert('Parse failure when reading URL contents:\n'+
this.get_node_value()+'\n'+
this.get_child_node_value('sourcetext')+'\n'
);
}
this.xml_obj=false;
bool=false;
}
}
else
{
bool=false;
}
if(!bool&&!suppress_warnings)
alert('Failed to load XML object from url '+xml_url);
return bool;
}
function xml_load_from_string(str,root_node_name)
{
var parser=false;
var xo=false;
var t_obj=false;
var bool=true;
if(root_node_name)
str="<"+root_node_name+">"+str+"</"+root_node_name+">";
try 
{
if(this.debug_level>3)
alert('xml_load_from_string: IE path');
xo=new ActiveXObject("Microsoft.XMLDOM");
xo.async="false";
xo.loadXML(str);
this.ie_xml_obj=xo;
}
catch(e)
{
try 
{
if(this.debug_level>3)
alert('xml_load_from_string: Non-IE path');
parser=new DOMParser();
xo=parser.parseFromString(str,"text/xml");
t_obj=xo.getElementsByTagName('parsererror');
if(t_obj.length>0)
{
if(this.debug_level>3)
{
alert('Parse failure when converting string to XML object');
this.debug_values();
}
bool=false;
}
}
catch(e)
{
alert(e.message);
bool=false;
}
}
this.parent_xml_obj=xo;
this.xml_obj=xo.firstChild;
this.initialise();
return bool;
}
function xml_load_from_object(t_xml_obj,parent_xml_obj,ie_xml_obj,node_position)
{
this.xml_obj=t_xml_obj;
this.parent_xml_obj=(typeof(parent_xml_obj)!='undefined'?parent_xml_obj:false);
this.ie_xml_obj=(typeof(ie_xml_obj)!='undefined'?ie_xml_obj:false);
this.position=(typeof(node_position)!='undefined'?node_position:-1);
this.initialise();
}
function xml_get_elements_by_tag_name(tag_name,max_depth)
{
var ret_list=new Array();
var tmp_list=new Array();
var i=0;
var t_node=false;
max_depth=(typeof(max_depth)!='undefined'?max_depth:-1);
if(this.xml_obj)
{
max_depth--;
for(i=0;i<this.child_nodes.length;i++)
{
t_node=this.child_nodes[i];
if(t_node.tag_name==tag_name)
ret_list.push(t_node);
if(t_node.child_nodes.length>0&&max_depth!=0)
{
tmp_list=t_node.get_elements_by_tag_name(tag_name,max_depth);
if(tmp_list.length>0)
ret_list=ret_list.concat(tmp_list);
}
}
}
else
{
alert('XML object has not yet been initialised: no actions possible');
}
return ret_list;
}
function xml_delete_node(node)
{
if(node.position!=-1)
this.delete_node_by_id(node.position);
}
function xml_delete_nodes_by_tag_name(node_name,max_count)
{
var i=0;
var tmp_node=false;
var found=0;
max_count=(typeof(max_count)!='undefined'?max_count:-1);
for(i=0;i<this.child_nodes.length;i++)
{
tmp_node=this.child_nodes[i];
if(tmp_node.node_name==node_name)
{
this.delete_node_by_id(i);
found++;
if(found==max_count)
break;
}
}
return found;
}
function xml_delete_nodes_by_attribute(attr_name,attr_value,tag_name,max_count)
{
var i=0;
var str='';
var found=0;
for(i=0;i<this.child_nodes.length;i++)
{
tmp_node=this.child_nodes[i];
if(!tmp_node.is_text_node()&&(!tag_name||tag_name==tmp_node.tag_name))
{
str=tmp_node.get_attribute(attr_name,'#*T*V11YYz!%');
if(str&&(!attr_value||str==attr_value))
{
this.delete_node_by_id(i);
found++;
if(found==max_count)
break;
}
}
}
return found;
}
function xml_delete_node_by_id(node_id)
{
var err_obj=false;
var tn=false;
try
{
this.child_nodes.splice(node_id,1);
tn=this.xml_obj.childNodes[node_id];
this.xml_obj.removeChild(tn);
if(this.debug_level>4)
alert('xml_delete_node_by_id: Removed child '+node_id);
}
catch(err_obj)
{
alert('xml_delete_node_by_id: failure for '+node_id+': '+err_obj.description);
throw(err_obj);
}
}
function xml_get_nodes_by_attribute(attr_name,attr_value,tag_name)
{
var i=0;
var str='';
var retlist=new Array();
for(i=0;i<this.child_nodes.length;i++)
{
tmp_node=this.child_nodes[i];
if(tmp_node.tag_name!='#text'&&(!tag_name||tag_name==tmp_node.tag_name))
{
str=tmp_node.get_attribute(attr_name,false);
if(str&&(!attr_value||str==attr_value))
retlist.push(tmp_node);
}
}
return retlist;
}
function xml_update_node(node_name,node_value,node_attributes)
{
this.delete_nodes_by_tag_name(node_name,1)
return this.insert_node(node_name,node_value,node_attributes);
}
function xml_insert_node(node_name,node_value,node_attributes)
{
var xo=false;
var ixo=false;
var tmp_node=false;
var child_node=false;
var text_node=false;
var node_list=false;
var i=0;
var str='';
var err_obj=false;
xo=this.xml_obj;
if(typeof(this.ie_xml_obj)!='boolean')
{
try
{
ixo=this.ie_xml_obj;
tmp_node=ixo.createNode(1,node_name,ixo.namespaceURI);
text_node=ixo.createTextNode(node_value);
}
catch(err_obj)
{
alert('xml_insert_node (IE path): failure creating new node: '+err_obj.description);
throw(err_obj);
}
}
else
{
try
{
xo=this.xml_obj;
tmp_node=document.createElementNS(xo.namespaceURI,node_name);
node_value=(typeof(node_value)!='undefined'?node_value:'');
text_node=document.createTextNode(node_value.toString());
}
catch(err_obj)
{
alert('xml_insert_node (non-IE path): failure creating new node: '+err_obj.description+'\n'+
i+': '+node_name+': '+this.node_value);
throw(err_obj);
}
}
tmp_node.appendChild(text_node);
if(node_attributes)
{
try
{
for(name in node_attributes)
tmp_node.setAttribute(name,node_attributes[name]);
}
catch(err_obj)
{
alert('xml_insert_node: failure parsing attributes: '+err_obj.description);
throw(err_obj);
}
}
try
{
xo.appendChild(tmp_node);
child_node=this.initialise_child_node(tmp_node)
}
catch(err_obj)
{
alert('xml_insert_node: failure parsing '+node_name+': '+err_obj.description);
throw(err_obj);
}
return child_node;
}
function xml_expand_xsl_includes(xsl_str,parent_dir)
{
xsl_dir=(typeof(xsl_dir)!='undefined'?xsl_dir:'.');
var re=false;
var t_obj=false;
var t_str='';
var t_re=false;
var child_xsl_filename='';
var child_wd='';
var i=0;
re= /<xsl:include\s+href=['"](.*?)['"].*?>/;
while(true)
{
t_obj=re.exec(xsl_str)
if(t_obj!=null)
{
child_xsl_filename=t_obj[1];
i=child_xsl_filename.lastIndexOf('/');
if(i!=-1)
{
i++;
child_wd=child_xsl_filename.substring(0,i);
child_xsl_filename=child_xsl_filename.substring(i,child_xsl_filename.length);
}
else
{
child_wd='./';
}
child_xsl_filename=parent_dir+child_wd+child_xsl_filename;
t_str=this.load_xsl_contents(child_xsl_filename,true);
t_re= /<xsl:(stylesheet|transform).*?>/mi;
t_str=trim_string(t_str,t_re,true);
t_re= /<\/xsl:(stylesheet|transform).*?>/mi;
t_str=trim_string(t_str,t_re,false);
xsl_str=xsl_str.replace(t_obj[0],t_str);
}
else
{
break;
}
}
return xsl_str;
}
function xml_load_xsl_contents(xsl_filename,cache_xsl)
{
var retval='';
var str='';
var t_obj=false;
var child_xsl_filename='';
var includes=false;
var current_wd='./';
var child_wd='./';
var re=false;
var t_re=false;
var i=0;
if(typeof(cache_xsl)=='undefined')
cache_xsl=this.xsl_cache_enabled;
if(typeof(this.xsl_cache[xsl_filename])=='undefined'||cache_xsl==false)
{
str=this.load_url_contents(xsl_filename);
if(str!='')
{
if(xsl_filename.match('/')!=null)
current_wd=xsl_filename.substring(0,xsl_filename.lastIndexOf('/')+1);
str=this.expand_xsl_includes(str,current_wd);
if(cache_xsl==true)
this.xsl_cache[xsl_filename]=str;
}
else
{
alert('xml_load_xsl_contents: unable to find content for '+xsl_filename);
this.xsl_cache[xsl_filename]=false;
}
}
if(cache_xsl==true)
retval=this.xsl_cache[xsl_filename];
else
retval=str;
if(!retval)
alert('xml_load_xsl_contents: parse failure for '+xsl_filename);
return retval;
}
function xml_render_with_xsl_to_div(div_id,xsl_filename,xsl_str,cache_xsl,output_xml)
{
var str=this.render_with_xsl_to_str(xsl_filename,xsl_str,cache_xsl,output_xml);
var div_obj=jxte_get_div_obj(div_id);
div_obj.innerHTML=str;
return str;
}
function xml_render_with_xsl(xsl_filename,cache_xsl,xsl_str,output_xml)
{
var str=this.render_with_xsl_to_str(xsl_filename,xsl_str,cache_xsl,output_xml);
return str;
}
function xml_render_with_xsl_to_str(xsl_filename,xsl_str,cache_xsl,output_xml)
{
var xsl_stylesheet=false;
var xsl_proc=false;
var parser=false;
var fragment=false;
var xsl_doc=false;
var xsl_template=false;
var i=0;
var str="";
var target_div=false;
cache_xsl=(typeof(cache_xsl)!='undefined'?cache_xsl:true);
output_xml=(typeof(output_xml)!='undefined'?output_xml:false);
if(!xsl_str)
xsl_str=this.load_xsl_contents(xsl_filename,cache_xsl);
else
xsl_str=this.expand_xsl_includes(xsl_str,'./');
if(xsl_str!=""&&document.implementation.createDocument) 
{
xsl_proc=new XSLTProcessor();
parser=new DOMParser();
xsl_stylesheet=parser.parseFromString(xsl_str,"text/xml");
try
{
xsl_proc.importStylesheet(xsl_stylesheet);
fragment=xsl_proc.transformToFragment(this.xml_obj,document);
}
catch(err_obj)
{
alert('XSL parse failure (Mozilla path) for '+xsl_filename+': '+err_obj.description+'\n');
throw(err_obj);
}
target_div=document.createElement("div");
target_div.appendChild(fragment);
str=target_div.innerHTML;
} 
else 
{
xsl_doc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xsl_doc.async=false;
xsl_template=new ActiveXObject("Msxml2.XSLTemplate");
try
{
xsl_doc.loadXML(xsl_str);
xsl_template.stylesheet=xsl_doc;
xsl_proc=xsl_template.createProcessor();
xsl_proc.input=this.xml_obj;
xsl_proc.transform();
str=xsl_proc.output;
}
catch(err_obj)
{
alert('XSL parse failure (IE path) for '+xsl_filename+': '+err_obj.description+'\n');
throw(err_obj);
}
}
str=xml_fix_html_tags(str,this.debug_level);
if(!output_xml)
{
if(str.indexOf('<?xml')==0)
{
i=str.indexOf('?>')+2;
str=str.substring(i,str.length);
}
}
else
{
str=str.replace('encoding="UTF-16"','encoding="ISO-8859-1"');
}
return str;
}
function xml_fix_html_tags(str)
{
var regex_list=new Array(/&lt;[\w].*?&gt;/g, /&lt;\/[\w].*?&gt;/g, /&lt;[\w].*?>/g, /&lt;\/[\w].*?>/g);
var i=0;
var j=0;
var k=0;
var t_list=false;
var regex=false;
var match_list=false;
var match_hash=new Object();
var old_tag='';
var new_tag='';
if(str)
{
for(i=0;i<regex_list.length;i++)
{
regex=regex_list[i];
match_list=str.match(regex);
if(match_list&&match_list.length>0)
{
for(j=0;j<match_list.length;j++)
{
old_tag=match_list[j];
if(typeof(match_hash[old_tag])=='undefined')
{
new_tag=old_tag.replace('&lt;','<');
new_tag=new_tag.replace('&gt;','>');
new_tag=new_tag.replace('&amp;','&');
match_hash[old_tag]=new_tag;
t_list=str.split(old_tag);
str='';
for(k=0;k<(t_list.length);k++)
{
str+=t_list[k]
if(k!=(t_list.length-1))
str+=new_tag;
}
}
}
}
}
regex= /(&amp;#?\w+;)/g;
match_list=str.match(regex);
if(match_list&&match_list.length>0)
{
for(j=0;j<match_list.length;j++)
{
old_tag=match_list[j];
new_tag='&'+old_tag.substring(5,old_tag.length);
str=str.replace(old_tag,new_tag);
}
}
str=str.replace(/(<a.*?href=["'])&#xA;\s+(.*?)&#xA;\s+?(["'].*?>)/gm,"$1$2$3");
}
return str;
}
function xml_get_child_node_value(node_name,default_value)
{
var retval='';
var matches=this.get_elements_by_tag_name(node_name,1);
if(matches.length>0)
retval=matches[0].get_node_value();
else
retval=default_value;
return retval;
}
function xml_get_child_node_attribute(node_name,attr_name,default_value)
{
var retval='';
var matches=this.get_elements_by_tag_name(node_name,1);
if(matches.length>0)
retval=matches[0].get_attribute(attr_name,default_value);
else
retval=default_value;
return retval;
}
function xml_set_child_node_attribute(node_name,attr_name,new_value)
{
var retval='';
var matches=this.get_elements_by_tag_name(node_name,1);
if(matches.length>0)
matches[0].set_attribute(attr_name,new_value);
else
alert('xml_set_child_node:attribute: Unable to find child node '+node_name);
}
function xml_get_node_value(trim_value,get_all_text_nodes)
{
trim_value=(typeof(trim_value)!='undefined'?trim_value:false);
get_all_text_nodes=(typeof(get_all_text_nodes)!='undefined'?get_all_text_nodes:true);
var i=0;
var cnl=0;
var ni=0;
var nt=0;
var str='';
var cn=false;
var retval='';
var err_obj=false;
var ws_re= /^\s+$/;
try
{
cnl=this.child_nodes.length;
for(i=0;i<cnl;i++)
{
cn=this.child_nodes[i];
if(cn.is_text_node())
{
str=cn.xml_obj.nodeValue;
if(str==null)
str='';
if(str!=''&&str.search(ws_re)==-1)
{
retval+=str;
ni=i+1;
if(ni<cnl&&!get_all_text_nodes&&!this.child_nodes[ni].is_text_node())
break;
}
}
}
}
catch(err_obj)
{
if(i==0)
retval='';
else
alert('xml_get_node_value: search failure: '+err_obj.description);
}
if(trim_value)
{
retval=retval.replace(/\n/gm,'');
retval=retval.replace(/\s+/gm,' ');
if(retval.charAt(0)==' ')
retval=retval.substring(1,retval.length);
}
return retval;
}
function xml_debug(output_alert,tabsize,show_values,trim_values)
{
output_alert=(typeof(output_alert)!='undefined')?output_alert:true;
tabsize=(typeof(tabsize)!='undefined')?tabsize:0;
show_values=(typeof(show_values)!='undefined')?show_values:false;
trim_values=(typeof(trim_values)!='undefined')?trim_values:false;
var str=(tabsize==0?'xml_debug':'');
var t_str='';
var i=0;
var tabs='';
var node_list=false;
var t_xm=false;
for(i=0;i<=tabsize;i++)
tabs+='|--';
if(tabsize==0)
{
if(show_values)
str=this.node_name+': '+this.get_node_value(trim_values)+'\n';
else
str=this.node_name+'\n';
}
if(this.child_nodes.length>0)
{
for(i=0;i<this.child_nodes.length;i++)
{
t_xm=this.child_nodes[i];
if(t_xm.is_text_node(true)==false)
{
if(show_values)
{
t_str=t_xm.get_node_value(trim_values);
if(trim_values&&t_str.length>25)
t_str=t_str.substring(0,22)+'...';
t_str=': '+t_str;
}
str+=tabs+t_xm.node_name+t_str+'\n';
if(t_xm.child_nodes.length>0)
str+=t_xm.debug(false,tabsize+1,show_values,trim_values);
}
}
}
else if(output_alert)
{
alert('xml_debug: No children found');
}
if(output_alert)
alert(str);
return str;
}
function xml_debug_values(output_alert,trim_values)
{
var output_alert=(typeof(output_alert)!='undefined'?output_alert:true);
var trim_values=(typeof(trim_values)!='undefined'?trim_values:true);
var str='';
return this.debug(output_alert,0,true,trim_values);
}
function xml_inspect_internals(output_alert)
{
var xo=false;
var f_str='';
var v_str='';
var o_str='';
var u_str='';
var i=0;
var err_obj=false;
if(typeof(this.parent_xml_obj)=='boolean')
xo=this.xml_obj;
else
xo=this.parent_xml_obj;
if(typeof(this.ie_xml_obj)=='boolean')
{
for(i in xo)
{
try
{
switch(typeof(xo[i]))
{
case 'function':
f_str+='Method: '+i+'\n';
break;
case 'object':
o_str+='Object: '+i+'\n';
break;
default:
v_str+='Attribute: '+i+': '+xo[i]+'\n';
break;
}
}
catch(err_obj)
{
u_str+='Unknown: '+i+'\n';
} 
}
if(output_alert)
{
alert(f_str);
alert(o_str);
alert(v_str);
alert(u_str);
}
else
{
return f_str+"\n"+o_str+"\n"+v_str+"\n"+u_str+"\n";
}
}
else
{
alert('IE XML object: unable to inspect');
}
}
function xml_inspect_wrapper(output_alert)
{
var str='';
str+="xml_obj: "+(this.xml_obj?'Initialised':'Uninitialised')+"\n";
str+="ie_xml_obj: "+(this.ie_xml_obj?'Initialised':'Uninitialised')+"\n";
str+="parent_xml_obj: "+(this.parent_xml_obj?'Initialised':'Uninitialised')+"\n";
str+="debug_level: "+(this.debug_level?this.debug_level:0)+"\n";
str+="child_nodes: "+(this.xml_obj?this.child_nodes.length:'Uninitialised')+"\n";
str+="position: "+(this.position?this.position:0)+"\n";
str+="tag_name: "+(this.tag_name?this.tag_name:'Undefined')+"\n";
str+="node_name: "+(this.node_name?this.node_name:'Undefined')+"\n";
str+="node_type: "+(this.node_type?this.node_type:'Undefined')+"\n";
if(output_alert)
alert(str);
else
return str;
}
function jxte_test_try_catch()
{
var tc=false;
try
{
tc=true;
}
catch(f)
{
tc=false;
}
return tc;
}
function jxte_get_request_object()
{
var req_obj=false;
if(window.ActiveXObject)
{
if(jxte_test_try_catch()==true)
{
try
{
req_obj=new ActiveXObject('Msxml2.XMLHTTP');}
catch(e)
{
try
{
req_obj=new ActiveXObject('Microsoft.XMLHTTP');}
catch(f)
{
throw "get_request_object: ActiveX calls failed";
}
}
}
else
{
req_obj=new ActiveXObject('Microsoft.XMLHTTP');}
}
else if(window.XMLHttpRequest)
{
req_obj=new XMLHttpRequest();}
return req_obj;
}
function xml_load_url_contents(my_url,debug)
{
var req_obj=jxte_get_request_object(); 
var str="";
if(debug)
alert('load_url_contents: '+my_url);
if(typeof(req_obj)=='object') 
{
try
{
if(req_obj.readyState>=0) 
{
req_obj.open('GET',my_url,false);
req_obj.send(null);
if(my_url.indexOf('http://')==0||my_url.indexOf('https://')==0)
{
}
str=req_obj.responseText;
}
else
{
alert('XML HTTP Request Object not ready');
}
}
catch(e)
{
alert('load_url_contents: Failed to get '+my_url);
throw(e);
}
}
else
{
alert('XML HTTP Request Object unavailable');
}
return str;
}
function jxte_get_div_obj(div_id)
{
var obj=false;
try
{
if(typeof(document.all)!='undefined'&&typeof(document.all[div_id])!='undefined')
obj=document.all[div_id];
else if(typeof(document.getElementById(div_id))!='undefined')
obj=document.getElementById(div_id);
else
obj=document[div_id];
if(obj==null)
throw 'get_div_obj: Unable to find '+div_name;
}
catch(e)
{
alert('Failed to find div '+div_id);
throw(e);
}
return obj;
}

