/* javaScript Document
Proyecto : Página web de Hotel Barrameda (Cádiz).
 Nombre: funciones.js .
Descripción: Rutinas para el funcionamiento de la pagina. www.hotelbarrameda.com.*/

/*************** COMIENZO FUNCIONES **************************/
function clickMenu (id,idSubMenu)
{	
	var celda = document.getElementById(id);
	alert('celda es: '+celda);
	var opcion = celda.id;
	alert('opcion elegida '+opcion);
	if(idSubMenu != "")
	{
		var tabla = document.getElementById(idSubMenu)
		alert('visibilidad '+tabla.style.visibility);
		if(tabla.style.visibility == "visible")
			borraSubMenu(idSubMenu);
			else
			despliegaSubMenu(idSubMenu);
	}	
	
}
function inicializaMenu()
{
	elem = document.getElementById('menu1').className='menu';
	elem.href='servicios.php';
	elem = document.getElementById('menu2').className='menu';
	elem.href='habitaciones.php';
	elem = document.getElementById('menu3').className='menu';
	elem.href='tarifas.php';
	elem = document.getElementById('menu4').className='menu';
	elem.href='ofertas.php';
	elem = document.getElementById('menu5').className='menu';
	elem.href='ofertas.php';
	elem = document.getElementById('menu6').className='menu';
	elem.href='reservas.php';
	elem = document.getElementById('menu7').className='menu';
	elem.href='contacto.php';
	
}
	
function inicializaCampos()
{
      if(document.referrer!="datosReserva.php")
        {
         alert("El formulario de reserva ha sido enviado correctamente");
	}
}
	
		
	   
function resaltaMenuSelec(elem)
{
	inicializaMenu();
	var elemResalt = document.getElementById('menu'+elem);
	elemResalt.className='menuSelec';
	
}
function campoSinCubrir(campo)
{
	alert("Debe cubrir todos los campos obligatorios*");
	campo.focus();
	return ;
}
	
	
function camposObligatorios ()
{
	
	campo1 = document.getElementById('fech_entra');
	if(campo1.value == '' || campo1.value==0)
		{ campoSinCubrir(campo1);
		  return 1;
		}
		 
	campo2 = document.getElementById('fech_sal');
	if(campo2.value == '' || campo2.value==0)
		{ campoSinCubrir(campo2);		
		  return 1;
		}
	campo3 = document.getElementById('nombre');
	if(campo3.value == '' || campo3.value==0)
		{ campoSinCubrir(campo3);
		  return 1;
		}
	campo4 = document.getElementById('dni');
	if(campo4.value == '' || campo4.value==0)
		{ campoSinCubrir(campo4);
		  return 1;
		}
	campo5 = document.getElementById('email');
	if(campo5.value == '' || campo5.value==0)
		{ campoSinCubrir(campo5);
		  return 1;
		}
	campo6 = document.getElementById('tfno1');
	if(campo6.value == '' || campo6.value==0)
		{ campoSinCubrir(campo6);
		  return 1;
		}
	return 0;
		
	
}
	  
			
	
function enviarForm(idformulario)
{
	var formulario = document.getElementById(idformulario);
	if(formulario.acepto_reserva.checked)
	{
		if(camposObligatorios())
			return;
		else
		formulario.submit();
	}
	else
	{
		alert("Debe aceptar los terminos de la reserva");
	}
}
	
	
function confirm_salir_form(vinculo)
{
	var salir=confirm("Si sale se borrarán los datos del formulario, ¿ desea salir de todos modos");
	if(salir)
	{
		window.location.href=vinculo;
	}
}
		

function nada ()
{
	var i=0;
}

function clickOcultaTexto(idTexto,idOculta)
{	
	var divtexto = document.getElementById(idTexto);

	var divOculta = document.getElementById(idOculta);

	if(divtexto.style.visibility == 'visible' || divtexto.style.visibility == '')
	{
		
		divtexto.style.visibility ='hidden';
		
		divOculta.innerHTML = "";
		
		divOculta.innerHTML = "ver texto";
	}
	else
	{
		divtexto.style.visibility = 'visible';
		divOculta.innerHTML = "";
		divOculta.innerHTML = "ver imágenes";
	}
}

function despliegaSubMenu(id,idbase)
{	
	objetobase = document.getElementById(idbase);
	var tabla = document.getElementById(id);
	
	if(tabla.style.visibility == "visible")
	{   borraSubMenu(id);
		return;
	}
	tabla.className="subMenu";
	var palabra = "habitaciones";
	
				for(i=0;i<2;i++)
				{
					if(i==1)
						palabra = "servicios";		
					var fila = document.createElement("TR");
					
					fila.id="trsubmenuhotel_"+i;
					var celda = document.createElement("TD");
					var contenido=null;
					celda.className="tdSubMenu";
						contenido = document.createTextNode(palabra);
						
						celda.id="tdsubmenu"+i;
					celda.appendChild(contenido);
					
					xnAddEvento(fila,"mouseover",fila_onMouseOver);
					xnAddEvento(fila,"mouseout",fila_onMouseOut);
					
					fila.appendChild(celda);
					tabla.appendChild(fila);
				}
				
				tabla.style.visibility = "visible";
				
}

function borraSubMenu (id)
{
	alert('entro borrasubmenu');
	alert('id es:'+id);
	var tabla = document.getElementById(id);
	var filas = tabla.getElementsByTagName('tr');
	alert('las filas son'+filas);
	alert('longitud de filas '+filas.length);
	longitud = filas.length;
	for(i=0,j=0;j<2;j++)
	{	alert('entro filas');
		tabla.removeChild(filas[i]);
		alert(i);
	}
	tabla.style.width = "0px";
	tabla.style.height = "0px";
	tabla.style.visibility = "hidden";
	alert('salgo submenu');
}
	

function fila_onMouseOver(evento)
		{
			evento = (evento) ? evento : ((window.event) ? window.event : "")
			if (evento)
			{
				var elemento = xnPropietarioEvento(evento);
				elemento.className="tdSubMenuOver";
				//alert(elemento.id);
			}
		}
function fila_onMouseOut(evento)
		{
			evento = (evento) ? evento : ((window.event) ? window.event : "")
			if (evento)
			{
				var elemento = xnPropietarioEvento(evento);
				elemento.className="tdSubMenu";
				//alert(elemento.id);
			}
		}
	


function redireccionar() {
	var url640x480 = "http://www.hotelbarrameda.com/640x480";
	var url800x600 = "http://www.hotelbarrameda.com/800x600";
	var url1024x768 = "http://www.hotelbarrameda.com/1024x768";
if ((screen.width == 640) && (screen.height == 480))
window.location.href= url640x480;
else if ((screen.width == 800) && (screen.height == 600))
window.location.href= url800x600;
else if ((screen.width == 1024) && (screen.height == 768))
window.location.href= url1024x768;
else window.location.href= url640x480;
}


function variasresoluciones ()
{
if (screen.width==800||screen.height==600) 
   window.location.replace("es800600/index.html")

// para resolucion 640x480
else if (screen.width==640||screen.height==480) 
   window.location.replace("es640480/index.html")

//para resolucion 1024x768
else if (screen.width==1024||screen.height==768) 
   window.location.replace("es1240768/index.html")

//para otras resoluciones
else 
   window.location.replace("es1240768/index.htm ")
}

function cambiaSrcImg(nameImg,srcNueva,imagenNueva)
{ 
  var Image = document.getElementById(nameImg);
  
  Image.src=srcNueva;
  
  
}
    


