﻿var oComment = {
	idInstancia : "",
	guid : "",
	idItem : "",
	capaID : "commentList",
	handler : "Admin/services/handlerClient.aspx",
	onLoad : function(response,num){},
	Data : function(pg,wvars,fname){
	    var _this = this;
		var peticion = Service.HTTP._create();
		peticion.url = _this.handler;
		peticion._add("pg",pg);
		peticion._add("idInstancia",_this.idInstancia);
		peticion._add("guid",_this.guid);
		peticion._add("idItem",_this.idItem);
		for (var att in wvars){
			peticion._add(att,wvars[att]);
		}
		peticion.onFinish = function(){
			if(fname)fname(peticion.response,peticion.responseXML);
		}
		peticion._post();
	},
	LoadPost : function(pagina){
	    var _this = this;
	    var arreglo = [];
	    arreglo["pnum"] = pagina;
	    _this.Data("loadcomments",arreglo,function(response,xml){
	        document.getElementById("commentList").innerHTML = response;
	        var num = Number(document.getElementById("ncountcomments").innerHTML);
	        _this.onLoad(num,response);
	    });
	},
    CleanForm : function(f){
        f.comment.value = "";
        f.name.value = "";
        f.email.value = "";
        f.url.value = "";
        
    },
	SavePost : function(f){
	    var _this = this;
	    var arreglo = [];
	    if(Utils.trim(f.comment.value)==""){
	        alert("FAVOR DE ESCRIBIR COMENTARIO");
	        f.comment.focus();
	        return;
	    }
	    if(Utils.trim(f.name.value).length<=2){
	        alert("FAVOR DE ESCRIBIR NOMBRE COMPLETO");
	        f.name.focus();
	        f.name.select();
	        return;
	    }
	    arreglo["comentario"] = f.comment.value;
	    arreglo["nombre"] = f.name.value;
	    arreglo["email"] = f.email.value;
	    arreglo["URL"] = f.url.value;
	    _this.Data("savepost",arreglo,function(response,xml){
	        //alert(response);
	         _this.CleanForm(f);
	        _this.LoadPost(1);
	        alert("GRACIAS POR TU COMENTARIO");
	        document.location = "#aclist";
	    });
	}
}