var FotoPrintProxy =
{
	_ceateRequestOptions: function(message)
	{//application/x-www-form-urlencoded
		//return {method: 'post', asynchronous: true, postBody: message, requestHeaders: ['Content-type', ''], onComplete: this._onComplete, onException: this._onException};
		return {method: 'post', asynchronous: true, postBody: message, onComplete: this._onComplete, onException: this._onException};
	},

	_onComplete: function(transport, json)
	{
		FotoPrintDocumentHelper.debug(transport.responseText);

		var response = transport.responseXML.getElementsByTagName("response");

		if (response != null && response.length == 1)
		{
			response = response[0];
		}

		FotoPrintProxy.callback(transport.status, response);
	},

	_onException: function(ajaxRequest, exception)
	{
		FotoPrintDocumentHelper.debug(exception);
	},

	getRandomProducts: function(categoryID, requestID, callback, count)
	{
		FotoPrintProxy.sendRequest('op=get_random_product_xml&category_id=' + categoryID + '&requestID=' + requestID + '&count=' + count, callback);

		FotoPrintDocumentHelper.debug("getRandomProducts sent");
	},

	sendCommand: function(name, parameters, callback)
	{
		var command = '<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>';

		command += name + "</methodName>";

		if (parameters)
		{
			command += "<params>";

			for (var i = 0;i < parameters.length; i++)
			{
				command += "<param><value>" + parameters[i] + "</value></param>";
			}

			command += "</params>";
		}

		command += "</methodCall>";

		this.callback = callback;

		var request = new Ajax.Request(fotoPrintProxySettings.proxyURL, this._ceateRequestOptions(command));

		FotoPrintDocumentHelper.debug("sent");
	},
	
	sendRequest: function(parameters, callback)
	{
		this.callback = callback;

		var request = new Ajax.Request(FotoPrintProxySettings.proxyURL, this._ceateRequestOptions(parameters));

		FotoPrintDocumentHelper.debug("sent");
	}
}