﻿
	function CreateRequest()
	{
		var request = null;
		
		try
		{
			request = new XMLHttpRequest();
		}
		catch (trymicrosoft)
		{
			try
			{
				request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (othermicrosoft)
			{
				try
				{
					request = new ActiveXOjbect("Microsoft.XMLHTTP");
				}
				catch (failed)
				{
					request = null;
				}
			}
		}
		
		if (request == null)
			alert("Error creating xml objcect");
			
		return request;
	}
	
	function getText(element)
	{
		var strText = "";
		
		if (element == null) return "";
		if (element.childNodes == null) return "";
		
		for (var i=0; i<element.childNodes.length; i++)
		{
			var childNode = element.childNodes[i];
			if (childNode.nodeValue != null)
				strText = strText + childNode.nodeValue;
		}
		
		return strText;
	}
	
	function getTextByElementID(strElementID)
	{
		var element = document.getElementById(strElementID);
		return getText(element);
	}

	function getTextByDocumentAndElementID(doc, strElementID)
	{
		var element = doc.getElementById(strElementID);
		return getText(element);
	}

	function clearText(element)
	{
		if (element == null) return;
		if (element.childNodes == null) return;
		
		for (var i=0; i<element.childNodes.length; i++)
		{
			var childNode = element.childNodes[i];
			element.removeChild(childNode);
		}
		
		return true;		
	}
	
	function replaceText(element, strText)
	{
		if (element == null) return;

		clearText(element);
		
		var newNode = document.createTextNode(strText);
		element.appendChild(newNode);
		
		return true;
	}
	
	function replaceTextByElementID(strElementID, strText)
	{
		var element = document.getElementById(strElementID);
		return replaceText(element, strText);
	}
	
	function replaceTextByDocumentAndElementID(doc, strElementID, strText)
	{
		var element = doc.getElementById(strElementID);
		if (element == null) return;
		
		clearText(element);

		var newNode = doc.createTextNode(strText);
		element.appendChild(newNode);
		
		return true;
	}

	function getValueFromXML(xmlDoc, strTagName)
	{
		try
		{
			var xmlValue = xmlDoc.getElementsByTagName(strTagName)[0];
			if (xmlValue == null) return null 
			
			var strValue = xmlValue.firstChild.nodeValue;
			return strValue;
		}
		catch (trymicrosoft) 
		{
		
		}
		return "";
	}
	
	function setInnerHTMLByElementID(strElementID, strText)
	{
		var element = document.getElementById(strElementID);
		if (element == null) return false;

		element.innerHTML = strText;		
		return true;
	}

	function GetXMLValue(xmlElement, strTagName)
	{
		var strValue = "";
		
		try
		{
			var xmlValue = xmlElement.getElementsByTagName(strTagName)[0];
			if (xmlValue != null)
			{
				if (xmlValue.firstChild.nodeValue != null)
					strValue = xmlValue.firstChild.nodeValue;
			}
		}
		catch (trymicrosoft) 
		{
		
		}
				
		return strValue;
	}
	