var _xmlHttpObj = null;

if (!_isIEBrowser)
  addMozillaXmlSupport();

function executeServerRequest(methodName, params) {
  var requestUrl = getObjectPath('svc/AjaxService.asmx') + '/' + methodName + (params == '' ? '' : '?' + params);
  _xmlHttpObj = getXmlHttpObject();
  if (!_xmlHttpObj)
    return;
  _xmlHttpObj.onreadystatechange = getResponseMethod(methodName);
  _xmlHttpObj.open('POST', requestUrl, true);
	//_xmlHttpObj.setRequestHeader('componentEngineRequest', 'true');
	try {
	  _xmlHttpObj.send(''); //must contain '' for mozilla
  }
  catch(e) {
    alert(e)
    return;
  }
}

function getResponseXml() {
  if (_xmlHttpObj.readyState == 4) {//Loaded
    if (_xmlHttpObj.status == 200) {//OK
      if (!_xmlHttpObj.responseXML || !_xmlHttpObj.responseXML.documentElement)
        return null;
        //alert (_xmlHttpObj.responseText)
        //prompt ("1", _xmlHttpObj.responseText)
      return _xmlHttpObj.responseXML.documentElement;
    }
    else {
      //alert (_xmlHttpObj.status + ' : ' + _xmlHttpObj.statusText);
      return null;
    }
  }
  else
    return null;
}

function addMozillaXmlSupport() {
  if (document.implementation.hasFeature("XPath", "3.0")) {
    XMLDocument.prototype.selectNodes = function(cXPathString, xNode) {
		  if (!xNode) { xNode = this; } 

		  var oNSResolver = this.createNSResolver(this.documentElement);
		  var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		  var aResult = [];
		  for( var i = 0; i < aItems.snapshotLength; i++)
			  aResult[i] =  aItems.snapshotItem(i);
		  return aResult;
	  }
	  
	  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;
	  }

	  Element.prototype.selectNodes = function(cXPathString) {
		  if(this.ownerDocument.selectNodes)
			  return this.ownerDocument.selectNodes(cXPathString, this);
		  else
		    throw "For XML Elements Only";
	  }

	  Element.prototype.selectSingleNode = function(cXPathString) {	
		  if(this.ownerDocument.selectSingleNode)
		    return this.ownerDocument.selectSingleNode(cXPathString, this);
		  else
		    throw "For XML Elements Only";
	  }
  }
}

function getXmlHttpObject() {
  // code for Mozilla
  if (window.XMLHttpRequest)
    return new XMLHttpRequest();
  // code for IE
  else if (window.ActiveXObject)
    return new ActiveXObject('Microsoft.XmlHttp');
}