function xmlHttpConnection()
{
  	var xmlhttp, bComplete = false;
  
	this.connect = function(sURL, sMethod, sVars, fnDone)
  	{
	
		var bComplete = false;
		var okHeader = false;

		// Make sure it's a GET or a POST, no funny capitalization
		sMethod = sMethod.toUpperCase();
		
		if (sMethod == "GET")
		{
			 $.ajax({
				type: "GET",
				url: sURL,
				processData: false,
				success: function(data)
				   {
						// If they want debug info, give it to them
						if (Debug)
						{
							// FireFox doesn't pre-populate the .xml attribute of 
							// XMLDocument objects, so we need to serialize it
							if (data.xml == null)
							{
								var serializer = new XMLSerializer();
								data.xml = serializer.serializeToString(data);
							}
							alert (data.xml);
						}
							
						// Check to make sure the returned information was valid XML
						if (!data|| !data.documentElement)
						{
							// Try to find a status bar, let them know it failed
							var statusBar = document.getElementById('statusBar');
							if (statusBar)
							{
								statusBar.innerHTML = '<b>Action failed.</b> Please try again, or if the problem continues, contact your Webmaster.';
							}
						}
						else
						{
							xmlDocument = data.documentElement;
							var responseMessages = xmlDocument.getElementsByTagName('responseMessage');

							for (messageNumber = 0; messageNumber < responseMessages.length; messageNumber++)
							{
								if (responseMessages[messageNumber].getAttribute('type') == 'debug')
								{
									alert(responseMessages[messageNumber].firstChild.nodeValue);							
								}
							}
						}
									
						fnDone(xmlDocument);
					}
			 });
								
		}
		else
		{
			 $.ajax({
				type: "POST",
				url: sURL,
				processData: false,
				data: sVars,
				dataType: "xml",
				contentType: "text/xml; charset=utf-8",
				success: function(data)
				   {
						// If they want debug info, give it to them
						if (Debug)
						{
							// FireFox doesn't pre-populate the .xml attribute of 
							// XMLDocument objects, so we need to serialize it
							if (data.xml == null)
							{
								var serializer = new XMLSerializer();
								data.xml = serializer.serializeToString(data);
							}
							alert (data.xml);
						}
							
						// Check to make sure the returned information was valid XML
						if (!data|| !data.documentElement)
						{
							// Try to find a status bar, let them know it failed
							var statusBar = document.getElementById('statusBar');
							if (statusBar)
							{
								statusBar.innerHTML = '<b>Action failed.</b> Please try again, or if the problem continues, contact your Webmaster.';
							}
						}
						else
						{
							xmlDocument = data.documentElement;
							var responseMessages = xmlDocument.getElementsByTagName('responseMessage');

							for (messageNumber = 0; messageNumber < responseMessages.length; messageNumber++)
							{
								if (responseMessages[messageNumber].getAttribute('type') == 'debug')
								{
									alert(responseMessages[messageNumber].firstChild.nodeValue);							
								}
							}
						}
									
						fnDone(xmlDocument);
					}
			 });

		}
		return true;

	};
  
	return this;
}

function XMLWriter()
{
	this.XML = [];
	this.Nodes = [];
	this.State = "";
	
	this.FormatXML = function(Str)
		{
			if (Str)
			{
				return Str.replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
			}
			else
			{
				return "";
			}				
		}
    
	this.BeginNode = function(Name)
		{
			if (!Name) return;
			if (this.State == "beg") this.XML.push(">");
			this.State = "beg";
			this.Nodes.push(Name);
			this.XML.push("<" + Name);
		}
    
	this.EndNode = function()
		{
			if (this.State == "beg")
			{
				this.XML.push("/>");
				this.Nodes.pop();
			}
			else if (this.Nodes.length > 0)
			{
				this.XML.push("</" + this.Nodes.pop() + ">");
        this.State="";
			}
    }

	this.Attrib = function(Name, Value)
		{
			if (this.State!="beg" || !Name) return;
			this.XML.push(" " + Name + "=\"" + this.FormatXML(Value) + "\"");
		}
	
	this.WriteString = function(Value)
		{
			if (this.State == "beg") this.XML.push(">");
			this.XML.push(this.FormatXML(Value));
			this.State = "";
		}
	
	this.Node = function(Name, Value)
		{
			if (!Name) return;
			if (this.State=="beg") this.XML.push(">");
			this.XML.push((Value == "" || !Value) ? "<" + Name + "/>" : "<" + Name + ">" + this.FormatXML(Value) + "</" + Name + ">");
			this.State = "";
		}

	this.Close = function()
		{
			while (this.Nodes.length > 0)	this.EndNode();
			this.State = "closed";
    }
	
	this.ToString = function()
		{
			return this.XML.join("");
		}
}
