//-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- function JUtil() {} JUtil.IE = 1001; JUtil.MOZ = 1002; JUtil.getNav = function() { var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1; var isMoz = document.implementation && document.implementation.createDocument; if ( isIE ) return this.IE; if ( isMoz) return this.MOZ; } /** * Redondea y formatea un número en base * a la precisión * @param (double) value Número a formatear * @param (int) precision Número de decimales */ Math.roundOFF = function (value, precision) { value = "" + value //convert value to string precision = parseInt(precision); var whole = "" + Math.round(value * Math.pow(10, precision)); if ( precision == 0) return whole; var decPoint = whole.length - precision; if(decPoint != 0) { result = whole.substring(0, decPoint); result += ","; result += whole.substring(decPoint, whole.length); if (result==",0") result="0,00"; } else { result = "0,"+whole; } return result; } // Funciones de cadena String.digito="0123456789"; String.puntoDecimal=".,"; String.caracterMayuscula="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String.caracterMinuscula="abcdefghijklmnopqrstuvwxyz"; String.caracer = String.caracterMayuscula + String.caracterMinuscula; String.alfaNumerico=String.digito+String.caracterMayuscula+String.caracterMinuscula; String.signos="_-."; String.arroba="@"; String.cadenaValida= String.alfaNumerico+String.signos+String.arroba; /** * Valida una cadena */ String.validarCadena = function (mascara,cadena) { if (cadena.length==0) return false; for(i=0;i4) return false; if (!String.validarCadena(String.caracterMayuscula+String.caracterMinuscula,cc)) return false; return true; } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto que controla las pilas globales * @return (void) */ function JPile() { // Propiedades this.arrRefObjects = Array(); this.arrRefDialogs = Array(); // Métodos this.addRefObject = JPileAddRefObject; this.getRefObject = JPileGetRefObject; this.addDialog = JPileAddDialog; this.getDialog = JPileGetDialog; this.popDialog = JPilePopDialog; } /** * Añade un nuevo dialogo a la pila */ function JPileAddDialog(obj) { this.arrRefDialogs.push(obj); } function JPileGetDialog() { if ( this.arrRefDialogs.length == 0 ) return null; return this.arrRefDialogs[ this.arrRefDialogs.length -1 ]; } function JPilePopDialog() { this.arrRefDialogs.pop(); } /** * Funcion que controla los objetos asignados * a elementos HTML * @param (Object) Objeto que se quiere añadir * @return (int) Identificador al objeto añadido */ function JPileAddRefObject( obj ) { id = this.arrRefObjects.length; this.arrRefObjects[id] = obj; return id; } /** * Recupera la referencia del objeto * @param (int) Identificador asignado del objeto * @return (Object) Objeto indicado o undefined si no se encuentra */ function JPileGetRefObject(id) { if ( this.arrRefObjects[id] ) return this.arrRefObjects[id]; return undefined; } // Instancia del objeto para poder utilizar sus propiedades jPile = new JPile(); //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto Formulario para controlar * el funcionamiento de un formulario */ function JForm( form ) { // Propiedades this.form = form; this.arrInputs = Array(); this.arrCalcul = Array(); this.mensaje = ""; this.asdf = "ADF"; this.action = form.getAttribute("action"); this.method = form.getAttribute("method")? form.getAttribute("method") : "POST" ; this.target = form.getAttribute("target")? form.getAttribute("target") : "_self"; // Metodos this.addInput = JFormAddInput; this.validar = JFormValidar; this.submit = JFormSubmit; this.ejecutarAccion = JFormEjecutarAccion; this.getInput = JFormGetInput; this.captureInputs = JFormCaptureInputs // Captura de los inputs this.captureInputs(); } /** * Captura automática de los inputs del formulario */ function JFormCaptureInputs() { var inp; var type; var sub; var jInp; for(i=0;i0) { temp+=cadena.charAt(i); numeros++; } } return temp; } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto para controlar el funcionamiento de un input * de tipo texto * @param (Object) input Objeto input * @param (String) alias Nombre identificativo del input * @param (String) tipo Tipo de input [texto,numerico,email] * @param (boolean) notNull Indica si puede contener nulos */ function JInput( input ) { // Captura de propiedades this.input = input; this.alias = this.input.getAttribute("alias"); this.tipo = this.input.getAttribute("tipo"); this.notNull = this.input.getAttribute("notNull")!=null? true : false; this.mensaje = this.input.getAttribute("mensaje"); this.log = ""; // Métodos this.validar = JInputValidar; // Asignación de eventos y estilos al input if ( !this.input.className && !this.input.onchange ) { this.input.onchange += JInputModificado; } if ( this.tipo == "numerico" ) { if ( this.input.addEventListener ) { this.input.setAttribute("onkeypress","return JInputNumericValidate(event);"); } else { this.input.onkeypress = JInputNumericValidate; } this.input.value = this.input.value.replace(/\./gi,","); } } /** * Cambia el estilo cuando un input es modificado * @return (void) */ function JInputModificado() { this.className = "inputMod"; } /** * Validación del input * @return (boolean) true si es válido, false en caso contrario */ function JInputValidar() { // Comprueba si acepta nulos if ( this.notNull ) { if ( this.input.value.length == 0 ) { if ( !this.mensaje ) this.log = "El campo " + this.alias + " no puede quedar vacio"; else this.log = this.mensaje; if ( this.input.type != "textarea") this.input.focus(); return false; } } // Tipo númerico if ( this.notNull && this.tipo == "numerico" && this.input.value == 0) { if ( !this.mensaje ) this.log = "El campo " + this.alias + " no puede ser 0"; else this.log = this.mensaje; this.input.focus(); return false; } // Formateado del valor númerico if ( this.tipo == "numerico" ) { numcomas = 0; for(i=0;i < this.input.value.length;i++) { numcomas += (this.input.value.charAt(i) == ",") ? 1 : 0; } this.input.value = this.input.value.replace(/\./gi,""); this.input.value = this.input.value.replace(/,/gi,"."); this.input.value = limpiaCeros( this.input.value ); if ( this.input.value.length == 0 ) this.input.value = 0; if ( isNaN(this.input.value) ) { this.input.value = this.input.value.replace(/\./gi,","); if ( this.mensaje ) alert(this.mensaje); else alert("El campo " + this.alias + " debe contener valores númericos"); this.input.focus(); return false; } } // Tipo email if ( this.tipo == "email" && !this.input.value.esMail() ) { if ( this.mensaje ) alert(this.mensaje); else alert("El campo "+ this.alias +" no contiene un formato de email válido"); this.input.focus(); return false; } return true; } /** * Valida la pulsación de una tecla en un * imput numérico * @param Event e Objeto Evento (solo en Netscape) */ function JInputNumericValidate(e) { if ( e ) { return JInputNumericValidateNS(e); } else { return JInputNumericValidateIE(event); } } /** * Valida la pulsación de una tecla en un * imput numérico * @param Event e Objeto Evento (solo en Netscape) */ function JInputNumericValidateIE(event) { src = event.srcElement; key = event.keyCode; keyNom = String.fromCharCode(key); validos = "0123456789.,"; if ( key == 46 ) { event.keyCode = 44; } if ( validos.search(keyNom)==-1 ) { msg = src.getAttribute("msgNum"); if ( !msg ) alert("Este campo solo admite valores númericos"); else alert(msg); event.keyCode = null; return; } return; } /** * Valida la pulsación de una tecla en un * imput numérico * @param Event e Objeto Evento (solo en Netscape) */ function JInputNumericValidateNS(event) { src = event.target; key = event.charCode? event.charCode : event.keyCode; if ( key == 0 || key == 9 || key == 116 ) { return true; } keyNom = String.fromCharCode(key); validos = "0123456789.,"; if ( key == 46 ) { src.value += ","; return false; } if ( validos.search(keyNom)==-1 ) { msg = src.getAttribute("msgNum"); if ( !msg ) alert("Este campo solo admite valores númericos"); else alert(msg); return false; } return true; } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto para controlar un Input de tipo * Select * @param (Object) select Objeto HTML select */ function JSelect(select) { // Propiedades this.select = select; this.textoInicial = this.select.getAttribute("textoIni"); this.valorInicial = this.select.getAttribute("valorIni"); // Métodos this.addValue = JSelectAddValue; this.ini = JSelectIni; this.setValue = JSelectSetValue; this.addOpcion = JSelectAddOpcion; } /** * Añade una nueva opción al select * @param (String) codigo Código de la opcion * @param (String) valor Texto de la opción * @param (boolean) selected Indica si esta opción estará seleccionada */ function JSelectAddValue(codigo,texto,selected) { selected = (selected) ? true : false; anadir(this.select, codigo, valor, selected); } /** * Inicializa los valores del select */ function JSelectIni() { this.select.length = 0; this.addValue(this.valorInicial,this.textoInicial,true); } /** * Selecciona un valor del select * @param (String) codigo Código de la opción */ function JSelectSetValue(codigo) { for(i=0;i<(this.select.length);i++) { if (this.select.options[i].value==codigo) this.select.options[i].selected=true; } } /** * Añade una nueva opción al select * @param (String) codigo Código de la opción * @param (String) texto Texto de la opción * @param (boolean) selected Indica si esta seleccionada */ function addOpcion(codigo,texto,selected) { this.select.length++; this.select.options[this.select.length-1].text=texto; this.select.options[this.select.length-1].value=codigo; this.select.options[this.select.length-1].selected=selected; } /** * Objeto que controla la selección de una fecha * @param (HTMLElement) input Elemento HTML que recogerá el valor */ function JDialogFecha(jInput) { // Propiedades this.ruta = "http://www.motardos.com/acceso_admin/funciones/calendar.php"; this.jInput = jInput; this.width = 210; this.height = 200; this.value = ""; this.div = null; // Métodos this.convFecha = JDialogFechaConvFecha; this.Show = JDialogFechaShow; this.returnValue = JDialogFechaReturnValue; this.cerrar = JDialogFechaClose; } /** * Establece la fecha en el input * @return (void) */ function JDialogFechaConvFecha(fecha) { tokens = fecha.split("-"); if ( tokens.length != 3 ) return ""; dia = parseInt(tokens[0],10); mes = parseInt(tokens[1],10); ano = parseInt(tokens[2],10); return ano+"-"+mes+"-"+dia; } /** * Muestra un popup con la fecha * @return (String) Fecha seleccionada */ function JDialogFechaShow(e) { dialog = new JDialog(this.ruta,this,"Seleccionar Fecha"); dialog.show(); } function JDialogFechaReturnValue(value) { this.jInput.setValue(this.convFecha(value)); } function JDialogFechaClose(e) { if ( e ) { obj = e.target; } else { obj = event.srcElement; } jDialog = obj.getAttribute("jDialog"); jDialog.div.style.display = "none"; jDialog.div = null; } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto que controla la creación, subida y edicion de una imagen * @param (Object) input Objeto HTML de tipo input=text */ function JInputImage( input ) { // Propiedades this.input = input; this.rutaImg = this.input.getAttribute("rutaImg"); this.tabla = this.input.getAttribute("tabla"); this.campo = this.input.getAttribute("campo"); this.notNull = this.input.getAttribute("notNull")? true : false; this.mensaje = this.input.getAttribute("mensaje")? this.input.getAttribute("mensaje") : ""; this.alias = this.input.getAttribute("alias")? this.input.getAttribute("alias") : ""; // privado this.img = null; // Métodos this.validar = JInputImageValidar; this.getImage = JInputImageGetImage; this.setValue = JInputImageSetValue; this.getValue = JInputImageGetValue; this.crearGUI = JInputImageCreateGUI; this.crearGUI(); } /** * Crea la interfaz de la imagen * @return (void) */ function JInputImageCreateGUI() { // Td td = this.input.parentNode; // Creación del icono de búsqueda img = document.createElement("img"); img.src = "http://www.motardos.com/graficos/ico_buscar.gif"; img.setAttribute("JInputImage",jPile.addRefObject(this)); img.style.cursor = "pointer"; img.title = "Buscar imagen"; img.onclick = JInputImageGetImage; td.appendChild(img); // Creación de un espacio nbsp = document.createTextNode(" "); td.appendChild(nbsp); // Creación de la imagens this.img = document.createElement("img"); this.img.border = 0; this.img.align = "absmiddle"; this.img.width = 50; this.img.height = 50; if ( this.input.value.length > 0 ) this.img.src = this.rutaImg + this.input.value; else this.img.src = this.rutaImg + "img_nodisponible.gif"; td.appendChild(this.img); } /** * Valida el campo imagen * @return (boolean) True si es válido, false en caso contrario */ function JInputImageValidar() { if ( this.notNull ) { if ( !this.mensaje ) alert("El campo ["+this.alias+"] no puede quedar vacío"); else alert(this.mensaje); this.input.focus(); return false; } return true; } /** * Crea un dialogo para extraer la imagen */ function JInputImageGetImage(e) { src = e? e.target : event.srcElement; idObj = src.getAttribute("JInputImage"); obj = jPile.getRefObject(idObj); imgDialog = new JDialogImagen(obj.tabla,obj.campo,obj); imgDialog.Show(); } /** * Establece la imagen */ function JInputImageSetValue(value) { this.input.value = value; this.img.src = this.rutaImg + this.input.value; } /** * Establece la imagen */ function JInputImageGetValue() { return ( this.input.value ); } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto que encapsula la búsqueda de una imagen */ function JDialogImagen(tabla,campo,current) { // Propiedades this.tabla = (tabla) ? tabla : ""; this.campo = (campo) ? campo : ""; this.current = current ? current : ""; this.width = 800; this.height = 500; // Métodos this.Show = JDialogImagenShow; this.UpLoad = JDialogImagenUpLoad; this.returnValue = JDialogImagenReturnValue; } function JDialogImagenReturnValue( value ) { this.current.setValue(value); } /** * Muestra un Dialog para seleccionar la imagen * @return (string) Imagen seleccionada , cadena vacía si no hubo selección */ function JDialogImagenShow() { url = "http://www.motardos.com/acceso_admin/funciones/mrk_imagenes.php?tabla="+this.tabla+"&campo="+this.campo+"¤t="+this.current.getValue(); temp = new JDialog(url,this); temp.width = this.width; temp.height = this.height; temp.show(); } function JDialogImagenUpLoad() { var imagen = window.showModalDialog( "http://www.motardos.com/acceso_admin/funciones/subir.php?tabla="+this.tabla+"&campo="+this.campo, "" , "dialogHeight:180px; dialogWidth:500px center:yes; edge:raised; scroll:no; status:no;"); if ( imagen ) { this.TextBox.value = imagen; this.Imagen.src = this.rutaImg+imagen; } return imagen; } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- /** * Objeto que crea un marco para * cargar URL's de modo ventana * @param (string) url Url que se desea cargar */ function JDialog(url,obj,title) { // Propiedades this.url = url; this.width = 230; this.height = 200; this.heightTitle = 21; this.title = title? title : "Dialog"; this.dialog = obj; // Private this.div = null; this.dragMode = false; this.dragX = 0 ; this.dragY = 0 ; // Metodos this.show = JDialogShow; this.close = JDialogClose; this.setReturnValue = JDialogSetReturnValue; jPile.addDialog(this); } function JDialogSetReturnValue(value) { document.body.removeChild(jPile.getDialog().div); jPile.popDialog(); this.dialog.returnValue(value); } function JDialogCaptureMove(e) { src = e? e.target : event.srcElement; oId = src.getAttribute("JDialog"); obj = jPile.getRefObject(oId); if ( obj.dragMode ) { if ( e && !e.x ) { obj.div.style.left = e.pageX - obj.dragX; obj.div.style.top = e.pageY - obj.dragY; } else { obj.div.style.left = event.x - obj.dragX; obj.div.style.top = event.y - obj.dragY; } } return; } function JDialogCaptureDown(e) { src = e? e.target : event.srcElement; src.style.cursor = "pointer"; oId = src.getAttribute("JDialog"); obj = jPile.getRefObject(oId); obj.dragMode = true; if ( e && !e.x) { obj.dragX = e.layerX; obj.dragY = e.layerY; } else { obj.dragX = event.offsetX; obj.dragY = event.offsetY; } return; } function JDialogCaptureUp(e) { src = e? e.target : event.srcElement; src.style.cursor = "auto"; oId = src.getAttribute("JDialog"); obj = jPile.getRefObject(oId); obj.dragMode = false; return; } function JDialogMouseOut(e) { src = e? e.target : event.srcElement; oId = src.getAttribute("JDialog"); obj = jPile.getRefObject(oId); if ( !obj ) return; obj.dragMode = false; } function JDialogShow(e) { oId = jPile.addRefObject(this); posX = (window.screen.width - this.width) / 2; posY = 30 if ( e ) { posX = e.layerX; posY = e.layerY; } else { } this.div = document.createElement("div"); this.div.style.left = posX; this.div.style.top = posY; this.div.style.position = "absolute"; this.div.className = "windowDiv"; this.div.setAttribute("JDialog",oId); this.div.innerHTML = "
"; this.div.onmouseout = JDialogMouseOut; document.body.appendChild(this.div); tbl = document.getElementById("tblDialog"); tbl.style.width = this.width; tbl.cellspacing = 0; tbl.cellpadding = 0; tr = tbl.insertRow(0); td = tr.insertCell(0); td.className = "windowTitle"; td.innerHTML = this.title; td.setAttribute("JDialog",oId); td.id = "Title"; td.width = "100%"; td.height = this.heightTitle; td.onmousedown = JDialogCaptureDown; td.onmousemove = JDialogCaptureMove; td.onmouseup = JDialogCaptureUp; // Imagen de cierre del popup td = tr.insertCell(1); td.setAttribute("JDialog",oId); td.className = "windowTitle"; img = document.createElement("img"); img.src = "http://www.motardos.com/graficos/ico_win_cerrar.gif"; img.style.cursor = "hand"; img.title = "Cerrar"; img.onclick = JDialogClose; img.setAttribute("JDialog",oId); td.appendChild(img); // Creación del frame tr = tbl.insertRow(1); td = tr.insertCell(0); td.coslpan = 2; td.width = "100%"; ifrm = document.createElement("iframe"); ifrm.frameBorder = 0; ifrm.marginHeight = 0; ifrm.marginWidth = 0; ifrm.width = "100%"; ifrm.height = this.height - this.heightTitle; ifrm.src = this.url; ifrm.scrolling = "no"; td.appendChild(ifrm); } function JDialogClose(e) { src = e? e.target : event.srcElement; obj = jPile.getRefObject(src.getAttribute("JDialog")); obj.setReturnValue(""); } //------------------------------------------------------------- //------------------------------------------------------------- //------------------------------------------------------------- //------------------------------------------------------------- /** * Objeto que controla la selección de un valor existente en * otra tabla * @param (Object) input Objeto HTML de tipo input=text */ function JInputLink( input ) { // Propiedades this.input = input; this.tabla = this.input.getAttribute("tabla"); this.notNull = this.input.getAttribute("notNull") ? true : false; this.mensaje = this.input.getAttribute("mensaje") ? this.input.getAttribute("mensaje") : ""; this.alias = this.input.getAttribute("alias") ? this.input.getAttribute("alias") : ""; this.inputLbl= null; // Métodos this.validar = JInputLinkValidar; this.setValue = JInputLinkSetValue; this.getValue = JInputLinkGetValue; this.crearGUI = JInputLinkCreateGUI; this.setID = JInputLinkSetID; this.show = JInputLinkShow; this.getID = JInputLinkGetID; this.getXML = JInputLinkGetXML; this.setXML = JInputLinkSetXML; // Eventos this.input.onblur = JInputLinkGetID; this.input.onchange = JInputLinkGetID; this.crearGUI(); } /** * */ function JInputLinkShow(e) { src = e? e.target : event.srcElement; idObj = src.getAttribute("JInputLink"); obj = jPile.getRefObject(idObj); temp = new JDialogLink(obj.tabla,obj); temp.Show(); } function JInputLinkGetID(e) { src = e? e.target : event.srcElement; idObj = src.getAttribute("JInputLink"); obj = jPile.getRefObject(idObj); obj.setID(); } function JInputLinkSetID() { if ( this.input.value.length == 0 ) { this.inputLbl.value = ""; return; } if ( JUtil.getNav() == JUtil.IE ) { jXml = new JXML("http://www.motardos.com/acceso_admin/funciones/recIdXML.php?tabla=" + this.tabla + "&valor="+this.input.value); docRoot = jXml.load(); this.setXML(docRoot); } if ( JUtil.getNav() == JUtil.MOZ) { jXml = new JXML("http://www.motardos.com/acceso_admin/funciones/recIdXML.php?tabla=" + this.tabla + "&valor="+this.input.value); jXml.setOwner(this); jXml.load(); } } function JInputLinkGetXML(xmlNode) { this.setXML(xmlNode); } function JInputLinkSetXML(docRoot) { if ( docRoot ) { if ( docRoot.getAttribute("type")=="ok") { this.inputLbl.value = docRoot.getAttribute("id"); this.input.value = docRoot.getAttribute("value"); } else { alert(docRoot.getAttribute("mensaje")); this.input.value = ""; } } } /** * Crea la interfaz de la imagen * @return (void) */ function JInputLinkCreateGUI() { // Td td = this.input.parentNode; this.input.setAttribute("JInputLink",jPile.addRefObject(this)); // Creación del icono de búsqueda img = document.createElement("img"); img.src = "http://www.motardos.com/graficos/ico_buscar.gif"; img.setAttribute("JInputLink",jPile.addRefObject(this)); img.style.cursor = "pointer"; img.title = "Buscar " + this.alias; img.onclick = JInputLinkShow; td.appendChild(img); // Creación de un espacio nbsp = document.createTextNode(" "); td.appendChild(nbsp); // Creación de la imagenes this.inputLbl = document.createElement("input"); this.inputLbl.setAttribute("readonly","readonly"); this.inputLbl.type = "text"; this.inputLbl.className = "inputLink"; this.inputLbl.tabIndex = -1; td.appendChild(this.inputLbl); } /** * Valida el campo imagen * @return (boolean) True si es válido, false en caso contrario */ function JInputLinkValidar() { if ( this.notNull ) { if ( !this.mensaje ) alert("El campo ["+this.alias+"] no puede quedar vacío"); else alert(this.mensaje); this.input.focus(); return false; } return true; } /** * Establece el valor */ function JInputLinkSetValue(value) { this.input.value = value; this.setID(); } /** * Establece la imagen */ function JInputLinkGetValue() { return ( this.input.value ); } //------------------------------------------------------------- //------------------------------------------------------------- //------------------------------------------------------------- //------------------------------------------------------------- /** * Objeto que encapsula la búsqueda de una imagen */ function JDialogLink(tabla,current) { // Propiedades this.tabla = (tabla) ? tabla : ""; this.current = current ? current : ""; this.width = 800; this.height = 500; // Métodos this.Show = JDialogLinkShow; this.UpLoad = JDialogLinkUpLoad; this.returnValue = JDialogLinkReturnValue; } function JDialogLinkReturnValue( value ) { this.current.setValue(value); } /** * Muestra un Dialog para seleccionar la imagen * @return (string) Imagen seleccionada , cadena vacía si no hubo selección */ function JDialogLinkShow() { url = "http://www.motardos.com/acceso_admin/forms/mnt_"+this.tabla+".php?modo=listado"; temp = new JDialog(url,this); temp.width = this.width; temp.height = this.height; temp.show(); } function JDialogLinkUpLoad() { var imagen = window.showModalDialog( "http://www.motardos.com/acceso_admin/funciones/subir.php?tabla="+this.tabla+"&campo="+this.campo, "" , "dialogHeight:180px; dialogWidth:500px center:yes; edge:raised; scroll:no; status:no;"); if ( imagen ) { this.TextBox.value = imagen; this.Imagen.src = this.rutaImg+imagen; } return imagen; } //----------------------------------------------------- //----------------------------------------------------- //----------------------------------------------------- //----------------------------------------------------- /** * Objeto para procesar xml's */ function JXML(url) { this.url = url; // Metodos this.load = JXMLLoad; this.createXmlObject = JXMLCreateXmlObject this.setOwner = JXMLSetOwner; // Inicialización this.xml = this.createXmlObject(); } function JXMLSetOwner(object ) { this.xml.owner = object; } /** * Carga el xml en forma asincrona */ function JXMLLoad(rootNode) { this.xml.load(this.url); if ( this.xml.documentElement ) return this.xml.documentElement; return null; } function JXMLCreateXmlObject() { // Caso netscape if (document.implementation && document.implementation.createDocument) { Document.prototype.owner = "ADF"; xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.onload = JXMLOnLoad; return xmlDoc; } else { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; return xmlDoc; } } function JXMLOnLoad() { this.owner.getXML(this.documentElement); } //--------------------------------------------------------- //--------------------------------------------------------- //--------------------------------------------------------- //--------------------------------------------------------- /** * Objeto fecha */ function JInputFecha( input ) { // Propiedades this.input = input; this.alias = this.input.getAttribute("alias"); this.notNull = this.input.getAttribute("notNull"); this.mensaje = this.input.getAttribute("mensaje"); this.dia = null; this.mes = null; this.ano = null; this.log = ""; // Metodos this.validar = JInputFechaValidar; this.crearGUI = JInputFechaCrearGui; this.getFecha = JInputFechaGetFecha; this.setValue = JInputFechaSetValue; this.validarFecha = JInputFechaValidarFecha; this.limpiaCeros = JInputFechaLimpiaCeros; // Creación de la interfaz grafica this.crearGUI(); // Asignación de la fecha this.setValue(this.input.value); } /** * Establece una fecha en formato MySQL */ function JInputFechaSetValue(value) { // Extracción de la fecha diaValue = ""; mesValue = ""; anoValue = ""; arrVal = value.split("-"); if ( arrVal.length == 3 ) { diaValue = arrVal[2]; mesValue = arrVal[1]; anoValue = arrVal[0]; } this.dia.value = diaValue; this.mes.value = mesValue; this.ano.value = anoValue; this.input.value = value; } /** * Muestra un selector de fechas */ function JInputFechaGetFecha(e) { if ( !e ) { obj = event.srcElement; } else { obj = e.target; } OID = obj.getAttribute("OID"); jInput = jPile.getRefObject(OID); inp = new JDialogFecha(jInput); inp.Show(e); } /** * Crea los inputs necesarios para introducir una fecha * @return (void); */ function JInputFechaCrearGui() { // // Creación de los inputs // // Dia this.dia = document.createElement("input"); this.dia.type = "text"; this.dia.setAttribute("alias",this.name+" dia " ); this.dia.setAttribute("tipo","numerico" ); this.dia.setAttribute("notNull",true ); this.dia.name = this.input.name+"_dia"; this.dia.size = 2; this.dia.maxLength = 2; this.dia.setAttribute("auto",1); inp = new JInput(this.dia); // Mes this.mes = document.createElement("input"); this.mes.type = "text"; this.mes.name = this.input.name+"_mes"; this.mes.setAttribute("alias",this.name+" mes " ); this.mes.setAttribute("tipo","numerico" ); this.mes.setAttribute("notNull",true ); this.mes.setAttribute("auto",1); this.mes.size = 2; this.mes.maxLength = 2; inp = new JInput(this.dia); // Año this.ano = document.createElement("input"); this.ano.type = "text"; this.ano.name = this.input.name+"_ano"; this.ano.setAttribute("alias",this.name+" año " ); this.ano.size = 4; this.ano.maxLength = 4; this.ano.setAttribute("tipo","numerico" ); this.ano.setAttribute("notNull",true ); this.ano.setAttribute("auto",1); inp = new JInput(this.dia); // Imagen para el calendar img = document.createElement("img"); img.src = "http://www.motardos.com/graficos/ico_calendar.gif"; img.className = "imgLink"; img.border = 0; img.align = "absmiddle"; img.title = "Obtener fecha"; img.onclick = JInputFechaGetFecha; img.setAttribute("Oid",jPile.addRefObject(this)); // Span para contener a los elementos tbl = document.createElement("table"); tr = tbl.insertRow(0); td = tr.insertCell(0); td.appendChild(this.dia); td = tr.insertCell(1); td.appendChild(this.mes); td = tr.insertCell(2); td.appendChild(this.ano); td = tr.insertCell(3); td.appendChild(img); // Incorporación de los inputs this.input.style.display = "none"; this.input.setAttribute("auto",1); obj = this.input.parentNode; obj.innerHTML = ""; obj.appendChild(tbl); obj.appendChild(this.input); } /** * Valida los datos introducidos * @return (boolean) true si es válido, false en caso contrario */ function JInputFechaValidar() { if ( this.notNull ) { if ( !this.dia.validar() ) return false; if ( !this.mes.validar() ) return false; if ( !this.ano.validar() ) return false; if ( dia.input.value==0 || mes.input.value==0 || ano.input.value == 0 ) { dia.input.value = ""; mes.input.value = ""; ano.input.value = ""; if ( this.mensaje ) this.log = this.mensaje; else this.log = "El campo [" + this.alias + "] no puede quedar vacío"; this.dia.focus(); return false; } } // Comprobación de la fecha if ( this.dia.value.length > 0 || this.mes.value.length > 0 || this.ano.value.length > 0) { if ( !this.validarFecha( this.dia.value , this.mes.value , this.ano.value )) { if ( this.mensaje ) this.log = this.mensaje; else this.log = "El campo [" + this.alias + "] no contiene una fecha válida"; this.dia.focus(); return false; } } return true; } /** * Valida una fecha * @param (String) dia Dia de la fecha * @param (String) mes Mes de la fecha * @param (String) ano Año de la fecha */ function JInputFechaValidarFecha(dia,mes,ano) { if ( dia.length == 0 ) return false; if ( mes.length == 0 ) return false; if ( ano.length == 0 ) return false; dia=parseInt(this.limpiaCeros(dia)); mes=parseInt(this.limpiaCeros(mes)); ano=parseInt(this.limpiaCeros(ano)); fecha = new Date(); if (mes<1 || mes>12) return false; meses = new Array(13) meses[1] = 31; if ( ( (ano%4)==0 && (ano%100)!=0 ) || (ano%400)==0 ) meses[2]=29; else meses[2]=28; meses[3] = 31; meses[4] = 30; meses[5] = 31; meses[6] = 30; meses[7] = 31; meses[8] = 31; meses[9] = 30; meses[10] = 31; meses[11] = 30; meses[12] = 31; if (dia<1 || dia>meses[mes]) return false; return true; } /** * Elimina los ceros antes de cualquier número * @param (String) cadena Cadena a limpioar */ function JInputFechaLimpiaCeros( cadena ) { temp=""; numeros=0; for(i=0;i0) { temp+=cadena.charAt(i); numeros++; } } return temp; }