﻿// zXmlHttpThreadArray is a Class Object that will keep track of all XmlHttp requests
function zXmlHttpThreadArray(name)
{
	this.name = name;
	this.threadId = new Array();
	this.threadArray = new Array();
}
zXmlHttpThreadArray.prototype.getLength = function(){return this.threadArray.length;};
zXmlHttpThreadArray.prototype.addThread = function(oXmlHttpThread)
{
	this.threadArray.push(oXmlHttpThread);
	this.threadId.push(oXmlHttpThread.id);
	return this.threadArray.length;
};
zXmlHttpThreadArray.prototype.removeThread = function(oXmlHttpThread)
{
	if (typeof(oXmlHttpThread) != "object") oXmlHttpThread = this.getThread(oXmlHttpThread);
	var arrayIndex = null;
	for (var i = 0; i < this.getLength(); i++)
		arrayIndex = (this.threadId[i] == oXmlHttpThread.id) ? i : arrayIndex;
	this.threadId[arrayIndex] = null;
	this.threadArray[arrayIndex] = null;
	this.threadId.splice(arrayIndex, 1);
	this.threadArray.splice(arrayIndex, 1);
	return null;
};
zXmlHttpThreadArray.prototype.getThread = function(arrayIdentifier)
{
	var arrayIndex = arrayIdentifier;
	if (typeof(arrayIdentifier) == "string")
	{
		for (var i = 0; i < this.getLength(); i++)
			arrayIndex = (this.threadId[i] == arrayIdentifier) ? i : arrayIndex;
	}
	return this.threadArray[arrayIndex];
};

// zXmlHttpThread is a Class Object that will hold a reference to an XmlHttp request
function zXmlHttpThread(id, type)
{
	this.id = id;
	this.type = type;
	this.request = zXmlHttp.createRequest();
}
zXmlHttpThread.prototype.getRequest = function(){return this.request;};
zXmlHttpThread.prototype.register = function(array){array.addThread(this);};
zXmlHttpThread.prototype.unregister = function(array){array.removeThread(this);};