

if(document.implementation && document.implementation.createDocument)
{
	XMLDocument.prototype.loadXML = function(xmlString)
	{
		var childNodes = this.childNodes;
		for (var i = childNodes.length - 1; i >= 0; i--)
			this.removeChild(childNodes[i]);

		var dp = new DOMParser();
		var newDOM = dp.parseFromString(xmlString, "text/xml");
		var newElt = this.importNode(newDOM.documentElement, true);
		this.appendChild(newElt);
	};

	// check for XPath implementation
	if( document.implementation.hasFeature("XPath", "3.0") )
	{
		XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function (xpath){
		         var  xpe  =   new  XPathEvaluator();
		         var  nsResolver  =  xpe.createNSResolver( this .ownerDocument  ==   null   ?
						this .documentElement :  this .ownerDocument.documentElement);
		         var  result  =  xpe.evaluate(xpath,  this , nsResolver,  0 ,  null );
		         var  found  =  [];
		         var  res;
		         while  (res  =  result.iterateNext())
		            found.push(res);
		         return  found;
		    }
	   // prototying the Element
	   Element.prototype.selectNodes = function(cXPathString)
	   {
		  if(this.ownerDocument.selectNodes)
		  {
			 return this.ownerDocument.selectNodes(cXPathString, this);
		  }
		  else{throw "For XML Elements Only";}
	   }
	}

	// check for XPath implementation
	if( document.implementation.hasFeature("XPath", "3.0") )
	{
	   // prototying the XMLDocument
	   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	   {
		  if( !xNode ) { xNode = this; }
		  var xItems = this.selectNodes(cXPathString, xNode);
		  if( xItems.length > 0 )
		  {
			 return xItems[0];
		  }
		  else
		  {
			 return null;
		  }
	   }

	   // prototying the Element
	   Element.prototype.selectSingleNode = function(cXPathString)
	   {
		  if(this.ownerDocument.selectSingleNode)
		  {
			 return this.ownerDocument.selectSingleNode(cXPathString, this);
		  }
		  else{throw "For XML Elements Only";}
	   }
	}
}




function vIFO_XML(xName)
{
	this.name=xName;
	this.xmldoc;
	this.xsldoc;
	this.node;
	this.xpath;
	this.Browser={
    IE:!!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/),
    Firefox:navigator.userAgent.indexOf('Firefox/') > 0
  };




	this.initxmldoc = function()
	{
		if(window.ActiveXObject)
		{
			this.xmldoc	= new ActiveXObject('Microsoft.XMLDOM');
			this.xsldoc	= new ActiveXObject('Microsoft.XMLDOM');
			this.xsldoc.async	= false;
			this.xmldoc.async	= false;
			this.xmldoc.setProperty('SelectionLanguage','XPath');
			this.xsldoc.setProperty('SelectionLanguage','XPath');

			return this.xmldoc;
		}
		else if (document.implementation&&document.implementation.createDocument)
		{
			this.xmldoc	= document.implementation.createDocument('', '', null);
			this.xsldoc	= document.implementation.createDocument('', '', null);
			this.xmldoc.async = false;
			this.xsldoc.async	= false;
			//this.xmldoc.setProperty('SelectionLanguage','XPath');
			//this.xsldoc.setProperty('SelectionLanguage','XPath');
			return this.xmldoc;
		}
		else
		{
			return null;
		}
	};

	this.selectNodes=function(xpath)
	{
		if(this.Browser.IE){
			this.node=this.xmldoc.selectNodes(xpath);
		}else
			{
				this.node=this.xmldoc.selectNodes(xpath);
			}
			this.xpath=xpath;
			return this.node;
	};
	this.GetText=function(oNode)
	{
		var sText = "";
		for (var i = 0; i < oNode.childNodes.length; i++)
		{
			if(oNode.childNodes[i].hasChildNodes()){
				sText += getText(oNode.childNodes[i]);
			} else{
				sText += oNode.childNodes[i].nodeValue;
			}
		}
		return sText;
	};

	this.GetValue=function(xname,index)
	{
		try
		{
			if(index===undefined) index=0;
			index=parseInt(index);
		}catch(ex){index=0;}
		if(index<0)index=0;
		var str="";
		try
		{
			this.node=this.xmldoc.selectNodes(this.xpath);
			if(this.Browser.IE)
				str=this.node.item(index).attributes.getNamedItem(xname).value;
			else
				str=this.node[index].attributes.getNamedItem(xname).value;
		}
		catch(ex)
		{
			try
			{
				this.node=this.xmldoc.selectNodes(this.xpath+"/"+xname);
				if(this.Browser.IE)	str=this.node.item(index).text;
				else
					str=this.GetText(this.node[index]);
			}catch(e)
			{

			}
		}

		return str;
	};

this.loadxsl=function(xmlfile,xslfile)
{
	this.initxmldoc();
	if(this.xmldoc)
	{
		this.xmldoc.load(xmlfile);
		this.xsldoc.load(xslfile);
	}else{
		return;
	}
	if( this.Browser.IE){
		return this.xmldoc.transformNode(this.xsldoc);
	}else
	{
		var xslProc = new XSLTProcessor();
		xslProc.importStylesheet(this.xsldoc);
		var result = xslProc.transformToDocument(this.xmldoc);
		var xmls = new XMLSerializer();
		return xmls.serializeToString(result);
	}
};
this.load = function(xmlfile)
{
	this.initxmldoc();
	if(this.xmldoc)
	{
		this.xmldoc.load(xmlfile);
	}
};
this.loadxml = function(xmlstr)
{

	this.initxmldoc();
	if(this.xmldoc)
	{
		if(window.ActiveXObject)
		{
			this.xmldoc.loadXML(xmlstr);
		}
		else
		{
				var oParser = new DOMParser();
				this.xmldoc = oParser.parseFromString(xmlstr,"text/xml");
		}
	}
};
}

