// JavaScript Document

function activar_desactivar(valor){
	switch (valor){
		case 'es_comida':
		var es_comida=document.getElementById('es_comida');
		es_comida.src="imgs/casillaON.gif";
		es_comida.title="Activado";
		var es_cena=document.getElementById('es_cena');
		es_cena.src="imgs/casillaOFF.gif";
		es_cena.title="Desactivado";
		document.getElementById('comida').value=1;
		document.getElementById('horaLlegadaComida').style.display="block";
		document.getElementById('horaLlegadaComida').selectedIndex=2;
		document.getElementById('horaLlegadaCena').style.display="none";
		document.getElementById('minLlegada').selectedIndex="00";
		break;

		case 'es_cena':
		var es_cena=document.getElementById('es_cena');
		var inputcena=document.getElementById('es_cena');
		es_cena.src="imgs/casillaON.gif";
		es_cena.title="Activado";
		var es_comida=document.getElementById('es_comida');
		es_comida.src="imgs/casillaOFF.gif";
		es_comida.title="Desactivado";
		document.getElementById('comida').value=0;
		document.getElementById('horaLlegadaCena').style.display="block";
		document.getElementById('horaLlegadaCena').selectedIndex=1;
		document.getElementById('horaLlegadaComida').style.display="none";
		document.getElementById('minLlegada').selectedIndex="00";
		break;
		
		case 'sifumador':
		var sifumador=document.getElementById('sifumador');
		sifumador.src="imgs/casillaON.gif";
		sifumador.title="Activado";
		var nofumador=document.getElementById('nofumador');
		nofumador.src="imgs/casillaOFF.gif";
		nofumador.title="Desactivado";
		document.getElementById('fumador').value="Fumadores";
		break;
		
		case 'nofumador':
		var nofumador=document.getElementById('nofumador');
		nofumador.src="imgs/casillaON.gif";
		nofumador.title="Activado";
		var sifumador=document.getElementById('sifumador');
		sifumador.src="imgs/casillaOFF.gif";
		sifumador.title="Desactivado";
		document.getElementById('fumador').value="No Fumadores";
		break;
		
		//Activación de los tipos de cocina y caracteristicas.
		default:
		var id=document.getElementById(valor);
		if (document.getElementById("id_"+valor).value==0){
			id.src="imgs/casillaON.gif";
			id.title="Activado";
			document.getElementById("id_"+valor).value=1;
		}else{
			id.src="imgs/casillaOFF.gif";
			id.title="Desactivado";
			document.getElementById("id_"+valor).value=0;
		}
	}
	
}
function activar_desactivar_index(valor){
	switch (valor){
		case 'es_comida':
		var es_comida=document.getElementById('es_comida');
		es_comida.src="imgs/casilla2ON.gif";
		es_comida.title="Activado";
		var es_cena=document.getElementById('es_cena');
		es_cena.src="imgs/casilla2OFF.gif";
		es_cena.title="Desactivado";
		document.getElementById('comida').value=1;
		document.getElementById('horaLlegadaComida').style.display="block";
		document.getElementById('horaLlegadaCena').style.display="none";
		document.getElementById('minLlegada').selectedIndex="00";
		break;

		case 'es_cena':
		var es_cena=document.getElementById('es_cena');
		var inputcena=document.getElementById('es_cena');
		es_cena.src="imgs/casilla2ON.gif";
		es_cena.title="Activado";
		var es_comida=document.getElementById('es_comida');
		es_comida.src="imgs/casilla2OFF.gif";
		es_comida.title="Desactivado";
		document.getElementById('comida').value=0;
		document.getElementById('horaLlegadaCena').style.display="block";
		document.getElementById('horaLlegadaComida').style.display="none";
		document.getElementById('minLlegada').selectedIndex="00";
		break;
		
		case 'sifumador':
		var sifumador=document.getElementById('sifumador');
		sifumador.src="imgs/casilla2ON.gif";
		sifumador.title="Activado";
		var nofumador=document.getElementById('nofumador');
		nofumador.src="imgs/casilla2OFF.gif";
		nofumador.title="Desactivado";
		document.getElementById('fumador').value="Fumadores";
		break;
		
		case 'nofumador':
		var nofumador=document.getElementById('nofumador');
		nofumador.src="imgs/casilla2ON.gif";
		nofumador.title="Activado";
		var sifumador=document.getElementById('sifumador');
		sifumador.src="imgs/casilla2OFF.gif";
		sifumador.title="Desactivado";
		document.getElementById('fumador').value="No Fumadores";
		break;
		
		//Activación de los tipos de cocina y caracteristicas.
		default:
		var id=document.getElementById(valor);
		if (document.getElementById("id_"+valor).value==0){
			id.src="imgs/casilla2ON.gif";
			id.title="Activado";
			document.getElementById("id_"+valor).value=1;
		}else{
			id.src="imgs/casilla2OFF.gif";
			id.title="Desactivado";
			document.getElementById("id_"+valor).value=0;
		}
	}
	
}

function elegirCasillaCiudadela(id,fecha,id_restaurante){
	for(var i=1;i<=7;i++){
		imagen=document.getElementById(i);
		if(imagen!=null){
			imagen.src="imgs/casilla2OFF.gif";
			imagen.title="Desactivado";
			document.getElementById("id_"+i).value=0;
		}
	}
	var imagen1=document.getElementById(id);
	if (document.getElementById("id_"+id).value==0){
		imagen1.src="imgs/casilla2ON.gif";
		imagen1.title="Activado";
		document.getElementById("id_"+id).value=1;
		document.getElementById("fecha").value=fecha;
		document.getElementById("id_restaurante").value=id_restaurante;
	}else{
		imagen1.src="imgs/casilla2OFF.gif";
		imagen1.title="Desactivado";
		document.getElementById("id_"+id).value=0;
	}
		

}

function reservar(id_restaurante,id_fisica,id_capacidad,limiteMax){
	
	document.paso1.id_restaurante.value=id_restaurante;
	document.paso1.id_fisica.value=id_fisica;
	document.paso1.id_capacidad.value=id_capacidad;
	var plazas=document.getElementById(id_restaurante+"_"+id_fisica+"_"+id_capacidad+"_plazas").value;
	document.paso1.num_ninos.value=document.getElementById(id_restaurante+"_"+id_fisica+"_"+id_capacidad+"_num_ninos").value;
	document.paso1.num_adultos.value=document.getElementById(id_restaurante+"_"+id_fisica+"_"+id_capacidad+"_num_adultos").value;
	document.paso1.num.value=parseInt(document.paso1.num_ninos.value) + parseInt(document.paso1.num_adultos.value);
	//alert("Número de plazas disponibles= " +plazas+"  Plazas que se quieren reservar="+document.paso1.num.value);
	if(parseInt(document.paso1.num.value) > parseInt(plazas)){
		alert("Lo sentimos, no hay tantas plazas disponibles, como máximo puede reservar "+plazas+" plazas.");
	}else{
			if(limiteMax < parseInt(document.paso1.num.value) && limiteMax!=0){
				alert("El restaurante solo permite reservar un máximo de "+limiteMax +" plazas");
			}else{
				if(parseInt(document.paso1.num_ninos.value)==0 && parseInt(document.paso1.num_adultos.value)==0 ){
					alert("El número de plazas no puede estar vacio.");
				}else{
					document.paso1.submit(); 
				}
			}
	}
}

function mostrarPopup(popup){
	document.getElementById("popup_"+popup).style.visibility="visible";
	document.getElementById("capaPopups").style.visibility="visible";
}
function ocultarPopup(){
	document.getElementById("popup_1").style.visibility="hidden";
	document.getElementById("popup_2").style.visibility="hidden";
	document.getElementById("capaPopups").style.visibility="hidden";
}
function VolverAtras(destino){
	document.forms.myform.action=destino;
	document.forms.myform.submit();
}


