function inicio()

{

$$('.noJS').each(function(elemento){

elemento.onclick = function() {return false}

})

}



Event.observe(document, 'dom:loaded', function()

{

inicio();

})

//Formatea NÃºmero

function fn(cantidad, sufijo)

{

var cantidad = parseFloat(cantidad)

cantidad = Math.round(cantidad) / 100;

cantidad = (cantidad == Math.floor(cantidad)) ? cantidad + '.00' : ( (cantidad*10 == Math.floor(cantidad*10)) ? cantidad + '0' : cantidad);

cantidad = cantidad + ' ' + sufijo;

return cantidad;

}

var cabecera = Class.create();

cabecera.prototype = {

initialize: function(idContenedor) {

this.imagenes = $$('.imgCabecera');

this.cantidadImagenes = this.imagenes.size();

var th = this;

if (this.cantidadImagenes > 1) {setInterval(function(){th.carrusel()}, 7000);}

//this.eventoIdiomas();

this.eventoHora();

},


eventoIdiomas: function() {


for (var i in globales.idiomas)

{

if(globales.idiomas[i]==1)

{

Event.observe($(i), 'click', function()

{

if(!globales.aliasRuta) globales.aliasRuta = "[lang]/inicio.php"; // el caso de que no esta reflejada la idioma.

window.location = globales.aliasRuta.replace(/\[lang\]/,this.id);

});

}

}

},

 

eventoMostarHora: function(timediff){

var th = this;


time = new Date();

time.setTime( time.getTime() + timediff );


var hora = time.getHours();

minuto = time.getMinutes();


str_minuto = new String (minuto)

if (str_minuto.length == 1) minuto = "0" + minuto


str_hora = new String (hora)

if (str_hora.length == 1) hora = "0" + hora



horaImprimible = "Hoy en " + globales.ciudad + ": <b>" + hora + ":" + minuto + " h</b> ";

$('hora').update(horaImprimible);

setTimeout(function(){th.eventoMostarHora(timediff)},1000);



},



eventoHora: function()

{

// si no existe global.hora, la pagina no tiene ni ciudad ni horario.

if (typeof globalesNoCache.hora == "undefined") return; 


var th = this;

now = new Date();

timediff = globalesNoCache.hora - now.getTime() 

th.eventoMostarHora(timediff); 

},


carrusel: function()

{

var th = this;

this.imagenes.each(function(imagen,key){

if(imagen.hasClassName('visible'))

{

if (key < (th.cantidadImagenes-1)) {

Effect.Fade(imagen);

imagen.removeClassName('visible');

Effect.Appear(th.imagenes[key + 1]);

th.imagenes[key + 1].addClassName('visible');

throw $break;

}

else

{

Effect.Fade(imagen);

imagen.removeClassName('visible');

Effect.Appear(th.imagenes[0]);

th.imagenes[0].addClassName('visible');

throw $break;

}


}

})

}

}

Event.observe(document, 'dom:loaded', function(){new cabecera()});

Event.observe(document, 'dom:loaded', function()

{

new Tip('miniCestaEnlace', $('miniCestaDesglose').innerHTML, 

{

hook:{target: 'topRight', tip: 'topRight'},

fixed: true,

hideOn: {element: 'tip', event: 'mouseleave'},

delay: 0.5 

});

});function cambiaMiga(idPagina, nuevaUrl)

{

$$('#migas a[rel="' + idPagina + '"]')[0].href = nuevaUrl;

}

Event.observe(document, 'dom:loaded', function()

{

globalesCopia = globales;

IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;

$$('.fcp_tab').each(function(tab){

Event.observe(tab, 'click', function(){seleccionaTab(tab.getAttribute('rel'))});

})


hashFormularios = new Hash();

hashFormularios.set('fpaq', new formularioPortada('fpaq', 4));

hashFormularios.set('ftar', new formularioPortada('ftar', 1));

hashFormularios.set('fabo', new formularioPortada('fabo', 2));

hashFormularios.set('ftou', new formularioPortada('ftou', 7));

hashFormularios.set('fent', new formularioEntradas('fent', 8));

hashFormularios.set('fhot', new formularioHoteles());

Ajax.Responders.register({

onCreate: function() {

$('ajaxCargando').show();

},

onComplete: function() {

$('ajaxCargando').hide();

}

});

tabActivo = false;

seleccionaTab('fpaq');


});

function seleccionaTab(rel)

{

//Reseteamos el formulario activo, en caso de haberlo

if(tabActivo)

{

hashFormularios.get(tabActivo).resetea(); 

}

hashFormularios.get(rel).resetea();


tabActivo = rel;


//Marcamos el radio button seleccionado, por si no se marca solo

$('fcp_opcion_' + rel).checked = true;


//Todos los tabs

tabs = $$('#fcp_tabs .fcp_tab');


//El tab seleccionado

tab = $$('#fcp_tabs li[rel="' + rel + '"].fcp_tab')[0];


//Todos los contenidos

contenidos = $$('#fcp_contenidos div.fcp_contenido');


//El contenido seleccionado

contenido = $(rel);

//El tÃtulo

titulo = contenido.select('.titulo')[0].innerHTML;

$('fcp_titulo').update(titulo);


tabs.each(function(t){t.removeClassName('seleccionada');t.addClassName('noSeleccionada');})

contenidos.each(function(c){c.hide();})

contenido.show();

tab.addClassName('seleccionada');

tab.removeClassName('noSeleccionada');

}

function rellenaSelect(selector,contenido)

{

selector.update('');

var opciones = '';

contenido.each(function(opcion)

{

opciones += '<option value="' + opcion.valor + '" rel="' + opcion.rel + '" title="' + opcion.nombre + '">' + opcion.nombre + '</option>';

})

selector.update(opciones);

}

 

var formularioPortada = Class.create();

formularioPortada.prototype = {

initialize: function(prefijo,idtipoProducto){

this.prf = prefijo;

this.idTipoProducto = idtipoProducto;

this.eventos();

},


eventos: function(){

var th = this;


Event.observe($(th.prf + '_selectDestino'), 'change', function(){

th.destinoElegido($(th.prf + '_selectDestino').value);

});


Event.observe($(th.prf + '_selectProducto'), 'change', function(){

th.productoElegido($(th.prf + '_selectProducto').value);

});


$(th.prf + '_fechaVisita').onchange = function(){

th.fechaElegida($(th.prf + '_fechaVisita').value)

};



},


resetea: function() {

this.muestraContenidoFalso(true);

$(this.prf + '_modelosProducto').update();

$(this.prf + '_selectProducto').update();

$(this.prf + '_enlaceDestino').hide();

$(this.prf + '_enlaceProducto').hide();

$(this.prf + '_selectProducto').disabled = true;

$(this.prf + '_selectDestino').value = -1;

$(this.prf + '_fechaVisita').value = globales.fechaDefecto;

ficha = new Array();

if (typeof(botonCesta) != 'undefined') {

botonCesta.actualizaPrecio();

}

},


destinoElegido: function(idDestino){

$(this.prf + '_modelosProducto').update();

if (idDestino < 1) {

$(this.prf + '_enlaceDestino').hide();

this.muestraContenidoFalso(true);

return;

}


$(this.prf + '_selectProducto').disabled = false;


$(this.prf + '_enlaceDestino').show().href = $(this.prf + '_selectDestino').options[$(this.prf + '_selectDestino').selectedIndex].getAttribute('rel');


this.muestraContenidoFalso(true)


var th = this;

new Ajax.Request(globales.lang + '/PaginaPrincipal/FormularioCompraPortada/getProductosDestino/' + idDestino + '/' + this.idTipoProducto, {

method: 'get',

onSuccess: function(transport, json){

rellenaSelect($(th.prf + '_selectProducto'), json.productos)

th.productoElegido($(th.prf + '_selectProducto').value);

}

})

},


fechaElegida: function(fecha){

//$(this.prf + '_selectProducto').disabled = false;

},


productoElegido: function(idProducto){


if (idProducto < 1) {

$(this.prf + '_enlaceProducto').hide();

$(this.prf + '_modelosProducto').update();

return

}


ficha = new Array();


$$('#' + this.prf + '_modelosProducto select').each(function(elemento){

elemento.update('').disabled = true;

})

//$(this.prf + '_modelosProducto').update('<img style="display:block;margin:auto;" src="img/estilo/formularioCompraPortada/ajax_cargando.gif" />');

globales = globalesCopia;



$(this.prf + '_enlaceProducto').show().href = $(this.prf + '_selectProducto').options[$(this.prf + '_selectProducto').selectedIndex].getAttribute('rel');


var th = this;

new Ajax.Updater(this.prf + '_modelosProducto', globales.lang + '/PaginaPrincipal/formularioCompra/' + idProducto, {

evalScripts: true,

onComplete: function(){

th.muestraContenidoFalso(false);

}

});

},


muestraContenidoFalso: function(mostrar){

if (mostrar) {

$$('.contenidoFalso').invoke('show');

}

else {

$$('.contenidoFalso').invoke('hide');

}

}

}

 

var formularioEntradas = Class.create();

formularioEntradas.prototype = {

initialize: function(prefijo, idTipoProducto) {

this.prf = prefijo;

this.eventos();

},


eventos: function(){

var th = this;


Event.observe($('fent_selectEspectaculo'), 'change', function(){

th.ocultaErrores();

th.espectaculoElegido($('fent_selectEspectaculo').value);

}); 

Event.observe($('fent_sesionesMes'), 'change', function(){

th.mesElegido($('fent_sesionesMes').value);

}); 

Event.observe($('fent_botonVerButacas'), 'click', function(){

if ($('fent_botonVerButacas').hasClassName('desactivao')) {

return;

}


window.location.href = $('fent_sesionesDia').options[$('fent_sesionesDia').selectedIndex].getAttribute('rel');

}); 

Event.observe($('fent_sesionesDia'), 'change', function(){

th.diaElegido($('fent_sesionesDia').value);

}); 


var selects = [$('fent_selectDestino'), $('fent_selectTipoEspectaculo')];

selects.each(function(elemento){

Event.observe(elemento, 'change', function(){

th.ocultaErrores();

th.destinoElegido($('fent_selectDestino').value, $('fent_selectTipoEspectaculo').value);

}); 

})

},


resetea: function() {},


destinoElegido: function(idDestino, idTipo){

$('fent_selectEspectaculo').update().disabled = true;

$('fent_sesionesMes').update().disabled = true;

$('fent_sesionesDia').update().disabled = true; 

if(idDestino == -1) {

return;

}

var th = this;

new Ajax.Request(globales.lang + '/PaginaPrincipal/FormularioCompraPortada/getEspectaculos/' + idDestino + '/' + idTipo, {

method: 'get',

onSuccess: function(transport, json){

rellenaSelect($('fent_selectEspectaculo'), json.espectaculos);

th.espectaculoElegido($('fent_selectEspectaculo').value);

}

})

},


espectaculoElegido: function(idEspectaculo)

{

if (idEspectaculo < 1 || !idEspectaculo) {

this.muestraError('fent_errorEspectaculos');

$('fent_enlaceProducto').hide();

this.muestraContenidoFalso(true);

return

}



$('fent_selectEspectaculo').disabled = false;

$('fent_sesionesMes').update().disabled = true;

$('fent_sesionesDia').update().disabled = true;


$('fent_enlaceProducto').show().href = $('fent_selectEspectaculo').options[$('fent_selectEspectaculo').selectedIndex].getAttribute('rel');

var th = this;

new Ajax.Request(globales.lang + '/PaginaPrincipal/FormularioCompraPortada/getSesiones/' + idEspectaculo, {

method: 'get',

onSuccess: function(transport, json){

th.dias = json.dias;

rellenaSelect($('fent_sesionesMes'), json.meses);

th.mesElegido($('fent_sesionesMes').value);

}

})

},


mesElegido: function(mes)

{

if(mes < 0 || mes > 12 || !mes) {

this.muestraError('fent_errorSesiones');

$('fent_sesionesMes').disabled = true;

return;

}


rellenaSelect($('fent_sesionesDia'), this.dias['m' + mes]);

$('fent_sesionesMes').disabled = false;

this.diaElegido($('fent_sesionesDia').value);

},


diaElegido: function(idSesion)

{

if(idSesion < 0) {

$('fent_sesionesDia').disabled = true;

return;

};

$('fent_sesionesDia').disabled = false;

$('fent_botonVerButacas').removeClassName('desactivado');

},


muestraError: function(error)

{

$(error).show();

Effect.BlindDown('fent_errores', {duration: 0.3 });

},


ocultaErrores: function()

{

$('fent_errores').hide();

$$('#fent_errores p').invoke('hide');

}



}

var formularioHoteles = Class.create();

formularioHoteles.prototype = {

initialize: function(){

this.ciudadSeleccionada = false;

this.selectPais = $('fhot_selectPais');

this.eventos();


},


resetea: function() {

$('fhot_selectPais').value='ES';

$('fhot_fechaEntrada').value = globales.fechaDefecto;

this.ciudadSeleccionada = false;

$('fhot_ciudad').value = $('fhot_ciudad').getAttribute('rel');

$('fhot_noches').value = 1;

$('fhot_individual').value = 0;

$('fhot_doble').value = 0;

$('fhot_dobleNino').value = 0

$('fhot_edadNino').value = 0;

$('fhot_edadNino').disabled = true;

$('fhot_Triple').value = 0; 


this.paisElegido('ES');

},


eventos: function(){

var th = this;


Event.observe($('fhot_muestraCiudades'), 'click', function(){

th.muestraCiudades($('fhot_selectPais').value);

}); 

Event.observe($('fhot_cerrarEleccionCiudad'), 'click', function(){

$('fhot_listaCiudades').setStyle({'overflow': 'hidden'});

Effect.SlideUp('fhot_eleccionCiudad', {afterFinish: function(){th.ocultaSelect(false)}});

}); 


$$('#fhot_alfabetoCiudades li').each(function(elemento){

Event.observe(elemento, 'click', function(){

th.muestraCiudades($('fhot_selectPais').value, elemento.innerHTML);

}); 

})


Event.observe($('fhot_selectPais'), 'change', function(){

th.paisElegido($('fhot_selectPais').value);

}); 


Event.observe($('fhot_ciudad'), 'focus', function(){

$('fhot_ciudad').focus();

$('fhot_ciudad').select();

}),

Event.observe($('fhot_ciudad'), 'click', function(){

$('fhot_ciudad').focus();

$('fhot_ciudad').select();

})


new Ajax.Autocompleter('fhot_ciudad', 'fhot_eleccionAutocompletado', 'PaginaPrincipal/FormularioCompraPortada/getCiudadesHotel', {

paramName: 'busquedaCiudad',

callback: function(parametro){

return 'busquedaCiudad=' + parametro.value + '&idPais=' + th.selectPais.value;

},

afterUpdateElement : function(texto,li) {

th.ciudadElegida(li.id)


}

});


$$('.fcp_opcionesHotel select').each(function(elemento){

Event.observe(elemento, 'change', function(){

th.tipoElegido();

}); 

})




Event.observe($('fhot_botonBuscaHotel'), 'click', function(){

if($('fhot_botonBuscaHotel').hasClassName('desactivado')) {return;}

var url = 'http://www.neoturismo.com/es/hoteles';

var opcionesUrl = new Hash();

opcionesUrl.set('fecha', $('fhot_fechaEntrada').value);

opcionesUrl.set('pais', $('fhot_selectPais').value);

opcionesUrl.set('ciudad', th.ciudadSeleccionada);

opcionesUrl.set('noches', $('fhot_noches').value);

opcionesUrl.set('individual', $('fhot_individual').value);

opcionesUrl.set('doble', $('fhot_doble').value);

opcionesUrl.set('doblen', $('fhot_dobleNino').value);

opcionesUrl.set('edadn', $('fhot_edadNino').value);

opcionesUrl.set('triple', $('fhot_Triple').value);

window.location.href = url + '?' + opcionesUrl.toQueryString();

})

},


paisElegido: function(idPais)

{

$('fhot_ciudad').value = $('fhot_ciudad').getAttribute('rel');

$('fhot_ciudad').disabled = false;

$('fhot_muestraCiudades').disabled = false;

this.ciudadSeleccionada = false;

this.activaBoton();

},


ciudadElegida: function (idCiudad, nombreCiudad)

{

this.ciudadSeleccionada = idCiudad;

if(nombreCiudad) { $('fhot_ciudad').value = nombreCiudad; }

this.activaBoton();

},


ocultaSelect: function(ocultar)

{

if(!IE6) {return};

valor = ocultar ? 'hidden' : 'visible';

$$('#fhot select').invoke('setStyle', {visibility: valor});

},


muestraCiudades: function(idPais, letra)

{

if(!idPais || idPais < 0) {return;}

if(!letra) {var letra = 'a'}

$('fhot_listaCiudades').update();

$('fhot_letraPoblacion').update(letra);

var th = this;

new Ajax.Updater('fhot_listaCiudades', 'PaginaPrincipal/FormularioCompraPortada/getCiudadesHotel', 

{

parameters: { 'idPais': idPais, 'busquedaCiudad': letra },

onComplete: function() {

if ($('fhot_eleccionCiudad').style.display == 'none') {

th.ocultaSelect(true);

Effect.SlideDown('fhot_eleccionCiudad', {

afterFinish: function() {

$('fhot_listaCiudades').setStyle({'overflow': 'auto'});

}

});

}

$$('#fhot_listaCiudades ul li').each(function(elemento){

Event.observe(elemento, 'click', function(){

th.ciudadElegida(elemento.id, elemento.innerHTML);

$('fhot_listaCiudades').setStyle({'overflow': 'hidden'});

Effect.SlideUp('fhot_eleccionCiudad', {afterFinish: function() {th.ocultaSelect(false)}});

})

})

}

});


},


tipoElegido: function()

{

if($('fhot_dobleNino').value > 0)

{

$('fhot_edadNino').disabled = false;

} 

else 

{

$('fhot_edadNino').disabled = true;

}

this.activaBoton();


},

activaBoton: function()

{

if(this.ciudadSeleccionada && ($('fhot_individual').value > 0 || $('fhot_doble').value > 0 || $('fhot_dobleNino').value > 0 || $('fhot_Triple').value > 0))

{

$('fhot_botonBuscaHotel').removeClassName('desactivado');

}

else

{

$('fhot_botonBuscaHotel').addClassName('desactivado');

}

}

}

var formularioCompra_PaqueteCombinado = Class.create();

formularioCompra_PaqueteCombinado.prototype = {

initialize: function(idProducto) {

this.idProducto = idProducto;

this.contenedor = $('formularioCompra_' + idProducto);

this.fichaDesplegable = $('fichaDesplegable_' + this.idProducto);

this.desplegador = this.contenedor.select('.desplegador')[0];

this.selectCantidad = this.contenedor.select('.cantidad')[0];

this.selectCantidadModelos = this.contenedor.select('.selectCantidad');

this.selectModelos = this.contenedor.select('.selectModelos'); 

this.contenedorPrecioModelo = this.contenedor.select('.precioModelo');

this.contenedorPrecioModeloConDescuento = this.contenedor.select('.precioModeloConDescuento'); 

this.contenedorDescuento = this.contenedor.select('.descuentoModelo');

this.contenedorCosteDia = this.contenedor.select('.costeDiaModelo');

this.contenedorSubTotales = this.contenedor.select('.subTotal'); 

this.contenedorSubTotal = this.contenedor.select('.subTotalPaquete')[0]; 

this.contenedorDescuentoTotal = this.contenedor.select('.DescuentoPaquete')[0]; 

this.contenedorIvaTotal = this.contenedor.select('.IvaPaquete')[0];

this.contenedorSubTotalSinDescuento = this.contenedor.select('.subTotalSinDescuento')[0];

this.seccionDescuento = this.contenedor.select('.seccionDescuento')[0]; 

this.seccionIva = this.contenedor.select('.seccionIva')[0]; 

this.fechaVisita = $('fechaVisita_' + this.idProducto);

this.subTotales = new Array();

this.descuentos = new Array();

this.ivas = new Array();

this.subTotalesSinDescuento = new Array();

this.subTotal = 0;

this.ivaTotal = 0;

this.descuentoTotal = 0;

this.subTotalSinDescuento = 0;

this.eventos();

this.actualizaPrecio();

},


eventos: function()

{

var th = this;

this.selectCantidadModelos.each(function(select)

{

Event.observe(select, 'change', function() { th.actualizaPrecio(); });

})

this.selectModelos.each(function(select)

{

Event.observe(select, 'change', function() { th.actualizaPrecio(); });

})

Event.observe(this.desplegador, 'click', function(){th.despliegaFicha()});

},


actualizaPrecio: function()

{

var th = this;

var sw = false;

this.selectModelos.each(function(modelo,key){

if(th.selectCantidadModelos[key].value > 0) {sw = true;}

var datosModelo = globales.datosModelos[th.idProducto][modelo.value];

th.contenedorPrecioModelo[key].update(fn(datosModelo.precio,'â‚¬'));

th.contenedorPrecioModeloConDescuento[key].update(fn(datosModelo.precioConDescuento,'â‚¬'));

th.contenedorDescuento[key].update(fn(datosModelo.descuento,'%'));

th.contenedorCosteDia[key].update(fn(datosModelo.costeDia,'â‚¬'));

th.subTotales[key] = datosModelo.precioConDescuento * th.selectCantidadModelos[key].value;

th.descuentos[key] = datosModelo.cantidadDescuento * th.selectCantidadModelos[key].value;

th.ivas[key] = datosModelo.cantidadIva * th.selectCantidadModelos[key].value;

th.subTotalesSinDescuento[key] = datosModelo.precio * th.selectCantidadModelos[key].value;

th.actualizaCantidades(datosModelo.cantidades, key);

th.contenedorSubTotales[key].update(fn(th.subTotales[key],'â‚¬'));

})


this.selectCantidad.value = sw ? 1 : 0;


this.subTotal = 0;

this.subTotales.each(function(cantidad)

{

th.subTotal += cantidad;

})

this.ivaTotal = 0;

this.ivas.each(function(cantidad)

{

th.ivaTotal += cantidad;

})

this.descuentoTotal = 0;

this.descuentos.each(function(cantidad)

{

th.descuentoTotal += cantidad;

})

this.subTotalSinDescuento = 0;

this.subTotalesSinDescuento.each(function(cantidad)

{

th.subTotalSinDescuento += cantidad;

})


this.contenedorSubTotalSinDescuento.update(fn(this.subTotalSinDescuento,'â‚¬'));

this.contenedorSubTotal.update(fn(this.subTotal,'â‚¬'));

this.contenedorDescuentoTotal.update(fn(this.descuentoTotal,'â‚¬'));

this.contenedorIvaTotal.update(fn(this.ivaTotal,'â‚¬'));


this.seccionDescuento[this.descuentoTotal ? 'show' : 'hide']();

this.seccionIva[this.IvaTotal ? 'show' : 'hide']();


if(typeof botonCesta != 'undefined') {botonCesta.actualizaPrecio()};

},


despliegaFicha: function()

{

if (this.enMarcha) {return;}

var idProducto = this.idProducto;

ficha.each(function(ficha){

if(ficha != undefined && typeof ficha.fichaDesplegable != 'undefined' && idProducto != ficha.idProducto && ficha.fichaDesplegable.style.display != 'none')

{

ficha.despliegaFicha(); 

}

})


var fichaAjaxCargada = $('fichaDesplegable_' + this.idProducto).select('.fichaDetallada').size();


if (!fichaAjaxCargada)

{

new Ajax.Updater('fichaDesplegable_' + this.idProducto, globales.lang + '/AbonosTuristicos/FichaDetallada/' + this.idProducto,

{evalScripts: true}

);

}


var th = this;

new Effect.toggle(this.fichaDesplegable,'slide', 

{

beforeStart: function(){th.enMarcha = true},

afterFinish: function(){th.enMarcha = false}

});



this.desplegador.getElementsBySelector('a').each(function(span)

{

span.toggle();

})

}, 


actualizaCantidades: function(cantidades, key)

{

if(!cantidades.size()) {return;}

valorSelect = this.selectCantidadModelos[key].value;

var selectCantidad = '<select name="cantidad" class="selectCantidad">';

cantidades.each(function(cantidad){

selectCantidad += '<option value="' + cantidad + '">' + cantidad + '</option>';

})

selectCantidad += '</select>';

this.selectCantidadModelos[key].replace(selectCantidad);

this.selectCantidadModelos[key] = this.contenedor.select('.selectCantidad')[key];

this.selectCantidadModelos[key].value = valorSelect;

var th = this;

Event.observe(this.selectCantidadModelos[key], 'change', function() { th.actualizaPrecio() });

},

datosCompra: function()

{

if(this.selectCantidad.value < 1) {return false;}


var rtn = new Object();

rtn.idproducto = this.idProducto;

rtn.cantidad = this.selectCantidad.value;

rtn.fechavisita = this.fechaVisita.value;

var modelos = new Array();

var divs = this.contenedor.select('.productoPaquete');

var th = this;

divs.each(function(elemento)

{

var pr = Form.serialize(elemento,true);

pr.fechavisita = th.fechaVisita.value; 

modelos.push(pr);

})

rtn.modelos = modelos;


return rtn;

}

};

if (globales.ajax != true) {

Event.observe(document, 'dom:loaded', function(){

if (typeof ficha == 'undefined') {

ficha = new Array()

}

globales.formularioCompra_PaqueteCombinado.each(function(idProducto){

ficha[idProducto] = new formularioCompra_PaqueteCombinado(idProducto);

//ficha[idProducto].actualizaPrecio();

})

//ficha = ficha.without(undefined);


});

}

function pruebaFechas(date, y, m, d)

{

var hoy = new Date();

if (date <= hoy)

return true;

else

return 'elegible'; 

};

var formularioCompra_AbonoTuristico = Class.create();

formularioCompra_AbonoTuristico.prototype = {

initialize: function(idProducto) {

this.idProducto = idProducto;


/**

* div contenedores

*/

this.contenedor = $('formularioCompra_' + idProducto);

this.contenedorSubTotal = this.contenedor.select('.subTotal')[0];

this.contenedorPrecioModelo = this.contenedor.select('.precioModelo')[0];

this.contenedorPrecioModeloXCantidad = this.contenedor.select('.precioModeloXCantidad')[0];

this.contenedorPrecioModeloConDescuento = this.contenedor.select('.precioModeloConDescuento')[0]; 

this.contenedorDescuento = this.contenedor.select('.descuentoModelo')[0];

this.contenedorCosteDia = this.contenedor.select('.costeDia')[0];

this.contenedorIVA = this.contenedor.select('.IVA')[0]; 

this.seccionCosteDia = this.contenedor.select('.seccionCosteDia')[0] 

this.seccionDescuento = this.contenedor.select('.seccionDescuento')[0] 

this.seccionIVA = this.contenedor.select('.seccionIVA')[0] 


this.formulario = this.contenedor.select('.formFormularioCompra')[0]; 


/**

* Selector (select) de los modelos de producto

*/

this.selectModelos = this.contenedor.select('.selectModelos')[0];


/**

* Selector (select) de la cantidad

*/

this.selectCantidad = this.contenedor.select('.selectCantidad')[0];


/**

* 'BotÃ³n' que despliega la ficha detallada

*/

this.desplegador = this.contenedor.select('.desplegador')[0];


/**

* Ficha desplegable

*/


this.fichaDesplegable = $('fichaDesplegable_' + this.idProducto); 


/**

* Fecha de visita

*/

this.fechaVisita = $('fechaVisita_' + this.idProducto);

/**

* Precio del modelo de producto seleccionado.

*/

this.precio = 0;


/**

* Subtotal del modelo de producto seleccionado

*/

this.subTotal = 0;

this.subTotalSinDescuento = 0;


this.enMarcha = false;


this.eventos();

},


eventos: function()

{

var th=this;

Event.observe(this.selectModelos, 'change', function() { th.actualizaPrecio() });

Event.observe(this.selectCantidad, 'change', function() { th.actualizaPrecio() });

//this.fechaVisita.onchange = function() { th.actualizaPrecioAjax() };

Event.observe(this.desplegador, 'click', function(){th.despliegaFicha()});

},


actualizaPrecio: function()

{

var datosModelo = globales.datosModelos[this.idProducto][this.selectModelos.value];

this.contenedorPrecioModelo.update(fn(datosModelo.precio, 'â‚¬'));

this.contenedorPrecioModeloConDescuento.update(fn(datosModelo.precioConDescuento,'â‚¬'));

this.contenedorDescuento.update(fn(datosModelo.descuento,'%'));


this.contenedorPrecioModeloXCantidad.update(fn(datosModelo.precio * this.selectCantidad.value, 'â‚¬'));


this.contenedorCosteDia.update(fn(datosModelo.costeDia, 'â‚¬'));

this.contenedorIVA.update(fn(datosModelo.cantidadIva * this.selectCantidad.value, 'â‚¬'));

this.contenedorDescuento.update(fn(datosModelo.cantidadDescuento * this.selectCantidad.value, 'â‚¬'));


this.seccionCosteDia[datosModelo.costeDia ? 'show' : 'hide']();

this.seccionIVA[datosModelo.cantidadIva * this.selectCantidad.value ? 'show' : 'hide']();

this.seccionDescuento[datosModelo.cantidadDescuento * this.selectCantidad.value ? 'show' : 'hide']();


this.subTotal = datosModelo.precioConDescuento * this.selectCantidad.value;

if(datosModelo.iva) 

this.subTotal += datosModelo.iva ? this.subTotal * (datosModelo.iva / 10000) : 0;

this.subTotalSinDescuento = datosModelo.precio * this.selectCantidad.value;

this.contenedorSubTotal.update(fn(this.subTotal,'â‚¬'));

if(datosModelo.cantidades) {this.actualizaCantidades(datosModelo.cantidades)};

if(typeof botonCesta != "undefined") {botonCesta.actualizaPrecio()};

},


actualizaCantidades: function(cantidades)

{

if(!cantidades.size()) {return;}

valorSelect = this.selectCantidad.value;

var selectCantidad = '<select name="cantidad" class="selectCantidad">';

cantidades.each(function(cantidad){

selectCantidad += '<option value="' + cantidad + '">' + cantidad + '</option>';

})

selectCantidad += '</select>';

this.selectCantidad.replace(selectCantidad);

this.selectCantidad = this.contenedor.select('.selectCantidad')[0];

this.selectCantidad.value = valorSelect;

var th = this;

Event.observe(this.selectCantidad, 'change', function() { th.actualizaPrecio() });

},



despliegaFicha: function()

{

if (this.enMarcha) {return;}

var idProducto = this.idProducto;

ficha.each(function(ficha){

if(ficha != undefined && typeof ficha.fichaDesplegable != 'undefined' && idProducto != ficha.idProducto && ficha.fichaDesplegable.style.display != 'none')

{

ficha.despliegaFicha(); 

}

})


var fichaAjaxCargada = $('fichaDesplegable_' + this.idProducto).select('.fichaDetallada').size();


if (!fichaAjaxCargada)

{

new Ajax.Updater('fichaDesplegable_' + this.idProducto, globales.lang + '/AbonosTuristicos/FichaDetallada/' + this.idProducto,

{evalScripts: true}

);

}


var th = this;

new Effect.toggle(this.fichaDesplegable,'slide', 

{

beforeStart: function(){th.enMarcha = true},

afterFinish: function(){th.enMarcha = false}

});



this.desplegador.getElementsBySelector('a').each(function(span)

{

span.toggle();

})

}, 


cambiaDesplegador: function()

{

this.desplegador.getElementsBySelector('span').each(function(span)

{

span.toggle();

})

},

datosCompra: function()

{

if(this.selectCantidad.value < 1) {return false;}


var rtn = new Object();

rtn.idproducto = this.idProducto;

rtn.idmodeloproducto = this.selectModelos.value;

rtn.cantidad = this.selectCantidad.value;

rtn.fechavisita = this.fechaVisita.value;

return rtn;

}

}

if (globales.ajax != true) {

Event.observe(document, 'dom:loaded', function(){

if (typeof ficha == 'undefined') {

ficha = new Array()

}

globales.formularioCompra_AbonoTuristico.each(function(idProducto){

ficha[idProducto] = new formularioCompra_AbonoTuristico(idProducto);

ficha[idProducto].actualizaPrecio();

})

});

}var formularioCompra_TarjetaTuristica = Class.create();

formularioCompra_TarjetaTuristica.prototype = {

initialize: function(idProducto) {

this.idProducto = idProducto;


/**

* div contenedores

*/

this.contenedor = $('formularioCompra_' + idProducto);

this.contenedorSubTotal = this.contenedor.select('.subTotal')[0];

this.contenedorPrecioModelo = this.contenedor.select('.precioModelo')[0];

this.contenedorPrecioModeloXCantidad = this.contenedor.select('.precioModeloXCantidad')[0];

this.contenedorPrecioModeloConDescuento = this.contenedor.select('.precioModeloConDescuento')[0]; 

this.contenedorDescuento = this.contenedor.select('.descuentoModelo')[0]; 

this.contenedorCosteDia = this.contenedor.select('.costeDia')[0];

this.contenedorIVA = this.contenedor.select('.IVA')[0];


this.seccionCosteDia = this.contenedor.select('.seccionCosteDia')[0] 

this.seccionDescuento = this.contenedor.select('.seccionDescuento')[0] 

this.seccionIVA = this.contenedor.select('.seccionIVA')[0] 


this.formulario = this.contenedor.select('.formFormularioCompra')[0];


/**

* Selector (select) de los modelos de producto

*/

this.selectModelos = this.contenedor.select('.selectModelos')[0];


/**

* Selector (select) de la cantidad

*/

this.selectCantidad = this.contenedor.select('.selectCantidad')[0];


/**

* 'BotÃ³n' que despliega la ficha detallada

*/

this.desplegador = this.contenedor.select('.desplegador')[0];


/**

* Ficha desplegable

*/


this.fichaDesplegable = $('fichaDesplegable_' + this.idProducto);


/**

* Fecha de visita

*/

this.fechaVisita = $('fechaVisita_' + this.idProducto);


/**

* Precio del modelo de producto seleccionado.

*/

this.precio = 0;


/**

* Subtotal del modelo de producto seleccionado

*/

this.subTotal = 0;

this.subTotalSinDescuento = 0;


this.enMarcha = false;


this.eventos();

},


eventos: function()

{

var th=this;

Event.observe(this.selectModelos, 'change', function() { th.actualizaPrecio() });

Event.observe(this.selectCantidad, 'change', function() { th.actualizaPrecio() });

//this.fechaVisita.onchange = function() { th.actualizaPrecioAjax() };

Event.observe(this.desplegador, 'click', function(){th.despliegaFicha()});

},


actualizaPrecio: function()

{

var datosModelo = globales.datosModelos[this.idProducto][this.selectModelos.value];

this.contenedorPrecioModelo.update(fn(datosModelo.precio, 'â‚¬'));

this.contenedorPrecioModeloConDescuento.update(fn(datosModelo.precioConDescuento,'â‚¬'));

this.contenedorDescuento.update(fn(datosModelo.descuento,'%'));


this.contenedorPrecioModeloXCantidad.update(fn(datosModelo.precio * this.selectCantidad.value, 'â‚¬'));


this.contenedorCosteDia.update(fn(datosModelo.costeDia, 'â‚¬'));

this.contenedorIVA.update(fn(datosModelo.cantidadIva * this.selectCantidad.value, 'â‚¬'));

this.contenedorDescuento.update(fn(datosModelo.cantidadDescuento * this.selectCantidad.value, 'â‚¬'));


this.seccionCosteDia[datosModelo.costeDia ? 'show' : 'hide']();

this.seccionIVA[datosModelo.cantidadIva * this.selectCantidad.value ? 'show' : 'hide']();

this.seccionDescuento[datosModelo.cantidadDescuento * this.selectCantidad.value ? 'show' : 'hide']();


this.subTotal = datosModelo.precioConDescuento * this.selectCantidad.value;

if(datosModelo.iva) 

this.subTotal += datosModelo.iva ? this.subTotal * (datosModelo.iva / 10000) : 0;

this.subTotalSinDescuento = datosModelo.precio * this.selectCantidad.value;

this.contenedorSubTotal.update(fn(this.subTotal,'â‚¬'));

if(datosModelo.cantidades) {this.actualizaCantidades(datosModelo.cantidades)};

if(typeof botonCesta != "undefined") {botonCesta.actualizaPrecio()};

},


actualizaCantidades: function(cantidades)

{

if(!cantidades.size()) {return;}

valorSelect = this.selectCantidad.value;

var selectCantidad = '<select name="cantidad" class="selectCantidad">';

cantidades.each(function(cantidad){

selectCantidad += '<option value="' + cantidad + '">' + cantidad + '</option>';

})

selectCantidad += '</select>';

this.selectCantidad.replace(selectCantidad);

this.selectCantidad = this.contenedor.select('.selectCantidad')[0];

this.selectCantidad.value = valorSelect;

var th = this;

Event.observe(this.selectCantidad, 'change', function() { th.actualizaPrecio() });

},


despliegaFicha: function()

{

if (this.enMarcha) {return;}

var idProducto = this.idProducto;

ficha.each(function(ficha){

if(ficha != undefined && typeof ficha.fichaDesplegable != 'undefined' && idProducto != ficha.idProducto && ficha.fichaDesplegable.style.display != 'none')

{

ficha.despliegaFicha(); 

}

})


var fichaAjaxCargada = $('fichaDesplegable_' + this.idProducto).select('.fichaDetallada').size();


if (!fichaAjaxCargada)

{

new Ajax.Updater('fichaDesplegable_' + this.idProducto, globales.lang + '/FormulariosCompra/producto/' + this.idProducto,

{evalScripts: true}

);

}


var th = this;

new Effect.toggle(this.fichaDesplegable,'slide', 

{

beforeStart: function(){th.enMarcha = true},

afterFinish: function(){th.enMarcha = false}

});



this.desplegador.getElementsBySelector('a').each(function(span)

{

span.toggle();

})

},


cambiaDesplegador: function()

{

this.desplegador.getElementsBySelector('span').each(function(span)

{

span.toggle();

})

},


datosCompra: function()

{

if(this.selectCantidad.value < 1) {return false;}


var rtn = new Object();

rtn.idproducto = this.idProducto;

rtn.idmodeloproducto = this.selectModelos.value;

rtn.cantidad = this.selectCantidad.value;

rtn.fechavisita = this.fechaVisita.value;

return rtn;

}

}

if (globales.ajax != true) {

Event.observe(document, 'dom:loaded', function(){

if (typeof ficha == 'undefined') {

ficha = new Array()

}

globales.formularioCompra_TarjetaTuristica.each(function(idProducto){

ficha[idProducto] = new formularioCompra_TarjetaTuristica(idProducto);

ficha[idProducto].actualizaPrecio();

})

});

}var carruselBloque = Class.create();

carruselBloque.prototype = {

initialize: function(){

this.elementos = $$('.contCarrusel .carrusel');

this.activo = 0; //quÃ© elemento estÃ¡ activo


var th = this;

setInterval(function(){th.cambia()}, 10000);

},


cambia: function() {

var mostrar = this.activo+1;

var ocultar = this.activo;

if(this.activo == 2) {

mostrar = 0;

ocultar = this.elementos.size()-1;

this.activo =-1;

}

this.muestra2(mostrar,ocultar);

this.activo++;

},


muestra: function(mostrar,ocultar)

{

this.elementos[ocultar].setStyle({zIndex:'3'});

this.elementos[mostrar].setStyle({

bottom: '-229px',

left: '0px',

zIndex: '5',

display: 'none'

});

//this.elementos[mostrar].show();


var th = this;

new Effect.Parallel([

new Effect.Appear(this.elementos[mostrar], {duration:0.9}),

new Effect.Morph(this.elementos[mostrar], {style: 'bottom:0px',duration:1}) 

], { 

afterFinish: function() {th.elementos[ocultar].hide();}

});

},

muestra2: function(mostrar,ocultar)

{

this.elementos[ocultar].setStyle({zIndex:'3'});

this.elementos[mostrar].setStyle({

bottom: '0px',

left: '582px',

zIndex: '5',

display: 'none'

});

//this.elementos[mostrar].show();


var th = this;

new Effect.Parallel([

new Effect.Appear(this.elementos[mostrar], {duration:0.5,delay:0.5}),

new Effect.Morph(this.elementos[mostrar], {style: 'left:0px',duration:1}) 

], { 

afterFinish: function() {th.elementos[ocultar].hide();}

});

},


muestraFade: function(mostrar, ocultar)

{

new Effect.Fade(this.elementos[ocultar]);

new Effect.Appear(this.elementos[mostrar]);

},


eventos: function(){

}

}

Event.observe(document, 'dom:loaded', function(){

cr = new carruselBloque();

});var botonAddCesta = Class.create();

botonAddCesta.prototype = {

initialize: function() {

this.total = 0;

this.totalSinDescuento = 0;

this.contenedorPrecio = $('totalCesta');

this.contenedorPrecioSinDescuento = $('totalDescuento');

this.eventos();

this.datosCompra = new Array();

this.inputDatosCompra = $('inputDatosCompra');

this.urlForm = $('formAddCesta').getAttribute('action');

},


eventos: function()

{

var th = this;

$('botonAddCesta').onclick = function() {return false}

Event.observe($('botonAddCesta'), 'click', function(){th.serializaDatos()});

},



actualizaPrecio: function()

{

this.total = 0;

this.totalSinDescuento = 0;

var th = this;

var activarBoton = false;

ficha.without(undefined).each(function(elemento) {

th.total = th.total + elemento.subTotal;

th.totalSinDescuento = th.totalSinDescuento + elemento.subTotalSinDescuento;

if (elemento.selectCantidad.value > 0)

{

activarBoton = true; 

}

})

this.contenedorPrecio.update(fn(this.total,'â‚¬'));

this.contenedorPrecioSinDescuento.update(fn(this.totalSinDescuento,'â‚¬'));


if(this.total < this.totalSinDescuento)

{

this.contenedorPrecioSinDescuento.show();

this.contenedorPrecio.removeClassName('noDescuento');

}

else

{

this.contenedorPrecioSinDescuento.hide();

this.contenedorPrecio.addClassName('noDescuento');

}


//Form.Element[activarBoton ? 'enable' : 'disable']('botonAddCesta');

$('botonAddCesta')[activarBoton ? 'removeClassName' : 'addClassName']('desactivado');


$$('.botonCesta').invoke(activarBoton ? 'removeClassName' : 'addClassName', 'desactivado');

},


serializaDatos: function()

{

if($('botonAddCesta').hasClassName('desactivado')) {return;}

this.datosCompra.clear();

var th = this;

ficha.without(undefined).each(function(formulario)

{

var datosFormulario = formulario.datosCompra();

if (datosFormulario)

{

th.datosCompra.push(datosFormulario);

}

})

this.inputDatosCompra.value = th.datosCompra.without(undefined).toJSON();


$('botonAddCesta').addClassName('desactivado');

$$('.botonCesta').invoke('addClassName', 'desactivado');


new Ajax.Request(this.urlForm, {

method: 'post',

parameters: {'datosCompra': this.inputDatosCompra.value},

onSuccess: function(transport, json) {

if(!json.errores)

{

window.location = json.redir;

}

else

{

$('botonAddCesta').removeClassName('desactivado');

$$('.botonCesta').invoke('removeClassName', 'desactivado');

}

}

});


}

}

Event.observe(document, 'dom:loaded', function(){

botonCesta = new botonAddCesta();

});
