function CommentController()
{
	var self=this;
	this.ref_err=null;
	this.ref_img=null;
	
	this.setstatus=function(status)
	{
		this.ref_img=document.getElementById('status_area');
		this.ref_img.innerHTML='<img src="'+URL+'images/ajax-loader.gif" width="30" height="8">';
		data = new Object();
		data.status = status
		$.post(URL+'index.php?page=utilizator&action=set_status',data,function(data){
			CommentController.getInstance().setstatusresponse(data);
		},
		"json");		
	}
	
	this.setstatusresponse=function(data)
	{
		result=eval(data);
		this.ref_img.innerHTML='';
		
		if(result[0]['text']=='ok')
		{
			document.getElementById('setstatus').value=result[0]['value'];
		}
		return false;
	}

	this.profilecomment=function(profile_id,comment)
	{
		this.ref=profile_id;
		this.ref_err=document.getElementById('mesaj_err_comm');
		this.ref_img=document.getElementById('adauga_place');
		this.ref_img.innerHTML='<img src="'+URL+'images/ajax-loader.gif" width="30" height="8">';
		data = new Object();
		data.profile_id = profile_id;
		data.page = 'utilizator';
		data.comment = comment.split("\n").join("<br>");
		$.post(URL+'index.php?action=post_comment',data,function(data){
			CommentController.getInstance().profilecommentresponse(data);
		},
		"json");		
	}
	this.profilecommentresponse=function(data)
	{
		result=eval(data);
		this.ref_img.innerHTML='';
		
		if(result[0]['text']=='ok')
		{
			this.ref_err.innerHTML='';
			document.getElementById('mesaj_err_comm1').innerHTML=result[0]['value'];
			document.getElementById('comm_nr').innerHTML=result[1]['value'];
			document.getElementById('comment').value='';
			CommentController.getInstance().getprofilecomments(this.ref);
		}
		else
		{
			this.ref_err.innerHTML=result[0]['value'];
		}
	}
	
	this.getprofilecomments=function(profile_id)
	{
		data = new Object();
		data.profile_id = profile_id;
		$.post(URL+'index.php?page=show_profile_comments',data,function(data){
			CommentController.getInstance().profilecommentsresponse(data);
		},
		"html");				
	}
	
	this.profilecommentsresponse=function(data)
	{
		result=data;
		document.getElementById('setstatus').focus();
		$("#comment_place").html(result).slideDown("slow");
		
		return true;
	}
	
	this.removeprofilecomment=function(profile_comment_id)
	{
		
		this.ref_err=document.getElementById('mesaj_err_comm1');
		data = new Object();
		data.page = "utilizator";
		data.profile_comment_id = profile_comment_id;
		$.post(URL+'index.php?action=remove_profile_comment',data,function(data){
			CommentController.getInstance().removeprofilecommentresponse(data);
		},
		"json");		
	}

	this.removeprofilecommentresponse=function(data)
	{
		result=eval(data);
		this.ref_err.innerHTML=result[0]['value'];
		if(result[0]['text']=='ok')
		{
			document.getElementById('comm_nr').innerHTML=result[1]['value'];
			if(result[2]['value'])
			{
				CommentController.getInstance().getprofilecomments(result[2]['value']);
			}
		}
		return true;
	}
	
	
	
	
	this.pozacomment=function(poza_id,comment)
	{
		this.ref=poza_id;
		this.ref_err=document.getElementById('mesaj_err_comm');
		this.ref_img=document.getElementById('adauga_place');
		this.ref_img.innerHTML='<img src="'+URL+'images/ajax-loader.gif" width="30" height="8">';
		data = new Object();
		data.poza_id = poza_id;
		data.page = 'poza';
		data.comment = comment.split("\n").join("<br>");
		$.post(URL+'index.php?action=post_comment',data,function(data){
			CommentController.getInstance().pozacommentresponse(data);
		},
		"json");		
	}
	this.pozacommentresponse=function(data)
	{
		result=eval(data);
		this.ref_img.innerHTML='';
		
		if(result[0]['text']=='ok')
		{
			this.ref_err.innerHTML='';
			document.getElementById('mesaj_err_comm1').innerHTML=result[0]['value'];
			document.getElementById('comment').value='';
			CommentController.getInstance().getpozacomments(this.ref);
		}
		else
		{
			this.ref_err.innerHTML=result[0]['value'];
		}
	}
	this.getpozacomments=function(poza_id)
	{
		data = new Object();
		data.poza_id = poza_id;
		$.post(URL+'index.php?page=show_poza_comments',data,function(data){
			CommentController.getInstance().pozacommentsresponse(data);
		},
		"html");				
	}
	
	this.pozacommentsresponse=function(data)
	{
		result=data;
		document.getElementById('setstatus').focus();
		$("#comment_place").html(result).slideDown("slow");
		
		return true;
	}

	this.removepozacomment=function(poza_comment_id)
	{
		
		this.ref_err=document.getElementById('mesaj_err_comm1');
		data = new Object();
		data.page = "poza";
		data.poza_comment_id = poza_comment_id;
		$.post(URL+'index.php?action=remove_comment',data,function(data){
			CommentController.getInstance().removepozacommentresponse(data);
		},
		"json");		
	}

	this.removepozacommentresponse=function(data)
	{
		result=eval(data);
		this.ref_err.innerHTML=result[0]['value'];
		if(result[0]['text']=='ok')
		{
			if(result[1]['value'])
			{
				CommentController.getInstance().getpozacomments(result[1]['value']);
			}
		}
		return true;
	}
	
	
}

CommentController.__instance__=null;
CommentController.getInstance=function()
{
	if(CommentController.__instance__==null)
	{
		CommentController.__instance__=new CommentController();
	}
	return CommentController.__instance__;
}