<!-- Begin
// ---------------------------------------------------------------------- //
//                                VARIABLES                               //
// ---------------------------------------------------------------------- //

// Esta variable indica si está bien dejar las casillas
// en blanco como regla general
var defaultEmptyOK = false

// Esta variable indica si se debe verificar la presencia de comillas
// u otros símbolos extraños en un campo, por omisión no, porque
// siempre crea problemas con las bases de datos o programas CGI
var checkNiceness = true;

// listas de caracteres
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnñopqrstuvwxyzáéíóúñüàèòù"
var uppercaseLetters = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÑÀÈÒÙ"
var letrasDNI="TRWAGMYFPDXBNJZSQVHLCKE";
var simbols = ":/\@=&¿?¡!|_-+.,()ºª;"
var simbolsext = ':/\@=&¿?¡!|_-+.,()ºª";'
var whitespace = " \t\n\r";

// caracteres admitidos en nos de telefono
var phoneChars = "()-+ ";

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

// ---------------------------------------------------------------------- //
//                     TEXTOS PARA LOS MENSAJES                           //
// ---------------------------------------------------------------------- //

// m abrevia "missing" (faltante)
var mMessage = "Error: no puede dejar este espacio vacio"

// p abrevia "prompt"
var pPrompt = "Error: ";
var pAlphanumeric = "introduzca un texto que contenga solo letras y/o números";
var pAlphabetic   = "introduzca un texto que contenga solo letras";
var pInteger = "introduzca un número entero";
var pNumber = "introduzca un número";
var pPhoneNumber = "introduzca un número de teléfono válido";
var pEmail = "introduzca una dirección de correo electrónico válida";
var pName = "introduzca un texto que contenga solo letras, números o espacios";
var pNice = "no puede utilizar comillas aqui";
var pCP = "introduzca un código postal";
var pDireccionWeb = "introduzca una dirección web";
var pFecha = "introduzca una fecha correcta";
var pDNI = "introduzca un DNI o pasaporte válido";

// ---------------------------------------------------------------------- //
//                  CODIGO PARA FUNCIONES BASICAS                         //
// ---------------------------------------------------------------------- //


// s es vacio
function esVacio(s)
{   return ((s == null) || (s.length == 0))
}

// s es vacio o solo caracteres de espacio
function esEspacioEnBlanco (s)
{   var i;
    if (esVacio(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

// Quita todos los caracteres que que estan en "bag" del string "s" s.
function quitarCarEnBolsa (s, bag)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Lo contrario, quitar todos los caracteres que no estan en "bag" de "s"
function quitarCarNoEnBolsa (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

// Quitar todos los espacios en blanco de un string
function quitarEspacioBlanco (s)
{   return quitarCarEnBolsa (s, whitespace)
}

// La rutina siguiente es para cubrir un bug en Netscape
// 2.0.2 - seria mejor usar indexOf, pero si se hace
// asi quitarEspacioBlancoIni() no funcionaria

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

// Quita todos los espacios que antecedan al string
function quitarEspacioBlancoIni (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

// c es una letra del alfabeto espanol
function esLetra (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}


// c es una simbolo
function esSimbolo (c)
{
    return ( simbols.indexOf( c ) != -1 )
}

// c es un simbolo extendido
function esSimboloExt (c)
{
    return ( simbolsext.indexOf( c ) != -1 )
}

// c es un digito
function esDigito (c)
{   return ((c >= "0") && (c <= "9"))
}

// c es letra o digito
function esLetraODigito (c)
{   return (esLetra(c) || esDigito(c))
}

// ---------------------------------------------------------------------- //
//                          NUMEROS                                       //
// ---------------------------------------------------------------------- //

// s es un numero entero (con o sin signo)
function esEntero (s)
{   var i;
    if (esVacio(s)) 
       if (esEntero.arguments.length == 1) return defaultEmptyOK;
       else return (esEntero.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!esDigito(c)) return false;
        } else { 
            if (!esDigito(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

// s es un numero (entero o flotante, con o sin signo)
function esNumero (s)
{   var i;
    var dotAppeared;
    dotAppeared = false;
    if (esVacio(s)) 
       if (esNumero.arguments.length == 1) return defaultEmptyOK;
       else return (esNumero.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!esDigito(c)) return false;
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!esDigito(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

// ---------------------------------------------------------------------- //
//                        STRINGS SIMPLES                                 //
// ---------------------------------------------------------------------- //

// s tiene solo letras
function esAlfabetico (s)
{   var i;

    if (esVacio(s)) 
       if (esAlfabetico.arguments.length == 1) return defaultEmptyOK;
       else return (esAlfabetico.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!esLetra(c))
        return false;
    }
    return true;
}


// s tiene solo letras y numeros y simbolos
function esAlfanumerico (s)
{   var i;

    if (esVacio(s)) 
       if (esAlfanumerico.arguments.length == 1) return defaultEmptyOK;
       else return (esAlfanumerico.arguments[1] == true);

    s = quitarCarEnBolsa( s, whitespace )
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (esLetra(c) || esDigito(c) || esSimbolo(c)) )
        return false;
    }

    return true;
}

function esAlfanumericoLimpio (s)
{   var i;

    if (esVacio(s)) 
       if (esAlfanumerico.arguments.length == 1) return defaultEmptyOK;
       else return (esAlfanumerico.arguments[1] == true);

    s = quitarCarEnBolsa( s, whitespace )
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (esLetra(c) || esDigito(c)) )
        return false;
    }

    return true;
}
// s tiene solo letras y numeros y simbolos extendidos
function esAlfanumericoExt (s)
{   var i;

    if (esVacio(s)) 
       if (esAlfanumerico.arguments.length == 1) return defaultEmptyOK;
       else return (esAlfanumerico.arguments[1] == true);

    s = quitarCarEnBolsa( s, whitespace )
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (esLetra(c) || esDigito(c) || esSimboloExt(c)) )
        return false;
    }

    return true;
}

// s tiene solo letras, numeros o espacios en blanco
function esNombre (s)
{
    if (esVacio(s)) 
       if (esNombre.arguments.length == 1) return defaultEmptyOK;
       else return (esNombre.arguments[1] == true);
    
    return( esAlfanumerico( quitarCarEnBolsa( s, whitespace ) ) );
}

// s tiene solo letras, numeros o espacios en blanco
function esDireccionWeb (s)
{
    if (esVacio(s)) 
       if (esNombre.arguments.length == 1) return defaultEmptyOK;
       else return (esDireccionWeb.arguments[1] == true);

    if (s.length < 10)
		return false;
	var http = s.substr(0,7);
	http = http.toUpperCase()
	if (http != "HTTP://")
		return false;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);			
        if (! (esLetra(c) || esDigito(c) || esSimbolo(c)) )
        return false;
    }

    return true;
}

// ---------------------------------------------------------------------- //
//                           FONO o EMAIL o CP                            //
// ---------------------------------------------------------------------- //

// s es numero mas letra de nif valida (añadido por Kike)
function esNIF(s) {
	// Si es >=12, es pasaporte, que es alfanumerico
	if (s.length>=12) 
		return esAlfanumerico(s);
	// Si no, comprobar si es un nif valido
	var letra;
	var numero,resto;
	letra=s.charAt(s.length-1);
	letra=letra.toUpperCase();
	numero=s.substr(0,s.length-1);
	if(esEntero(numero)) {
		// comprobar la validez de la letra
		numero=parseInt(numero);
		resto=numero%23;
		if(letra==letrasDNI.charAt(resto))
			return true;
		else 
			return false		
	} else {
		return false;
	}
}

// s es numero de Codigo Postal valido
function esCP (s)
{   
    if (esVacio(s)) 
       if (esCP.arguments.length == 1) return defaultEmptyOK;
       else return (esCP.arguments[1] == true);

    if (s.length != 5) return false;
 
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!esDigito(c)) return false;
        } 
    }
    return true;
}

// s es numero de telefono valido
function esTelefono (s)
{   var modString;

    if (esVacio(s)) 
       if (esTelefono.arguments.length == 1) return defaultEmptyOK;
       else return (esTelefono.arguments[1] == true);
    modString = quitarCarEnBolsa( s, phoneChars );
	//modificado por domingo
	if(modString.length>=9)
	    return (esEntero(modString));
	else
		return false;
}

// s es una direccion de correo valida
function esEmail (s)
{
    if (esVacio(s)) 
       if (esEmail.arguments.length == 1) return defaultEmptyOK;
      	else return (esEmail.arguments[1] == true);
    if (esEspacioEnBlanco(s)) return false;
    var i = 0;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { 
		if(esAlfanumerico(s.charAt(i)))
			i++
		else
			return false;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { 
		if(esAlfanumerico(s.charAt(i)))
			i++
		else
			return false;
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else
	{
	    while ((i < sLength))
    	{ 
			if(esAlfanumerico(s.charAt(i)))
				i++
			else
				return false;
	    }
	}
	return true;
}

function esBonito(s)
{
        var i = 1;
        var sLength = s.length;
        var b = 1;
        while(i<sLength) {
                if( (s.charAt(i) == "\"") || (s.charAt(i) == "'" ) ) b = 0;
                i++;
        }
        return b;
}

// ---------------------------------------------------------------------- //
//                           FECHA                                        //
// ---------------------------------------------------------------------- //

function esAnyo (s)
{   if (esVacio(s)) 
       if (esAnyo.arguments.length == 1) return defaultEmptyOK;
       else return (esAnyo.arguments[1] == true);

    if (!esEntero(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function esMes (s)
{   if (esVacio(s)) 
       if (esMes.arguments.length == 1) return defaultEmptyOK;
       else return (esMes.arguments[1] == true);
    return ((s >= 1) && (s <= 12))
}



// esDia (STRING s [, BOOLEAN emptyOK])
// 
// esDia returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function esDia (s)
{   if (esVacio(s)) 
       if (esDia.arguments.length == 1) return defaultEmptyOK;
       else return (esDia.arguments[1] == true);   
    return ((s >= 1) && (s <= 31))
}



// diasEnFebrero (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function diasEnFebrero (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}



// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 

function esFecha (day,month,year)
{   

    // catch invalid years (not 2- or 4-digit) and invalid months and days.

    if (! (esAnyo(year, false) && esMes(month, false) && esDia(day, false))) {
		return false;
	}
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth])  {
	 return false; 
	}

    if ((intMonth == 2) && (intDay > diasEnFebrero(intYear))) return false;

    return true;
}

function esFechaJunta (fecha)
{
	var ArrayFecha=fecha.split("/");
	var intTamanyo=ArrayFecha.length;
	if(intTamanyo!=3) return false;
	
	var intYear=ArrayFecha[2];
	var intMonth=ArrayFecha[1];
	var intDay=ArrayFecha[0];
	if (intYear=='aaaa'&&intMonth=='mm'&&intDay=='dd'){
	return true;
	
	} else if (!esFecha(intDay,intMonth,intYear)) return false;
	
	return true;
}

	

// ---------------------------------------------------------------------- //
//                  FUNCIONES PARA RECLAMARLE AL USUARIO                  //
// ---------------------------------------------------------------------- //

// pone el string s en la barra de estado
function estadoBarra (s)
{   window.status = s
}

// notificar que el campo theField esta vacio
function warningVacio (theField)
{   theField.focus()
    alert(mMessage)
    estadoBarra(mMessage)
    return false
}

// notificar que el campo theField es invalido
function warningInvalido (theField, s)
{   theField.focus()
    
    alert(s)
    theField.select()
    estadoBarra(pPrompt + s)
    return false
}

// el corazon de todo: checkCampo
function checkCampo (theField, theFunction, emptyOK, s)
{   
    var msg;
    if (checkCampo.arguments.length < 3) emptyOK = defaultEmptyOK;
    if (checkCampo.arguments.length == 4) {
        msg = s;
    } else {
        if( theFunction == esAlfabetico ) msg = pAlphabetic;
		if( theFunction == esAlfanumericoLimpio ) msg = pAlphanumeric;
        if( theFunction == esAlfanumerico ) msg = pAlphanumeric;
        if( theFunction == esAlfanumericoExt ) {
			msg = pAlphanumeric;
			checkNiceness=false;
		}
        if( theFunction == esEntero ) msg = pInteger;
        if( theFunction == esNumero ) msg = pNumber;
        if( theFunction == esEmail ) msg = pEmail;
        if( theFunction == esTelefono ) msg = pPhoneNumber;
		if( theFunction == esFechaJunta ) msg = pFecha;
        if( theFunction == esNombre ) msg = pName;
		if( theFunction == esCP ) msg = pCP;
		if( theFunction == esDireccionWeb) msg = pDireccionWeb;
		if( theFunction == esNIF) msg=pDNI;
    }

    if ((emptyOK == true) && (esVacio(unescape(theField.value)))) return true;
    
    if (((emptyOK == false) && (esVacio(unescape(theField.value)))) ) 
        return warningVacio(theField);

    if ( (checkNiceness && !esBonito(unescape(theField.value))))
            return warningInvalido(theField, pNice);
    
    if (theFunction(unescape(theField.value)) == true) 
        return true;
    else
        return warningInvalido(theField,msg);

}


function validarPrompt (Ctrl, PromptStr) {
        alert (PromptStr)
        Ctrl.focus();
        return;
}

//-->
