var fadeFireFox = 0;
var fadeWin = 0;

function preloadImages(img){
	image = new Image();
	image.src = img;
}

/* NOTICIAS */

function verNoticia(id){
	document.getElementById('introduccion').style.visibility = 'hidden';
	
	document.getElementById('noticia_1').style.visibility = 'hidden';
	document.getElementById('noticia_2').style.visibility = 'hidden';
	document.getElementById('noticia_3').style.visibility = 'hidden';
	
	document.getElementById('noticia_'+id).style.visibility = 'visible';
}

function cerrarNoticiasHome(){
	document.getElementById('noticia_1').style.visibility = 'hidden';
	document.getElementById('noticia_2').style.visibility = 'hidden';
	document.getElementById('noticia_3').style.visibility = 'hidden';
	
	document.getElementById('introduccion').style.visibility = 'visible';
}

/* CONTACTO */

function validarForm(){
	var error = false;
	
	if (document.contacto.nombre.value == ""){
		document.contacto.nombre.className = "error";
		error = true;
	}
	if (document.contacto.company.value == ""){
		document.contacto.company.className = "error";
		error = true;
	}
	if (document.contacto.mail.value == "" || !isEmailAddress(document.contacto.mail)){
		document.contacto.mail.className = "error";
		error = true;
	}
	if (document.contacto.comments.value == ""){
		document.contacto.comments.style.border = '1px solid #FF0000';
		error = true;
	}
	
	if (!error) document.contacto.submit();
}

function ponerNormal(cual){
	if (cual.name == "comments") cual.style.border = '1px solid #ffba2c';
	else cual.className = "normal";
}

function crearResultado(){
	var h = 0;
	
	if (navigator.appVersion.indexOf("MSIE") != -1) h = document.documentElement.clientHeight;
	else h = window.innerHeight;
	
	document.write("<div id='resultado' style='height:" + h +"px;' onclick='cerrarResultado()'>");
	document.write("<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>Thank you very much for your mail, we shall acknowledge receipt in due course.<br/>Your partner in Spain,<br/><br/>ITB dmc.");
	document.write("</div>");
	
	if (navigator.appVersion.indexOf("MSIE") != -1) document.getElementById('resultado').style.filter = "alpha(opacity=0)";
	else document.getElementById('resultado').style.opacity = 0;
	
	setTimeout(aplicarFade,500);
}

function aplicarFade(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		fadeWin = fadeWin + 15;
		document.getElementById('resultado').style.filter = "alpha(opacity="+fadeWin+")";
		if (fadeWin < 75 ) setTimeout(aplicarFade,10);
	}else{
		fadeFireFox = fadeFireFox + 0.15;
		document.getElementById('resultado').style.opacity = fadeFireFox;
		if (fadeFireFox < 0.75) setTimeout(aplicarFade,10);
	}
}

function cerrarResultado(){
	setTimeout(cerrarFade,100);
}

function cerrarFade(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		fadeWin = fadeWin - 15;
		document.getElementById('resultado').style.filter = "alpha(opacity="+fadeWin+")";
		if (fadeWin > 0 ) setTimeout(cerrarFade,10);
		else document.getElementById('resultado').style.visibility = 'hidden';
	}else{
		fadeFireFox = fadeFireFox - 0.15;
		document.getElementById('resultado').style.opacity = fadeFireFox;
		if (fadeFireFox > 0) setTimeout(cerrarFade,10);
		else document.getElementById('resultado').style.visibility = 'hidden';
	}
}

/* NEWS */

function verFotoGrande(nombre){
	var h = 0;
	var posicionScroll = 0;
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		posicionScroll = document.documentElement.scrollTop;
	}else{
		h = window.innerHeight;
		posicionScroll = window.scrollY;
	} 
	
	document.getElementById('fotoGrande').style.height = h + "px";
	document.getElementById('fotoGrande').style.top = posicionScroll + "px";
	document.getElementById('fotoGrande').style.visibility = 'visible';
	
	document.getElementById('fondoFotoGrande').style.top = posicionScroll + "px";
	document.getElementById('fondoFotoGrande').style.height = h + "px";
	document.getElementById('fondoFotoGrande').style.visibility = 'visible';
	
	var salida = "";
	salida = "<table cellpadding=0 cellspacing=0 width='100%'><tr><td valign='middle' align='center'  height='" + h + "'>";
	salida = salida + "<div id='marco'><img name='imagenGrande' src='img/noticias/" + nombre +"' onload='ajustarMarco()' height='404'/></div>";
	salida = salida + "</td></tr></table>";
	
	document.getElementById('fotoGrande').innerHTML = salida;
}

function aplicarFadeFoto(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		fadeWin = fadeWin + 20;
		document.getElementById('fotoGrande').style.filter = "alpha(opacity="+fadeWin+")";
		document.getElementById('cerrar').style.filter = "alpha(opacity="+fadeWin+")";
		if (fadeWin < 100 ) setTimeout(aplicarFadeFoto,10);
	}else{
		fadeFireFox = fadeFireFox + 0.2;
		document.getElementById('fotoGrande').style.opacity = fadeFireFox;
		document.getElementById('cerrar').style.opacity = fadeFireFox;
		if (fadeFireFox < 1) setTimeout(aplicarFadeFoto,10);
	}
}

function cerrarFadeFoto(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		fadeWin = fadeWin - 20;
		document.getElementById('fotoGrande').style.filter = "alpha(opacity="+fadeWin+")";
		document.getElementById('cerrar').style.filter = "alpha(opacity="+fadeWin+")";
		if (fadeWin > 0) setTimeout(cerrarFadeFoto,10);
		else{
			document.getElementById('fotoGrande').style.visibility = 'hidden';
			document.getElementById('fondoFotoGrande').style.visibility = 'hidden';
			document.getElementById('cerrar').style.visibility = 'hidden';
		} 
	}else{
		fadeFireFox = fadeFireFox - 0.2;
		document.getElementById('fotoGrande').style.opacity = fadeFireFox;
		document.getElementById('cerrar').style.opacity = fadeFireFox;
		if (fadeFireFox > 0) setTimeout(cerrarFadeFoto,10);
		else{
			document.getElementById('fotoGrande').style.visibility = 'hidden';
			document.getElementById('fondoFotoGrande').style.visibility = 'hidden';
			document.getElementById('cerrar').style.visibility = 'hidden';
		} 
	}
}


function ajustarMarco(){
	document.getElementById('marco').style.width = document.imagenGrande.width + "px";
	document.getElementById('marco').style.height = document.imagenGrande.height + "px";
	
	var h, w,posicionScroll;
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
		posicionScroll = document.documentElement.scrollTop
	}else{
		h = window.innerHeight;
		w = window.innerWidth;
		posicionScroll = window.scrollY;
	}
	document.getElementById('cerrar').style.visibility = 'visible';
	document.getElementById('cerrar').style.top = posicionScroll + h/2 - document.imagenGrande.height/2 - 10 + "px";
	document.getElementById('cerrar').style.left = w/2 + document.imagenGrande.width/2 + "px";
	
	setTimeout(aplicarFadeFoto,1);
}

function posicionarCapas(){
	if (document.getElementById('fotoGrande').style.visibility == 'visible'){
		var posicionScroll = 0;
		
		if (navigator.appVersion.indexOf("MSIE") != -1){
			h = document.documentElement.clientHeight;
			posicionScroll = document.documentElement.scrollTop;
		}else{
			h = window.innerHeight;
			posicionScroll = window.scrollY;
		}
		
		document.getElementById('cerrar').style.top = posicionScroll + h/2 - document.imagenGrande.height/2 - 10 + "px";
		document.getElementById('fotoGrande').style.top = posicionScroll + "px";
		document.getElementById('fondoFotoGrande').style.top = posicionScroll + "px";
	}
}

function posicionCapasHorizontal(){
	if (document.getElementById('fotoGrande').style.visibility == 'visible') {
		if (navigator.appVersion.indexOf("MSIE") != -1){
			w = document.documentElement.clientWidth;
		}else{
			w = window.innerWidth;
		}
		
		document.getElementById('cerrar').style.left = w/2 + document.imagenGrande.width/2 + "px";
	}
}

/* ITINERARIOS */
function verIssuu(cual){
	var salida = "";
	
	if (cual == "madrid"){
		salida = '<div><object style="width:925px;height:600px" ><param name="movie" value="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf?username=ViajesITB&amp;docName=itb-programa-madrid&amp;documentId=090226165626-0d4084fd28df4da4abe076e7010c58b0&amp;autoFlip=true" /><embed src="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf" type="application/x-shockwave-flash" style="width:925px;height:600px" flashvars="username=ViajesITB&amp;docName=itb-programa-madrid&amp;documentId=090226165626-0d4084fd28df4da4abe076e7010c58b0&amp;autoFlip=true" /></object></div>';
	}
	if (cual == "valencia"){
		salida = '<div><object style="width:925px;height:600px" ><param name="movie" value="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf?username=ViajesITB&amp;docName=itb-programa-valencia&amp;documentId=090227084638-f22b827a7ee042b88953395f015cdc09&amp;autoFlip=true" /><embed src="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf" type="application/x-shockwave-flash" style="width:925px;height:600px" flashvars="username=ViajesITB&amp;docName=itb-programa-valencia&amp;documentId=090227084638-f22b827a7ee042b88953395f015cdc09&amp;autoFlip=true" /></object></div>';
	}
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}else{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	
	document.getElementById('fondoPresentacion').style.visibility = 'visible';
	document.getElementById('fondoPresentacion').style.height = h + "px";
	
	document.getElementById('presentacion').innerHTML = salida;
	document.getElementById('presentacion').style.visibility = 'visible';
	document.getElementById('presentacion').style.left = w/2 - 925/2 + "px";
	document.getElementById('presentacion').style.top = h/2 - 600/2 + "px";
}

function cerrarPresentacion(){
	document.getElementById('fondoPresentacion').style.visibility = 'hidden';
	document.getElementById('presentacion').style.visibility = 'hidden';
	
	document.getElementById('presentacion').innerHTML = "";
}

function posicionCapasItinerarios(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}else{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	
	document.getElementById('fondoPresentacion').style.height = h + "px";
	
	document.getElementById('presentacion').style.left = w/2 - 925/2 + "px";
	document.getElementById('presentacion').style.top = h/2 - 600/2 + "px";
}

