var comObj = new function() {
	this.ajax = new Ajax();
	this.tool = false;
	this.toolid = false;
	this.cmore = false;
	
	this.showHide = function(tool, toolid, action) {
		if(action == "show") {
			var c = document.getElementById("comments_show_"+tool+"_"+toolid);
			c.style.display = "none";
			
			comObj.changePage(tool, toolid, 1);
		} else {
			var c = document.getElementById("comments_"+tool+"_"+toolid);
			c.style.display = "none";
			
			var c = document.getElementById("comments_show_"+tool+"_"+toolid);
			c.style.display = "block";
		}
		return false;
	};
	
	this.changePage = function(tool, toolid, page) {
		if(!comObj.tool && !comObj.toolid) {
			comObj.tool = tool;
			comObj.toolid = toolid;
			
			comObj.ajax.setMimetype="text/html";
			comObj.ajax.responseFormat="text";
			comObj.ajax.doGet("/includes/comments/src/index.php?xaction=get+comments"+
					"&tool="+tool+
					"&toolid="+toolid+
					"&page="+page, 
				comObj.finishChange, "text"); 
		}
		return false;
	};
	
	this.finishChange = function(ajax_html) {
		if(comObj.tool && comObj.toolid) {
			var c = document.getElementById("comments_"+comObj.tool+"_"+comObj.toolid);
			c.innerHTML = ajax_html;
			c.style.display = "block";
			
			comObj.tool = false;
			comObj.toolid = false;
		}
	};
	
	this.submitComment = function(tool, toolid, fe) {
		if(!comObj.tool && !comObj.toolid && fe.c_text.value.length > 0) {
			comObj.tool = tool;
			comObj.toolid = toolid;
			
			comObj.ajax.setMimetype="text/html";
			comObj.ajax.responseFormat="text";
			comObj.ajax.doGet("/includes/comments/src/index.php?xaction=submit+comment"+
					"&tool="+tool+
					"&toolid="+toolid+
					"&c_text="+escape(fe.c_text.value), 
				comObj.finishComment, "text");
		}
	};
	
	this.finishComment = function(ajax_text) {
		var c = document.getElementById("comments_"+comObj.tool+"_"+comObj.toolid+"_form");
		c.innerHTML = ajax_text;
		
		comObj.tool = null;
		comObj.toolid = null;
	};
	
	this.report = function(c_id) {
		document.getElementById("comment_"+c_id).style.display="none";

		comObj.ajax.setMimetype="text/html";
		comObj.ajax.responseFormat="text";
		comObj.ajax.doGet("/includes/comments/src/index.php?xaction=report"+
				"&c_id="+c_id, 
			comObj.finishAbuse, "text");
		return false;
	};
	
	this.finishAbuse = function(ajax_text) {
		
	};
	
	this.showMore = function(c_id) {
		if(!comObj.cmore) {
			comObj.cmore = c_id;
			comObj.ajax.setMimetype="text/html";
			comObj.ajax.responseFormat="text";
			comObj.ajax.doGet("/includes/comments/src/index.php?xaction=show+more"+
					"&c_id="+c_id, 
				comObj.finishShowMore, "text");
		}
		return false;
	};
	
	this.finishShowMore = function(ajax_text) {
		if(comObj.cmore > 0 ) {
			var c = document.getElementById("comment_"+comObj.cmore);
			c.innerHTML = ajax_text;
			
			var c = document.getElementById("comment_more_"+comObj.cmore);
			c.innerHTML = "";
		}
		
		comObj.cmore = false;
	};
}	

