﻿var oComment = {
	idInstancia : "",
	guid : "",
	idItem : "",
	capaID : "commentList",
	handler : "Admin/services/handlerClient.aspx",
	onLoad : function(response,num){},
	Data : function(pg,wvars,fname,isget){
	    var _this = this;
		var peticion = Service.HTTP._create();
		peticion.url = _this.handler;
		peticion._add("pg",pg);
		for (var att in wvars){
			peticion._add(att,wvars[att]);
		}
		peticion.onFinish = function(){
			if(fname)fname(peticion.response,peticion.responseXML);
		}
		if(!isget)
			peticion._post();
		else
			peticion._get();
	},
	LoadPost : function(pagina){
	    var _this = this;
	    var arreglo = [];
	    arreglo["pagina"] = pagina;
		arreglo["entidadID"] = entidad.currentID;
	    _this.Data("listarcomentario",arreglo,function(response,xml){
	        document.getElementById("element_list_comments").innerHTML = response;
	        var num = Number(document.getElementById("ncountcomments").innerHTML);
	        _this.onLoad(num,response);
	    },true);
	},
    CleanForm : function(f){
        f.comments_comment.value = "";
        f.comments_title.value = "";
        
    },
	SavePost : function(f){
	    var _this = this;
	    var arreglo = [];
	    if(Fujar.Utils.trim(f.comments_comment.value)==""){
	        alert("FAVOR DE ESCRIBIR COMENTARIO");
	        f.comments_comment.focus();
	        return;
	    }
	    if(Fujar.Utils.trim(f.comments_title.value).length<=2){
	        alert("FAVOR DE ESCRIBIR TITULO");
	        f.comments_title.focus();
	        f.comments_title.select();
	        return;
	    }
	    arreglo["descripcion"] = f.comments_comment.value;
	    arreglo["entidadID"] = entidad.currentID;
	    arreglo["titulo"] = f.comments_title.value;
	    _this.Data("insertarcomentario",arreglo,function(response,xml){
	         _this.CleanForm(f);
	        _this.LoadPost(1);
	        alert("GRACIAS POR TU COMENTARIO");
	        document.location = "#aclist";
	    });
	}
}