Revision: 3346
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 13, 2007 01:21 by MartinY
Initial Code
function activarDiv (numero, elementos) {
/* en caso de no pasarle numero se pone 0 por defecto */
if ((numero == null) || (numero == '')) numero = 0;
if (numero > elementos[1].length-1) numero = 0;
for (i=0;i<elementos[1].length;i++){
if (numero == i) {
$(elementos[1][i]).style.display = "";
$(elementos[2][i]).className = "activo";
}
else {
$(elementos[1][i]).style.display = "none";
$(elementos[2][i]).className = "";
}
}
$(elementos[0]).value = numero;
}
function mostrarZona(zona,mostrar) {
if ($(zona))
if (mostrar) $(zona).style.display = "";
else $(zona).style.display = "none";
else
alert('La zona ('+zona+') a mostrar no existe');
}
Array.prototype.inArray = function (value) {
var i;
for (i=0; i < this.length; i++) {
if (this[i] == value) {
return true;
}
}
return false;
}
Array.prototype.indexOf = function(s) {
for (var x=0;x<this.length;x++) if(this[x] == s) return x;
return false;
}
String.prototype.trim = function() { return this.replace(/^s+|s+$/g,'') }
String.prototype.zeroFill = function(n) {
var d=this;
for(var x=this.length;x<n;x++)
d='0'.concat(d);
return d;
}
// rellenar string con ceros
function zeroFill(o,n) {
for(var x=o.value.length;x<n;x++)
o.value='0'+o.value
}
Object.prototype.selectedValue = function(v) {
if (this.type != 'select-one') return;
for(var x=0;x<this.options.length;x++){
if(this.options[x].value == v){
this.selectedIndex = x;
return;
}
}
}
// selecciona un valor de un SELECT
function seleccionarValor(o,v) {
for(var x=0;x<o.options.length;x++){
if(o.options[x].value == v){
o.selectedIndex = x;
return;
}
}
}
/* get, set, and delete cookies */
function getCookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+"="+escape( value ) +
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
/* quick getElement reference */
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
function validarFecha(input_fecha){
if (!/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/.test(input_fecha.value)){
alert("El formato de la fecha debe ser dd/mm/aaaa");
input_fecha.value='';
return;
}
valor = input_fecha.value.split('/');
if(valor[0]>31 || valor[0]<1){
alert("DÃa incorrecto");
input_fecha.value='';
}else{
if(valor[1]>12 || valor[1]<1){
alert("Mes incorrecto");
input_fecha.value='';
}else{
if (valor[1]== 2 || valor[1]== 4 || valor[1]== 6 || valor[1]== 9 || valor[1]== 11){
if(valor[0]>30){
alert("DÃa incorrecto");
input_fecha.value='';
}
}
if(valor[1]== 2){
anio = valor[2]%4;
if(anio!=0 && valor[0]>28){
alert("DÃa incorrecto");
input_fecha.value='';
}else{
if(valor[0]>29){
alert("DÃa incorrecto");
input_fecha.value='';
}
}
}
}
}
}
function validarNumero(numero){
if (!/^([0-9])*$/.test(numero.value)){
alert("El valor " + numero.value + " no es un número");
numero.value='';
}
}
function validarTelefonoMovil(telefono) {
if(!/^6[0-9]{8}$/.test(telefono.value)){
alert("El valor " + telefono.value + " no es correcto");
telefono.value = '';
telefono.focus();
}
}
function validarTelefonoFijo(telefono) {
if(!/^9[0-9]{8}$/.test(telefono.value)){
alert("El valor " + telefono.value + " no es correcto");
telefono.value = '';
telefono.focus();
}
}
function validarEmail(email )
{
var filtro=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (email.value.length == 0 ) return true;
if (filtro.test(email.value))
return true;
else{
alert("Ingrese una dirección de correo válida");
email.value='';
email.focus();
return false;
}
}
Initial URL
Initial Description
Initial Title
Funciones varias JavaScript
Initial Tags
Initial Language
JavaScript