// ************************************************************
// Helpers for Ajax Creation/
// ************************************************************
function AjaxTools()
{
	this.CreateXmlHttpRequest = ajaxTools_CreateXmlHttpRequest;
	this.GetFirstNode = ajaxTools_GetFirstNode;
	this.GetNodeValue = ajaxTools_GetNodeValue;
	this.SelectNodes = ajaxTools_SelectNodes;
	this.SelectSingleNode = ajaxTools_SelectSingleNode;

	// Generic 
	function ajaxTools_CreateXmlHttpRequest() 
	{
		var xmlhttp;

		// IE6
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) 
		{
			xmlhttp = null;
		}
		
		// IE5
		if (xmlhttp==null)
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				xmlhttp = null;
			}
		}
		
		// Netscape
		if (xmlhttp==null)
		{
			try 
			{
				xmlhttp = new XMLHttpRequest();
			} 
			catch (e) 
			{
				xmlhttp = null;
			}
		}

		return (xmlhttp);
	}

	// Gets the first node from a xml
	function ajaxTools_GetFirstNode(node, path)
	{
		var nodeList = node.getElementsByTagName(path);

		if(nodeList.length > 0)
		{
			return(nodeList[0]);
		}
		
		return(null);
	}

	// Gets the value of the xml node
	function ajaxTools_GetNodeValue(node)
	{
		if(node != null)
		{
			if(node.firstChild != null)
			{
				return(node.firstChild.nodeValue);
			}
		}
		return('');
	}

	// Gets a list of nodes with the required tag name (only searches direcly below the current node)
	function ajaxTools_SelectNodes(node, tagname)
	{
		var ret = new Array();
		if(node!=null)
		{
			if(node.childNodes!=null)
			{
				for(var i=0;i<node.childNodes.length;i++)
				{
					if(node.childNodes[i].tagName==tagname) ret[ret.length] = node.childNodes[i];
				}
			}
		}
		return(ret);
	}

	// Gets the first node with the required tag name (only searches direcly below the current node)
	function ajaxTools_SelectSingleNode(node, tagname)
	{
		if(node!=null)
		{
			if(node.childNodes!=null)
			{
				for(var i=0;i<node.childNodes.length;i++)
				{
					if(node.childNodes[i].tagName == tagname) return(node.childNodes[i]);
				}
			}
		}
		return(null);
	}
}
