// JavaScript Document
//function used to generate a http request object 
function getHttpRequestObj(){
	// code for Mozilla, etc.
	var xmlhttp;
	if (window.XMLHttpRequest){
		// xmlhttp=new XMLHttpRequest();
		var tempObj = new XMLHttpRequest();
		tempObj.overrideMimeType("application/xml");
		return tempObj;
	}
	// code for IE
	else if (window.ActiveXObject){

	 var tempObj = new ActiveXObject("Microsoft.XMLHTTP");

	
	  return tempObj;
	
	 }
	
	
	
}
/*
*   Helper function that gets xml tags by their tag name
*   x   xml document
*   s   tag name
*/
function getNode(x,s){
	var requestedNodes = x.getElementsByTagName(s);
	/*
	for(var i = 0; i < requestedNodes.length; i++){
	    
	    if(requestedNodes[i].firstChild.nodeName == "#text"){
	        requestedNodes[i].removeChild(requestedNodes[i].firstChild);
	    }
	    
	}
	*/
	return  requestedNodes;
}
/*
*   Function that connects to a web service view a GET URL and sends back xml
*   @param  u   GET URL
*/
function getAjaxXML(u){
   //creating our ajax/http request object
	tempAjaxObj = getHttpRequestObj();
	//opening a connection, please note this is set to be a synchronous call
	tempAjaxObj.open('GET',u,false);
	//sending request
	tempAjaxObj.send(null);	
	//checking to see if we got a response
	if (tempAjaxObj.responseText != null) {
		//firefox 
		if(window.ActiveXObject == null){
			//setting the response xml
			var x  = tempAjaxObj.responseXML;
			//checking to see if there are any errors
			if(x.firstChild.nodeName == "parsererror"){
			    //if error alert and send null back to caller
			    alert("WebService Response Error: Response XML not formatted properly.\nServer Response:\n"+tempAjaxObj.responseText);
		        return null;
			}else{
			    //if all is well return xml
			    return x;
			}
	    //explorer
		}else{
		    //setting the response xml
		    var x  = tempAjaxObj.responseXML;
		    //checking to see if there are any errors
		    if(x.firstChild == null){
		        //if error alert and send null back to caller
		        alert("WebService Response Error: Response XML not formatted properly.\nServer Response:\n"+tempAjaxObj.responseText);
		        return null;
		    }else{
			    //if all is well return xml
			    x.removeChild(x.firstChild);
			    return x;
			}
		}
		
		
	}else{
	    //if we don't receive response text alert and return null
	    alert("WebService Response Error: Response Text was returned as null.");
	    return null;
	}
	
}