
var CreatingSiteXml = function()
{}

CreatingSiteXml.prototype.GetHttpRequest = function()
{
   var request;
   try {
      request = new XMLHttpRequest();
      //alert('XMLHttpRequest created');
   } catch (trymicrosoft) {
      try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
         //alert('Msxml2.XMLHTTP created');
      } catch (othermicrosoft) {
         try {
            request = new ActiveCObject("Microsoft.XMLHTTP");
            //alert('Microsoft.XMLHTTP created');
         } catch (failed) {
            xmlHttp = false;
         }
      }
   }
   
   if (!request) {
      alert('Error initializing XMLHttpRequest');
   }
   
   return request;
}

CreatingSiteXml.prototype.LoadUrl = function(urlToCall, asyncFunctionPointer)
{
   //alert('LoadUrl: URL = ' + urlToCall);
   var oCreatingSiteXml = this;
   
   var oXmlHttp = this.GetHttpRequest();
   	
   oXmlHttp.open("GET", urlToCall, true);
	
   oXmlHttp.onreadystatechange = function() 
   {
      if (oXmlHttp.readyState == 4)
      {
         oCreatingSiteXml.DOMDocument = oXmlHttp.responseXML;
         oCreatingSiteXml.TextMessage = oXmlHttp.responseText;
         if (oXmlHttp.status == 200 || oXmlHttp.status == 304) {
            //alert('Response: ' + oXmlHttp.responseText);
            asyncFunctionPointer(oCreatingSiteXml);
         }
         else {
            alert('XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')');
         }
      }
   }
	
	oXmlHttp.send(null) ;
}

CreatingSiteXml.prototype.GetTextMessage = function()
{
   return this.TextMessage;
}

CreatingSiteXml.prototype.SelectNodes = function(xpath)
{
   if (document.all)		// IE
      return this.DOMDocument.selectNodes(xpath);
   else					   // Gecko
   {
      var aNodeArray = new Array();
      
      var xPathResult = this.DOMDocument.evaluate(xpath, this.DOMDocument, 
            this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
      if (xPathResult)
      {
         var oNode = xPathResult.iterateNext();
         while(oNode)
         {
            aNodeArray[aNodeArray.length] = oNode;
            oNode = xPathResult.iterateNext();
         }
      }
      return aNodeArray;
   }
}

CreatingSiteXml.prototype.SelectSingleNode = function(xpath)
{
   if (document.all)		// IE
      return this.DOMDocument.selectSingleNode(xpath);
   else					   // Gecko
   {
      var xPathResult = this.DOMDocument.evaluate(xpath, this.DOMDocument,
            this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
      
      if (xPathResult && xPathResult.singleNodeValue)
         return xPathResult.singleNodeValue;
      else	
         return null;
   }
}
