var rating; var voto_id; var on_ajax = false; $(document).ready(function() { $(".votacion_leido").click(function() { if (on_ajax) return false; on_ajax = true; var tmp = $(this).attr("id").split("_"); var value = tmp[1]; var seccion; $("#loadingLeido").removeClass("hidden"); $.ajax({ type: 'POST', url: 'http://libros.innatia.com/scripts/ajax.php', data: 'a=libros_votacion_add_vote&l=16792&f=leido&v='+value, success: function(result) { res = eval('('+result+')'); on_ajax = false; $("#loadingLeido").addClass("hidden"); if (res["success"] == 0) { alert(res["error"]); return false; } seccion = (value == 's') ? 'SI' : 'Gracias'; voto_id = res["vid"]; $("#opina").hide(); $("#opina"+seccion).show().removeClass("hidden"); } }); return false; }); $(".votacion_gustado").click(function() { if (on_ajax) return false; on_ajax = true; var tmp = $(this).attr("id").split("_"); var value = tmp[1]; $("#loadingGustado").removeClass("hidden"); $.ajax({ type: 'POST', url: 'http://libros.innatia.com/scripts/ajax.php', data: 'a=libros_votacion_add_vote&l=16792&f=gustado&vid='+voto_id+'&v='+value, success: function(result) { res = eval('('+result+')'); on_ajax = false; $("#loadingGustado").addClass("hidden"); if (res["success"] == 0) { alert(res["error"]); return false; } rating = (value == 's') ? 1 : -1; $("#opinaShare").show().removeClass("hidden"); $("#opinaSI").hide(); } }); return false; }); $(".button_satisfaccion").click(function() { if (on_ajax) return false; var n = jQuery.trim($("#name-input").val()).replace(/&/g, "%26"); var e = jQuery.trim($("#email-input").val()).replace(/&/g, "%26"); var t = jQuery.trim($("#comenta").val()).replace(/&/g, "%26"); var q = $("#chk_conditions").attr("checked"); if (!(/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.([A-Za-z0-9_.]+[A-za-z])+$/.test(e))) { alert("El mail no es una valido!"); return false; } if (n == '' || n == 'Introduce tu nombre' || t == '') { alert("Debe completar todos los campos!"); return false; } on_ajax = true; $("#loadingShare").removeClass("hidden"); $.ajax({ type: 'POST', url: 'http://libros.innatia.com/scripts/ajax.php', data: 'a=libros-satisfaccion_comentario&l=16792&vid='+voto_id+'&r='+rating+'&n='+n+'&e='+e+'&t='+t+'&q='+q, success: function(result) { on_ajax = false; res = eval('('+result+')'); $("#loadingShare").addClass("hidden"); if (res["success"] == 1) { $("#opinaShare").hide(); $("#opinaGracias").show().removeClass("hidden"); if(typeof comment_add == 'function') comment_add(-1, 1, n, t); } else alert("Error: "+res["error"]); } }); }); });