var comments = {
	addurl		: '/comments/add/',
	reporturl	: '/comments/report/',
	showformurl : '/comments/showform/',
	delurl 		: '/comments/delete/',
	blockurl	: '/comments/block/',
	ratingurl 	: '/comments/rating/',
	listurl		: '/comments/list/',
	validateurl : '/comments/validate/',
	mypage		: '',
	last_open_form : '',
	set_params : function(table, table_id){
		this.addurl 		= this.addurl+table+','+table_id;
		this.reporturl  	= this.reporturl+table+','+table_id;
		this.showformurl   	= this.showformurl+table+','+table_id;
		this.blockurl		= this.blockurl+table+','+table_id;
		this.delurl    		= this.delurl+table+','+table_id;
		this.ratingurl		= this.ratingurl+table+','+table_id; 
		this.listurl		= this.listurl+table+','+table_id;
	},
	showform : function (parent_id, html_id){
		$("[id^='forma_']").html("&nbsp;");
		if(this.last_open_form!='')
			$("#"+this.last_open_form).html('');
		this.last_open_form = html_id;
		$.ajax({
				url:this.showformurl,
				type:"POST",
				timeout: 20000,
		        data: {parent_id:parent_id, html_id:html_id, multi_disable:false},
		        error: function(){
		            /*alert("klaida");*/
		        },
		        success: function(html){
		           $("#"+html_id).html(html);
		           return true;
		        }
			});	
	},
	
	delcom : function (id){
		$.ajax({
				url:this.delurl,
				type:"POST",
				timeout: 20000,
		        data: {id:id, multi_disable:false},
		        error: function(){
		            /*alert("klaida");*/
		        },
		        success: function(html){
		            $("#kom_body").html(html);
		           return true;
		        }
			});			
	},
	blockcom : function (id){
		$.ajax({
				url:this.blockurl,
				type:"POST",
				timeout: 20000,
		        data: {id:id, multi_disable:false},
		        error: function(){
		            /*alert("klaida");*/
		        },
		        success: function(html){
		            $("#kom_body").html(html);
		           return true;
		        }
			});			
	},
	bad_cmt : function (cmt_id){
		$.ajax({
	        url: this.reporturl,
	        type: "POST",
	        timeout: 20000,
	        data: {id:cmt_id, multi_disable:false},
	        error: function(){
	            /*alert("klaida");*/
	        },
	        success: function(html){
	           $("#reportmsg"+cmt_id).html(html);
	           return true;
	        }
	    });
	},
	add : function(html_id){

		if ($("#parent_id").val()==0){
			var pdata = {
				username	: $("#username").val(),
				email		: $("#email").val(),
				comment		: $("#comment").val(),
				parent_id	: $("#parent_id").val(),
			    multi_disable:false
			}
		} else {
			var pdata = {
				username	: $("#username").val(),
				email		: $("#email").val(),
				comment		: $("#comment").val(),
				parent_id	: $("#parent_id").val(),
			    multi_disable:false,
				page : this.mypage
			}
		}

		$("#pcontrol").hide();
		$.ajax({
				url: this.validateurl,
		        type: "POST",
		        timeout: 20000,
		        data: pdata,
		        error: function(){
		            /*alert("klaida");*/
		        },
		        success: function(html){
		           if (html=="ok"){
		           		$.ajax({
		           			url: comments.addurl,
					        type: "POST",
					        timeout: 20000,
					        data: pdata,
					        error: function(){
					            /*alert("klaida");*/
					        },
					        success: function(html){
					        	$("#kom_body").html(html);
					        	return true;
					        }
		           		});
		           }else{
		           		$("#formmsg"+html_id).html(html);
		           		$("#formmsg"+html_id).css('display','block');
		           		$("#pcontrol").show();
		           }
		           
		           return true;
		        }			
		}); 
		
	},
	rating : function (id,score){
		$.ajax({
			url: this.ratingurl,
	        type: "POST",
	        timeout: 20000,
	        data: {id:id,score:score, multi_disable:false},
	        error: function(){
	            /*alert("klaida");*/
	        },
	        success: function(html){
	           $("#ratingbar_"+id).html(html);
	           return true;
	        }			
		});		
	},
	close : function(html_id){
		$("#"+html_id).html("&nbsp;");
	},
	page : function(page){
		this.mypage = page;
		$.ajax({
	        url: this.listurl,
	        type: "POST",
	        timeout: 20000,
	        data: {page:this.mypage,multi_disable:false},
	        error: function(){
	            /*alert("klaida");*/
	        },
	        success: function(html){
	           $("#kom_body").html(html);
	           return true;
	        }
	    });		
	}
	
} 
