// JavaScript Document
//Funciones comunes
function getPage(page)
{
	var cargando = "<h2><img src='img/loading.gif' alt='Loading' />Cargando. Espere por favor</h2>";
	elem = document.getElementById("contenido");
	elem.innerHTML = cargando;
	ruta = "paginas/"+page;
	petAjax(ruta,elem,"fillCuerpo");
	//estadisticas ¿?
	ruta ="operations/estadisticasOperations.php?_operation@update=update&page="+page;
	petAjax(ruta,null, null);
}

function fillCuerpo(txt)
{
	
	//Cadena de hora que va a llegar SIEMPRE igual 
	//<!-- filemtime=26/03/2008 04:26:27 -->
	cad_hora_base = "<!-- filemtime=DD/MM/AAAA HH:MM:SS -->";
	cad_hora_base_start = "<!-- filemtime=";
	cad_hora_base_end = " -->";
	txtstart = txt.indexOf(cad_hora_base_start,0);
	str_hora = txt.substring(txtstart,txtstart+cad_hora_base.length);
	str_hora = str_hora.substring(cad_hora_base_start.length,(cad_hora_base.length-cad_hora_base_end.length));
	document.getElementById("contenido").innerHTML = txt;
	//Es necesario ver si tiene codigo JS para ejecutarlo
	//Funcion no muy depurada aun, para salir del paso. 20080530
	start = txt.search(/<script/);
	if(start>0)
	{
		var scr = txt.substring(start+8,txt.search(/<\/script>/));
		eval(scr);
	}
	//**************************************//
	cad_status = "<h3><br />Última Actualización: "+str_hora+". 1024x768</h3>";
	//document.getElementById("pie").innerHTML = cad_status;
}

//Funciones de calendario

function getDayInfo(txt)
{
	
	ruta = "operations/calendarioOperations.php?_operation@getDayInfo=getDayInfo";
	cad = "day="+txt;
	elem = document.getElementById("textCalendario");
	petAjax(ruta, elem,"showDayInfo", cad);
}
function showDayInfo(txt)
{
	document.getElementById("textCalendario").innerHTML = txt;	
}
/**************************/

/****
		Formularios de Contactos
******/

function reloadForm(type)
{
	switch(type)
	{
		case 1: document.getElementById("formularioContacto").style.display="block";
				document.getElementById("formularioReserva").style.display="none";
				break;
		case 2: document.getElementById("formularioContacto").style.display="none";
				document.getElementById("formularioReserva").style.display="block";
				break;
	}
	
		
		
}

function showCondiciones()
{
	$("#condiciones_legales").toggle('slow');
	return false;
}

function validateContactForm(opc)
{
	var text = "";
	var ok = true;
	if(opc==1)
	{
		if(document.getElementById("email").value=="")
		{
			text+="Debe rellenar el campo email\r\n";
			ok=false;
		}
		if(document.getElementById("comentario").value=="")
		{
			text+="Debe rellenar el campo comentario\r\n";
			ok=false;
		}
		
	}
	if (opc==2)
	{
		if(document.getElementById("nombre").value=="")
		{
			text+="Debe rellenar el campo nombre\r\n";
			ok=false;
		}
		if(document.getElementById("telefono").value=="")
		{
			text+="Debe rellenar el campo telefono\r\n";
			ok=false;
		}
		if(document.getElementById("actividad").value==0)
		{
			text+="Debe elegir una actividad\r\n";
			ok=false;
		}
		if(document.getElementById("emailres").value=="")
		{
			text+="Debe rellenar el campo email\r\n";
			ok=false;
		}
		if(document.getElementById("comentariores").value=="")
		{
			text+="Debe rellenar el campo comentario\r\n";
			ok=false;
		}
		if(!document.getElementById("condiciones").checked)
		{
			text+="Debe aceptar las condiciones\r\n";
			ok=false;
		}
	}
	if(!ok)
		alert(text);
			
	return ok;
}
/******************************/

/**** Fotografias *********/
function viewPhoto(src)
{
	window.open(src,"Fotografía" , "scrollbars=NO")	
}
