// Objeto pregunta
var familia = {
	obtenerTiposHabitacion: function(codigoFamilia, familias) {
		pintarHabitaciones(codigoFamilia.value, familias);
	}
}

var paradorCercano = {
	obtenerTiposHabitacion: function(codigo) {
		if(document.getElementById("reservasParadorPaso2Cercano")){
			var miFormulario = document.getElementById("reservasParadorPaso2Cercano");
			miFormulario.codigoParador.value = codigo.value;
		}
		document.forms["reservasParadorPaso2Cercano"].submit();  
	}
}
var hab = {
	obtenerNumHabitacion: function(idhabitacion,codigos) {
		if(document.getElementById("externaReservasParadorPaso3Form")){
			var miForm = document.getElementById("externaReservasParadorPaso3Form");
			var habitaciones = miForm.habitaciones.value;
			if (habitaciones < comprobarNumHabitacionesSelecciondas()) {
				document.getElementById("idhabitacion"+idhabitacion).value = "0"+codigos;
				alert(errorMasHabParte1 + habitaciones + errorMasHabParte2);
			}
		}
 	}
}

function comprobarNumHabitacionesSelecciondas() {
	var opc = document.getElementsByName("idOpciones");
	var suma = 0;
	for(var x=0; x<opc.length; x++){
		suma += parseInt(opc[x].value.charAt(0)); 
	}
	return suma;
}

/**
 * Validación del formulario
 * 
 * @param formulario  Formulario para validar
 */
function validarExternaReservasParadorPaso3Form(formulario) {
	var sMensaje = "";
	var bFlag = validateExternaReservasParadorPaso3Form(formulario);
	if (bFlag) {
		if(comprobarNumHabitacionesSelecciondas() != formulario.habitaciones.value){
			bFlag = false;
			sMensaje += errorNoSeleccionHab + ".\n";
		} 
		if ((formulario.proteccionDatos.value == 0))	
		{		
			bFlag = false;
			sMensaje += errorProteccionDatos + ".\n";
		}
		if (!bFlag) {
			alert(sMensaje);
		}
	}
	return bFlag;
}
/**
* Función para pintar las habitaciones en función de la familia elegida
*/
function pintarHabitaciones(codigoFamilia, familias) {
	var trozos = familias.split ("_");
	//llego hasta menos un elemento por que el último siempre llegará vacio
	for(var j=0; j<trozos.length-1; j++){
		if (codigoFamilia != trozos[j]) {
			if(document.getElementById(trozos[j])) {
				document.getElementById(trozos[j]).style.display = 'none';
				}
		} else if (codigoFamilia == trozos[j]) {
			if(document.getElementById(trozos[j])) {
				document.getElementById(trozos[j]).style.display = '';
			}
		}
	}
}

function pintarComboCategorias() {
	if(document.getElementById('combocat')) {
		document.getElementById('combocat').className ="combo td50especial";
	}
}

var ie = document.all;
var windowx = 500;
var windowy = 500;

/**
 *  Calcula la posición relativa a la página en FF
 */
function getMouseXY (Event) {
	if (ie) {
		windowx = event.clientX + document.documentElement.scrollLeft;
		windowy = event.clientY + document.documentElement.scrollTop;
	} else {
		windowx = Event.pageX;
		windowy = Event.pageY;
	}
	//return {x:windowx, y:windowy}
}

if (!ie) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmouseover = getMouseXY;
		
//Crea una función con los argumentos para ser llamada desde on mouse over

function crearTooltip(texto){
	if (texto != '') {
		var obj;
		if(!document.getElementById('capa_condiciones_tarifa')) {
			obj = document.createElement('div');
			obj.id = 'capa_condiciones_tarifa';
		} else {
			obj = document.getElementById('capa_condiciones_tarifa');
		}
		obj.style.left = ''+(windowx+20)+'px';
		obj.style.top = ''+(windowy+20)+'px';
		obj.style.width = '400px';
		obj.style.backgroundColor = '#F8F7F3';
		obj.style.border = '1px solid #000';
		obj.style.padding= '5px';
		obj.style.position ='absolute';	
		obj.style.fontSize = '0.7em';
		obj.style.textAlign = 'left';
		obj.innerHTML = texto;
		obj.style.visibility='visible';
		document.body.appendChild(obj);
	}
}

//Hace invisible la capa que contiene las condiciones de la tarifa
function ocultaTooltip(){
	if(document.getElementById('capa_condiciones_tarifa')) {
 		var obj = document.getElementById('capa_condiciones_tarifa');
 		obj.style.visibility='hidden';
 	}
}

