function limitText(limitField, limitNum) { var form=document.getElementById(getNetuiTagName("form")); var n=document.getElementById(getNetuiTagName("mensaje")); largo = n.value.length; if (limitField.value.length > limitNum) { alert("El texto no debe sobrepasar los " + limitNum + " caracteres..."); limitField.value = limitField.value.substring(0, limitNum); }else{ form.escritos.value = largo; form.restantes.value = (limitNum-largo); } } function buscarUser() { var form=document.getElementById(getNetuiTagName("form")); var rut=document.getElementById(getNetuiTagName("rut")); form.action='/FormularioWeb/FormTransparencia/buscar.do?rut=' + rut.value; form.submit(); } function validaRut() { var form=document.getElementById(getNetuiTagName("form")); var rut=document.getElementById(getNetuiTagName("rut")); if(rut.value=='') { alert("Debe ingresar su rut"); rut.focus(); return false; }else { form.submit(); } } function disableButton(id) { var boton=document[getNetuiTagName("form", this)][getNetuiTagName(id, this)]; //alert(boton.disabled); boton.disabled=true; } function extracheck(obj) { return !obj.disabled; } function tipoCanal(tCanal){ var canal = tCanal.value; if (canal == 'Correo'){ direc2.style.display="none"; direc.style.display=""; }else{ direc2.style.display=""; direc.style.display="none"; } if (canal == 'email'){ mail2.style.display="none"; mail.style.display=""; }else{ mail2.style.display=""; mail.style.display="none"; } if (canal == 'Telefono'){ tel2.style.display="none"; tel.style.display=""; }else{ tel2.style.display=""; tel.style.display="none"; } } function tipoCanal2(){ var canal = document.getElementById(getNetuiTagName('tCanal')).value; if (canal == 'Correo'){ direc2.style.display="none"; direc.style.display=""; }else{ direc2.style.display=""; direc.style.display="none"; } if (canal == 'email'){ mail2.style.display="none"; mail.style.display=""; }else{ mail2.style.display=""; mail.style.display="none"; } if (canal == 'Telefono'){ tel2.style.display="none"; tel.style.display=""; }else{ tel2.style.display=""; tel.style.display="none"; } } function check(rut) { if(isNaN(rut.value)){ alert("Ingrese rut sin puntos ni comas..."); rut.focus(); }else{ buscarUser(rut); } } /*************************************************** Función que Valida que una Fecha sea correcta. ***************************************************/ function validaFecha(dateStr) { // Checks for the following valid date format: // DD-MM-YYYY // Also separates date into month, day, and year variables var datePat = /^(\d{2})(-)(\d{2})(-)(\d{4})$/; var matchArray = dateStr.match(datePat); // is the format ok? if(matchArray == null) { alert("La fecha no tiene un formato v" + String.fromCharCode(225) + "lido(dd-mm-aaaa).") return false; } day = matchArray[1]; // parse date into variables month = matchArray[3]; year = matchArray[5]; if(month < 1 || month > 12) { // check month range alert("El mes debe ser entre 1 y 12."); return false; } if(day < 1 || day > 31) { alert("El d"+String.fromCharCode(237)+"a debe ser entre 1 y 31."); return false; } if((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) { alert("Este mes " + month + " no tiene 31d" + String.fromCharCode(237) + "as."); return false; } if(month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if(day > 29 || (day == 29 && !isleap)) { alert("Febrero " + year + " no tiene " + day + "d" + String.fromCharCode(237) + "as."); return false; } } return true; // date is valid } function validaHora(horaStr) { // Valida el siguiente formato hora // HH:MI // //var horaPat = /^(\d{2})(:)(\d{2})$/; var horaPat = /^(\d{1,2})(:)(\d{2})$/; var matchArray = horaStr.match(horaPat); // is the format ok? if(matchArray == null) { alert("La hora no tiene un formato v" + String.fromCharCode(225) + "lido(hh:mi).") return false; } hora = matchArray[1]; minuto = matchArray[3]; if(hora < 0 || hora > 23) { alert("La hora debe ser entre 0 y 23."); return false; } if(minuto < 0 || minuto > 59) { alert("Los minutos deben ser entre 0 y 59."); return false; } return true; //hora es valida } /*************************************************** Función que Valida que un Texto no sea vacío. También se valida que el nombre de un archivo no se vacío en elementos FileUpload ***************************************************/ function validaTexto(elemento) { if(elemento.type == "text" || elemento.type == "textarea" || elemento.type == "file") { if(elemento.value == "" || AllTrim(elemento.value).length == 0) { elemento.focus(); return false; } } return true; } /*************************************************** Función que elimina los espacios en Blanco a la Izquierda y a la Derecha del elemento. ***************************************************/ function AllTrim(elemento) { return RTrim(LTrim(elemento)); } /*************************************************** Función que elimina los espacios en Blanco a la Izquierda del elemento. ***************************************************/ function LTrim(elemento) { while(''+elemento.charAt(0)==' ') elemento=elemento.substring(1,elemento.length); return elemento; } /*************************************************** Funcion que elimina los espacios en Blanco a la Derecha del elemento. ***************************************************/ function RTrim(elemento) { while(''+elemento.charAt(elemento.length-1)==' ') elemento=elemento.substring(0,elemento.length-1); return elemento; } /*************************************************** Funcion que verifica que el valor ingresado sea de tipo INT. ***************************************************/ function checkInt(objName) { var numfield = objName; if(chkInt(objName.value) == false) { numfield.select(); alert("Ingrese Rut sin puntos ni comas"); //numfield.value=""; numfield.focus(); return false; } else { buscarUser(); } } function checkInteger(objName) { var numfield = objName; if (chkInt(objName.value) == false) { return false; } else { return true; } } /*************************************************** Funcion que verifica que el valor ingresado sea de tipo FLOAT y que tenga 'nroDecimales' digitos depues del punto decimal. ***************************************************/ function checkFloatDecimales(objName, nroDecimales) { var numfield = objName; if(chkFloat(objName.value) == false) { numfield.select(); alert("Este número es inválido. Inténtelo de nuevo."); numfield.focus(); return false; } else if(objName.value.indexOf(".") != -1) { if(objName.value.substr(objName.value.indexOf(".") + 1).length > nroDecimales) { numfield.select(); alert("Este número es inválido. Solo se permiten " + nroDecimales + " dígitos decimales"); numfield.focus(); return false; } } return true; } /*************************************************** Funcion que verifica que el valor ingresado sea de tipo FLOAT y que tenga exactamente 'nroDecimales' digitos depues del punto decimal. Acepta nroDecimales >= 0 ***************************************************/ function checkFloatDecimalesExactos(objName, nroDecimales) { var numfield = objName; if(chkFloat(objName.value) == false) { numfield.select(); alert("Este número es inválido. Inténtelo de nuevo."); numfield.focus(); return false; } else if(objName.value.indexOf(".") != -1) { if(objName.value.substr(objName.value.indexOf(".") + 1).length != nroDecimales) { numfield.select(); alert("Este número es inválido. Debe tener " + nroDecimales + " dígitos decimales"); numfield.focus(); return false; } } else { /* no viene el punto decimal. En este caso aceptamos en numero si nroDecimales == 0 */ if (nroDecimales > 0) { numfield.select(); alert("Este número es inválido. Debe tener " + nroDecimales + " dígitos decimales"); numfield.focus(); return false; } } return true; } /*************************************************** Funcion que verifica que el valor ingresado sea de tipo FLOAT. ***************************************************/ function checkFloat(objName) { var numfield = objName; if(chkFloat(objName.value) == false) { numfield.select(); alert("Este número es inválido. Inténtelo de nuevo."); //numfield.value=""; numfield.focus(); return false; } else { return true; } } /*************************************************** Funcion que verifica que el valor ingresado sea de tipo INT. ***************************************************/ function chkInt(num) { var parsednum; var pat; var res = new Array(); pat = /(\.)/g; res = num.match(pat); if(res != null) if(res.length>0) return false; pat=/(\D)/g; res=num.match(pat); if(res != null) if(res.length > 1) return false; else if(res[0]=='-') { parsednum=parseInt(num); if(parsednum == num) return true; else return false; } else return false; else return true; } /*************************************************** Funcion que verifica que el valor ingresado sea de tipo FLOAT. ***************************************************/ function chkFloat(num) { var parsednum; var pat; var res = new Array(); pat = /(\.)/g; res = num.match(pat); if(res!=null) if(res.length>1) return false; pat = /(\D)/g; res = num.match(pat); if(res != null) if(res.length > 2) return false; else if(res.length == 1) if(res[0] == '-' || res[0] == '.') { parsednum = parseFloat(num); if(parsednum == num) return true; else return false; } else return false; else //res.length es 2 if(res[0] == '-' && res[1] == '.') { parsednum = parseFloat(num); if(parsednum == num) return true; else return false; } else return false; else return true; } /*************************************************** Funcion que valida si un campo de tipo Texto tiene caracteres permitidos o no. ***************************************************/ function validateOnlyChar(field) { var valid = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"+ "abcdefghijklmnñopqrstuvwxyz"+ " 0123456789"+ "á�éÉí�óÓúÚöäüÄÖÜ$º()/¿?!¡%#@_-+*~:\n\r.&"; var ok = "yes"; var temp; for (var i=0; i dezplazada) { return false; } return true; } function comparaFechas(fechaMenor, fechaMayor) { //compara fechas en fechaMenor y fechaMayor. //retorna true si fechaMenor es menor o igual a //fechaMayor //Ambas fechas deben tener formato dd-mm-yyyy var mMayor = fecha2milis(fechaMayor); var mMenor = fecha2milis(fechaMenor); if(mMayor == 0 || mMenor == 0) { return false; } if(mMayor < mMenor) { return false; } return true; } function fecha2milis(dateStr) { // Recibe una fecha valida y la convierte en milisegundos // Also separates date into month, day, and year variables var datePat = /^(\d{2})(-)(\d{2})(-)(\d{4})$/; var matchArray = dateStr.match(datePat); // is the format ok? if(matchArray == null) { return 0; } day = matchArray[1]; // parse date into variables month = matchArray[3]; year = matchArray[5]; fecha = new Date(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10)); return fecha.getTime() } // Le saca los decimales, que está determinado por el caracter ".", retornando un arreglo de la parte Entera y la parte Decimal. function sacaDecimal(Valor) { var indice = Valor.indexOf("."); if (indice <= 0) indice = Valor.indexOf(","); // Si no ha encontrado el decimal de punto ".", lo buscará con la coma "," var Decimal = ""; if (indice > 0) { Decimal = Valor.substring(indice+1,Valor.length); Valor = Valor.substring(0,indice); }; var Arreglo = new Array(2); Arreglo[0] = Valor; Arreglo[1] = Decimal; return Arreglo; }; // Esta función debe colocar los caracteres iniciales como finales y viceversa. function rotarString(contenido) { var value = ""; for (i=0; i < contenido.length ; i++) { value = contenido.charAt(i) + value; }; return value; }; // Función Principal ! // Esta función debe convertir el valor a formato de número function toConFormato(valor) { var v = valor; v = AllTrim(v); // Le saca los espacios en blanco // Si el valor es del Tipo Float if (chkFloat(v)) { var Arreglo = sacaDecimal(v); // Le saca los decimales, que está determinado por el caracter ".". v = Arreglo[0]; var valorRotado = rotarString(v); // Esta función debe colocar los caracteres iniciales como finales y viceversa var newValor = ""; for (i=0; i < valorRotado.length ; i++) { if (((i % 3) == 0) && i != 0) newValor += ","; // Le incorpora el caracter de separador de miles newValor += valorRotado.charAt(i); }; v = rotarString(newValor); // Si contiene una parte decimal, entonces se la incorpora if (Arreglo[1].length > 0) { v += "." + Arreglo[1]; // Le incorpora la parte decimal }; }; valor = v; return(valor); }; // Formatea el Monto function Formatear(numero,monto) { var n = numero.value; numero.value = n.replace(/,/gi, ''); // Pichigateo por que en Netscape tiene otro comportamiento monto.value = toConFormato(numero.value); } // Desformatea el Monto function Desformatear(numero,monto) { var n = numero.value; numero.value = n.replace(/,/gi, ''); // Pichigateo por que en Netscape tiene otro comportamiento monto.value = numero.value; } // Asigna el Monto a la variable Hidden que corresponde al Número function Valor(numero,monto) { var m = AllTrim(monto.value); if (m.indexOf(",")) numero.value = m.replace(/,/gi, ''); // Pichigateo por que en Netscape tiene otro comportamiento else numero.value = AllTrim(monto.value); } // Valida que el tamaño NO exceda a 14 function validaTamanio(monto, monto_txt) { // Si tiene más de 14 caracteres, entonces if (AllTrim(monto.value).length > 14) { alert("El monto NO debe contener más de 14 dígitos"); monto_txt.select(); monto_txt.focus(); return false; } else { Formatear(monto_txt,monto_txt); // Pichigateo por que en Netscape tiene otro comportamiento return true; }; }; // Esta función debe comparar 2 horas (hh:mm), donde debe retornar : // 1 = Si Ini es < (menor) a Ter - 0 = Si Ini es = (igual) a Ter - -1 = Si Ini es > (mayor) a Ter function comparaHora(Ini, Ter) { // Recibe validado el formato hora // HH:MI var horaPat = /^(\d{1,2})(:)(\d{2})$/; var matchArray = Ini.match(horaPat); // is the format ok? var horaIni = parseInt(matchArray[1],10); var minutoIni = parseInt(matchArray[3],10); matchArray = Ter.match(horaPat); // is the format ok? var horaTer = parseInt(matchArray[1],10); var minutoTer = parseInt(matchArray[3],10); minutoIni += horaIni * 60; minutoTer += horaTer * 60; if (minutoIni < minutoTer) return 1; else if (minutoIni = minutoTer) return 0; else return -1; }; // para seleccionar opciones en select. function marcaSelect(select) { var itemsSelect = select.length; for(var i = 0; i < itemsSelect; i++) { select.options[i].selected = true; } }; // para manejo de listas de seleccion multiple function agregar(opcion, destino, indice) { var formulario = destino.form; var opcionNueva = new Option(opcion.text, opcion.value); eval("formulario." + destino.name + ".options[" + indice + "]=opcionNueva"); }; // para manejo de listas de seleccion multiple function eliminarOpcion(seleccion, nroSeleccion) { seleccion.options[nroSeleccion] = null; } function compare(opcion1, opcion2) { if(opcion1.text < opcion2.text) return -1 if(opcion1.text > opcion2.text) return 1 return 0 } function traspasoOpciones(origen, destino) { // para manejo de listas de seleccion multiple var inicioGrupos = origen.selectedIndex; var largoGrupos = (inicioGrupos == -1 ? -1 : origen.length); var largoDestino = destino.length; var destinoArray = new Array(largoDestino); for(var i = 0; i < largoDestino; i++) { destinoArray[i] = destino.options[i]; } for(var i = inicioGrupos; i < largoGrupos; i++) { var opcion = origen.options[i]; if(opcion.selected) { destinoArray.push(opcion); eliminarOpcion(origen, i); i--; largoGrupos--; } } destinoArray.sort(compare); for(var i = 0; i < destinoArray.length; i++) { agregar(destinoArray[i], destino, i); } }