function agregarcomentario_click(e, referenceclass) {
    comentario_switch($('divagregarcomentario'), referenceclass);
    return false;
}

function recomendar_click() {
    //alert(obj);
    var divRecomendar = $('divRecomendar');    
    if (divRecomendar.getStyle('display').toLowerCase() == 'block') {
        divRecomendar.setStyle('display', 'none');        
    } else {
        divRecomendar.setStyle('display', 'block');        
    }
}

function agregarcomentario_ins(que, objectType) {
    var QBody = que;

    //var RXid = /[?&]id=(\d+)/i;
    var urlrequest = location.href;
    var arrid = urlrequest.split('-'); //RXid.exec(location.search);
    var Qid = arrid[1];
    //si es null el id en la url natural, se pregunta por las dudas por el querystring Id por si es un contenido accedido desde url vieja
    if (Qid == null) {
        var RXid = /[?&]id=(\d+)/i;
        arrid = RXid.exec(location.search);
        Qid = arrid[1];
    }

    var myAjax = new Ajax('Comentarios.aspx?command=comment&ObjectType=' + objectType + '&ObjectId=' + Qid + '&Body=' + QBody, {
        method: 'get',
        onSuccess: function(result) {
            var avgRating = this.response.text;
            var redirect;
            var RXredirect = /^redirect:(.*)$/m;
            if (redirect = RXredirect.exec(avgRating)) {
                var href = redirect[1];
                location.href = href;
            } else {
                alert("Gracias por comentar!");
                location.href = location.href;
            }
        }
	, onFailure: function(result) {
	    alert("Hubo un error al comentar, por favor intentelo mas tarde");
	}
	, evalScripts: true
    }).request();
}
function comentario_textareachanges(e) {
    var max = 500;
    var ntext = comentario_truncatemaxlength(this.value, max);
    if (ntext) {
        this.value = ntext;
    };

    comentario_reversecount(this.value, max);
}
function comentario_truncatemaxlength(que, max) {
    if (que.length > max) {
        return que.substr(1, max);
    } else {
        return null;
    }
}
function comentario_reversecount(que, max) {
    $('comentario_caracteresrestantes').setHTML(max - que.length);
}
function comentario_cerrar(e) {
    comentario_switch($('divagregarcomentario'));
    return false;
}

var comentarioLastClass = "";
function comentario_switch(obj, referenceclass) {
    var divagregarcomentario = obj;
    if (divagregarcomentario.getStyle("display").toLowerCase() == 'block') {
        divagregarcomentario.setStyle('display', 'none');
        divagregarcomentario.className = comentarioLastClass;
    } else {
        divagregarcomentario.setStyle('display', 'block');
        comentarioLastClass = divagregarcomentario.className;
        if (referenceclass) {
            divagregarcomentario.addClass(referenceclass);
        }
    }
}

