function CommentController()
{
	this.reqWidgetQueue= new Array();//queue with the widgets that made a request through this controller object
	var self=this;
	this.localWidgetReff = null;
	this.ref=null;
	this.ref_err=null;
	this.ref_nr=null;
	this.applycomment=function(link_id,comment,name)
	{
		comment=comment.split("\n").join("<br>");
		this.ref=link_id;
		this.ref_err=document.getElementById('mesaj_err_comm');
		var rqid=RequestManager.getInstance().createRequest(CommentController.getInstance(),URL+"index.php?page=link&action=post_comment&link_id="+link_id+'&comment='+comment+'&user_name='+name);
		RequestManager.getInstance().startRequest(rqid);
	}
	
	/**
	 * @param The manager index of the request 
	 * @desc This method is a handler for the completition of one request
	 */
	this.handleResponse=function (managerIndex)
	{	
		this.ref_err.innerHTML="";
		var respContent=RequestManager.getInstance().getRequestObj(managerIndex).getResponseContent();
		result=eval(respContent);
		this.ref_err.innerHTML=result[0]['value'];
		if(result[0]['text']=='ok')
		{
			document.getElementById('comm_nr').innerHTML=result[1]['value'];
			//call to get list of tags and to refresh existing tag list
			RequestManager.getInstance().createRequest(CommentListController.getInstance().getCommentsList(this.ref));
		}
		if(result[0]['text']=='vote_ok')
		{
			if(result[1]['value']>=0)
			{
				if(result[1]['value']>0)
				{
					nr_show="+"+result[1]['value'];
				}
				else
				{
					nr_show=result[1]['value'];
				}
				document.getElementById('ref_nr_'+this.ref_nr).innerHTML=nr_show;
				document.getElementById('ref_nr_'+this.ref_nr).className='votBalancePlus';
				document.getElementById('ref_nr_'+this.ref_nr).setAttribute("class","votBalancePlus");
			}
			else
			{
				nr_show=result[1]['value'];
				document.getElementById('ref_nr_'+this.ref_nr).innerHTML=nr_show;
				document.getElementById('ref_nr_'+this.ref_nr).className='votBalanceMinus';
				document.getElementById('ref_nr_'+this.ref_nr).setAttribute("class","votBalanceMinus");
			}

		}
		
		return true;					
	}
}

CommentController.__instance__=null;

CommentController.getInstance=function()
{
	if(CommentController.__instance__==null)
	{
		CommentController.__instance__=new CommentController();
	}
	return CommentController.__instance__;
}
