// JavaScript Document

/*--------------------------------------------------------------------
----------------------------------------------------------------------	GLOBALES
---------------------------------------------------------------------- 
*/
function send(frm){
	f = document.getElementById(frm);
	f.submit();
}
/*
---------------------------------------------------------------------- 
*/
function terms() {
   newwin =  window.open('terminos.php','Muchoticket','left=160,top=150,height=550,width=350,scrollbars=yes');
   newwin.focus();
   }
/*
---------------------------------------------------------------------- 
*/
function seguro() {
   newwin =  window.open('segurocancelacion.php','Muchoticket','left=160,top=150,height=350,width=550,scrollbars=yes');
   newwin.focus();
   }
/*
---------------------------------------------------------------------- 
*/
function titulares() {
   newwin =  window.open('titulares.php','Muchoticket','left=160,top=150,height=550,width=350,scrollbars=yes');
   newwin.focus();
   }   
 
/*--------------------------------------------------------------------
----------------------------------------------------------------------	CALENDARIO DE FIESTAS
---------------------------------------------------------------------- 
*/
function calendario_semana() {
   newwin =  window.open('calendario_semana.php','Muchoticket','left=40,top=90,height=650,width=850,scrollbars=yes');
   newwin.focus();
}
/*--------------------------------------------------------------------
----------------------------------------------------------------------	HOME
---------------------------------------------------------------------- */
var dactual = 'home';
function div_view(sd){
	d = document.getElementById(dactual);
	d.style['display'] = 'none'; 
	d = document.getElementById(sd);
	d.style['display'] = 'block';
	dactual = sd;
}

function ver_resultados(){
	d = document.getElementById('portada');
	d.style['display'] = 'none'; 
	de = document.getElementById('result');
	de.style['display'] = 'block';
}

function ver_submenu(mod){
	ocultar_submenu('submenu_clubs');
	ocultar_submenu('submenu_fiestas');
	ocultar_submenu('submenu_calendario');
	ocultar_submenu('submenu_ayuda');
	d = document.getElementById('submenu_'+mod);
	d.style['display'] = 'block'; 
}

function ocultar_submenu(mod){
	d = document.getElementById(mod);
	d.style['display'] = 'none'; 
}

/*--------------------------------------------------------------------
----------------------------------------------------------------------	CALENDARIO TEASER
---------------------------------------------------------------------- */
//var mes_inicial = 5;
var mes_final = 10;
//var mes_actual = 5;

function nextmes(){
	if(mes_actual<mes_final){
		d = document.getElementById('ch_mes_'+mes_actual);
		d.style['display'] = 'none';
		mes_actual = mes_actual +1; 
		d = document.getElementById('ch_mes_'+mes_actual);
		d.style['display'] = 'block'; 
	}
}

function backmes(){
	if(mes_actual>mes_inicial){
		d = document.getElementById('ch_mes_'+mes_actual);
		d.style['display'] = 'none'; 
		mes_actual = mes_actual -1; 
		d = document.getElementById('ch_mes_'+mes_actual);
		d.style['display'] = 'block'; 
	}
}


/*--------------------------------------------------------------------
----------------------------------------------------------------------	MAPA
---------------------------------------------------------------------- */
var map;

function changeSlider() {
	if (changeSlider.changed !== true) {
	var images = map.getContainer().getElementsByTagName('img');
	for (var imgIndex = 0; imgIndex < images.length; imgIndex++){
		if (images[imgIndex].src.search(/mapcontrols2/) >= 0) {
		  changeSlider.changed = true;
		  images[imgIndex].src = images[imgIndex].src.replace(/mapcontrols2/, "mapcontrols3d");
		}
	  }

	  // Keep trying until it succeeds
	  if (changeSlider.changed !== true) {
		setTimeout(changeSlider, 1);
	  }
	}
 } 
  
function load_map(lat,lon) {
  if (document.getElementById('map')) {
	if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(lat,lon), 11);
		var latlng = new GLatLng(lat,lon);
        map.addOverlay(new GMarker(latlng));
		setMapMode('hyb');
		changeSlider();
	  }
   }
}

function setMapMode(mode) {
   switch(mode) {
	  case 'map': map.setMapType(G_NORMAL_MAP); break;
	  //case 'sat': map.setMapType(G_SATELLITE_TYPE); break;
	  case 'hyb': map.setMapType(G_HYBRID_TYPE); break;
   }
}

function ver_mapa(numf,lat,lon){
   for(n=0;n<numf;n++){
   	 f = document.getElementById('img_0_' + n);
   	 f.style['display'] = 'none';
   }
   m = document.getElementById('map');
   m.style['display'] = 'block';
   load_map(lat,lon);
}

/*--------------------------------------------------------------------
----------------------------------------------------------------------	GALERIA
---------------------------------------------------------------------- */
var foto_actual = '0';
//-----------------------------------------------------------
function show_foto(img) {
   
   fa = document.getElementById('img_' +foto_actual);
   fa.style['display'] = 'none'; 
   
   foto_actual = img;
   
   d = document.getElementById('img_' +img);
   d.style['display'] = 'block'; 
}
/*--------------------------------------------------------------------
----------------------------------------------------------------------	VALIDA
---------------------------------------------------------------------- */
function check_booking(events,textalerta){
	var check_status = true;
	for(e=1;e<events;e++){
		check_status = check(e,eventos[e]);		
	}
	
	if(!check_status){
		alert(textalerta);
	}else{
	   f = document.getElementById('frm_pago');
	   f.submit(); 
	}
}

function check(evento,num){
	var valida = true;
	for(n=1;n<num+1;n++){
		i_val = 'tit_'+evento+'_'+n;
		i = document.getElementById(i_val);
		if(i.value=='')valida=false;
	
		d_val = 'dat_'+evento+'_'+n;
		d = document.getElementById(d_val);
		if(d.value=='')valida=false;
	
	}
  return valida;
}

function check_pay(){
	var check_status = true;
	var msg = ''; 
	
	n = document.getElementById('c_nombre');
	a = document.getElementById('c_apellidos');
	m = document.getElementById('c_mail');
	m2 = document.getElementById('c_mail2');
	c = document.getElementById('c_ciudad');
	p = document.getElementById('c_pais');
	t = document.getElementById('c_tel');
	ch = document.getElementById('chk_acepto');
	
   if(n.value==''){ check_status=false; msg = msg + '** Debe introducir su nombre.\n'; }
   if(a.value==''){ check_status=false; msg = msg + '** Debe introducir sus apellidos.\n'; }
   if(c.value==''){ check_status=false; msg = msg + '** Debe introducir el nombre de su ciudad.\n'; }
   if(p.value==''){ check_status=false; msg = msg + '** Debe introducir su país.\n'; }
   if(check_email(m.value)==false){check_status=false; msg = msg + '** La dirección email no és válida o su formato no es correcto.\n';}
   if(m.value!=m2.value){ check_status=false; msg = msg + '** Las direcciones de correo no coincíden.\n'; }
   if(ch.checked==false){ check_status=false; msg = msg + '** Debe aceptar las condiciones y terminos.\n'; }
	
   if(!check_status){
		alert(msg); 
	}else{
	   f = document.getElementById('frm_pago');
	   f.submit(); 
	}
}
/*--------------------------------------------------------------------
----------------------------------------------------------------------	
---------------------------------------------------------------------- */
var div_club_act = 1;

function tabler_club(dclub){
   dc = document.getElementById('tablet_club_'+div_club_act);
   dstyle = document.getElementById('div_sel_'+div_club_act);
   
   dn = document.getElementById('tablet_club_'+dclub);
   dnstyle = document.getElementById('div_sel_'+dclub);
   
   dc.style['display']='none';
   dn.style['display']='block';
   
   dstyle.setAttribute("class", "home_btns");
   dnstyle.setAttribute("class", "home_btns_nos");
   
   div_club_act = dclub;
}
/*--------------------------------------------------------------------
----------------------------------------------------------------------	
---------------------------------------------------------------------- */




