
var nbf={};nbf.funcInit=[];nbf.tt=[];nbf.ready=function(f){nbf.funcInit.push(f);};nbf.init=function(jq){if(!jq)
jq=$("body");for(var i=0;i<this.funcInit.length;i++)
this.funcInit[i](jq);};nbf.initJQueryUI=function(funcionOk,version){if(!version)
version="1.8.14";if(!nbf.objetoDefinido("$.ui")){nbf.cargarJs("/nbf/js/jquery-ui-"+version+".custom.min.js",function(){if(funcionOk)
funcionOk();});}else{if(funcionOk)
funcionOk();}};nbf.toJSON=function(obj){if($.isPlainObject(obj)||$.isArray(obj))
return $.toJSON(obj);else
return obj;};nbf.parseJSON=function(obj){if(obj.indexOf("{")>-1||obj.indexOf("[")>-1){try{return $.parseJSON(obj);}catch(e){return obj;}}else
return obj;};nbf.parseFormVals=function(valoresForm){var obj={};for(var i in valoresForm)
obj[valoresForm[i].name]=valoresForm[i].value;return obj;};nbf.cargarJs=function(urlJs,funcionRetorno){var script=document.createElement("script");script.setAttribute("type","text/javascript");if(funcionRetorno){script.onreadystatechange=function(){if(this.readyState=='complete'||this.readyState=='loaded')
funcionRetorno();};script.onload=funcionRetorno;}
script.setAttribute("src",urlJs);document.getElementsByTagName("head")[0].appendChild(script);};nbf.objetoDefinido=function(nombreObjeto,tipo){if(!tipo)
tipo="object";return eval("(typeof "+nombreObjeto+").toLowerCase() == '"+tipo.toLowerCase()+"'");};nbf.codificarDatoClass=function(dato){return"d-"+$.base64Encode(nbf.toJSON(dato).toString()).replace(/=/g,"_")+"-d";};nbf.extraerDatos=function(jqElem){var classCss=jqElem.attr("class");var patron=/d\-[a-zA-Z0-9_]+\-d/;var coin=patron.exec(classCss);if(coin){var ret=nbf.parseJSON($.base64Decode(coin.toString().replace(/-d/,"").replace(/d-/,"").replace(/_/g,"=")));if(isNaN(ret))
return ret;else
return eval(ret);}
return null;};nbf.generarIdAleatorio=function(){var n=parseInt(Math.random()*1000000);while($("#nbf"+n).size()>0)
n=parseInt(Math.random()*1000000);return"nbf"+n;};nbf.dbg=function(obj){};nbf.ejecutar=function(funcion,parametros,funcionOk){return nbf.ejecutarBase(funcion,parametros,true,funcionOk);};nbf.ejecutarSync=function(funcion,parametros){return nbf.ejecutarBase(funcion,parametros,false);};nbf.ejecutarBase=function(funcion,parametros,async,funcionOk){var procesarRespuesta=function(respuesta){return nbf.parseJSON(respuesta);};var ret=$.ajax({type:'POST',async:async,url:"/nbf/pag/ajax-exec.php?"+Math.random(),data:{"func":funcion,"params":nbf.toJSON(parametros),"url":window.location.toString()}});if(!async)
return procesarRespuesta(ret.responseText);else{ret.success(function(data){if(funcionOk)
funcionOk(procesarRespuesta(data));});return ret;}};nbf.lanzar=function(milisegundos,funcion){if(nbf.tt[funcion])
clearTimeout(nbf.tt[funcion]);nbf.tt[funcion]=setTimeout(function(){funcion();},milisegundos);return nbf.tt[funcion];};$(document).ready(function(){nbf.init();});function dbg(obj){nbf.dbg(obj);}
nbf.selector={};nbf.selector.Selector=function(claseSelector,propiedades,valorInicial,navegacionInicial,jqNavegacion,jqInfo,jqInput){var thisSel=this;this.actualizarNavegacion=function(funcionOk){nbf.ejecutar(this.claseSelector+"::ajaxParsearNavegacion",[this.propiedades,this.navegacion,this.valor],function(datos){if($.isPlainObject(datos)){thisSel.navegacion=datos.navegacion;thisSel.valor=datos.valor;if(datos.finalizar)
thisSel.asignarValor(datos.valor);else{nbf.ejecutar(thisSel.claseSelector+"::ajaxNavegacion",[thisSel.propiedades,thisSel.navegacion,thisSel.valor],function(html){if(html.indexOf("<")>-1){thisSel.historialNavegacion.push(nbf.toJSON(thisSel.navegacion));if(thisSel.jqNavegacion){thisSel.jqNavegacion.empty();thisSel.jqNavegacion.append(html);nbf.init(thisSel.jqNavegacion);thisSel.mostrarNavegacion();}
if(funcionOk)
funcionOk();}else
nbf.dbg(html);});}}else
nbf.dbg(datos);});};this.actualizarInfo=function(funcionOk){if(this.jqInput)
this.jqInput.val(nbf.toJSON(this.valor));if(this.jqInfo){nbf.ejecutar(this.claseSelector+"::ajaxInfo",[this.propiedades,this.valor],function(html){thisSel.jqInfo.html(html);nbf.init(thisSel.jqInfo);if(funcionOk)
funcionOk();});}};this.mostrarNavegacion=function(){if(this.jqNavegacion){if(!this.jqNavegacion.is(":visible"))
this.jqNavegacion.show();this.jqNavegacion.find(".paginaSelector").css("z-index",ui.zIndex++);}};this.ocultarNavegacion=function(){if(this.jqNavegacion){if(this.jqNavegacion.is(":visible"))
this.jqNavegacion.hide();}};this.atrasNavegacion=function(){if(this.historialNavegacion.length>1){var nav=nbf.parseJSON(this.historialNavegacion[this.historialNavegacion.length-2]);this.historialNavegacion.pop();this.asignarNavegacion(nav,true,function(){thisSel.historialNavegacion.pop();});}};this.cerrarNavegacion=function(){this.navegacion=this.navegacionInicial;this.ocultarNavegacion();};this.vaciarValor=function(ignorarChange){this.valor="";this.actualizarInfo();if(!ignorarChange)
this.change();};this.asignarValor=function(valor,funcionOk,ignorarChange){this.valor=valor;this.cerrarNavegacion();this.actualizarInfo(funcionOk);if(!ignorarChange)
this.change();};this.anadirItemValor=function(item,funcionOk,ignorarOnChange){if(!this.valor)
this.valor=[];if($.isArray(this.valor)){var pos=this.posItemValor(item);if(pos>-1)
this.valor[pos]=item;else
this.valor.push(item);this.asignarValor(this.valor,funcionOk,ignorarOnChange);}};this.anadirItemsValor=function(items,funcionOk,ignorarOnChange){var valor=this.valor;if(!valor)
valor=[];if($.isArray(valor)){for(var i=0;i<items.length;i++){var pos=this.posItemValor(items[i]);if(pos>-1)
valor[pos]=items[i];else
valor.push(items[i]);}
this.asignarValor(valor,funcionOk,ignorarOnChange);}};this.eliminarItemValor=function(item,funcionOk,ignorarOnChange){if($.isArray(this.valor)){var pos=this.posItemValor(item);if(pos>-1)
this.eliminarItemPos(pos,funcionOk,ignorarOnChange);}
return false;};this.eliminarItemPos=function(pos,funcionOk,ignorarOnChange){this.valor.splice(pos,1);if(this.valor.length==0)
this.valor="";this.asignarValor(this.valor,funcionOk,ignorarOnChange);return true;};this.tieneItemValor=function(item){return(this.posItemValor(item)>-1);};this.posItemValor=function(item){if($.isArray(this.valor)){for(var i=0;i<this.valor.length;i++)
if(this.compararItemsValor(this.valor[i],item))
return i;}
return-1;};this.compararItemsValor=function(a,b){if($.isArray(a)&&$.isArray(b))
return a[0]==b[0];else if($.isPlainObject(a)&&$.isPlainObject(b)&&a.id&&b.id)
return a.id==b.id;else
return a==b;};this.asignarNavegacion=function(navegacion,resetearNavegacion,funcionOk){if(!resetearNavegacion){if(!this.navegacion||this.navegacion.length==0)
this.navegacion={};for(var valor in navegacion)
this.navegacion[valor]=navegacion[valor];}else
this.navegacion=navegacion;this.actualizarNavegacion(funcionOk);};this.change=function(funcion){this.evento("change",funcion);};this.evento=function(evento,funcion){if(funcion){if(!this.ev[evento])
this.ev[evento]={"funciones":[],"omitir":false};this.ev[evento].funciones.push(funcion);}else{if(this.ev[evento]){if(!this.ev[evento].omitir){for(var i=0;i<this.ev[evento].funciones.length;i++)
this.ev[evento].funciones[i](this);}}}};this.omitirEvento=function(evento,omitir){if(this.ev[evento])
this.ev[evento].omitir=omitir;};this.claseSelector=claseSelector;this.ev=[];if(jqInput){this.jqInput=jqInput;this.jqInput.data("selector",this).addClass("nbfSelector");}
if(jqInfo){this.jqInfo=jqInfo;this.jqInfo.data("selector",this).addClass("nbfSelector");}
if(jqNavegacion)
this.jqNavegacion=jqNavegacion;else
this.jqNavegacion=$("<div />").appendTo($("body"));this.jqNavegacion.data("selector",this).addClass("nbfSelector");this.propiedades=propiedades;if(!valorInicial&&this.jqInput)
this.asignarValor(nbf.parseJSON(this.jqInput.val()));else
this.asignarValor(valorInicial);this.navegacionInicial={};if(navegacionInicial)
this.navegacionInicial=navegacionInicial;this.navegacion=this.navegacionInicial;this.historialNavegacion=[];};nbf.selector.obtener=function(jqElem){jqElem=$(jqElem);if(jqElem.hasClass("nbfSelector"))
return jqElem.eq(0).data("selector");else{var closest=jqElem.closest(".nbfSelector");if(closest.size()>0)
return closest.eq(0).data("selector");else
return jqElem.find(".nbfSelector").eq(0).data("selector");}};nbf.selector.jqPaginaSelector=function(jqElem){return jqElem.closest(".paginaSelector");};nbf.selector.crearSelectorObjetoBase=function(claseObjeto,funcionOk,multiple){var claseSelector="selector\\SelectorObjetoBase";if(multiple)
claseSelector="selector\\SelectorObjetoBaseConjunto";var sel=new nbf.selector.Selector(claseSelector,{"claseObjeto":claseObjeto},null,null,$("<div />").appendTo($("body")));sel.change(function(){funcionOk(sel.valor);});sel.actualizarNavegacion();return sel;};
nbf.txt={};nbf.txt.textos=[];nbf.txt.v=function(variable){if(!nbf.txt.textos[variable]){nbf.txt.textos[variable]=nbf.ejecutarSync("\\datos\\txt::ajaxObtenerVariable",[variable]);}
return nbf.txt.textos[variable];};nbf.txt.vDef=function(variable,valor){nbf.txt.textos[variable]=valor;};
nbf.str={};nbf.str.esEmail=function(email){var patron=/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;return(patron.test(email)==true);};nbf.str.esUrl=function(url){var patron=new RegExp();patron.compile("^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+");return(patron.test(url)==true);};
nbf.url={};nbf.url.parseUrlParams=function(params){var asigs=params.split("&");var obj={};for(var i=0;i<asigs.length;i++){var asig=asigs[i].split("=");obj[asig[0]]=asig[1];}
return obj;};nbf.url.componerUrlParams=function(params){var cadena=[];for(var p in params)
cadena.push(p+"="+params[p]);return cadena.join("&");};nbf.url.leerParamHash=function(param){var hash=window.location.hash.substring(1);var params=nbf.url.parseUrlParams(hash);return params[param];};nbf.url.escribirParamHash=function(param,valor){var hash=window.location.hash.substring(1);var params=nbf.url.parseUrlParams(hash);params[param]=valor;window.location.hash="#"+nbf.url.componerUrlParams(params);};
