var countLoadingRequest=0;var countWaitingRequest=0;function callServer(p_oDef){this.DocTxt;this.DocXml;this.controlLoad=0;this.onLoad=null;this.onLoading=null;this.onInteractive=null;this.onLoaded=null;this.onError=null;this.sendValues;this.detectScript=false;this.textScript="";this.backgroundLoad=false;var me=this;var xmlhttp;var ret;var xmlTXT;if(p_oDef){for(_p in p_oDef){this[_p]=p_oDef[_p]}}this.loadXMLhttp=function(url,metodo,asc){xmlTXT=0;xmlHttpLoad(url,metodo,asc)};this.loadTXThttp=function(url,metodo,asc){xmlTXT=1;xmlHttpLoad(url,metodo,asc)};function xmlHttpLoad(url,metodo,asc){countLoadingRequest++;if(!me.backgroundLoad){if(countWaitingRequest==0&&((document.getElementById("defaultDialog")&&document.getElementById("defaultDialog").style.display=="none")||!document.getElementById("defaultDialog"))){try{if(G_default_dialog==undefined){G_default_dialog=new G_simple_dialog()}G_default_dialog.request({title:"Espere un momento por favor",msg:"Espere un momento por favor",modal:true})}catch(e){}}countWaitingRequest++}_onLoadingHandled=false;_onLoadedHandled=false;_onInteractiveHandled=false;_onLoadHandled=false;if(metodo==undefined){metodo="GET"}if(asc==undefined){asc=true}var _sendValues="";if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();_sendValues=null;if(asc){xmlhttp.onreadystatechange=state_Change}}else{if(window.ActiveXObject){try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){xmlhttp=null}}}}if(xmlhttp){try{xmlhttp.onreadystatechange=state_Change}catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.onreadystatechange=state_Change}catch(e){xmlhttp=null}}}if(xmlhttp){xmlhttp.open(metodo,url,asc);xmlhttp.setRequestHeader("P3P",'CP="CAO PSA OUR"');xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");if(me.sendValues==undefined){xmlhttp.send(_sendValues)}else{xmlhttp.send(me.sendValues)}if(!asc){if(window.XMLHttpRequest){state_Change()}}}return ret}function state_Change(){me.controlLoad=1;if(xmlhttp.readyState==1){_onLoading()}else{if(xmlhttp.readyState==2){_onLoaded()}else{if(xmlhttp.readyState==3){_onInteractive()}else{if(xmlhttp.readyState==4){_onLoad()}}}}}var _onLoadingHandled=false;function _onLoading(){if(_onLoadingHandled){return }if(typeof (me.onLoading)=="function"){try{me.onLoading(me)}catch(e){alert("User Function onLoading -> "+(e.message)?e.message:e.description)}}_onLoadingHandled=true}var _onLoadedHandled=false;function _onLoaded(){if(_onLoadingHandled){return }if(typeof (me.onLoaded)=="function"){try{me.onLoaded(me)}catch(e){alert("User Function onLoaded -> "+(e.message)?e.message:e.description)}}_onLoadedHandled=true}var _onInteractiveHandled=false;function _onInteractive(){if(_onInteractiveHandled){return }if(typeof (me.onInteractive)=="function"){try{me.onInteractive()}catch(e){alert("User Function onInteractive -> "+(e.message)?e.message:e.description)}}_onInteractiveHandled=true}var _onLoadHandled=false;function _onLoad(){if(_onLoadHandled){return }try{if(xmlhttp.status==200){ret=true;if(xmlTXT==0){me.DocXml=xmlhttp.responseXML}else{var _aux=xmlhttp.responseText;if(me.detectScript){me.textScript="";_aux=_aux.replace(/\/\*.[^\*\/]*\*\//g,"");var re=new RegExp(/<script>[\{\}a-zA-Z0-9,_.=+;:!><()\/'"\-\*\?\s\&\[\]%#$]+<\/script>/);while(_aux.search(re)>-1){var _script_found=RegExp.lastMatch;var _script=_script_found;_script=_script.replace(/<script>|<\/script>/ig,"");G_generate_code(_script);_aux=_aux.replace(_script_found,"");me.textScript=me.textScript+_script_found}}me.DocTxt=_aux}if(typeof (me.onLoad)=="function"){try{me.onLoad(true)}catch(e){alert("User Function onLoad -> "+(e.message)?e.message:e.description)}}}else{ret=false;if(typeof (me.onError)=="function"){me.onError(xmlhttp.statusText)}else{alert("Problemas al recibir datos:"+xmlhttp.statusText)}}countLoadingRequest--;if(!me.backgroundLoad){countWaitingRequest--;if(countWaitingRequest==0){try{G_default_dialog.hide()}catch(e){}}}}catch(e){if(navigator.appName=="Netscape"){msg=e.message}else{msg=e.description}alert("Error: "+msg)}_onLoadHandled=true}this.isNull=function(valor,retorno){if((valor==null)||(valor=="null")){return retorno}else{return valor}};this.xmlToArray=function(listaFields){var ret=new Object();var f_array=listaFields.split(",");for(var i=0;i<f_array.length;i++){var _nTag=f_array[i];var _nField=f_array[i].replace(".","_");var _nodes=me.getCampo(_nTag);var _sconcat="";if(_nodes.length>0){for(var j=0;j<_nodes.length;j++){var v="";if(_nodes[j].hasChildNodes()){v=_nodes[j].firstChild.nodeValue}_sconcat=_sconcat+v+"|"}_sconcat=_sconcat.substr(0,_sconcat.length-1);var _str="ret."+_nField+"=_sconcat.split('|');";eval(_str)}}return ret};this.xmlToCombo=function(IdCombo,fieldTexto,fieldValor,inicio){try{var myCombo=document.getElementById(IdCombo);if(inicio==undefined){inicio=0}myCombo.options.length=inicio;aTexto=me.getCampo(fieldTexto);aValor=me.getCampo(fieldValor);for(i=0;i<aTexto.length;i++){myCombo.options.add(new Option(me.isNull(me.getValue(fieldTexto,i),""),me.isNull(me.getValue(fieldValor,i),"")))}}catch(e){}};this.xmlToObj=function(IdObj,campo,i){if(i==undefined){i=0}try{var myObj=document.getElementById(IdObj);var aCampo=me.getCampo(campo);myObj.value=aCampo[i].firstChild.nodeValue}catch(e){alert("Error en xmlToObj-> IdObj:"+IdObj+" ,campo: "+campo)}};this.xmlToAllObjPrefix=function(listaFields,i,iF,Prefix){if(i==undefined){i=0}if(iF==undefined){iF=0}if(Prefix==undefined){Prefix=""}if(listaFields==undefined){}var listaNodos=listaFields;var s;var newLista="";var f_array=listaFields.split(",");for(s=0;s<f_array.length;s++){newLista=newLista+Prefix+f_array[s]+","}newLista=newLista.substring(0,newLista.length-1);this.xmlToAllObj(newLista,i,iF,listaNodos)};this.xmlToAllObj=function(listaFields,i,iF,listaNodos){var f_array,n_array;if(i==undefined){i=0}if(iF==undefined){iF=0}if(listaFields==undefined){}else{f_array=listaFields.split(",")}if(listaNodos==undefined){n_array=listaFields.split(",")}else{n_array=listaNodos.split(",")}try{var s;for(s=0;s<f_array.length;s++){this.xmlToObj(f_array[s],n_array[s],i)}}catch(e){alert("Error en xmlToAllObj-> no se pudo definir Matriz de Objetos")}};this.getCampo=function(campo){var aResp;try{aResp=me.DocXml.getElementsByTagName(campo)}catch(e){alert("Error en getCampo-> No se ha encontrado el Campo")}return aResp};this.getValue=function(campo,i){var _node;var _text=null;_node=me.getCampo(campo)[i];try{var _nodeType=_node.firstChild.nodeType;if((_nodeType==3)||(_nodeType==4)){_text=_node.firstChild.nodeValue}}catch(e){}return _text};this.setBackgroundLoad=function(mode){me.backgroundLoad=mode}}function G_generate_code(B,A){if(B){var C=document.createElement("script");C.type="text/javascript";C.text=B;C.language="Javascript";if(A){if(navigator.appName=="Netscape"){C.onload=function(){A()}}else{C.onreadystatechange=function(){if(C.readyState=="loaded"){A()}}}}document.getElementsByTagName("head")[0].appendChild(C)}}function isLoadingRequest(){return(countLoadingRequest>0||(window.opener&&window.opener.countLoadingRequest>0))};
function toXML(){this.form2XML=function(B){if(B==undefined){B=0}var E=document.forms[B].elements.length;var A="<main><registro>";var G;var D;var C;var F;for(i=0;i<E;i++){G=document.forms[B].elements[i].name;D=document.forms[B].elements[i].value;C=document.forms[B].elements[i].type;if((C!="button")&&(D!="")&&(G!="")&&(D!=undefined)&&(G!="D.XML")&&(G!=undefined)){if(C=="radio"){if(document.forms[B].elements[i].checked==true){A=A+"<"+G+">"+D+"</"+G+">"}}else{A=A+"<"+G+">"+D+"</"+G+">"}}}A=A+"</registro></main>";return A};this.toBorrar=function(C){var A="";if(C!=""){A=A+"<main>";var D=C.split(",");var B;for(B=0;B<D.length;B++){A=A+"<registro><D.k>"+D[B]+"</D.k><D.action>remove</D.action></registro>"}A=A+"</main>"}return A};this.form2param=function(A){if(A==undefined){A=0}var E=document.forms[A].elements.length;var H="";var D="";var G;var C;var B;var F;for(i=0;i<E;i++){G=document.forms[A].elements[i].name;C=document.forms[A].elements[i].value;B=document.forms[A].elements[i].type;if((B!="button")&&(G!="")&&(C!=undefined)&&(G!=undefined)){if(B=="radio"){if(document.forms[A].elements[i].checked==true){H+=G+"="+escape(C)+"&"}}else{H+=G+"="+escape(C)+"&"}}}if(H.length>0){D=H.substr(0,H.length-1)}return D};this.toBorrarParam=function(A,B){var C="";if(B!=""){C=C+"D.y="+A+"&D.k="+B+"&D.action=remove"}return C}};
function serverLoad(){this.COUNT=0;this.context="local";this.text="";this.detectScript=false;this.textScript="";this.sendValues=undefined;this.onLoad=undefined;this.onLoading=undefined;this.onInteractive=null;this.onLoaded=null;this.onError=null;var me=this;this.loadTXT=function(url,metodo,asc){var mySend=new callServer();mySend.detectScript=me.detectScript;mySend.onLoading=me.onLoading;mySend.onInteractive=me.onInteractive;mySend.onLoaded=me.onLoaded;mySend.onError=me.onError;mySend.onLoad=function(ok){if(ok){me.text=mySend.DocTxt;me.textScript=mySend.textScript;if(me.onLoad==undefined){window.status="Ok"}else{me.onLoad(true)}}};mySend.sendValues=me.sendValues;mySend.loadTXThttp(url,metodo,asc)};this.loadVar=function(url,metodo,asc){var mySend=new callServer();mySend.detectScript=me.detectScript;mySend.onLoading=me.onLoading;mySend.onInteractive=me.onInteractive;mySend.onLoaded=me.onLoaded;mySend.onError=me.onError;mySend.onLoad=function(ok){if(ok){me.makeVar(mySend.DocTxt);me.text=mySend.DocTxt;me.textScript=mySend.textScript;if(me.onLoad==undefined){window.status="Ok"}else{me.onLoad(true)}}};mySend.sendValues=me.sendValues;mySend.loadTXThttp(url,metodo,asc)};this.makeVar=function(varString){var _msgError=" serverLoad.makeVar -> error en creación de variables";if(me.context.toLowerCase()!="public"){varString=varString.replace(/\/\*.[^\*\/]*\*\//g,"");var re=new RegExp(/(\(\)|[(a-zA-Z0-9,_.]+\))\{[\{\}a-zA-Z0-9,_.=+;()\/'"\s]+\}/);var var_array=varString.split("function");var oFunc=new Object();var i=0;varString="";for(var j=0;j<var_array.length;j++){var aux=var_array[j];if(aux.search(re)>-1){var _key="__func"+i.toString();oFunc[_key]="function"+RegExp.lastMatch;aux=aux.replace(re,_key);i++}varString=varString+aux}var def_array=varString.split(";");var var_str="";for(var i=0;i<def_array.length-1;i++){if(def_array[i].indexOf("__func")>0){for(var _p in oFunc){if(def_array[i].indexOf(_p)>0){def_array[i]=def_array[i].replace(_p,oFunc[_p]);oFunc[_p]=undefined}}}me.COUNT++;var_str="me."+def_array[i]+";";try{eval(var_str)}catch(e){alert(_msgError+" - "+e.message)}}}else{try{eval(varString)}catch(e){alert(_msgError+" - "+e.message)}}}};
