
//****************************************************************************
// MANEJADOR DE EVENTO DE TECLADO
//
// Observaciones: Hay que tener incluidas las Constantes de Teclado 
// "ConstantesTeclas.js" 
// tecla <Enter> para el submit del buscador.
//****************************************************************************


// Otras constantes
var NOMBRE_EVENTO = "keypress";

function handledTeclado(event){
	var evento;
	var objeto;
	var key;
	var formulario;
	var idFormulario;
	if(window.event) { // IE
		key 	= window.event.keyCode;
		evento 	= window.event;
		objeto  = evento.srcElement;
	} else { // Netscape/Firefox/Opera
		key 	= event.which;
		evento 	= event;
		objeto  = evento.target;
	}

	if ( evento.type != NOMBRE_EVENTO )  {
		return true;
	}

	try{
		formulario = "";
		formulario = objeto.form.getAttribute('name');
		idFormulario = objeto.form.getAttribute('id');
	}catch(err){
		formulario = "";
	}
	
	var esBusquedaGestion = (( key == TECLA_ENTER ) && ( idFormulario.match('gestionBuscador')=='gestionBuscador' ));

	var esBusqueda = (( key == TECLA_ENTER ) && ( formulario == 'buscador' ));
	if (( key == TECLA_ENTER ) && ( objeto.name == 'numHabitaciones' )) { esBusqueda = true; }
	if (( key == TECLA_ENTER ) && ( objeto.name == 'lugar' )) { esBusqueda = true; }
	if (( key == TECLA_ENTER ) && ( objeto.name == 'ocupacion' )) { esBusqueda = true; }
	if (( key == TECLA_ENTER ) && ( objeto.name == 'fechaEntrada' )) { esBusqueda = true; }
	if (( key == TECLA_ENTER ) && ( objeto.name == 'fechaSalida' )) { esBusqueda = true; }
	if (( key == TECLA_ENTER ) && ( objeto.name == 'numDias' )) { esBusqueda = true; }

	if ( esBusqueda == true ) {
		mostrar('idBuscando', true); 
		objeto.form.evento.value = 'buscar';
		objeto.form.submit();
		return false;
	}
	
	if ( esBusquedaGestion == true ) {
		objeto.form.evento.value = 'buscar';
		objeto.form.submit();
		return false;
	}
	
	return true;
}
document.onkeypress	= handledTeclado;
