var PF_TEMP_REF = null;

/**
 * constructor for the get-post-form AJAX-request
 *
 * @param string postFormID the id of the post-form
 * @param string fieldID the id of the textarea
 * @param string requestURL the url of the PHP-script
 */
function getPostFormAJAXConstr(postFormID,fieldID,requestURL)
{
	// fields
	this.postFormID = postFormID;
	this.bbcFieldID = fieldID;
	this.requestURL = requestURL;
	this.type = '';
	this.XMLHTTP = null;
	
	// methods
	this.getPostForm = getPostForm;
}

/**
 * starts the AJAX-request
 *
 * @param string type the type to request: simple, advanced or applet
 */
function getPostForm(type)
{
	this.XMLHTTP = getXmlHttpObject();
	this.type = type;
	PF_TEMP_REF = this;
	
	var callback = function()
	{
		if(PF_TEMP_REF.XMLHTTP.readyState == 4 || PF_TEMP_REF.XMLHTTP.readyState == "complete")
		{
			xmlHttpIsBusy = false;
			var form = document.getElementById(PF_TEMP_REF.postFormID);
			var field = document.getElementById(PF_TEMP_REF.bbcFieldID);
			if(field != null && form != null)
			{
				var text = '';
				if(PF_TEMP_REF.type == 'applet')
					text = field.value;
				else if(field.getBBCode || typeof field.getBBCode == 'function')
					text = field.getBBCode();
				
				form.innerHTML = PF_TEMP_REF.XMLHTTP.responseText;
				
				field = document.getElementById(PF_TEMP_REF.bbcFieldID);
				if(PF_TEMP_REF.type == 'applet')
					field.insertText(text);
				else
					field.value = text;
			}
		}
	
		delete PF_TEMP_REF;
	};
	
	var url = this.requestURL.replace(/%s%/,type);
	sendHTTPRequest(this.XMLHTTP,url,callback);
}
