function doOnLoad(pg) {
	if(pg == 'sesiones') {
		//haz onloads para pagina sesiones
		
		popCrear(); //haz popups dinamicamente para cada <a> que tiene class="pop1" pop2 pop3 etc
		if(document.getElementById('todasSesiones') != null)
			document.getElementById('todasSesiones').style.display = 'none'; //ocultar lista completa  de sesiones
		//document.getElementById('todoVendido').style.display = 'none'; //ocultar mensaje de vendido
	}
}
function abreventanascroll(mipage,mititulo,ancho,alto)
{
	miresize="no"
	if (navigator.appName == "Netscape")
	{
		miresize="yes"
	}
	aWindow= open(mipage,mititulo,'scrollbars=yes,toolbar=no,status=no,resizable=' + miresize + ',width=' + ancho + ',height=' + alto);
}

function abreventana(mipage,mititulo,ancho,alto)
{
	aWindow= open(mipage,mititulo,'scrollbars=no,toolbar=no,status=no,resizable=no,width=' + ancho + ',height=' + alto);
}

function abrePublicidad()
{
    var nAlturaVentana
    var nAnchuraVentana
	var nPosicionIzquierda
	var nPosicionArriba

    nAnchuraVentana = 343
	nAlturaVentana = 596

    nPosicionIzquierda = (screen.width) ? (screen.width - nAnchuraVentana)/2 : 0
	nPosicionArriba = (screen.height) ? (screen.height - nAlturaVentana)/2 : 0
	ventanaAyuda = window.open("http://www.mediabit.com/mb/atCliente.aspx?webMb=MV","vVentas","height=" + nAlturaVentana + ",width=" + nAnchuraVentana + ",left=" + nPosicionIzquierda + ",top=" + nPosicionArriba + ",directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no")

}

function abreventanatop(mipage,mititulo,ancho,alto)
{
	aWindow= open(mipage,mititulo,'scrollbars=no,toolbar=no,status=no,resizable=no,width=' + ancho + ',height=' + alto + ',top=0,left=0');
}

function MostrarEspera()
	{
		document.getElementById("Espera").style.visibility="visible";
		document.getElementById("Espera").focus();
		document.getElementById("Contenido").style.visibility="hidden";
	}
//Funcione apra el control de la factura
function comprueba_telefono(tt)
{
	contar=0;
	err=0;
	for(i=0;i<tt.length;i++)
	{
		if (tt.substr(i,1)==" ")
		{
			contar=contar+1;
		}
	}
	if (contar==tt.length)
	{
		err=1;
	}	
	else
	{
		if (tt.length<9)
		{
			err=2;
		}
		else
		{
			if (isNaN(tt))
			{
				err=3;
				
			}
			else
			{
				if (tt.length>9)
				{
					if ((tt.charAt(0)!="0" && tt.charAt(1)!="0") || (tt.charAt(0)!="0" && tt.charAt(1)!="7"))
					{
						err=4;
					}
				}
			}
		}	
	}	
return err;
}

function comprueba_mail(dir)
{	
	var car='';
	var encon='no';
	var longi=dir.length;
	e=0;
	for (i=0;i<longi;i++)
	{
		car=dir.charAt(i);
		if (car=='@')
		{
			encon='si';
			posarroba=i;
		} 
    } 

	if (encon=='no')	
	{
		e=1;
	}  
	else
	{
		//existe la arroba, se comprueba que haya algo antes
   
		if (posarroba==0)
		{
			e=1;
		}
		else
		{
			//existe la arroba y no esta en la primera posicion
			//se comprueba que despues de la arroba hay algo
    
		    if (posarroba==dir.length - 1)
			{
				e=1;
			}
			else
			{	//existe la arroba y no esta en la primera posicion
				// y despues hay algo, se comprueba que no sea un punto    
				car=dir.charAt(posarroba+1)
				if (car=='.')
				{
					e=1;
				}
				else
				{
					//existe la arroba y no esta en la primera posicion
					// y despues hay algo distinto de punto
					//se comprueba que lo ultimo no sea un punto
      
					car=dir.charAt(dir.length - 1);
					if (car=='.')
					{
						e=1;
					} 
					else
					{
					 //finalmente se comprueba que haya un punto despues de la arroba
					 var ar2='';
					 encon2='no'
					 for(k=posarroba;k<dir.length;k++)
					 { 
					  car2=dir.charAt(k);
					  if (car2=='.')
					   {
					     encon2='si';
					   }  
					 }
					 
					 if (encon2=='no')
					  {
						e=1;
					  } 
					}
				}  	
			} 
		}	
	}
	
	return e;
}
//din control factura

function popup(path, alto, ancho){
	var parametros = "resizeable, scrollbars = yes, toolbar=no, width = " + ancho + ", height = " + alto;
	window.open(path, '', parametros);
 }
 
function popCrear() {
	//autor: hayden
	//este funcion crea popup links dinamicamente cuando llamado en un onload
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("pop1")) {
      links[i].onclick=function() {window.open(this.href, "","scrollbars=1,resizable=1,width=580,height=500"); return false;}
    } else if (links[i].className.match("pop2")) {
      links[i].onclick=function() {window.open(this.href, "","scrollbars=1,resizable=1,width=850,height=500"); return false;}
    }
  }
}

function textToggle(txt, targ, desc) {
	//autor: hayden
	//este funcion cambia texto entre "cerrar" y "abrir"
	//y inicia el slide effect
	var t = document.getElementById(txt).innerHTML
	if(handle_click()) {
		var res = (t == "mostrar " + desc + " " ? "ocultar" : "mostrar");
		document.getElementById(txt).innerHTML = res + " " + desc + " ";
		Effect.toggle(targ,'slide'); 
	}
	return true;
}

//autor: hayden
//handle_click, doubleclick_timer, reset_timer, start_timer
//estan utilizados para medir el tiempo entre clicks para textToggle
var max_elapsed = 200;	//less than is double click / more than is 2 individual clicks
var timerID = 0;		// Timer ID
var time_elapsed = 0;	// The time between two clicks
function handle_click(){
	if(!time_elapsed) {
		time_elapsed = 0;
		timerID = start_timer();
		return true; // because its the first click
	}
	if(time_elapsed >= max_elapsed) {
		reset_timer();
		time_elapsed = 0;
		timerID = start_timer();
		return true; // because its a second click a long time later
	}
	// We have a second (or third or fourth etc) click inside time allowed
	return false;		
}
function doubleclick_timer(){
	time_elapsed++;
	start_timer();
}
function reset_timer(){
	clearTimeout(timerID);
	timerID = 0;
}
function start_timer(){
	return(setTimeout("doubleclick_timer()", 1));
}

function sesTab(targ) {
	//autor: hayden
	//este funcion cambia entre el calendario y lista de todas sesiones
	if(document.getElementById('sesTab') != null) {
		if(targ == "cal") {
			//han pinchado la pestaña de calendario
				document.getElementById('sesTab').className = "sesTabCal";
				document.getElementById('sesCal').className = "t3 c8 ulx pL4 pR3 pT1 pB1 fb";
				document.getElementById('sesFecha').className = "t3 c5 ul pL4 pR3 pT1 pB1 fb";
				document.getElementById('todasSesiones').style.display = "none";
				Effect.Appear('calCont');
		} else {
			//han pinchado la pestaña de lista de todas las sesiones
				document.getElementById('sesTab').className = "sesTabFecha";
				document.getElementById('sesCal').className = "t3 c5 ul pL4 pR3 pT1 pB1 fb";
				document.getElementById('sesFecha').className = "t3 c8 ulx pL4 pR3 pT1 pB1 fb";
				document.getElementById('calCont').style.display = "none";
				Effect.Appear('todasSesiones');
		}
	} else {
		alert("no sesTab");
	}
	return false;
}
 
 function validar()
{

	if (document.getElementById("tb_nombre").value.length == 0) {
		alert("Escriba su nombre y apellidos.");
		document.getElementById("tb_nombre").focus();
		return (false);}
		
	if (document.getElementById("tb_apellidos").value.length == 0) {
		alert("Escriba su nombre y apellidos.");
		document.getElementById("tb_apellidos").focus();
		return (false);}
		
	if (document.getElementById("tb_nif").value.length < 9) {
		alert("Escriba su Nif correctamente, 9 caracteres sin espacios.");
		document.getElementById("tb_nif").focus();
		return (false);}
		
	if (document.getElementById("tb_nif").value.length > 9) {
		alert("Escriba su Nif correctamente, 9 caracteres sin espacios.");
		document.getElementById("tb_nif").focus();
		return (false);}

	if (document.getElementById("tb_telefono").value.length == 0) {
		alert("Escriba su telefono.");
		document.getElementById("tb_telefono").focus();
		return (false);}
		
	if (comprueba_mail(document.getElementById("tb_email").value) == 1){
		alert("Escriba un email correcto.");
		document.getElementById("tb_email").focus();
		return (false);}
		
	if (document.getElementById("tb_email").value.length == 0) {
		alert("Escriba su email.");
		document.getElementById("tb_email").focus();
		return (false);}
		
	if (document.getElementById("tb_email").value != document.getElementById("tb_email2").value) {
		alert("Repita su email correctamente.");
		document.getElementById("tb_email").focus();
		return (false);}
		
	if (document.getElementById("tb_CodPostal").value.length == 0) {
		alert("Escriba su C\u00f3digo Postal");
		document.getElementById("tb_CodPostal").focus();
		return (false);}
		
	if (document.getElementById("tb_CodPostal").value.length < 5) {
		alert("El c\u00f3digo postal debe tener como minimo 5 caracteres");
		document.getElementById("tb_CodPostal").focus();
		return (false);}	
					
	if (document.getElementById("tb_num_tarjeta1").value.length == 0) {
		alert("Introduzca el numero de tarjeta.");
		document.getElementById("tb_num_tarjeta1").focus();
		return (false);}
		
	if (document.getElementById("tb_num_tarjeta1").value.length < 12) {
		alert("El numero de tarjeta debe tener como minimo 12 caracteres");
		document.getElementById("tb_num_tarjeta1").focus();
		return (false);}	
		
//	if (ValidarTJ(document.getElementById("tb_num_tarjeta1").value) == false) {
//		alert("Escriba un numero de tarjeta valido");
//		document.getElementById("tb_num_tarjeta1").focus();
//		return (false);}	
		
	if (document.getElementById("tb_tiutlar").value.length == 0) {
		alert("Escriba el nombre del titular de la tarjeta.");
		document.getElementById("tb_tiutlar").focus();
		return (false);}
	
	if (document.getElementById("tb_cvv").value.length < 3) {
		alert("Escriba el CVV de la tarjeta.");
		document.getElementById("tb_cvv").focus();
		return (false);}
		
	if (document.getElementById("check_condiciones").checked == false) {
		alert("Antes de continuar debes leer y aceptar las condiciones de uso.");
		document.getElementById("check_condiciones").focus();
		return (false);}
		
	if (document.getElementById("RadioAcepto").checked == false && document.getElementById("RadioNoAcepto").checked == false)
	{
	    alert("Debes elegir si quieres seguro de anulacion o no, antes de poder continuar con la reserva.");
		document.getElementById("RadioAcepto").focus();
		return (false);
	}	
	
	MostrarEspera();
}

function ValidarTJ(numero_tarjeta) {
 var cadena = numero_tarjeta.toString();
 var longitud = cadena.length;
 var cifra = null;
 var cifra_cad=null;
 var suma=0;
 for (var i=0; i < longitud; i+=2){
   cifra = parseInt(cadena.charAt(i))*2;
   if (cifra > 9){ 
     cifra_cad = cifra.toString();
     cifra = parseInt(cifra_cad.charAt(0)) + 
parseInt(cifra_cad.charAt(1));
   }
   suma+=cifra;
 }
 for (var i=1; i < longitud; i+=2){
   suma += parseInt(cadena.charAt(i));
 }
	
 if ((suma % 10) == 0){ 
  //alert("Número de tarjeta correcto");
  return (true);
 } else {
  //alert("El número de tarjeta no es válido");
  return (false);
 }
}

