var texto=new Array(3);

texto["es"]=new Array(2);
texto["es"][0]="Debes introducir el nombre.";
texto["es"][1]="Debes introducir el email.";
texto["es"][2]="Dirección de correo electrónico no válida.";
texto["es"][3]="La visita en ese horario tiene incluidas las tapas con la degustación.";
texto["es"][4]="Debes introducir el teléfono.";
texto["es"][5]="Debes introducir el número de personas.";
texto["es"][6]="Debes seleccionar día y hora para la visita.";
texto["es"][7]="Debes aceptar las condiciones de la licencia.";
texto["es"][8]="Va a solicitar una visita con la siguiente información:";
texto["es"][9]="\nFecha: ";
texto["es"][10]="\nHora: ";
texto["es"][11]="\nIdioma: ";
texto["es"][12]="\nPrecio: ";
texto["es"][13]="Español";
texto["es"][14]="Inglés";
texto["es"][15]="Alemán";
texto["es"][16]="Francés";
texto["es"][17]="Holandés";
texto["es"][18]="Reproduciendo";
texto["es"][19]="Detenido";
texto["es"][20]="Almacenando en buffer... ";
texto["es"][21]="completado";
texto["es"][22]="En pausa";
texto["es"][23]="Para salir del modo 'Pantalla completa' pulse la tecla Esc";
texto["es"][24]="Disculpe, su navegador no soporta esta opción.";


texto["en"]=new Array(2);
texto["en"][0]="You must enter your name.";
texto["en"][1]="You must enter your e-mail address.";
texto["en"][2]="Invalid e-mail address.";
texto["en"][3]="The tour at this time includes a selection of Tapas.";
texto["en"][4]="You must enter you telephone number.";
texto["en"][5]="You must enter the number of persons.";
texto["en"][6]="You must select the date and time of your tour.";
texto["en"][7]="You must accept the licensing conditions.";
texto["en"][8]="You will request a  tour with the following information:";
texto["en"][9]="\nDate: ";
texto["en"][10]="\nTime: ";
texto["en"][11]="\nLanguage: ";
texto["en"][12]="\nPrice: ";
texto["en"][13]="Spanish";
texto["en"][14]="English";
texto["en"][15]="German";
texto["en"][16]="French";
texto["en"][17]="Dutch";
texto["en"][18]="Copying";
texto["en"][19]="Stopped";
texto["en"][20]="Storing in buffer…";
texto["en"][21]="completed";
texto["en"][22]="Pause";
texto["en"][23]='To exit "Full screen" press the Esc key.';
texto["en"][24]="Sorry, your navigator will not accept this option.";


texto["de"]=new Array(2);
texto["de"][0]="Sie müssen Ihren Namen eingeben.";
texto["de"][1]="Sie müssen Ihr Email eingeben.";
texto["de"][2]="Ungültige Email-Adresse.";
texto["de"][3]="Ein Besuch zu diesen Öffnungszeiten schließt Tapas und Weinprobe ein.";
texto["de"][4]="Sie müssen eine Telefonnummer eingeben.";
texto["de"][5]="Sie müssen die Zahl der Personen eingeben.";
texto["de"][6]="Sie müssen Tag und Uhrzeit Ihres Besuches eingeben.";
texto["de"][7]="Sie müssen die Lizenzbedingungen akzeptieren.";
texto["de"][8]="Sie wünschen einen Besuch mit folgendem Inhalt:";
texto["de"][9]="\nDatum:";
texto["de"][10]="\nUhrzeit:";
texto["de"][11]="\nSprache:";
texto["de"][12]="\nPreis:";
texto["de"][13]="Spanisch";
texto["de"][14]="Englisch";
texto["de"][15]="Deutsch";
texto["de"][16]="Französisch";
texto["de"][17]="Holländisch";
texto["de"][18]="Neuaufbau";
texto["de"][19]="Gestoppt";
texto["de"][20]="Speichern im Buffer...";
texto["de"][21]="durchgeführt";
texto["de"][22]="Pause";
texto["de"][23]='Um aus dem Modus "ganzer Bildschirm” herauszukommen, drücken Sie Escape';
texto["de"][24]="Ihr Browser unterstützt diese Option nicht.";

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

function comprobarmail(lang)
{//Se comprueba si el mail es correcto
  var dir = document.all.txtemail.value; 
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (filter.test(dir)){
    return true;
  }else{
    alert(texto[lang][2]);
    document.all.txtemail.value="";
    document.all.txtemail.focus();
    document.all.txtemail.select();
    return false;
  }
}


function ComprobarCamposUsuClub(lang)
{//Comprueba que no existan campos vacíos
  var valido=true;

  if(document.all.txtnombre.value==""){
	alert(texto[lang][0]);
    document.all.txtnombre.focus();
    valido=false;
  }
  if( (valido) && (document.all.txtemail.value=="") ){
    alert(texto[lang][1]);
    document.all.txtemail.focus();
    valido=false;
  }
  if( (valido) && (!document.all.eula.checked)){
	alert(texto[lang][7]);
	document.all.eula.focus();
	valido=false;
  }	
  if(valido)
    valido=comprobarmail(lang);	
  
  return valido;
}

function ComprobarCamposAltaNW(lang)
{//Comprueba que no existan campos vacíos
  var valido=true;

  if(document.all.txtnombrealtaNW.value==""){
	alert(texto[lang][0]);
    document.all.txtnombrealtaNW.focus();
    valido=false;
  }
  if( (valido) && (document.all.txtemailaltaNW.value=="") ){
    alert(texto[lang][1]);
    document.all.txtemailaltaNW.focus();
    valido=false;
  }
  if( (valido) && (!document.all.eulaaltaNW.checked)){
	alert(texto[lang][7]);
	document.all.eulaaltaNW.focus();
	valido=false;
  }	
  if(valido){
	  //Se comprueba si el mail es correcto
	  var dir = document.all.txtemailaltaNW.value;
	  var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	  if (filter.test(dir))
	    valido=true;
	  else{
	    alert(texto[lang][2]);
	    document.all.txtemailaltaNW.value="";
	    document.all.txtemailaltaNW.focus();
	    document.all.txtemailaltaNW.select();
	    valido=false;
	  }
  }
  return valido;
}

function ComprobarCamposBajaNW(lang)
{//Comprueba que no existan campos vacíos
  var valido=true;
  if(document.all.txtemailbajaNW.value==""){
	alert(texto[lang][1]);
    document.all.txtemailbajaNW.focus();
    valido=false;
  }
  if(valido){
	  //Se comprueba si el mail es correcto
	  var dir = document.all.txtemailbajaNW.value;
	  var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	  if (filter.test(dir))
	    valido=true;
	  else{
	    alert(texto[lang][2]);
	    document.all.txtemailbajaNW.value="";
	    document.all.txtemailbajaNW.focus();
	    document.all.txtemailbajaNW.select();
	    valido=false;
	  }
  }
  return valido;
}

function ComprobarCamposContacto(lang)
{//Comprueba que no existan campos vacíos
  var valido=true;
  //Se comprueba si se ha rellenado el mail y si es correcto
  if(document.all.txtemail.value==""){
    alert(texto[lang][1]);
    document.all.txtemail.focus();
    valido=false;
  }
  if( (valido) && (!document.all.eula.checked)){
	alert(texto[lang][7]);
	document.all.eula.focus();
	valido=false;
  }	  
  if(valido)
    valido=comprobarmail(lang);	

  return valido;
}

function popup(theURL) 
{
	window.open(theURL, 'Noticia', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=419,height=450');
}

function popupeula(theURL) 
{
	weula=window.open(theURL, 'eula', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=425,height=450');
	weula.focus();
}

function popupContacto(theURL) 
{
	wcontacto=window.open(theURL, 'Contacto', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=570,height=470');
	wcontacto.focus();
}

function popupVideo(theURL) 
{
	ventana=window.open(theURL, 'Video', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=419,height=410');
	ventana.focus();
}

function popupCartel(cartel) 
{
	ventana=window.open('cartel.php?cartel='+cartel, 'Cartel', 'fullscreen=no,width=420,height=560,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}

function popupTapa(id) 
{
	ventana=window.open('tapa.php?tapa='+id, 'Tapa', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=419,height=490');
	ventana.focus();
}

function popupFamilia(id) 
{
	ventana=window.open('popupFamilia.php?parrafo='+id, 'Tapa', 'fullscreen=no,width=570,height=455,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}
function popUpVilarnau(){
	ventana=window.open('vilarnau.html', 'Vilarnau', 'fullscreen=no,width=800,height=600,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}
function popupTioPepeHistoria(id) 
{
	ventana=window.open('popupTioPepeHistoria.php?parrafo='+id, 'TioPepe', 'fullscreen=no,width=570,height=455,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}
function popupTioPepeUniversal(lang) 
{
	ventana=window.open('tiopepeuniversal/index.php?lang='+lang, 'TioPepeUniversal', 'width=866,height=508,fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}
function popupTioPepeUniversal(lang) 
{
	ventana=window.open('tiopepeuniversal/index.php?lang='+lang, 'TioPepeUniversal', 'width=866,height=508,fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}

function popupImagen(imagen) 
{
	ventana=window.open('imagen.php?imagen='+imagen, 'Imagen', 'width=10,height=10,fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
	ventana.focus();
}

function popupMiniTour(capa,lang) 
{
	if(mStour[capa]!=0)
	{
		wpanorama=window.open('tour/minitour.php?f='+mStour[capa]+'&lang='+lang, 'Panorama', 'fullscreen=no,width=448,height=304,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no');
		wpanorama.focus();
	}
}


function imprimir(){
    if (window.print)
        window.print();
    else
        alert("Disculpe, su navegador no soporta esta opción.");
}

function SistemaOperativo() 
{ 
	if (navigator.userAgent.indexOf('IRIX') != -1) {var SO = "Irix" } 
	else if ((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('98') != -1)) {var SO= "Windows 98"} 
	else if ((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1)) {var SO= "Windows 95"} 
	else if (navigator.appVersion.indexOf("16") !=-1) {var SO= "Windows 3.1"} 
	else if (navigator.userAgent.indexOf("NT 5.1") !=-1) {var SO= "Windows XP"} 
	else if (navigator.appVersion.indexOf("NT") !=-1) {var SO= "Windows NT"} 
	else if (navigator.appVersion.indexOf("SunOS") !=-1) {var SO= "SunOS"} 
	else if (navigator.appVersion.indexOf("Linux") !=-1) {var SO= "Linux"} 
	else if (navigator.userAgent.indexOf('Mac') != -1) {var SO= "Macintosh"} 
	else if (navigator.appName=="WebTV Internet Terminal") {var SO="WebTV"} 
	else if (navigator.appVersion.indexOf("HP") !=-1) {var SO="HP-UX"} 
	else {var SO= "No identificado"} 
	return SO;
} 
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// RESERVAS ////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
var precioAdulto=0;
var precioMenor=0;
var precioTapa=0;

function getRadioArray(groupName) { 
    var retval = new Array(); 
    var nodeList = document.getElementsByTagName("input");
    var index=0;

    for(var i = 0; i < nodeList.length; i++) {
        if(nodeList.item(i).name == groupName){
			retval[index] = nodeList.item(i);
			index++;
		}
    } 
    return retval; 
}

var tapasAct=false;
function chkTapas(cbTapas)
{
	if(!cbTapas.checked && tapasAct){
		cbTapas.checked=true;
		alert(texto['es'][3]);
	}
	calcularPrecio();
}

function chkHoras()
{
	var tapas=document.all.tapas;
	var idiomaSel;
	var tapafija=document.all.tapafija.value;

	if(tapafija=='true')
	{
		tapas.checked= true;
		tapas.readOnly= true;
		tapasAct=true;
	}else{
		tapas.checked= false;
		tapas.readOnly= false;
		tapasAct=false;
	}
	calcularPrecio();	
}

function calcularPrecio()
{
	var costeTotal;
	var adultos=document.all.npers.value*1;	
	var menores=document.all.nmenor.value*1;
	
	if(document.all.tapas.checked)
	{
		var precioAdulto= document.all.ptapa.value*1;
		var precioMenor= document.all.ptapamenor.value*1;
	}
	else
	{
		var precioAdulto= document.all.padult.value*1;
		var precioMenor= document.all.pmenor.value*1;
	}

	document.all.npers.value=adultos;
	document.all.nmenor.value=menores;
	costeTotal=(adultos*precioAdulto)+(menores*precioMenor);
	
	document.all.coste.value=costeTotal;
}

function chkDatos(lang)
{
	if(document.reserva.txtnombre.value==""){
		alert(texto[lang][0]);
		document.reserva.txtnombre.focus();
		return false;
	}
	if(document.reserva.txttlf.value==""){
		alert(texto[lang][4]);
		document.reserva.txttlf.focus();
		return false;
	}
	if(isNaN(document.reserva.txttlf.value)){
		alert(texto[lang][4]);
		document.reserva.txttlf.focus();
		return false;
	}
	if(document.reserva.txtemail.value==""){
		alert(texto[lang][1]);
		document.reserva.txtemail.focus();
		return false;
	}
	valido=comprobarmail(lang);
	if (valido==false){
		document.reserva.txtemail.focus();
		return false;
	}
	if(document.reserva.npers.value=="" || document.reserva.npers.value==0){
		alert(texto[lang][5]);
		document.reserva.npers.focus();
		return false;
	}
	if(document.reserva.txtfecha.value==""){
		alert(texto[lang][6]);
		return false;
	}
	if(!document.reserva.eula.checked){
		alert(texto[lang][7]);
		document.reserva.eula.focus();
		return false;
	}
	var info=texto[lang][8]+texto[lang][9]+document.reserva.txtfecha.value;
	info+=texto[lang][10]+document.reserva.hora.value;
	switch(document.reserva.idioma.value)
	{
		case 'ES': var idioma=texto[lang][13];
			break;
		case 'EN': var idioma=texto[lang][14];
			break;
		case 'DE': var idioma=texto[lang][15];
			break;
		case 'FR': var idioma=texto[lang][16];
			break;
		case 'HO': var idioma=texto[lang][17];
			break;
	}
	info+=texto[lang][11]+idioma;
	info+=texto[lang][12]+document.reserva.coste.value+" €";
	return confirm(info);
	
}

////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////  //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
function mueveImagen(capa, direccion)
{
	salto=200*direccion;
	var sig=document.getElementById("s"+capa);
	var ant=document.getElementById("a"+capa);
	var miniTa=document.getElementById("Ma"+capa);
	dw_scrollObj.scrollBy("wn_i"+capa,salto,0);
	capa--;
	sitImg[capa]-=direccion;
	if(sitImg[capa]==0){
		sig.style.visibility= 'visible';
		ant.style.visibility= 'hidden';
	}else if(sitImg[capa]==(numImg[capa])){
		sig.style.visibility= 'hidden';
		ant.style.visibility= 'visible';
	}else{
		sig.style.visibility= 'visible';
		ant.style.visibility= 'visible';
	}

	if(mtour[capa+1][sitImg[capa]]!=0){
		mStour[capa+1]=mtour[capa+1][sitImg[capa]];
		miniTa.style.visibility= 'visible';
	}else{
		mStour[capa+1]=0;
		miniTa.style.visibility= 'hidden';
	}
	return false;
}


function cargaParent(pagina)
{
	if(typeof(self.parent.sincambio)!='boolean'){
		var loc=new String(window.location);
		if (loc.indexOf('#')!=-1){
			cad=loc.substring(loc.indexOf('#'),loc.length);
			window.location=pagina+cad;
		}else{
			window.location=pagina;
		}
	}
}

function cargaHijo(pagina)
{
	var loc=new String(window.location);
	if (loc.indexOf('#')!=-1){
		cad=loc.substring(loc.indexOf('#'),loc.length);
		document.all.iFrame1.src=pagina+cad;
	}else{
		document.all.iFrame1.src=pagina;
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// CRONOLOGÍA //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

//Array con los años que se van a mostrar
var anios=new Array(35);
anios[0]=1835;
anios[1]=1836;
anios[2]=1838;
anios[3]=1843;
anios[4]=1844;
anios[5]=1850;
anios[6]=1855;
anios[7]=1856;
anios[8]=1857;
anios[9]=1859;
anios[10]=1862;
anios[11]=1863;
anios[12]=1869;
anios[13]=1870;
anios[14]=1882;
anios[15]=1884;
anios[16]=1887;
anios[17]=1888;
anios[18]=1890;
anios[19]=1896;
anios[20]=1904;
anios[21]=1908;
anios[22]=1935;
anios[23]=1941;
anios[24]=1963;
anios[25]=1969;
anios[26]=1972;
anios[27]=1980;
anios[28]=1982;
anios[29]=1983;
anios[30]=1985;
anios[31]=1988;
anios[32]=2000;
anios[33]=2001;
anios[34]=2005;


//Nº de pixels que ocupa cada año
var factor=3

//Posición y tamaño de la línea de tiempo
var timelinetop = 0
var timelineleft = 0
var timelinewidth = 630
var timelineheight = 34

var timelineoffset =20 //donde comienzan a contar los años

//Posición inicial (en el primer año) del slider y del año que contiene. La posición es relativa al timeline
//El slider se compone de dos imágenes (Top+Inf) y del texto con el año
var sliderToptop=-10
var sliderTopleft=2
var sliderInftop=8
var sliderInfleft=20
var slideraniotop=-10
var slideranioleft=7

function desplazamiento(anio)
{//Se obtiene el desplazamiento (en pixels) de un anio del primer anio de la línea de tiempo
	return anio + (anios[anios.length-1] - anios[0]) - anios[anios.length-1];
}

function mover(posRatonX,posRatonY)
{//Se desplaza horizontal y verticalmente
	if ( ((timelineleft+timelineoffset)<=posRatonX) && (posRatonX<=((timelineleft+timelineoffset)+timelinewidth)) && 
		 (timelinetop<=posRatonY) &&(posRatonY<=(timelinetop+timelineheight)) ){
		//Estamos en la región del timeline
		document.getElementById('timeline').style.cursor='default';
		ocultarPosonCursor();
		for (i=0; i<anios.length; i++){
			if (((timelineleft+timelineoffset)+(factor*desplazamiento(anios[i])))==posRatonX){
				mostrarPosonCursor(anios[i],posRatonX,posRatonY);
				break;
			}
		}
	}
}

function mostrarPosonCursor(anio,posRatonX,posRatonY)
{//Mostramos la posición del cursor en el Timeline
	var desp = factor * desplazamiento(anio);
	document.getElementById('timeline').style.cursor='hand';
	document.getElementById('sliderCursor').style.display='block';
	document.getElementById('sliderCursor').style.left=posRatonX + 15;
	document.getElementById('sliderCursor').style.top=posRatonY + 10;
	document.getElementById('sliderAnioCursor').style.display='block';
	document.getElementById('sliderAnioCursor').style.left=posRatonX + 19;
	document.getElementById('sliderAnioCursor').style.top=posRatonY + 10;
	document.getElementById('sliderPosonCursor').style.display='block';
	document.getElementById('sliderPosonCursor').style.left=sliderInfleft + desp;
	document.getElementById('anioCursor').style.display='block';
	document.getElementById('anioCursor').value=anio;
}

function ocultarPosonCursor()
{
	document.getElementById('sliderCursor').style.display='none';
	document.getElementById('sliderPosonCursor').style.display='none';
	document.getElementById('anioCursor').style.display='none';	
}

function hacerclick(posRatonX,posRatonY)
{//Se desplaza horizontal y verticalmente
	if ( ((timelineleft+timelineoffset)<=posRatonX) && (posRatonX<=((timelineleft+timelineoffset)+timelinewidth)) && 
		 (timelinetop<=posRatonY) &&(posRatonY<=(timelinetop+timelineheight)) ){
		//Estamos en la región del timeline
		for (i=0; i<anios.length; i++){
			if (((timelineleft+timelineoffset)+(factor*desplazamiento(anios[i])))==posRatonX){	
				mostrarAnio(anios[i]);
				ocultarPosonCursor();
				break;
			}
		}
	}
}

function mostrarAnio(anio)
{//Mostramos la capa de un año y ocultamos el resto
	for (i=0; i<anios.length; i++){
		if (document.getElementById('anio'+anio)==document.getElementById('anio'+anios[i])){
			document.getElementById('anio'+anios[i]).style.display='block';
			mostrarSlider(anio);
		}else{
			document.getElementById('anio'+anios[i]).style.display='none';
		}
	}
}

function mostrarSlider(anio)
{//Mostramos en el timeline el slider que indica el año del que se están viendo las imágenes
	var desp = factor * desplazamiento(anio);
	document.getElementById('sliderTop').style.left=sliderTopleft + desp;
	document.getElementById('sliderTop').style.top=sliderToptop;
	document.getElementById('sliderInf').style.left=sliderInfleft + desp;
	document.getElementById('sliderInf').style.top=sliderInftop;
	document.getElementById('sliderAnio').style.left=slideranioleft + desp;
	document.getElementById('sliderAnio').style.top=slideraniotop;
	document.getElementById('anio').value=anio;
}

function cambiaImagen(posicion,anio,direccion)
{//Nos estamos moviendo entre las imágenes que tiene un mismo año
	imgNumAnt=posicion+1;
	
	if (direccion==1){ //Nos movemos a la derecha
		imgNum=imgNumAnt+1;
		document.getElementById("divim"+anio+"_"+imgNumAnt).style.display='none';
		//alert("divim"+anio+"_"+imgNum);
		document.getElementById("divim"+anio+"_"+imgNum).style.display='block';
	}else{
		imgNum=imgNumAnt-1;
		document.getElementById("divim"+anio+"_"+imgNumAnt).style.display='none';
		document.getElementById("divim"+anio+"_"+imgNum).style.display='block';
	}
}