function Requester()
{
	this.action = null;
	this.XML = null;
	this.commInterface = null;

	// Initialise XMLHttpRequest object
	this.resetXMLHR();

	return true;
}

/* Check if the XMLHttpRequest object is available */
Requester.prototype.isAvailable = function()
{
	if (this.commInterface == null)
	{
		return false;
	}
	
	return true;
}




/* Execute the action which has been associated with the completion of this object */
Requester.prototype.executeAction = function()
{
	// If XMLHR object has finished retrieving the data
	if (this.commInterface.readyState == 4)
	{
		// If the data was retrieved successfully
		try
		{
			if (this.commInterface.status == 200)
			{
				this.responseText = this.commInterface.requestXML;
				this.action();
			}
			// IE returns status = 0 on some occasions, so ignore
			else if (this.commInterface.status != 0)
			{
				alert("There was an error while retrieving the URL: " + this.commInterface.statusText);
			}
		}
		catch (error)
		{
		}
	}

	return true;
}




/* Return responseText */
Requester.prototype.getText = function()
{
	return this.commInterface.responseText;
}




/* Return responseXML */
Requester.prototype.getXML = function()
{
	return this.commInterface.responseXML;
}




/* Initialise XMLHR object and load URL */
Requester.prototype.loadURL = function(URL, CGI)
{
	requester.resetXMLHR();
	requester.commInterface.open("GET", URL + "?" + CGI);
	requester.commInterface.send(null);

	return true;
}




/* Turn off existing connections and create a new XMLHR object */
Requester.prototype.resetXMLHR = function()
{
	var self = this;

	if (this.commInterface != null && this.commInterface.readyState != 0 && this.commInterface.readyState != 4)
	{
		this.commInterface.abort();
	}

	try
	{
		this.commInterface = new XMLHttpRequest();
	}
	catch (error)
	{
		try
		{
			this.commInterface = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (error)
		{
			return false;
		}
	}

	this.commInterface.onreadystatechange = function()
		{
			self.executeAction();

			return true;
		};

	return true;
}




/* Assign the function which will be executed once the XMLHR object finishes retrieving data */
Requester.prototype.setAction = function(actionFunction)
{
	this.action = actionFunction;

	return true;
}

function schedule(objectID, functionCall, iteration)
{
	if (iteration == null)
	{
		iteration = 0;
	}
	
	if (objectID == "window")
	{
		var oldonload = window.onload;
		
		if (typeof window.onload != "function")
		{
			window.onload = functionCall;
		}
		else
		{
			window.onload = function()
			{
				oldonload();
				functionCall();
			}
		}
	}
	else if (document.getElementById(objectID))
	{
		functionCall();
	}
	else if (iteration < 300)
	{
		setTimeout(function(){schedule(objectID, functionCall, iteration + 1)}, 10);
	}
	
	return true;
}

String.prototype.addClass = function(theClass)
{
	if (this != "")
	{
		if (!this.classExists(theClass))
		{
			return this + " " + theClass;
		}
	}
	else
	{
		return theClass;
	}
	
	return this;
}




String.prototype.classExists = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	if (regExpression.test(this))
	{
		return true;
	}
	
	return false;
}




String.prototype.isValidEmail = function()
{
	return this.match(/\w+@\w+\.\w+/);
}




String.prototype.removeClass = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	return this.replace(regExpression, "");
}

initStylesheets();


function initStylesheets()
{
	/* Turn on specific stylesheet for JS-capable browsers */
	setStylesheet("JavaScript", false, true);
	
	return true;
}




function setStylesheet(styleTitle, styleStatus, reset)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				if (reset)
				{
					currTag.disabled = true;
				}

				if(currTag.title == styleTitle)
				{
					if (styleStatus == "switch" && currTag.disabled == true)
					{
						/* Set disabled to opposite of current value */
						currTag.disabled = false;
					}
					else if (styleStatus == "switch")
					{
						/* Set disabled to opposite of current value */
						currTag.disabled = true;
					}
					else
					{
						/* Set disabled to passed status */
						currTag.disabled = styleStatus;
					}
				}
			}
		}
	}
	
	return true;
}

