// CALENDARIO
// displayCalendarFor(campo_formulario)
//
// Muestra un calendario para seleccionar una fecha, justo debajo del campo del formulario.
//
// Llamada: 
// <input name="nombre_campo" id="nombre_campo"  size="12" maxlength="10" title="DD/MM/YYYY" READONLY> 
// <a href="#" OnClick="displayCalendarFor('nombre_campo');">
// 		<img src="images/calendario.gif" width=27 height=20 border=0 align="absmiddle">
// </a>
//
//---------------------------------------------------------------------------------------------
	//--Global -------------------------------------------------------
	var fc_ie = false;
	if (document.all) { fc_ie = true; }
	
	var calendars = Array();
	var fc_months = Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
	var globalelement;
	var fc_openCal;

	var fc_calCount = 0;
	
	function getCalendar(fieldId) {
		return calendars[fieldId];
	}
	
	function displayCalendarFor(fieldId) {
		var formElement = fc_getObj(fieldId);
		globalelement = formElement;
		displayCalendar(formElement);
	}
	
	function displayCalendar(formElement) {
		if (!formElement.id) {
			formElement.id = fc_calCount++;
		} 
		var cal = calendars[formElement.id];
		if (typeof(cal) == 'undefined') {
			cal = new floobleCalendar();
			cal.setElement(formElement);
			calendars[formElement.id] = cal;
		}
		if (cal.shown) {
			cal.hide();
		} else {
			cal.show();
		}
	}
	
	function display3FieldCalendar(me, de, ye) {
		if (!me.id) { me.id = fc_calCount++; }
		if (!de.id) { de.id = fc_calCount++; }
		if (!ye.id) { ye.id = fc_calCount++; }
		var id = me.id + '-' + de.id + '-' + ye.id;
		var cal = calendars[id];
		if (typeof(cal) == 'undefined') {
			cal = new floobleCalendar();
			cal.setElements(me, de, ye);
			calendars[id] = cal;
		}
		if (cal.shown) {
			cal.hide();
		} else {
			cal.show();
		}
	}

	//--Class Stuff--------------------------------------------------
	function floobleCalendar() {
		// Define Methods
		this.setElement = fc_setElement;
		this.setElements = fc_setElements;
		this.parseDate = fc_parseDate;
		this.generateHTML = fc_generateHTML;
		this.show = fc_show;
		this.hide = fc_hide;
		this.moveMonth = fc_moveMonth;
		this.setDate = fc_setDate;
		this.formatDate = fc_formatDate;
		this.setDateFields = fc_setDateFields;
		this.parseDateFields = fc_parseDateFields;
		
		this.shown = false;
	}
	
	function fc_setElement(formElement) {
		this.element = formElement;
		this.format = this.element.title;
		this.value = this.element.value;
		this.id = this.element.id;
		this.mode = 1;
	}
	
	function fc_setElements(monthElement, dayElement, yearElement) {
		this.mElement = monthElement;
		this.dElement = dayElement;
		this.yElement = yearElement;
		this.id = this.mElement.id + '-' + this.dElement.id + '-' + this.yElement.id;
		this.element = this.mElement;
		if (fc_absoluteOffsetLeft(this.dElement) < fc_absoluteOffsetLeft(this.element)) {
			this.element = this.dElement;
		}
		if (fc_absoluteOffsetLeft(this.yElement) < fc_absoluteOffsetLeft(this.element)) {
			this.element = this.yElement;
		}
		if (fc_absoluteOffsetTop(this.mElement) > fc_absoluteOffsetTop(this.element)) {
			this.element = this.mElement;
		}
		if (fc_absoluteOffsetTop(this.dElement) > fc_absoluteOffsetTop(this.element)) {
			this.element = this.dElement;
		}
		if (fc_absoluteOffsetTop(this.yElement) > fc_absoluteOffsetTop(this.element)) {
			this.element = this.yElement;
		}

		this.mode = 2;
	}
	
	function fc_parseDate() {
		if (this.element.value) {
			this.date = new Date();
			var out = '';
			var token = '';
			var lastCh, ch;
			var start = 0;
			lastCh = this.format.substring(0, 1);
			for (i = 0; i < this.format.length; i++) {
				ch = this.format.substring(i, i+1);
				if (ch == lastCh) { 
					token += ch;
				} else {
					fc_parseToken(this.date, token, this.element.value, start);
					start += token.length;
					token = ch;
				}
				lastCh = ch;
			}
			fc_parseToken(this.date, token, this.element.value, start);

		} else {
			this.date = new Date();
		}
		if ('' + this.date.getMonth() == 'NaN') {
			this.date = new Date();
		}
	}	
	
	function fc_parseDateFields() {
		this.date = new Date();
		if (this.mElement.value) this.date.setMonth(fc_getFieldValue(this.mElement) - 1);
		if (this.dElement.value) this.date.setDate(fc_getFieldValue(this.dElement));
		if (this.yElement.value) this.date.setFullYear(fc_getFieldValue(this.yElement));
		if ('' + this.date.getMonth() == 'NaN') {
			this.date = new Date();
		}
	}
	
	function fc_setDate(d, m, y) {
		this.date.setYear(y);
		this.date.setMonth(m);
		this.date.setDate(d);
		if (this.mode == 1) {
			//alert(globalelement.id);
			globalelement.value = this.formatDate();
			//this.element.value = this.formatDate(); 
			//document.getElementById("antiguedad").value = this.formatDate();
		} else {
			this.setDateFields();
		}
		this.hide();
	}
	
	function fc_setDateFields() {
		fc_setFieldValue(this.mElement, fc_zeroPad(this.date.getMonth() + 1));
		fc_setFieldValue(this.dElement, fc_zeroPad(this.date.getDate()));
		fc_setFieldValue(this.yElement, this.date.getFullYear());
	}
	
	function fc_formatDate() {
		var out = '';
		var token = '';
		var lastCh, ch;
		lastCh = this.format.substring(0, 1);
		for (i = 0; i < this.format.length; i++) {
			ch = this.format.substring(i, i+1);
			if (ch == lastCh) { 
				token += ch;
			} else {
				out += fc_formatToken(this.date, token);
				token = ch;
			}
			lastCh = ch;
		}
		out += fc_formatToken(this.date, token);
		return out;
	}
	
	function fc_show() {
		if (typeof(fc_openCal) != 'undefined') { fc_openCal.hide(); }
	
		if (this.mode == 1) {
			this.parseDate();
		} else {
			this.parseDateFields();
		}
		this.showDate = new Date(this.date.getTime());
		if (typeof(this.div) != 'undefined') {
			this.div.innerHTML = this.generateHTML();
		}
		
		if (typeof(this.div) == 'undefined') {
			this.div = document.createElement('DIV');
			this.div.style.position = 'absolute';
			this.div.style.display = 'none';
			this.div.className = 'fc_main';
			this.div.innerHTML = this.generateHTML();
			this.div.style.left = fc_absoluteOffsetLeft(this.element) + "px";
			this.div.style.top = fc_absoluteOffsetTop(this.element) + this.element.offsetHeight + 1 + "px";
			document.body.appendChild(this.div);
		}
		this.div.style.display = 'block';
		this.shown = true;
		fc_openCal = this;
	}
	
	function fc_generateHTML() {
		var html = '<TABLE><TR><TD CLASS="fc_head" COLSPAN="6"><DIV STYLE="float: right"></DIV>Seleccione una fecha:</TD><TD CLASS="fc_date" onMouseover="this.className = \'fc_dateHover\';" onMouseout="this.className=\'fc_date\';" onClick="getCalendar(\'' + this.id + '\').hide();"><B>X</B></TD></TR>';
		html += '<TR><TD CLASS="fc_date" onMouseover="this.className = \'fc_dateHover\';" onMouseout="this.className=\'fc_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(-12);"><B>&lt;&lt;</B></TD><TD CLASS="fc_date" onMouseover="this.className = \'fc_dateHover\';" onMouseout="this.className=\'fc_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(-1);"><B>&lt;</B></TD><TD COLSPAN="3" CLASS="fc_wk">' + fc_months[this.showDate.getMonth()] + ' ' + fc_getYear(this.showDate) + '</TD><TD CLASS="fc_date" onMouseover="this.className = \'fc_dateHover\';" onMouseout="this.className=\'fc_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(1);"><B>&gt;</B></TD><TD CLASS="fc_date" onMouseover="this.className = \'fc_dateHover\';" onMouseout="this.className=\'fc_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(12);"><B>&gt;&gt;</B></TD></TR>';
		html += '<TR><TD WIDTH="14%" CLASS="fc_wk">Lun</TD><TD WIDTH="14%" CLASS="fc_wk">Mar</TD><TD WIDTH="14%" CLASS="fc_wk">Mie</TD><TD WIDTH="14%" CLASS="fc_wk">Jue</TD><TD WIDTH="14%" CLASS="fc_wk">Vie</TD><TD class="fc_wknd" WIDTH="14%">Sab</TD><TD class="fc_wknd" WIDTH="14%">Dom</TD></TR>';
		html += '<TR>';
		var dow = 0;
		var i, style;
		var totald = fc_monthLength(this.showDate);
		for (i = 0; i < fc_firstDOW(this.showDate); i++) {
			dow++;
			html += '<TD>&nbsp;</TD>';
		}
		for (i = 1; i <= totald; i++) {
			if (dow == 0) { html += '<TR>'; }
			if (this.showDate.getMonth() == this.date.getMonth() && this.showDate.getYear() == this.date.getYear() && this.date.getDate() == i) { 
				style = ' style="font-weight: bold;"';
			} else {
				style = '';
			}
			html += '<TD CLASS="fc_date" onMouseover="this.className = \'fc_dateHover\';" onMouseout="this.className=\'fc_date\';" onClick="getCalendar(\'' + this.id + '\').setDate(' + i + ', ' + this.showDate.getMonth() + ', ' + this.showDate.getFullYear() + ');" ' + style + '>' + i + '</TD>';
			dow++;
			if (dow == 7) {
				html += '</TR>';
				dow = 0;
			}
		}
		if (dow != 0) {
			for (i = dow; i < 7; i++) {
				html += '<TD>&nbsp;</TD>';
			}
		}
		html +='</TR>';
		html += '</TABLE>';
		return html;
	}
	
	function fc_hide() {
		if (this.div != false) {
			this.div.style.display = 'none';
		}
		this.shown = false;
		fc_openCal = undefined;
	}
	
	function fc_moveMonth(amount) {
		var m = this.showDate.getMonth();
		var y = fc_getYear(this.showDate);
		if (amount == 1)  {
			if (m == 11)  {
				this.showDate.setMonth(0);
				this.showDate.setYear(y + 1);
			} else {
				this.showDate.setMonth(m + 1);
			}
		} else if (amount == -1)  {
			if (m == 0)  {
				this.showDate.setMonth(11);
				this.showDate.setYear(y - 1);
			} else {
				this.showDate.setMonth(m - 1);
			}
		} else if (amount == 12) {
			this.showDate.setYear(y + 1);
		} else if (amount == -12) {
			this.showDate.setYear(y - 1);
		}
		this.div.innerHTML = this.generateHTML();
	}
	
	//--Utils-------------------------------------------------------------
	function fc_absoluteOffsetTop(obj) {
     	var top = obj.offsetTop;
	/* alert(top); */
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
     		top += parent.offsetTop;
		/* alert(top); */
     		parent = parent.offsetParent;
     	}
	/* alert(top); */
     	return top;
     }
     
     function fc_absoluteOffsetLeft(obj) {
     	var left = obj.offsetLeft;
	/* alert(left); */
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
     		left += parent.offsetLeft;
		/* alert(left); */
     		parent = parent.offsetParent;
     	}
	/* alert(left); */
     	return left;
     }
     
     function fc_firstDOW(date) {
     	var dow = date.getDay();
     	var day = date.getDate();
 		if (day % 7 == 0) return dow;
     	return (7 + dow - (day % 7)) % 7; 
     }
     
     function fc_getYear(date) {
     	var y = date.getYear();
     	if (y > 1900) return y;
     	return 1900 + y;
     }
     
     function fc_monthLength(date) {
		var month = date.getMonth();
		var totald = 30;
		if (month == 0 
			|| month == 2
			|| month == 4
			|| month == 6
			|| month == 7
			|| month == 9
			|| month == 11) totald = 31;
		if (month == 1) {
			var year = date.getYear();
			if (year % 4 == 0 && (year % 400 == 0 || year % 100 != 0))
		 		totald = 29;
			else
				totald = 28;
		}
		return totald;
     }
     
     function fc_formatToken(date, token) {
		var command = token.substring(0, 1);
		if (command == 'y' || command == 'Y') {
			if (token.length == 2) { return fc_zeroPad(date.getFullYear() % 100); }
			if (token.length == 4) { return date.getFullYear(); } 
		}
		if (command == 'd' || command == 'D') {
			if (token.length == 2) { return fc_zeroPad(date.getDate()); }
		}
		if (command == 'm' || command == 'M') {
			if (token.length == 2) { return fc_zeroPad(date.getMonth() + 1); }
			if (token.length == 3) { return fc_months[date.getMonth()]; } 
		}
		return token;
     }
     
     function fc_parseToken(date, token, value, start) {
		var command = token.substring(0, 1);
		var v;
		if (command == 'y' || command == 'Y') {
			if (token.length == 2) { 
				v = value.substring(start, start + 2);
				if (v < 70) { date.setFullYear(2000 + parseInt(v)); } else { date.setFullYear(1900 + parseInt(v)); } 
			}
			if (token.length == 4) { v = value.substring(start, start + 4); date.setFullYear(v);} 
		}
		if (command == 'd' || command == 'D') {
			if (token.length == 2) { v = value.substring(start, start + 2); date.setDate(v); }
		}
		if (command == 'm' || command == 'M') {
			if (token.length == 2) { v = value.substring(start, start + 2); date.setMonth(v - 1); }
			if (token.length == 3) { 
				v = value.substring(start, start + 3);
				var i;
				for (i = 0; i < fc_months.length; i++) {
					if (fc_months[i].toUpperCase() == v.toUpperCase()) { date.setMonth(i); }
				}
			} 
		}
     }
     
     function fc_zeroPad(num) {
		if (num < 10) { return '0' + num; }
		return num;
     }

	function fc_getObj(id) {
		if (fc_ie) { return document.all[id]; } 
		else { return document.getElementById(id);	}
	}

      function fc_setFieldValue(field, value) {
                if (field.type.substring(0,6) == 'select') {
                        var i;
                        for (i = 0; i < field.options.length; i++) {
                                if (fc_equals(field.options[i].value, value)) {
                                        field.selectedIndex = i;
                                }
                        }
                } else {
                        field.value = value;
                }
      }

      function fc_getFieldValue(field) {
                if (field.type.substring(0,6) == 'select') {
                        return field.options[field.selectedIndex].value;
                } else {
                        return field.value;
                }
      }
      
      function fc_equals(val1, val2) {
      		if (val1 == val2) return true;      		
      		if (1 * val1 == 1 * val2) return true;
      		return false;
      }

// ----------------------------------------------------------------------
//           validaform.js 
// ----------------------------------------------------------------------
// Rutinas para verificacion campos de formularios.
//
// isAlphabetic(string) Retorna verdadero si y solo sí el contenido de string sólo está compuesto por // letras (mayúsculas o minúsculas, caracteres españoles incluídos)
//
// isAlphanumeric(string) Retorna verdadero si y solo sí el contenido de string sólo está compuesto
// por letras (mayúsculas o minúsculas, caracteres españoles incluídos) o número
//
// isName(string) Retorna verdadero si y solo sí el contenido de string sólo está compuesto por letras
// (mayúsculas o minúsculas, caracteres españoles incluídos), números o espacios en blanco
//
// isInteger(string) Retorna verdadero si y solo sí el contenido de string representa un número 
// entero, con o sin signo
//
// isNumber(string) Retorna verdadero si y solo sí el contenido de string representa un número entero 
// o decimal, con o sin signo
//
// isEmail(string) Retorna verdadero si y solo sí el contenido de string tiene la forma de una 
// dirección de correo electrónica válida
//
// isPhoneNumber(string) Retorna verdadero si y solo sí el contenido de string tiene la forma de un 
// número de teléfono válido (se aceptan números, paréntesis, guiones y espacios)
//
// isColor(string) Retorna verdadero si y solo sí el contenido de string tiene la forma de un 
// valor de color valido (numeros o letras A a F) 
//
// isFecha(string) Retorna verdadero si y solo sí el contenido de string tiene la forma de un 
// valor de fecha valido (numeros o /-) y es una fecha valida 
//
// isHora(string) Retorna verdadero si y solo sí el contenido de string tiene la forma de un 
// valor de hora valido (numeros o :) y es una hora valida 
//
// isRadio(formulario,campo) Retorna verdadero si y solo sí se ha seleccionado una de las opciones
//
// ---------------------------------------------------------------------- 

var defaultEmptyOK = false
var checkNiceness = false;
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñüâêîôû_-"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑÂÊÎÔÛ_-"
var whitespace = " \t\n\rºª:.,;\\";
var phoneChars = "()-+ ";
var colores = "abcdefABCDEF#";
var horas = ":";
var fechaChars = "/";
var mMessage = "Error: no puede dejar campos obligatorios vacios."
var pPrompt = "Error: ";
var pAlphanumeric = "Introduzca un texto que contenga solo letras y/o numeros";
var pAlphabetic   = "Introduzca un texto que contenga solo letras, sin espacios";
var pInteger = "Introduzca un numero entero";
var pNumber = "Introduzca un numero";
var pPhoneNumber = "Introduzca un número de teléfono";
var pEmail = "Introduzca una dirección de correo electrónico válida";
var pName = "Introduzca un texto que contenga solo letras, numeros o espacios";
var pColor = "Introduzca un color hexadecimal valido sólo numeros y letras (a/A - f/F)";
var pFecha = "Introduzca una fecha valida y con formato (dd/mm/aaaa o dd-mm-aaaa)";
var pHora = "Introduzca una hora valida y con el formato indicado (HH:MM) ó (HH:MM:SS)";
var pLibre = "Introduzca un texto a su elección sin restricciones";
var pRadio = "Debe seleccionar una de las opciones";
var pCheckBox = "Debe marcar la casilla";
var pNice = "No puede utilizar comillas aqui";

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;
    if (isEmpty(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;
}


function stripCharsInBag (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;
}


function stripCharsNotInBag (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;
}


function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

function isLetterColor (c)
{
    return( colores.indexOf( c ) != -1 ) 
}

function isLetterHora (c)
{
    return( horas.indexOf( c ) != -1 ) 
}

function isCharFecha (c)
{
    return( fechaChars.indexOf( c ) != -1 ) 
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}


function isNumber (s)
{   var i;
    var dotAppeared;
    dotAppeared = false;
    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isNumber.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 (!isDigit(c)) return false;
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

function isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    return true;
}


function isName (s)
{
    if (isEmpty(s)) 
       if (isName.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    
    return( isAlphanumeric( stripCharsInBag( s, whitespace ) ) );
}

function isPhoneNumber (s)
{   var modString;
    if (isEmpty(s)) 
       if (isPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isPhoneNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    return (isInteger(modString))
}

function isEmail (s)
{
    if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isColor (s)
{   var i;

    if (isEmpty(s)) 
       if (isColor.arguments.length == 1) return defaultEmptyOK;
       else return (isColor.arguments[1] == true);

	if (document.getElementById('isColor.arguments[1]').selectedIndex==0)
	{
		return false;
	}	
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetterColor(c) || isDigit(c) ) )
        return false;
    }

    return true;
}

function isHora (s)
{   var i;

	if (isEmpty(s)) 
       if (isHora.arguments.length == 1) return defaultEmptyOK;
       else return (isHora.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetterHora(c) || isDigit(c) ) )
        return false;
    }
	
	hora=s;
	if (hora.length>5) {
		alert("Introdujo una cadena mayor a 5 caracteres");
		return false;
	}
	if (hora.length!=5) {
		alert("Introducir HH:MM");
		return false;
	}
	a=hora.charAt(0) //<=2
	b=hora.charAt(1) //<4
	c=hora.charAt(2) //:
	d=hora.charAt(3) //<=5
	if ((a==2 && b>3) || (a>2)) {
		alert("El valor que introdujo en la Hora no corresponde, introduzca un digito entre 00 y 23");
		return false;
	}
	if (d>5) {
		alert("El valor que introdujo en los minutos no corresponde, introduzca un digito entre 00 y 59");
		return false;
	}
	if (c!=':') {
		alert("Introduzca el caracter ':' para separar la hora y los minutos");
		return false;
	}
  
  return true;
}


function isLibre (s)
{   var i;

    if (isEmpty(s)) 
       if (isColor.arguments.length == 1) return defaultEmptyOK;
       else return (isColor.arguments[1] == true);

    return true;
}

function isFecha (s)
{   var i;

    if (isEmpty(s)) 
       if (isFecha.arguments.length == 1) return defaultEmptyOK;
       else return (isFecha.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isCharFecha(c) || isDigit(c) ) )
        return false;
    }

	return true;
}

function isNice(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;
}

function statBar (s)
{   window.status = s
}

function warnEmpty (theField)
{   theField.focus()
    alert(mMessage)
    statBar(mMessage)
    return false
}

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    statBar(pPrompt + s)
    return false
}

function checkField (theField, theFunction, emptyOK, s)
{   
	var msg;
	
    if (checkField.arguments.length < 3) emptyOK = defaultEmptyOK;
    if (checkField.arguments.length == 4) {
        msg = s;
    } else {
        if( theFunction == isAlphabetic ) msg = pAlphabetic;
        if( theFunction == isAlphanumeric ) msg = pAlphanumeric;
        if( theFunction == isInteger ) msg = pInteger;
        if( theFunction == isNumber ) msg = pNumber;
        if( theFunction == isEmail ) msg = pEmail;
        if( theFunction == isPhoneNumber ) msg = pPhoneNumber;
        if( theFunction == isName ) msg = pName;
		if( theFunction == isColor ) msg = pColor;
		if( theFunction == isFecha ) msg = pFecha;
		if( theFunction == isLibre ) msg = pLibre;
		if( theFunction == isHora ) msg = pHora;
    }
	
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

    if ((emptyOK == false) && (isEmpty(theField.value))) 
       	return warnEmpty(theField);

    if (checkNiceness && !isNice(theField.value))
    	return warnInvalid(theField, pNice);

	if (theFunction(theField.value) == true) 
        return true;
    else
       	return warnInvalid(theField,msg);
}

function validarBotonRadio(f,c,msg) {
	var marcado = "no";
	
	with (f) {
		for ( var i = 0; i < c.length; i++ ) {
			if ( c[i].checked ) {
				return true;
			}
		}
		if ( marcado == "no" ){
			alert(msg) ;
			return false;
		}
	}
}

function validarCheckBox(f,c,msg) {
	var marcado = "no";
	
	with (f) {
		if ( c.checked ) {
			return true;
		}
		if ( marcado == "no" ){
			alert(msg) ;
			return false;
		}
	}
}

function validarLista(f,c,msg) {
	var marcado = "no";
	
	if (c.selectedIndex > 0) {
		return true;
	}

	if ( marcado == "no" ){
		alert(msg) ;
		return false;
	}
}

function validarPassword(f,c1,c2,msg) {
	
	clave1=c1.value;
	clave2=c2.value;
	
	if (clave1 != clave2 ) {
		alert(msg);
		c1.focus()
    	c1.select()
		return false;
	} else {
			
		return true;
	} 
}

// Validación ACCESO COLEGIADO
function valida_faccesocolegiado () {
	if( checkField( document.faccesocolegiado.user, isLibre, false ) &&  
		checkField( document.faccesocolegiado.pass, isLibre, false )) {
			return true;
		} else {
			return false;
		}
}

// Validación ACCESO JUNTA GOBIERNO
function valida_faccesojunta () {
	if( checkField( document.faccesojunta.user, isLibre, false ) &&  
		checkField( document.faccesojunta.pass, isLibre, false )) {
			return true;
		} else {
			return false;
		}
}

// Validación SUBIR DOC JUNTA GOBIERNO
function valida_fsubirdoc () {
	if( checkField( document.fsubirdoc.titulo, isLibre, false ) &&  
		checkField( document.fsubirdoc.archivo, isLibre, false )) {
			return true;
		} else {
			return false;
		}
}

// Validación BUSCADOR AGENTES PORTADA
function valida_fbuscagentes () {
	if( validarBotonRadio( document.fbuscagentes,document.fbuscagentes.buscapor,"Debe seleccionar si quiere buscar por agente o por agencia." ) &&  
		checkField( document.fbuscagentes.nombre, isLibre, false )) {
			return true;
		} else {
			return false;
		}
}


// Validación EMAIL CONTRASEÑA NUEVA
function valida_femailpassnueva () {
	if( checkField( document.femailpassnueva.email, isEmail, false )) {
			return true;
		} else {
			return false;
		}
}

<!-- Pop up de confimación de borrado GENERAL -->
function preguntar(nom_formulario,msg) { 
	confirmar=confirm(msg); 
	if (confirmar) {
	//Aquí pones lo que quieras si da a Aceptar 
		document.forms[nom_formulario].submit()
	} 
}
<!-- End Pop up de confimación de borrado -->
