//TODO: should just be xbrowser; a compatibility library

function isIe() {
	return window.navigator.userAgent.match(/MSIE/);
}

function isIe6() {
	return window.navigator.userAgent.match(/MSIE 6/);
}

function xBrowserXmlParse(string) {
       var response = null;
        if (window.ActiveXObject) {
               //like XMLHTTP, there are a number of different implementations for the DomDocument... should look into
               //them and do something like we do in the FactoryXMLHttpRequest to get the best impl available
                response = new ActiveXObject("MSXML.DomDocument");
                response.loadXML(string);
        }
        else
                response = new DOMParser().parseFromString(string, "application/xml");
       return response
}

function parseUrl(url, postFunc) {
	var asyn = new Asynchronous();
	asyn.complete = function(status, statusText, responseText, responseXml) {
		if (responseXml != null) postFunc(responseXml);
		else postFunc(xBrowserXmlParse(responseText));
		
	}
	alert(url);
	asyn.call(url);
}

//help out challenged IE
if (!document.ELEMENT_NODE) {
  document.ELEMENT_NODE = 1;
  document.ATTRIBUTE_NODE = 2;
  document.TEXT_NODE = 3;
  document.CDATA_SECTION_NODE = 4;
  document.ENTITY_REFERENCE_NODE = 5;
  document.ENTITY_NODE = 6;
  document.PROCESSING_INSTRUCTION_NODE = 7;
  document.COMMENT_NODE = 8;
  document.DOCUMENT_NODE = 9;
  document.DOCUMENT_TYPE_NODE = 10;
  document.DOCUMENT_FRAGMENT_NODE = 11;
  document.NOTATION_NODE = 12;
}

/* Credit Anthony Holdener, http://www.alistapart.com/articles/crossbrowserscripting; IE does not support import node; 
   not sure at the moment why he uses '_importNode' rather than condititionally defining 'importNode' if needed, but we 
   follow his example in case there's some consistency issue between the regular importNode (which is defined in Gecko 
   browsers). */
document._importNode = function(node, allChildren) {
  switch (node.nodeType) {
    case document.ELEMENT_NODE:
      var newNode = document.createElement(node.nodeName);
      /* does the node have any attributes to add? */
      if (node.attributes && node.attributes.length > 0)
        for (var i = 0; i < node.attributes.length; i++)
          newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i] .nodeName));
      /* are we going after children too, and does the node have any? */
      if (allChildren && node.childNodes && node.childNodes.length > 0)
        for (var i = 0; i < node.childNodes.length; i++)
          newNode.appendChild(document._importNode (node.childNodes[i], allChildren));
      return newNode;
      break;
    case document.TEXT_NODE:
    case document.CDATA_SECTION_NODE:
    case document.COMMENT_NODE:
      return document.createTextNode(node.nodeValue);
      break;
  }
};