﻿// JScript File

  function General_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        posicion=texto.indexOf("@@@");
        target=texto.substring(0,posicion);
        document.getElementById(target).innerHTML = texto.substring(posicion+3);
        
  }
  
  function verificaBono()
  {
        bonoRegalo=document.getElementById("txtCodigoBonoRegalo").value;
        if (bonoRegalo!="")
        {
            document.location.href="javascript:p0.VerificaBono('"+bonoRegalo+"',VerificaBono_CallBack);"
        }
  }

  function VerificaBono_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        switch (texto)
        {
            case "0": //correcto
                break;
            
            case "1": //bono desactivado
                codigo=document.getElementById("txtCodigoBonoRegalo").value;
                document.getElementById("txtCodigoBonoRegalo").value="";
                document.getElementById("txtCodigoBonoRegalo").focus();
                alerta("Lo sentimos. El Bono Regalo ("+codigo+") especificado no está activo. Revisa el código introducido.");
                break;
            
            case "2": //bono con saldo restante 0
                codigo=document.getElementById("txtCodigoBonoRegalo").value;
                document.getElementById("txtCodigoBonoRegalo").value="";
                document.getElementById("txtCodigoBonoRegalo").focus();
                alerta("Lo sentimos. El Bono Regalo ("+codigo+") especificado no dispone de saldo. Revisa el código introducido.");
                break;
            
            case "3": //bono inexistente 
                codigo=document.getElementById("txtCodigoBonoRegalo").value;
                document.getElementById("txtCodigoBonoRegalo").value="";
                document.getElementById("txtCodigoBonoRegalo").focus();
                alerta("Lo sentimos. El Bono Regalo ("+codigo+") especificado no existe. Revisa el código introducido.");
                break;
        }        
  }
  
  function VerificaMail_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        if (texto=="1")
        {
            alert('Lo sentimos. Ya existe un usuario registrado en nuestra base con este mismo email. Revisa tus datos, por favor.');
            document.getElementById("PnlDerecho1_ctrlIdentificacionDatos1_txtEmail").focus();
        }
  }
  
  
  function CambiarVoucherVisualizado_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        lista=texto.split("Ø");
        
        document.getElementById("textoVoucher").innerHTML = lista[0];
        document.getElementById("listaActividades").innerHTML = lista[1];
        document.getElementById("idPedidoVoucher").innerHTML = lista[2];
        
  }
  
  function EnviarVoucherCliente_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        if (texto=="error")
        {
            alerta("<%=CestaEmpresa[9] %>");
        }
        else
        {
            alerta("<%=CestaEmpresa[10] %>");
        }
        
   }

  function AnularPedidoCliente_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        if (texto=="error")
        {
            confirma2("<%=CestaEmpresa[15] %>", "<%=CestaEmpresa[18] %>", 80,"actualizarPaginaSi()");
        }
        else
        {
            confirma2("<%=CestaEmpresa[16] %>", "<%=CestaEmpresa[18] %>", 80,"actualizarPaginaSi()");
        }
        
   }
  

  function ActividadesHijas_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        posicion=texto.indexOf("@@@");
        titulo=texto.substring(0,posicion);
        posicion1=titulo.indexOf("|||");
        alto=parseInt(titulo.substring(0,posicion1));
        actividadesHijas(titulo.substring(posicion1+3),texto.substring(posicion+3),alto);
   }


   function alerta(mensaje)
   {
        document.getElementById('mensaje_alerta').innerHTML=mensaje;
        ponerCapaNegra2('capa_alerta','aceptar_alerta',350, 120,1);
   }


   function confirma(mensaje, buttonYes, buttonNo, valorHeight, fncSi, fncNo) 
   {
        document.getElementById('mensaje_confirmacion').innerHTML=mensaje;
        document.getElementById('btnSi').value=buttonYes;
        document.getElementById('btnNo').value=buttonNo;
        document.getElementById('respSi').value=fncSi;
        document.getElementById('respNo').value=fncNo;
        ponerCapaNegra2('capa_confirmacion','cerrar_confirmacion', 350, valorHeight,1);   
   }

   function confirma2(mensaje, buttonYes, valorHeight, fncSi) 
   {
        document.getElementById('mensaje_confirmacion2').innerHTML=mensaje;
        document.getElementById('btnSi2').value=buttonYes;
        document.getElementById('respSi2').value=fncSi;
        ponerCapaNegra2('capa_confirmacion2','cerrar_confirmacion2', 350, valorHeight,1);   
   }

   function actividadesHijas(padre, mensaje,alto)
   {
        document.getElementById('tituloPadre').innerHTML=padre;
        document.getElementById('mensaje_actividadesHijas').innerHTML=mensaje;
        ponerCapaNegra2('actividadesHijas','aceptar_actividadesHijas',610, alto,1);
   }


  function LoginarUsuario_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        posicion=texto.indexOf("@@@");
        saludo=texto.substring(0,posicion);
        tipos=texto.substring(posicion+3);

        if (saludo=="mensajeError" || saludo=="mensajeErrorLogin")
        {
            if (saludo=="mensajeErrorLogin")
            {
                alerta(tipos.substring(1));
            }
            if (tipos.substring(0,1)=="U")
            {
                document.getElementById("mensajeErrorUsuario").style.visibility='visible';        
            }
            else
            {
                document.getElementById("mensajeError").style.visibility='visible';        
            }            
        }
        else
        {
            document.getElementById("saludoUsuario").innerHTML=saludo;
            document.getElementById("pnlLoginUsuario").style.visibility="hidden";

            if (tipos.substring(0,1)=="U")
            {
                //Nada
                location.href="http://www.todoactividades.com/";
            }
            else
            {
                if (tipos.substring(1,2)=="2")
                {
                    //Agencia
                    location.href="http://www.todoactividades.com/";
                }
                else
                {
                    if (tipos.substring(2,3)=="1")
                    {
                        location.href="redirect.aspx?_f=114";
                    }
                    else
                    {
                        location.href="redirect.aspx?_f=118";
                    }
                }
            }
        }
        
   }
   
   function AjustarOpcion_CallBack(response)
   {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        posicion=texto.indexOf("@@@");
        Personas=texto.substring(0,posicion);
        OtrosCargos=texto.substring(posicion+3);
        document.getElementById("pnlPersonas").innerHTML=Personas;
        document.getElementById("pnlOtrosCargos").innerHTML=OtrosCargos;
        document.getElementById("tblDisponibilidad").style.visibility="hidden";
        document.getElementById("tblDatosReserva").style.visibility="hidden";
   }

   function BuscarDisponibilidad_CallBack(response)
   {
        //Formato recibido:
        //IDActividad + "|" +           0
        //TituloActividad + "|" +       1
        //Opcion + "|" +                2
        //TituloOpcion + "|" +          3
        //fecha + "|" +                 4
        //strPersonas + "|" +           5
        //numPersonas + "|" +           6
        //descPersonas + "|" +          7
        //strOtrosCargos + "|" +        8
        //descOtrosCargos + "|" +       9
        //codigo + "|" +                10
        //descuentoCodigo + "|" +       11
        //regalar + "|" +               12
        //costeRegalo + "|" +           13
        //numPrecioTotal + "|" +        14
        //Lugar + "|" +                 15
        //Duracion + "|" +              16
        //Telefono + "|" +              17
        //BonoRegalo;                   18
   
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        
        
        if (texto.indexOf("no disponible")>=0)
        {
            plazasReales=parseInt(texto.split("¬")[1]);
            telefono=texto.split("¬")[2];
            if (plazasReales>0)
            {
                mensaje="<%=CestaEmpresa[13] %>";
                mensaje=mensaje.replace("«X»",""+plazasReales);
                mensaje=mensaje.replace("«telefono»",telefono);
                document.getElementById("textoPlazas").innerHTML=mensaje;
                mostrar('capa_plazas');
                return;
            }
            else
            {
                mensaje="<%=CestaEmpresa[12] %>";
                mensaje=mensaje.replace("«telefono»",telefono);
                document.getElementById("textoPlazas").innerHTML=mensaje;
                mostrar('capa_plazas');
                return;
            }
        }

        if (texto.indexOf("cp erroneo")>=0)
        {
            mensaje="<%=CestaEmpresa[14] %>";
            alerta(mensaje);
            return;
        }
        
        items=texto.split("@");
        
        //Ajustar los valores correspondientes
        
        document.getElementById("DatosCompletosReserva").value=texto;
        

        //Montar Personas
        lasPersonas="<br>";
        if (items[5]!="")
        {
            itemsPersonas=items[5].split("¬");
            
            //Promocion
            inicio=0;
            if (itemsPersonas[0].substring(0,9)=="PROMOCION")
            {
                inicio=1;        
            }
            
            for (i=inicio;i<itemsPersonas.length;i++)
            {
                valores=itemsPersonas[i].split("|");
                if (valores[2]!="0")
                {
                    if (lasPersonas!="<br>") lasPersonas +="<br>";
                    lasPersonas +=valores[2].split("|")+" x "+ eval(valores[3].replace(",","."))+" €&nbsp;&nbsp;&nbsp;&nbsp;<span class='txt10RojoB'>"+valores[4]+"</span>";            
                }
            }
        }

        if (lasPersonas=="<br>") lasPersonas="";
        
        //Montar Otros Cargos
        losCargos="<br>";
        if (items[8]!="")
        {
            itemsCargos=items[8].split("¬");
            for (i=0;i<itemsCargos.length;i++)
            {
                valores=itemsCargos[i].split("|");
                if (valores[2]!="0")
                {
                    if (losCargos!="<br>") losCargos +="<br>";
                    losCargos +=valores[2].split("|")+" x "+ eval(valores[3].replace(",","."))+" €";            
                }
            }
        }
        if (losCargos=="<br>") losCargos="";

        
        //Datos de los campos        
        document.getElementById("tblDatosReservaActividad").innerHTML=items[1];
        document.getElementById("tblDatosReservaLugar").innerHTML=items[15];
        document.getElementById("tblDatosReservaDuracion").innerHTML=items[16];
        document.getElementById("tblDatosReservaTelefono").innerHTML=items[17];
        if (items[11]=="0")
        {
            document.getElementById("tblDatosReservaCodigo").innerHTML ="";
        }
        else
        {
            document.getElementById("tblDatosReservaCodigo").innerHTML +=items[11]+" €";
        }
        if (items[4]=="<%=CestaEmpresa[8] %>")
        {
            document.getElementById("tblDatosReservaFecha").innerHTML="<%=CestaEmpresa[8] %>";
        }
        else
        {
            document.getElementById("tblDatosReservaFecha").innerHTML=items[4];
        }
        
        if (items[13]=="0")
        {
            document.getElementById("tblDatosReservaRegalo").innerHTML ="";
        }
        else
        {
            document.getElementById("tblDatosReservaRegalo").innerHTML +=items[13]+" €";
        }
        
        document.getElementById("tblDatosReservaPersonas").innerHTML +=lasPersonas;
        document.getElementById("tblDatosReservaPrecioTotal").innerHTML=items[14]+" €";
        if (losCargos=="")
        {
            document.getElementById("tblDatosReservaOtrosCargos").innerHTML ="";
        }
        else
        {
            document.getElementById("tblDatosReservaOtrosCargos").innerHTML +=losCargos;
        }
        
        
        //Bono Regalo
        document.getElementById("tblDatosBonoRegalo").innerHTML =items[18];
        
        //document.getElementById('tblDatosReserva').style.visibility='visible';
        //document.getElementById('tblDatosReserva').style.display='block';
        //document.location.href="#RBusqueda";
        document.getElementById("chkCondiciones").checked=true;
        
        aceptarReserva("");
        
   }

   function AceptarReserva_CallBack(response)
   {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;
        posicion=texto.indexOf("@@@");
        
        document.getElementById("tblDatosReserva").style.visibility="hidden";
        //alerta(texto.substring(posicion+3));
        
        //Actualizar carrito
        //document.getElementById("textoCarrito").innerHTML=texto.substring(0,posicion);
        location.href="redirect.aspx?_f=31";
   }

   function EliminarItemCarrito_CallBack(response)
   {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;

        //Actualizar carrito
        location.href=texto;
   }

  function MostrarPedido_CallBack(response)
  {
        if (response.error != null){
          alert("Se presentó un error ");
          return;
        }
        texto=response.value;

        actividadesHijas("Información de reservas",texto,500);
   }
   
    function abrirCapaFondo()
	{
	    resize();
    	document.getElementById("capaFondo").style.visibility="visible";
	}
	
    function cerrarCapaFondo()
	{
		document.getElementById("capaFondo").style.visibility="hidden";
	}
	
	function resize()
	{ 
	    var htmlheight = document.body.scrollHeight;
	    var windowheight = window.screen.height; 
	    var frame = document.getElementById("capaFondo"); 
	    if ( htmlheight < windowheight )  
	    { 
	        frame.style.height = windowheight + "px"; 
	    }
	    else
	    {
	        if ( htmlheight > windowheight )  
	        { 
	            frame.style.height = htmlheight + "px"; 
	        }
	    }
	    
	     
	}


