function comprueba_requeridos( formulario ){
	var lista = formulario.requeridos.value;
	var mensaje = "";
	var ok = true;

	var pos = lista.indexOf(",");
	while ( pos != -1 && ok ) {
		var nombre_campo = lista.substring(0, pos);

		//if ( formulario[nombre_campo].type == "text" ){
			if ( formulario[nombre_campo].value == "" ){
				formulario[nombre_campo].focus();
				mensaje = "faltan valores";
				ok = false;
			}
		//} else if ( formulario[nombre_campo].type == "text" ){
		//}
		lista = lista.substr( pos + 1 );
		pos = lista.indexOf(",");
	}
	// Compruebo el último
	if ( lista != "" && ok ){
		if ( formulario[lista].value == "" ){
			formulario[lista].focus();
			mensaje = "faltan valores";
			ok = false;
		}
	}
	return mensaje;
}

//
// Funciona con IE y Mozilla
// Uso: onkeypress="return isNumberKey(event)"
//
function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode
	
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	
	return true;
}

function isNumberCharKey(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode

	// Comprobamos que sea un número
	var esTeclaFunc = (charCode <= 31);
	var esNumero = (charCode >= 48 && charCode <= 57);
	var esLetraMayuscula = (charCode >= 65 && charCode <= 90); 
	var esLetraMinuscula = (charCode >= 97 && charCode <= 122); 
	if ( esTeclaFunc || esNumero || esLetraMayuscula || esLetraMinuscula )
		return true;
	else return false;
}

function isNumberDateKey(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode

	// Comprobamos que sea un número
	var esTeclaFunc = (charCode <= 31);
	var esNumeroFecha = (charCode >= 47 && charCode <= 57);
	if ( esTeclaFunc || esNumeroFecha )
		return true;
	else return false;
}

function recarga_pagina( formulario, pagina ){
	formulario.action = pagina;
	formulario.submit();
}

function genera_lista( formulario, nombre_campo ){
	var lista_temp = ""; 
	var i;
	for ( i = 0; i < formulario.elements.length; i++ ){
		if ( formulario.elements[i].name.substring(0, nombre_campo.length) == nombre_campo ) {
			// Compruebo que está marcado
			if ( formulario.elements[i].checked )
				lista_temp = lista_temp + "," + formulario.elements[i].value;
		}
	}
	if ( lista_temp.length > 1 ) lista_temp = lista_temp.substr( 1 ); 
	else lista_temp = "";
	//alert( lista_temp );
	return lista_temp;
}

function desmarca_hijos( formulario, nombre_campo ){
	var i;
	for ( i = 0; i < formulario.elements.length; i++ ){
		if ( formulario.elements[i].value.substring(0, nombre_campo.length) == nombre_campo ) {
			// Desmarco la casilla
			formulario.elements[i].checked = false;
		}
	}
}

function marca_padres( formulario, nombre_campo ){
	var i;
	for ( i = 0; i < formulario.elements.length; i++ ){
		valor_padre = formulario.elements[i].value;
		pos = valor_padre.indexOf("-");
		if ( pos > -1 )
			valor_padre = valor_padre.substring(0, pos);
		if ( valor_padre.length < nombre_campo.length ){
			if ( nombre_campo.substring(0, valor_padre.length) == valor_padre ) {
				// Marco la casilla
				formulario.elements[i].checked = true;
			}
		}
	}
	
	
}



