	function _CommentStore()
	{
		this.factoryInstance;
	}	
	
	var __commentStore = new _CommentStore();
	
	function _CommentFactory()
	{
		this.container_id;
		this.comment_type;
		this.ajaxCreateComplete;
		this.multiLang = 0;
		this.maxLength = 2500;
		__commentStore.factoryInstance = this;
	}
	
	_CommentFactory.prototype.init = function()
	{
		this.parseToggle();
	}
	
	
	_CommentFactory.prototype.parseToggle = function()
	{
		$("._toggleComment").click(function()
		{
			var comment_id = $(this).attr("id").replace("_toggleComment_","");
		
			$.ajax(
			{
				type: "POST",
				url: "/page/comment/comment.toggle.ajax.php",
				data: "&container_id=" + __commentStore.factoryInstance.container_id + "&comment_type=" + __commentStore.factoryInstance.comment_type + "&comment_id=" + comment_id + "&multilang=" + __commentStore.factoryInstance.multiLang,
				cache: false,
				success: __commentStore.factoryInstance.refresh
			});	
		});
	}
	
	_CommentFactory.prototype.createComment = function()
	{
		var comment_text = $("#commenttextarea").attr("value").replace(/\s+$/,"").replace(/^\s+/,"").replace(/[+]/g,"%2b").replace(/&/g,"##AMP##");
				
		if (comment_text.length == 0)
		{
			return;
		}

		if (comment_text.length > this.maxLength)
		{
			alert($("#maxlengthwarning").html());
			return;
		}
	
	
		$.ajax(
		{
			type: "POST",
			url: "/page/comment/comment.create.ajax.php",
			data: "&container_id=" + this.container_id + "&comment_type=" + this.comment_type + "&comment=" + comment_text + "&multilang=" + __commentStore.factoryInstance.multiLang,
			cache: false,
			success: this.refresh
		});
		
		$("#commenttextarea").attr("value","");
	}
	
	
	_CommentFactory.prototype.refresh = function(result)
	{
		__commentStore.factoryInstance.doRefresh(result);
	}
	
	_CommentFactory.prototype.doRefresh = function(result)
	{
		document.getElementById("comments").innerHTML = result;
		
		this.parseToggle();
		
		if (typeof(this.ajaxCreateComplete) == "function")
		{
			this.ajaxCreateComplete();
		}
	}
