var GlobalPersistRequest;

//*** Class RemoteRequest ******************************************************************

function RemoteRequest(photo, post, url, callback, errorHandle)
{
	this.userRequest;
	this.photoFormKey;
	this.photoFormValue;
	this.postFormKey;
	this.postFormValue;
	this.remoteResource;
	this.callbackMethod;
	this.errorHandler;
	this.initialize(photo, post, url, callback, errorHandle);
}

RemoteRequest.prototype.initialize = function(photo, post, url, callback, errorHandle)
{
	this.photoFormKey = "PhotoID";
	this.photoFormValue = photo;
	this.postFormKey = "PostID";
	this.postFormValue = post;
	this.remoteResource = url;
	this.callbackMethod = callback;
	this.errorHandler = errorHandle;
	GlobalPersistRequest = this;
	
	if(window.XMLHttpRequest)
		this.userRequest = new XMLHttpRequest();
	else if(window.ActiveXObject)
		this.userRequest = new ActiveXObject("Msxml2.XMLHTTP");
		
	if(this.userRequest)
	{
		var formCollection = this.photoFormKey + "=" + this.photoFormValue +
		        "&" + this.postFormKey + "=" + this.postFormValue;
	
		this.userRequest.onreadystatechange = processRequestChange;
		this.userRequest.open("POST", this.remoteResource, true);
		this.userRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.userRequest.setRequestHeader("OroborosContentHeader", "true");
		this.userRequest.send(formCollection);
	}
}

//*** RemoteRequest Library ****************************************************************

function processRequestChange()
{
	if(GlobalPersistRequest.userRequest.readyState == 4)
	{
		if(GlobalPersistRequest.userRequest.status == 200)
		{
			GlobalPersistRequest.callbackMethod(GlobalPersistRequest.userRequest.responseXML);
		}
		else
		{
			GlobalPersistRequest.errorHandler(GlobalPersistRequest.userRequest.responseText);
		}
	}
}
