var icon_error = "
";
var icon_ok = "";
var username_min = 2; var username_max = 25; var comErrFlag=0;
//not setting
var user_errorF=0;
var captcha_errorF=0;
function show_comment_form(type,id){
if (type=="logged"){
__$("#commentDivForm_"+id).hide();
__$("#commentDivLogged_"+id).show();
__$("#comentario_tab_2_"+id).addClass("seleccionado");
__$("#comentario_tab_1_"+id).removeClass("seleccionado");
__$("#comentario_tab_2_"+id).parent("li").addClass("active");
__$("#comentario_tab_1_"+id).parent("li").removeClass("active");
return login_window();
}else{
__$("#commentDivLogged_"+id).hide();
__$("#commentDivForm_"+id).show();
__$("#comentario_tab_1_"+id).addClass("seleccionado");
__$("#comentario_tab_2_"+id).removeClass("seleccionado");
__$("#comentario_tab_1_"+id).parent("li").addClass("active");
__$("#comentario_tab_2_"+id).parent("li").removeClass("active");
}
}
function assignSubmit(id){
__$("#"+id+" .input").focus(function(){
__$(this).addClass("txt_selected_reduced");
clearerralert(__$(this).attr('id'),"txt_");
__$(this).removeClass("txt_error_reduced");
__$(this).removeClass("txt_error");
__$(this).removeClass("txt_ok_reduced");
});
__$("#"+id+" .input").blur(function(){ __$(this).removeClass("txt_selected_reduced"); });
__$("#"+id+" textarea").blur(function(){check_comment_text(__$(this).attr('id'));});
}
function validateComment(com_id){
var res=true;
if (!com_id)return false;
comErrFlag=0;
noerralert("none","",com_id);
comErrFlag=1;
if (__$("#txt_nombre_"+com_id).attr("type")){
if (!check_username(com_id))res=false;
if (!__$("#subscr_"+com_id).attr("checked") || __$("#subscr_"+com_id).attr("checked")==false) {
//
}else{
if (!check_semail(com_id))res=false;
}
if (__$("#captcha_ingresado_"+com_id).attr("type")){
if (captcha_errorF==1){
myerralert('El código introducido no coincide con el de la imagen.','captcha_ingresado_'+com_id,"br","captcha_",com_id);
res=false;
} else if (!check_captcha_test(com_id))res=false;
}
if (user_errorF)res=false;
}
if (!check_comment_text(com_id))res=false;
if (res==true){
alerttype="comment";
if (ta_check_extra("#"+com_id)){
__$.blockUI({ message: "

Por favor, espera mientras se publica tu comentario...
|
" });
res=true;
}else res=false;
}
comErrFlag=0;
return res;
}
function check_comment_text(com_id){
var res = true;
clearerralert(com_id,"");
if(!__$("#"+com_id).attr("value")) {
myerralert('Por favor, añada un comentario',com_id,"","",com_id);
res = false;
}
res &= ta_check_extended('#'+com_id,'',com_id);
if (res){
noerralert(com_id,"",com_id);
}
return res;
}
function check_captcha_truth(com_id){
captch=__$("#captcha_ingresado_"+com_id).attr("value");
if (!captch || captcha_errorF)return false;
__$.ajax({
url: "/includes/check_captcha.php",
type:"post",
data:"captcha_ingresado="+captch,
cache: false,
beforeSend: function (req){
show_loader('#err_captcha_'+com_id);
return req;
},
complete: function (req,status){
hide_loader();
return req;
},
success: function(html){
if (html){
myerralert(html,'captcha_ingresado_'+com_id,"br","captcha_",com_id);
captcha_errorF=1;
}else{
noerralert('captcha_ingresado_'+com_id,"captcha_",com_id);
captcha_errorF=0;
}
}
});
}
function check_captcha_test(com_id){
clearerralert('captcha_'+com_id,"");
if (!__$("#captcha_ingresado_"+com_id).attr("value")){
myerralert('El código introducido no coincide con el de la imagen.','captcha_ingresado_'+com_id,"br","captcha_",com_id);
captcha_errorF=1;
return false;
}else{
if (captcha_errorF==1)noerralert('captcha_ingresado_'+com_id,"captcha_",com_id); captcha_errorF=0;
return true;
}
}
function check_email(com_id)
{
return check_email_complex(com_id,"email_");
}
function check_semail(com_id)
{
return check_email_complex(com_id,"semail_");
}
function check_email_complex(com_id,pref)
{
clearerralert(pref+com_id,"");
email=__$("#txt_"+pref+com_id).attr("value");
if (!email && pref!="semail_")return true;
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
noerralert(pref+com_id,"txt_",com_id);
return true;
} else {
myerralert('Por favor, introduce una dirección e-mail válida',pref+com_id,"br","txt_",com_id);
return false;
}
}
function check_username(com_id)
{
clearerralert('nombre_'+com_id,"");
username=__$("#txt_nombre_"+com_id).attr("value");
if (!username){
myerralert('Por favor, introduce tu alias','nombre_'+com_id,"br","txt_",com_id);
user_errorF=1;
return false;
}
if (new RegExp ("^([a-zA-ZçñáéíóúàèìòùüïöüÁÉÍÓÚÀÈÌÒÙÜÏÖÜ\\s0-9-]{"+username_min+","+username_max+"})$","i").test(username)){
if (user_errorF==1){
noerralert('nombre_'+com_id,"txt_",com_id);
}
user_errorF=0;
return true;
}else{
myerralert('Por favor, introduce un nombre de usuario válido. Sólo se admiten a-z, A-Z, 0-9, entre 2 y 25 caracteres.','nombre_'+com_id,"br","txt_",com_id);
user_errorF=1;
return false;
}
}
function check_user_onChange(com_id){
if (check_username(com_id)){
check_user_availability(com_id);
}
}
function check_user_availability(com_id){
username=__$("#txt_nombre_"+com_id).attr("value");
if (!username)return false;
__$.ajax({
url: "registrarse_ajax_username_check.php?username="+username,
cache: false,
beforeSend: function (req){
show_loader('#err_nombre_'+com_id);
return req;
},
complete: function (req,status){
hide_loader();
return req;
},
success: function(html){
__$('#err_nombre_'+com_id).html(html);
if (__$('#username_result').attr ("value")=='available'){
noerralert('nombre_'+com_id,"txt_",com_id);
user_errorF=0;
}
if(__$('#username_result').attr("value")=='taken'){
myerralert("Este nombre de usuario ya está siendo utilizado por un usuario registrado. Por favor, escoge otro diferente.",'nombre_'+com_id,"br","txt_",com_id);
user_errorF=1;
}
}
});
}
function show_loader(origin){
__$(origin).html("
");
}
function hide_loader(){
__$('#progress_indic_small').remove();
}
var myerralert=function(txt,name,type,prefix,com_id){
var mainname=prefix+name;
var errname=name;
if (prefix=="captcha_"){
mainname=name;
errname=prefix+com_id;
}
if (type=="normal"){
alert(txt);
return;
}
var br_var="";
if (type=="br"){
br_var="
";
}
__$("#"+mainname).removeClass("txt_ok_reduced");
__$("#err_"+errname).html( " " + icon_error + txt); //+ br_var
__$("#err_"+errname).addClass("form_error");
__$("#"+mainname).removeClass("txt_ok");
__$("#"+mainname).addClass("txt_error_reduced");
__$("#err_buttons_"+com_id).html("
El formulario contiene uno o varios errores, que han sido marcados en rojo. Por favor, corrígelos y después vuelve a pulsar sobre el botón Publicar
");
__$("#err_buttons_"+com_id).addClass("form_error");
}
var noerralert=function(name,prefix,com_id){
var mainname=prefix+name;
var errname=name;
if (prefix=="captcha_"){
mainname=name;
errname=prefix+com_id;
}
__$("#err_"+errname).html(icon_ok);
__$("#"+mainname).removeClass("txt_error_reduced");
__$("#"+mainname).addClass("txt_ok_reduced");
if (comErrFlag!=1){
__$("#err_buttons_"+com_id).html("");
}
}
var clearerralert=function(name,prefix){
__$("#err_"+name).html("");
if (comErrFlag!=1){
__$(".err_buttons").html("");
}
}
var oncheckbox=function (dis,com_id){
if (__$(dis).attr('checked')!=false && __$(dis).attr('checked')){
__$('#sub_email_'+com_id).show();
}else {
__$('#sub_email_'+com_id).hide();
}
}
__$(document).ready(function() {
assignSubmit("frm_comentarios");
});