/*
Name: createHTTPObject
Created : 20/06/2007
Created By : Naseer Mohsin
Purpose : This function is used to create HTTP object which is used in AJAX to send request

*/

	function createHTTPObject()
	{
		var obj
		try
		{
			// object for firefox safari etc
			return new XMLHttpRequest()
		}
		catch(e)	
		{
			try
			{
				// object for IE6 or 7
				return new ActiveXObject('MSXML2.XMLHTTP')
			}	
		
			catch(e)	
			{
				try
				{
					// object for older version of IE 
					return new ActiveXObject('Microsoft.XMLHTTP')
				}
				catch(e)	
				{
					// if objwect is not crerated then send false result
					return false;
				}
			}
		}
	}

	/*
	Name: SelectSingleNode
	Created : 22/06/2007
	Created By : Naseer Mohsin
	Purpose : selectSingleNode is DOM function but this is not working in firefox, i have created a function which will work in both IE and firefox
	
	*/

    function SelectSingleNode(xmlDoc, elementPath)
    {
        if(window.ActiveXObject)
        {
            return xmlDoc.selectSingleNode(elementPath);
        }
        else
        {
           var xpe = new XPathEvaluator();
           var nsResolver = xpe.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
           var results = xpe.evaluate(elementPath,xmlDoc,nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE, null);
           return results.singleNodeValue; 
        }
    }


/*
Prefix-correcting evaluate statement from http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/119
*/

if( document.implementation.hasFeature("XPath", "3.0") ){
 XMLDocument.prototype.selectNodes = function(cXPathString, xNode){
  if( !xNode ) {
   xNode = this;
  }
    
  var defaultNS = this.defaultNS;

  var aItems = this.evaluate(cXPathString, xNode,{
   normalResolver:
    this.createNSResolver(this.documentElement),
        lookupNamespaceURI : function (prefix) {
           switch (prefix) {
             case "dflt":
                return defaultNS;
             default:
                return this.normalResolver.lookupNamespaceURI(prefix);
           }
        }
      },XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

  var aResult = [];
  for( var i = 0; i < aItems.snapshotLength; i++){
           aResult[i] =  aItems.snapshotItem(i);
  }
  return aResult;
 }

 Element.prototype.selectNodes = function(cXPathString){
  if(this.ownerDocument.selectNodes){
   return this.ownerDocument.selectNodes(cXPathString, this);
  }else{
   throw "For XML Elements Only";
  }
 }

 /* set the SelectionNamespaces property the same for NN or IE: */
 XMLDocument.prototype.setProperty = function(p,v){
  if(p=="SelectionNamespaces" && v.indexOf("xmlns:dflt")==0){
   this.defaultNS = v.replace(/^.*=\'(.+)\'/,"$1");
  }
 }

 XMLDocument.prototype.defaultNS;

}



    