/*
		AJAX Utilities - Benjamin Dry
		
		Call loadXMLDoc(url) passing in the URL with any variables required. 
		no posting done to this utility yet
*/


var xmlhttp;
var isIE = false;
var parseFnc = "";

function loadXMLDoc(url,parser)
{
// code for Mozilla, etc.



parseFnc = parser;

if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=xmlhttpChange
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    isIE = true;
    xmlhttp.onreadystatechange=xmlhttpChange;
    
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}
		
function xmlhttpChange()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
   		eval(parseFnc+"()")
    }
  else
    {
    alert("Problem retrieving Event data")
    }
  }
}

// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
	     // the namespace versions of this method 
	     // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        try{
			if (result.childNodes.length > 1) {
	            return result.childNodes[1].nodeValue;
	        } else {
    	        return result.firstChild.nodeValue;    		
       	 }
		} catch(e) {
	        return "";			
		}
    } else {
        return "";
    }
}

// retrieve text of an XML document elements attribute, including
// elements using namespaces
function getAttributeTextNS(prefix, local, parentElem, index, attr) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index].getAttribute(attr);
    } else {
	     // the namespace versions of this method 
	     // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index].getAttribute(attr);
    }
    return result;
}	

