function validarErr(html){
    scriptsREGEXP = /false/gi;  //validar que el false esté al final...
    result = html.match(scriptsREGEXP);
    if(result){
        window.location = "http://www.parasaber.com/perfil/login.html"; 
    }else
			return true;
}


//CSS_ONTHEFLY_BH
var CSS_OTF;
function createCss(){
  try{
    CSS_OTF = document.createStyleSheet();
  }catch(e){
    var css = document.createElement("style");
    document.getElementsByTagName("head")[0].appendChild(css);
    CSS_OTF = document.styleSheets[document.styleSheets.length -1]
  }
}
createCss();


//MENUS TABS
try{
    CSS_OTF.addRule(".tabContenido","display:none;");
    CSS_OTF.addRule(".tSel","display:block;");
}catch(e){
    CSS_OTF.insertRule(".tabContenido { display: none; }", 0);
    CSS_OTF.insertRule(".tSel { display: block; }", 1);
}

//TABDISPLAY_BH
var rules_tab = {
    evento :   function(){
         $('a.tD').click(rules_tab.ejecutar);
         },
    ejecutar : function(){
            j = this;
           idTab = j.id.split("_")[0]+ j.id.split("_")[1];
               lis   = $("#"+j.id.split("_")[0]+" .tabs li").get();
           for (var z = 0; z<lis.length; z++)
               lis[z].className = "";
           tabsH = $("#"+j.id.split("_")[0]+" .tabContenido").get();
           for (var i = 0; i<tabsH.length; i++){
               tabsH[i].style.display = "none";
           }
           j.parentNode.className = "activo";
           $("#"+idTab).css("display","block");
           return false;
      }
}
$(document).ready(rules_tab.evento);

function parametros(url){
      var p = new Array();
      var esDeCod = url.match(/\?/g);
      if (esDeCod==null)
        url = unescape(url);
      var argsDec = url.split("?")[1];
      var aP      = argsDec.split("aP=")[1];
      p["aP"]     = unescape(aP.split("&")[0]);
      var ctn     = argsDec.split("ctn=")[1];
      p["ctn"]    = ctn.split("&")[0];
      var params  = unescape(p["aP"].split("params=")[1]);
      var aP2     = params.split("aP2=")[1];
      if(aP2)
          p["aP2"] = unescape(aP2.split("&")[0]);
      return p;
}

function  parametrosForm(idForm){
    var inputs;
    getInputs = function(i){
        inputs+='&'+this.id+'='+this.value;
    }
    $("#"+idForm+" :input").each(getInputs);
    $("#"+idForm+" :text").each(getInputs);
    $("#"+idForm+" :radio:checked").each(getInputs);
    $("#"+idForm+" :checkbox:checked").each(getInputs);
    $("#"+idForm+" :submit").each(getInputs);
    $("#"+idForm+" :button").each(getInputs);
    $("#"+idForm+" :file").each(getInputs);
    var ctn=$("#"+idForm+" #ctn").val();
    var modulo=$("#"+idForm+" #modulo").val();
    var aP = "modulo="+modulo+"&params="+escape(inputs); 
    var p= new Array();
    p["aP"]=aP;
    p["ctn"]=ctn;
    return p;
}

rules_form_enviar_msj = {
evento : function() {
             $("form.formEnvioMsj").submit(rules_form_enviar_msj.ejecutar);
         },
ejecutar : function() {
               idForm = this.id;
               asunto=$("#"+idForm+" #asunto").val();
               mensaje=$("#"+idForm+" #mensaje").val();
               if(asunto==null || asunto== "" || mensaje==null || mensaje==""){
                   $("#"+idForm+" p.error_validacion").css('display','block');
                  return false;
               }
               p = parametrosForm(idForm);
               fin = function (html){
									 if(validarErr(html)){
											 $("#"+p['ctn']).html(html);
											 $("#"+p['ctn']).each(rules_cerrar.evento);
											 $("#"+p['ctn']).each(rules_form_enviar_msj.evento);
									 }
               }
               $.ajax({ url: "/modulo/comunidad.html", data: p['aP'], success: fin });
               return false;
           }
}

rules_enviar_msj = {
    evento : function() {
             $("a.enviarMsj").click(rules_enviar_msj.ejecutar);
    },
    ejecutar : function() {
               p = parametros(this.href);
               idItem= p["ctn"].split("-")[1];
               fin = function (html){
									 if(validarErr(html)){
											 $("#"+p["ctn"]).html(html);
											 $("#item-"+idItem).each(rules_cerrar.evento);
											 $("#item-"+idItem).each(rules_form_enviar_msj.evento);
									 }
							 }
               $.ajax({ url: "/modulo/comunidad.html", data: p["aP"], success: fin });
               return false;
               }
}
$(document).ready(rules_enviar_msj.evento);

rules_cerrar = {
    evento : function() {
             $("a.cerrarCtn").click(rules_cerrar.ejecutar);
             $("input.cerrarCtn").click(rules_cerrar.ejecutar);
    },
    ejecutar : function() {
               idA = this.id;
               var idItem = idA.split("-")[1];
               $("#item-"+idItem).remove();
               return false;
               }
}
$(document).ready(rules_cerrar.evento);


rules_ficha = {
    evento : function() {
                 $("a.verFicha").click(rules_ficha.ejecutar);
             },
    ejecutar : function() {
               p = parametros(this.href);
               fin = function (html){
                   $("#"+p["ctn"]).html(html);
                   $("#"+p["ctn"]).each(rules_recargar.recargar_ficha);
               }
               $.ajax({ url: "/modulo/index.html", data: p["aP"], success: fin });
               return false;
           }
}
$(document).ready(rules_ficha.evento);


rules_peticion_doble= {
    evento : function() {
                 $("a.peticionD").click(rules_peticion_doble.ejecutar);
             },
    ejecutar : function() {
               p = parametros(this.href);
							 fin = function (html){
									 if(validarErr(html)){
											 fin2 = function(html){
													 $("#"+p['ctn']).html(html);
													 $("#"+p['ctn']).each(rules_peticion_doble.doble_evento);
											 }
											 $.ajax({ url: "/modulo/comunidad.html", data: p['aP2'], success: fin2 });
									 }
							 }
               $.ajax({ url: "/modulo/comunidad.html", data: p["aP"], success: fin });
               return false;
           }
}
$(document).ready(rules_peticion_doble.evento);




