// JavaScript Document

var acordeon_activo = false;

//Inicialización
function inicializa_pagina_inicio()
	{
	$('marcador_scroll').setStyle({'top': $('mini_museo1').cumulativeOffset()[1]-3+'px','left': $('mini_museo1').cumulativeOffset()[0]+'px'});
	$('marcador_scroll').show();
	inicia_scroll();
	$('contenedor_museos_inicio').observe('mouseover', function(event){pe_museos.stop();});
	$('contenedor_museos_inicio').observe('mouseout', function(event){inicia_scroll();});
	}
//Fin Inicialización


//Inicio Submenu
var menu_baja = 0;
var menu_sube = 0;
var dentro_menu = 0;
var dentro_submenu = 0;
var submenu_abierto = 0;

function abre_submenu(id_submenu)
	{
	//if ((menu_baja == 0) && (menu_sube == 0) && (dentro_submenu == 0) && (submenu_abierto == 0))
	//	{
		$('sub'+id_submenu).setStyle({'top': $(id_submenu).cumulativeOffset()[1]+$(id_submenu).getHeight()-9+'px','left': $(id_submenu).cumulativeOffset()[0]+'px'});
		$('esquina_sub'+id_submenu).setStyle({'width': $(id_submenu).getWidth()-22+'px'});
		//Effect.Appear('submenu'+id_submenu,{ duration: 0.4 , beforeStart: function(){menu_baja = 1;}, afterFinish: function(){submenu_abierto = 1;menu_baja = 0;if ((dentro_menu == 0) && (dentro_submenu == 0)){cierra_submenu(id_submenu);}}}); 
		$('sub'+id_submenu).show();
		return false;
	//	}
	}
function cierra_submenu(id_submenu)
	{
	//if ((menu_baja == 0) && (menu_sube == 0) && (dentro_menu == 0) && (dentro_submenu == 0) && (submenu_abierto == 1))
	//	{
		//Effect.SlideUp('submenu'+id_submenu,{ duration: 0.4 , beforeStart: function(){menu_sube = 1;}, afterFinish: function(){submenu_abierto = 0;menu_sube = 0;}});
		//submenu_abierto = 0;
		$('sub'+id_submenu).hide();
		return false;
	//	}
	}
//Fin submenu

//Inicio marquesina	
var id_imagen_galeria = 0;

function inicializa_marquesina()
	{
	new PeriodicalExecuter(carga_contenido_marquesina, 5);
	}
	
function carga_contenido_marquesina()  //Función de carga de las páginas
	{
	var aleatorio=Math.random(); 
	var url = 'marquesina_inicio.asp';
	var cad_temporal = "";
	
	new Ajax.Request(url+'?nocache='+aleatorio+'&id_imagen_galeria='+id_imagen_galeria, 
					{
					method: 'get', 
					onSuccess: function(transport) 
					 	{
						cad_temporal = transport.responseText;
						var fondo_trasero = $("marquesina_trasero").getStyle("backgroundImage");
						$("marquesina_delantero").setStyle({backgroundImage:fondo_trasero});
						$("marquesina_delantero").setOpacity(1);
						$("marquesina_trasero").setStyle({backgroundImage:"url('"+transport.responseText+"')"});
						new Effect.Opacity("marquesina_delantero",{duration:1, from:1.0, to:0});
						id_imagen_galeria = parseInt(cad_temporal.substring(cad_temporal.indexOf('?id_imagen_galeria = ',0)+21,cad_temporal.length));
						}
					});
	}
//Fin marquesina


//Inicio Scroll Museos
var myEffect;
var haciendoscroll = false;
var museoactual = 1;
var pe_museos;
var velocidad_scroll = 4; //Segundos que tarda en cambiar el scroll

function inicia_scroll()
	{
	pe_museos = new PeriodicalExecuter(function(pe) {
		if(museoactual < 7){museoactual+=1}
		else (museoactual = 1)
		moveTo('scroll_museos','museo'+museoactual);
		new Effect.Move($('marcador_scroll'), { x: $('mini_museo'+museoactual).cumulativeOffset()[0], y: $('mini_museo'+museoactual).cumulativeOffset()[1]-3, mode: 'absolute' });}, velocidad_scroll);
	}

function mover_scroll_museos(posicion)
	{
	pe_museos.stop();
	museoactual = posicion;
	moveTo('scroll_museos','museo'+posicion);
	new Effect.Move($('marcador_scroll'), { x: $('mini_museo'+posicion).cumulativeOffset()[0], y: $('mini_museo'+posicion).cumulativeOffset()[1]-3, mode: 'absolute' });
	}

Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }

    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;

    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } else {

    }
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});

function moveTo(container, element) //Funcion para hacer scroll de una div dentro de otra
	{
	Position.prepare();
	container_y = Position.cumulativeOffset($(container))[1]
	element_y = Position.cumulativeOffset($(element))[1]
	if (haciendoscroll) {myEffect.cancel();}
	myEffect = new Effect.Scroll(container, {x:0, y:(element_y-container_y), afterFinish : haciendoscroll = false});
	haciendoscroll = true;
	return false;
	}
//Fin Scroll Museos	


function carga_cadena(id_elemento,cadena) //Función de control de errores
	{
	if(cadena.indexOf('<!--##OK##-->')>-1)
		{Element.update(id_elemento, cadena);$(id_elemento).show();}
	else
		{
		if (id_elemento == "div_form_cont")
			{
			Element.update(id_elemento, "<div align='center'><br/><br/><br/><img src='images/email_error.png' width='100' height='68' alt='correcto' /><br/><br/><br/><br/><span style='font-size:16px; color:#900'>ERROR</span><br/><br/>No hemos recibido correctamente su información, por favor, vuelva a contactar con nosotros. Muchas gracias.<br/><br/></div>");$(id_elemento).show();
			}
		}
	}
	
function carga_contenido(id_elemento,url,parametros,acciones_post)  //Función de carga de las páginas
	{
	var aleatorio = Math.random(); 
	var path_final = '';

	new Ajax.Request(path_final+url+'?nocache='+aleatorio+parametros, 
					{
					method: 'get', 
					onSuccess: function(transport) 
					 	{
						if(id_elemento!='no_elem')
							{
							carga_cadena(id_elemento, transport.responseText);
							}
						eval(acciones_post);
						},
					onFailure: function(failure)
					 	{
						alert(failure.responseText);
						}
					});
	} 

function envia_form(formulario) //Funcion de envío de formularios
	{
	var accion = document.getElementById(formulario).action;
	
	new Ajax.Request(accion, {method:'post', 
					 		  postBody: Form.serialize(formulario),
								onSuccess: function(transport) 
									{
									if ((formulario == 'form_contacto'))
										{
										carga_cadena('div_form_cont', transport.responseText);
										}
									},
								onFailure: function(failure)
									{
									if ((formulario == 'form_contacto'))
										{
										carga_cadena('div_form_cont', "<div align='center'><br/><br/><br/><img src='images/email_error.png' width='100' height='68' alt='correcto' /><br/><br/><br/><br/><span style='font-size:16px; color:#900'>ERROR</span><br/><br/>No hemos recibido correctamente su información, por favor, vuelva a contactar con nosotros. Muchas gracias.<br/><br/><a href='#' onclick='carga_contenido('formulario_contacto','formulario_contacto.asp','&pagina="+$('pag_consulta').value+"','');'>Volver a contactar</a></div>");
										}
									else {alert(failure.responseText);}
									}
								});
	}
	
function form_contacto_validado()
	{
	var formvalidado = true;
	var cadena_validacion = "Se han producido los siguiente errores:\n";
	var cad_email = $("email").value;
	
	if ($("nombre").value == ""){formvalidado = false;cadena_validacion += "   -rellene corecctamente su nombre\n"}
	if ($("provincia").value == ""){formvalidado = false;cadena_validacion += "   -rellene corecctamente su provincia\n"}
	if (((cad_email.indexOf(".") > 2) && (cad_email.indexOf("@") > 0)) == false){formvalidado = false;cadena_validacion += "   -rellene corecctamente su email\n"}
	if ($("telefono").value == ""){formvalidado = false;cadena_validacion += "   -rellene corecctamente su teléfono\n"}
	if (formvalidado == false){alert(cadena_validacion);}
	return formvalidado;
	}
	
	
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
var max_incr = 9;
var cont_incr = parseInt(max_incr/2);
var inc_cont = false;
function increaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
		 if (p[i].style.fontSize.indexOf("px") > -1){var s = parseInt(p[i].style.fontSize.replace("px",""));}
		 if (p[i].style.fontSize.indexOf("smaller") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("xx-small") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("x-small") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("larger") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("small") > -1){var s = 16;}
		 if (p[i].style.fontSize.indexOf("medium") > -1){var s = 19;}
		 if (p[i].style.fontSize.indexOf("large") > -1){var s = 22;}
		 if (p[i].style.fontSize.indexOf("x-large") > -1){var s = 26;}
		 if (p[i].style.fontSize.indexOf("xx-large") > -1){var s = 34;}
      } else {
         var s = 14;
      }
      if(cont_incr < max_incr) {
         s += 1;
		 inc_cont = true;
      }
      p[i].style.fontSize = s+"px"
   }
   p = document.getElementsByTagName('span');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
		 if (p[i].style.fontSize.indexOf("px") > -1){var s = parseInt(p[i].style.fontSize.replace("px",""));}
		 if (p[i].style.fontSize.indexOf("smaller") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("xx-small") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("x-small") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("larger") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("small") > -1){var s = 16;}
		 if (p[i].style.fontSize.indexOf("medium") > -1){var s = 19;}
		 if (p[i].style.fontSize.indexOf("large") > -1){var s = 22;}
		 if (p[i].style.fontSize.indexOf("x-large") > -1){var s = 26;}
		 if (p[i].style.fontSize.indexOf("xx-large") > -1){var s = 34;}
      } else {
         var s = 14;
      }
      if(cont_incr < max_incr) {
         s += 1;
		 inc_cont = true;
      }
      p[i].style.fontSize = s+"px"
   }
   if (inc_cont){cont_incr += 1;inc_cont = false;};
   Cufon.now();
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
		 if (p[i].style.fontSize.indexOf("px") > -1){var s = parseInt(p[i].style.fontSize.replace("px",""));}
         if (p[i].style.fontSize.indexOf("smaller") > -1){var s = 10;}
		 if (p[i].style.fontSize.indexOf("xx-small") > -1){var s = 10;}
		 if (p[i].style.fontSize.indexOf("x-small") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("larger") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("small") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("medium") > -1){var s = 16;}
		 if (p[i].style.fontSize.indexOf("large") > -1){var s = 19;}
		 if (p[i].style.fontSize.indexOf("x-large") > -1){var s = 22;}
		 if (p[i].style.fontSize.indexOf("xx-large") > -1){var s = 26;}
      } else {
         var s = 14;
      }
	  if(cont_incr > 0) {
         s -= 1;
		 inc_cont = true;
      }
      p[i].style.fontSize = s+"px"
   }   
   p = document.getElementsByTagName('span');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
		 if (p[i].style.fontSize.indexOf("px") > -1){var s = parseInt(p[i].style.fontSize.replace("px",""));}
         if (p[i].style.fontSize.indexOf("smaller") > -1){var s = 10;}
		 if (p[i].style.fontSize.indexOf("xx-small") > -1){var s = 10;}
		 if (p[i].style.fontSize.indexOf("x-small") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("larger") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("small") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("medium") > -1){var s = 16;}
		 if (p[i].style.fontSize.indexOf("large") > -1){var s = 19;}
		 if (p[i].style.fontSize.indexOf("x-large") > -1){var s = 22;}
		 if (p[i].style.fontSize.indexOf("xx-large") > -1){var s = 26;}
      } else {
         var s = 14;
      }
	  if(cont_incr > 0) {
         s -= 1;
		 inc_cont = true;
      }
      p[i].style.fontSize = s+"px"
   }   
   if (inc_cont){cont_incr -= 1;inc_cont = false;};
   Cufon.now();
}

function normalFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
		 if (p[i].style.fontSize.indexOf("px") > -1){var s = parseInt(p[i].style.fontSize.replace("px",""));}
		 if (p[i].style.fontSize.indexOf("smaller") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("xx-small") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("x-small") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("larger") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("small") > -1){var s = 16;}
		 if (p[i].style.fontSize.indexOf("medium") > -1){var s = 19;}
		 if (p[i].style.fontSize.indexOf("large") > -1){var s = 22;}
		 if (p[i].style.fontSize.indexOf("x-large") > -1){var s = 26;}
		 if (p[i].style.fontSize.indexOf("xx-large") > -1){var s = 34;}
      } else {
         var s = 14;
      }

		 s = s + (parseInt(max_incr/2) - cont_incr);


      p[i].style.fontSize = s+"px"

   }
   p = document.getElementsByTagName('span');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
		 if (p[i].style.fontSize.indexOf("px") > -1){var s = parseInt(p[i].style.fontSize.replace("px",""));}
		 if (p[i].style.fontSize.indexOf("smaller") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("xx-small") > -1){var s = 12;}
		 if (p[i].style.fontSize.indexOf("x-small") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("larger") > -1){var s = 14;}
		 if (p[i].style.fontSize.indexOf("small") > -1){var s = 16;}
		 if (p[i].style.fontSize.indexOf("medium") > -1){var s = 19;}
		 if (p[i].style.fontSize.indexOf("large") > -1){var s = 22;}
		 if (p[i].style.fontSize.indexOf("x-large") > -1){var s = 26;}
		 if (p[i].style.fontSize.indexOf("xx-large") > -1){var s = 34;}
      } else {
         var s = 14;
      }

	 s = s + (parseInt(max_incr/2) - cont_incr);

      p[i].style.fontSize = s+"px"

   }
	cont_incr = parseInt(max_incr/2);
	inc_cont = false;
   Cufon.now();
}

function campos_obligatorios_formulario (formulario,lista_campos,texto){
	devolver="true";
	array_lista_campos = lista_campos.split(',');
	for (var i=0;i<array_lista_campos.length;i++){
			//alert(eval("document.crea_usu."+(array_lista_campos[i])+".value"))
			if (eval("document."+formulario+"."+(array_lista_campos[i])+".value")=='')
			{
			devolver="false";
			}
			//alert(devolver);
		} 

	if (devolver=="false")
	{
		if (texto!='') {alert(texto);} else {alert('Ha de rellenar los campos indicados con un *')}
	return false;
	}
	else
	{
	return true;
	}
}

function validar_email (campo,texto){
	if (eval(campo) != ""){
		
	if( !(/^[A-Za-z][A-Za-z0-9_\-\.]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-.]+[A-za-z]$/.test(eval(campo))) )
	{
	alert(texto);
	return false;
	}
	else
	{
	return true;
	}
	}
	else{return true;}
}


function campos_numericos_formulario (formulario,lista_campos,texto){
	devolver="true";
	array_lista_campos = lista_campos.split(',');
	for (var i=0;i<array_lista_campos.length;i++){
			//alert(eval("document.crea_usu."+(array_lista_campos[i])+".value"))
			if (isNaN(eval("document."+formulario+"."+(array_lista_campos[i])+".value")))
			{
			devolver="false";
			}
			//alert(devolver);
		} 

	if (devolver=="false")
	{
		if (texto!='') {alert(texto);} else {alert('Revise los campos numericos del formulario')}
	return false;
	}
	else
	{
	return true;
	}
}


function corregir_campos_formulario (formulario,lista_campos){
	array_lista_campos = lista_campos.split(',');
	for (var i=0;i<array_lista_campos.length;i++){
			campo=eval("document."+formulario+"."+(array_lista_campos[i])+".value");
			$(array_lista_campos[i]).value=reemplazar(campo)
			//alert(campo)
		} 

}

function corregir_campos_formulario_con_etiqueta (formulario,lista_campos){
	array_lista_campos = lista_campos.split(',');
	for (var i=0;i<array_lista_campos.length;i++){
			campo=eval("document."+formulario+"."+(array_lista_campos[i])+".value");
			$(array_lista_campos[i]).value=reemplazar_con_etiquetas(campo)
			//alert(campo)
		} 

}

function reemplazar(cadena)
{
	var cadena_final = cadena;
	
	cadena_final = cadena_final.replace(/&/g,"&amp;");
	cadena_final = cadena_final.replace(/'/g,"\"");
	cadena_final = cadena_final.replace(/\“/g,"&quot;");
	cadena_final = cadena_final.replace(/\”/g,"&quot;");
	cadena_final = cadena_final.replace(/\"/g,"&quot;");
	cadena_final = cadena_final.replace(/\n/g,'<br />');
	cadena_final = cadena_final.replace(/</g,"< ");
	cadena_final = cadena_final.replace(/>/g," >");
	cadena_final = cadena_final.replace(/<  /g,"< ");
	cadena_final = cadena_final.replace(/  >/g," >");
	cadena_final = cadena_final.replace(/< br \/ >/g,"<br />");
	cadena_final = cadena_final.replace(/< b >/g,"<b>");
	cadena_final = cadena_final.replace(/< \/b >/g,"</b>");
	cadena_final = cadena_final.replace(/< em >/g,"<em>");
	cadena_final = cadena_final.replace(/< \/em >/g,"</em>");
	cadena_final = cadena_final.replace(/< span/g,"<span");
	cadena_final = cadena_final.replace(/< \/span >/g,"</span>");
	
	return cadena_final;
}

function validarEmail(valor)
	{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
		{
		return (true);
		}
	else 
		{
		return (false);
		}
	}



function validar_contacto(formulario) //Valida el formulario de envío de contacto
	{
	if (formulario == "form_contacto")
		{
		if (($(formulario).nombre.value == "") || ($(formulario).nombre.value == "persona de contacto*"))
			{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - El nombre de la persona de contacto no puede estar vacio, es un campo obligatorio</div>');
			//new Effect.Highlight('persona', {startcolor : '#C00000'});
			return false;
			}
		else{
			if (($(formulario).email.value == "") || ($(formulario).email.value == "correo electronico*") || (validarEmail($(formulario).email.value) == false))
				{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - Debe introducir un email correcto, es un campo obligatorio</div>');
				//new Effect.Highlight('email', {startcolor : '#C00000'});
				return false;
				}
			else
				{
					if (($(formulario).personas.value == "") || ($(formulario).personas.value == "descripcion del proyecto*"))
						{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - El campo número de personas nos indica las personas de la reserva, es un campo obligatorio</div>');
						//new Effect.Highlight('consulta', {startcolor : '#C00000'});
						return false;
						}
					else
						{return true}	
				}	
			}
		}
	if (formulario == "form_registro")
		{
		if (($(formulario).empresa.value == "") || ($(formulario).empresa.value == "optica/centro*"))
			{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - El nombre del centro no puede estar vacio, es un campo obligatorio</div>');
			new Effect.Highlight('empresa', {startcolor : '#C00000'});
			return false;
			}
		else{
			if (($(formulario).persona.value == "") || ($(formulario).persona.value == "persona de contacto*"))
				{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - El nombre de la persona de contacto no puede estar vacio, es un campo obligatorio</div>');
				new Effect.Highlight('persona', {startcolor : '#C00000'});
				return false;
				}
			else{
				if (($(formulario).email.value == "") || ($(formulario).email.value == "correo electronico*") || (validarEmail($(formulario).email.value) == false))
					{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - Debe introducir un email correcto, es un campo obligatorio</div>');
					new Effect.Highlight('email', {startcolor : '#C00000'});
					return false;
					}
				else
					{
					if (($(formulario).telefono.value == "") || ($(formulario).telefono.value == "telefono*"))
					{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - El telefono de contacto no puede estar vacio, es un campo obligatorio</div>');
					new Effect.Highlight('telefono', {startcolor : '#C00000'});
					return false;
						}
					else
						{
						if (($(formulario).direccion.value == "") || ($(formulario).direccion.value == "direccion*"))
						{Element.update('form_contact', '<div style="width:100%; background-color:#C30; color:#FFF; font-size:14px; font-weight:bolder; text-align:center">Error - La direccion no puede estar vacia, es un campo obligatorio</div>');
						new Effect.Highlight('direccion', {startcolor : '#C00000'});
						return false;
							}
						else
							{
								return true	
							}
						}
					}	
				}
			}

		}
	}


function envia_contacto(formulario) //envia un formulario de contacto
	{

var aleatorio=Math.random(); 
	var direccion_final;
	var parametros;
	Element.update('form_contact', '<img src="images/loading2.gif" width="220" height="19" alt="Validando formulario" />');
	if (validar_contacto(formulario))
		{
		direccion_final = $(formulario).action + '?nocache=' + aleatorio;
		parametros = $(formulario).serialize();
		//Element.update('columna_derch' + idioma_actual, eval('mensaje_carga_pag' + idioma_actual));
		new Ajax.Request(direccion_final,
						{
						method: 'post', 
						parameters:parametros,
						onSuccess: function(transport) 
							{
							Element.update('form_contact', transport.responseText);
							},
						onFailure: function(failure)
							{
							//Element.update('columna_derch' + idioma_actual, failure.responseText);
							}
						});
		}
	return false;
	}

//Inicio Captcha
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	var objImage2 = document.images['imgCaptcha2'];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	//alert(objImage.src);
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
	if (objImage2 != undefined) {
		objImage2.src = objImage.src;
	}
}

function validar_env(){
	if(campos_obligatorios_formulario('form_contacto','nombre,email,personas,captchacode,telefono','Para poder realizar el envío es necesario rellenar los siguientes datos: \n - Nombre. \n - Correo electrónico. \n - Teléfono.\n - Número de personas.\n - Código de seguridad.') && validar_email('document.form_contacto.email.value','El campo email es incorrecto'))
	{corregir_campos_formulario('form_contacto','nombre,email,personas,comentario,telefono,entidad');return true;}
	else{return false;}
	}


function acordeon(elemento)//Expande las listas
	{
	var elementodiv = "div_"+elemento;
	var elementoimg = "img_"+elemento;

	element = document.getElementById(elemento).style;
	if (acordeon_activo==false){
		acordeon_activo = true;
		if (element.display == 'none')
			{
			Effect.BlindDown(elemento,{duration:1,afterFinish:function() {acordeon_activo=false;}});
			//$(elementoimg).src='images/simbolo_expandir.gif';
			}
		else
			{
			Effect.BlindUp(elemento,{afterFinish:function() {acordeon_activo=false;}});
			//$(elementoimg).src='images/simbolo_contraer.gif';
			}
		}
	}

function acordeon2(elemento)//Expande las listas
	{
	var elementodiv = "div_"+elemento;
	var elementoimg = "img_"+elemento;

	element = document.getElementById(elemento).style;
	if (acordeon_activo==false){
		acordeon_activo = true;
		if (element.display == 'none')
			{
			Effect.Grow(elemento,{duration:0.2,afterFinish:function() {acordeon_activo=false;}});
			//$(elementoimg).src='images/simbolo_expandir.gif';
			}
		else
			{
			Effect.Shrink(elemento,{duration:0.6,afterFinish:function() {acordeon_activo=false;}});
			//$(elementoimg).src='images/simbolo_contraer.gif';
			}
		}
	}

function expandir_contraer_mapa(id)
	{
	if ($('btn_titulo_mapa_'+id).title == "Expandir")
		{
		$('bloque_mapa_'+id).show();
		$('btn_titulo_mapa_'+id).href = "#contraer";
		$('btn_titulo_mapa_'+id).title = "Contraer";
		$('btn_titulo_mapa_'+id).setStyle({'backgroundImage': 'url(/images/contraer.png)'});	
		}
	else
		{
		$('bloque_mapa_'+id).hide();
		$('btn_titulo_mapa_'+id).href = "#expandir";
		$('btn_titulo_mapa_'+id).title = "Expandir";
		$('btn_titulo_mapa_'+id).setStyle({'backgroundImage': 'url(/images/expandir.png)'});
		}
	}
	
function cargar_hidden (formulario,lista_valores,lista_campos){
	array_lista_campos = lista_campos.split(',');
	array_lista_valores = lista_valores.split('#-#');
	for (var i=0;i<array_lista_valores.length;i++){
			//campo=eval("document."+formulario+"."+(array_lista_campos[i])+".value");
			//alert(array_lista_valores[i])
			//campo_valores=eval("document."+formulario+"."+(array_lista_valores[i])+".value");
			if($(array_lista_campos[i])){$(array_lista_campos[i]).value=array_lista_valores[i]}
			//alert(campo)
		} 
		//if ($('direccion')){$('direccion').innerHTML = array_lista_valores[1];}

}

function ocultar_select(valor_actual,lista_campos){
	
	for (var i=0;i<=n_contactos;i++){
		$('tipo_'+i).selectedIndex  = 0;
		$('tipo_'+i).disabled = true;
	} 
		$('tipo_'+valor_actual).disabled = false;
		cargar_hidden ('como_llegar_ruta','#-#',lista_campos)

}

function openWindow(url, name, ancho, alto) { 
popupWin = window.open(url, name, 'scrollbars,resizable,width='+ancho+',height='+alto+',status=0,toolbar=0,menubar=0') 
}

function mostrar_info(id){
	alert(id)
}
