function Negocio ( )
{

	this.Contenido = new Object ( );
	this.Contenido.Item 	= new Array ( );
	this.Contenido.Recintos = new Array ( );
	this.Contenido.Eventos  = new Array ( );
	this.Contenido.TipoE    = new Array ( );

	this.Session = new Object ( );

	this.existenDestacados  = false;
	this.ModoAgencia 		= false;
	this.IdImagenRobot 		= "";



	Negocio.prototype.Init = function ( )
	{


		this.DefineInformacion ( "TipoE" );
		this.DefineInformacion ( "Pais" );
		this.DefineInformacion ( "Provincia" );
		this.DefineInformacion ( "Poblacion" );
		this.DefineInformacion ( "Recinto" );
		this.DefineInformacion ( "Evento" );
		this.DefineInformacion ( "Calendario" );
		this.DefineInformacion ( "Sesion" );
		this.DefineInformacion ( "Bloque" );
		this.DefineInformacion ( "Pago" );
		this.DefineInformacion ( "Operacion" );

	}

	Negocio.prototype.ClearInformacion = function ( tipo )
	{
		switch ( tipo )
		{
			case "Idioma" :
				break;

			case "TipoE" :
				this.DefineInformacion ( "Pais" );
				this.DefineInformacion ( "Provincia" );
				this.DefineInformacion ( "Poblacion" );
				this.DefineInformacion ( "Recinto" );
				this.DefineInformacion ( "Evento" );
				this.DefineInformacion ( "Calendario" );
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );

				break;

			case "Pais" :
				this.DefineInformacion ( "Provincia" );
				this.DefineInformacion ( "Poblacion" );
				this.DefineInformacion ( "Recinto" );
				this.DefineInformacion ( "Evento" );
				this.DefineInformacion ( "Calendario" );
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );
				break;

			case "Provincia" :
				this.DefineInformacion ( "Poblacion" );
				this.DefineInformacion ( "Recinto" );
				this.DefineInformacion ( "Evento" );
				this.DefineInformacion ( "Calendario" );
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );
				break;

			case "Poblacion" :
				this.DefineInformacion ( "Recinto" );
				this.DefineInformacion ( "Evento" );
				this.DefineInformacion ( "Calendario" );
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );
				break;

			case "Recinto" :
				this.DefineInformacion ( "Evento" );
				this.DefineInformacion ( "Calendario" );
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );
				break;

			case "Evento" :
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );

				break;
			case "Sesion" :
				this.DefineInformacion ( "Sesion" );
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );

				break;
			case "Bloque" :
				this.DefineInformacion ( "Bloque" );
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );

				break;
			case "Pago" :
				this.DefineInformacion ( "Pago" );
				this.DefineInformacion ( "Operacion" );

				break;
			case "Operacion" :

				this.DefineInformacion ( "Operacion" );
				break;

			case "Agencia" :
				this.DefineInformacion ( "Agencia" );
				break;

			default :
				break;

		}
	}

	Negocio.prototype.DefineInformacion = function ( tipo )
	{
		switch ( tipo )
		{
			case "Idioma" :
				this.Session.Idioma		   = new Object ( );
				this.Session.Idioma.Id 	   = "";
				this.Session.Idioma.Nombre = "";
				break;

			case "TipoE" :
				this.Session.TipoE		  = new Object ( );
				this.Session.TipoE.Id 	  = "";
				this.Session.TipoE.Nombre = "";
				break;

			case "Pais" :
				this.Session.Pais		   = new Object ( );
				this.Session.Pais.Id 	   = "";
				this.Session.Pais.Nombre   = "";
				break;

			case "Provincia" :
				this.Session.Provincia	   	  = new Object ( );
				this.Session.Provincia.Id 	  = "";
				this.Session.Provincia.Nombre = "";
				break;

			case "Poblacion" :
				this.Session.Poblacion	  	  = new Object ( );
				this.Session.Poblacion.Id 	  = "";
				this.Session.Poblacion.Nombre = "";
				break;

			case "Recinto" :
				this.Session.Recinto		   = new Object ( );
				this.Session.Recinto.Id 	   = "";
				this.Session.Recinto.Nombre    = "";
				this.Session.Recinto.Logo      = "";
				break;

			case "Evento" :
				this.Session.Evento		   		  = new Object ( );
				this.Session.Evento.Id 	   		  = "";
				this.Session.Evento.Titulo 		  = "";
				this.Session.Evento.Logo   		  = "";
				this.Session.Evento.UseCalendario = false;
				this.Session.Evento.DesdeFecha    = "";
				this.Session.Evento.HastaFecha    = "";
				this.Session.Evento.AliasCalif    = "";
				this.Session.Evento.Calificacion  = "";

				break;

			case "Calendario" :
				this.Session.Calendario		       = new Object ( );
				this.Session.Calendario.FechaDesde = "";
				this.Session.Calendario.FechaHasta = "";

				break;

			case "Sesion" :
				this.Session.Sesion		   		  = new Object ( );
				this.Session.Sesion.Id 		  	  = "";
				this.Session.Sesion.HoraSes 		  = "";
				this.Session.Sesion.Fecha 		  = "";
				this.Session.Sesion.Hora 		  = "";
				this.Session.Sesion.MaxTickets 	  = 0;
				this.Session.Sesion.MinTickets 	  = 0;
				this.Session.Sesion.VerDisponible = false;
				this.Session.Sesion.RegistroWeb   = false;

				break;
			case "Bloque" :
				this.Session.Bloque		   		  = new Object ( );
				this.Session.Bloque.IdNivel  	  = "";
				this.Session.Bloque.IdArea   	  = "";
				this.Session.Bloque.IdZona   	  = "";
				this.Session.Bloque.IdBloque 	  = "";
				this.Session.Bloque.Zona     	  = "";
				this.Session.Bloque.Bloque   	  = "";
				this.Session.Bloque.LiteralFila   = "";
				this.Session.Bloque.LiteralButaca = "";
				this.Session.Bloque.Numerado 	  = "";
				this.Session.Bloque.Comisiones 	  = new Array ( );
				this.Session.Bloque.MultiZona 	  = false;
				this.Session.Bloque.MultiBloque   = false;
				this.Session.Bloque.Acceso   	  = "";
				this.Session.Bloque.Puerta   	  = "";
				this.Session.Bloque.Info   		  = "";
				this.Session.Bloque.Mapa   		  = "";


				break;
			case "Pago" :
				this.Session.Pago		    = new Object ( );
				this.Session.Pago.Tarjeta   = "";
				this.Session.Pago.Caduca    = "";
				this.Session.Pago.Cvc       = "";
				this.Session.Pago.Nombre    = "";
				this.Session.Pago.Tlf       = "";
				this.Session.Pago.Email     = "";
				this.Session.Pago.Boletines = "";

				break;
			case "Operacion" :
				this.Session.Operacion	  		       			  = new Object ( );
				this.Session.Operacion.IdReserva       			  = "";
				this.Session.Operacion.Importe 	       			  = 0;
				this.Session.Operacion.ImporteSinTajeta		 	  = 0;
				this.Session.Operacion.ImporteNeto     			  = 0;
				this.Session.Operacion.Comision        			  = 0;
				this.Session.Operacion.Dto 	  	      			  = 0;
				this.Session.Operacion.Contiguas       			  = true;
				this.Session.Operacion.IdOperacion     			  = "";
				this.Session.Operacion.IdAgrupacion    			  = "";
				this.Session.Operacion.RefGlobal       			  = "";
				this.Session.Operacion.Entradas        			  = new Array ( );
				this.Session.Operacion.EntradasTarjeta 			  = new Array ( );
				this.Session.Operacion.ComisionesAplicadasTarjeta = new Array ( );

				this.Session.Operacion.Oficina 			  		  = new Object( );
				this.Session.Operacion.Oficina.Envio 			  = false;
				this.Session.Operacion.Oficina.Codigo 			  = "";
				this.Session.Operacion.Oficina.Provincia 		  = "";
				this.Session.Operacion.Oficina.Poblacion 		  = "";
				this.Session.Operacion.Oficina.Direccion 		  = "";
				this.Session.Operacion.Oficina.Nombre 		  	  = "";

				break;
			case "Agencia" :

				this.ModoAgencia = false;

				this.Session.Agencia	    		= new Object ( );
				this.Session.Agencia.Id 			= "";
				this.Session.Agencia.Nombre 		= "";
				this.Session.Agencia.IdUsuario 		= "";
				this.Session.Agencia.NombreUsuario 	= "";
				this.Session.Agencia.Recintos 		= "";
				this.Session.Agencia.Login			= "";
				this.Session.Agencia.Passwd			= "";
			default :
				break;
		
		}
	}

	Negocio.prototype.ExistenDestacados = function ( )
	{
		return this.existenDestacados;
	}
	Negocio.prototype.DefineDestacados = function ( lista )
	{
		this.Contenido.Destacados = lista;
		this.existenDestacados = true;
	}

	Negocio.prototype.Procesar = function ( nivel , datos )
	{
		var rc = false;

		switch ( nivel )
		{
			case "ComoFunciona" :
				var datos = new Array ( );
				datos['Nivel'] = "ComoFunciona";
				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;


			case "Inicio" :
				datos['Nivel'] = "Inicio";
				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;

			case "Destacados" :
				var datos = new Array ( );
				datos['Nivel'] = "Destacados";
				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;

			case "Detalle_1_Sesion" :
				var idSesion = datos;
				var datos = new Array ( );
				datos['Nivel']   = "Detalle_1_Sesion";
				datos['idSesion']  = idSesion;

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;


			case "Sesiones" :
				var idSesion = datos;
				var datos = new Array ( );
				datos['Nivel']   = "Sesiones";
				datos['idRecinto'] = this.Session.Recinto.Id;
				datos['idEvento']  = this.Session.Evento.Id;
				datos['idSesion']  = idSesion;

				if ( this.Session.Calendario.Desde != "" )
				{
					datos['fechaInicio']  = this.Session.Calendario.FechaDesde;
				}
				if ( this.Session.Calendario.Desde != "" )
				{
					datos['fechaFin']  = this.Session.Calendario.FechaHasta;
				}

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;

			case "CalendarioEvento" :
				var mes = datos;
				var datos = new Array ( );
				datos['Nivel']       = "CalendarioEvento";
				datos['idRecinto']   = this.Session.Recinto.Id;
				datos['idEvento']    = this.Session.Evento.Id;
				datos['fechaInicio'] = mes;

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;


			case "Buscador" :

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;

			case "DetalleAforo" :
				var datos = new Array ( );
				datos['Nivel']   = "DetalleAforo";
				datos['idSesion'] = this.Session.Sesion.Id;

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "Concesiones" :
				var datos = new Array ( );
				datos['Nivel']    = "Concesiones";
				datos['idSesion'] = this.Session.Sesion.Id;
				datos['idNivel']  = this.Session.Bloque.IdNivel;
				datos['idArea']   = this.Session.Bloque.IdArea;
				datos['idZona']   = this.Session.Bloque.IdZona;
				datos['idBloque'] = this.Session.Bloque.IdBloque;

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "Disponibilidad" :
				var datos = new Array ( );
				datos['Nivel']    = "Disponibilidad";
				datos['idSesion'] = this.Session.Sesion.Id;
				datos['idNivel']  = this.Session.Bloque.IdNivel;
				datos['idArea']   = this.Session.Bloque.IdArea;
				datos['idZona']   = this.Session.Bloque.IdZona;
				datos['idBloque'] = this.Session.Bloque.IdBloque;

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "Reserva" :
        var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
        //atca.43840.Negocio.Procesar Reserva ???
        // Se suben a la sesion los datos de Butacas (Cadena) y  el objeto Entradas
        this.Session.ButacasNoModal = datos['Butacas'];
        this.Session.EntradasNoModal = this.Session.Operacion.Entradas;
        ///atca.43840.Negocio.Procesar Reserva


				break;
			case "ModificarReserva" :
        var datos = new Array ( );
				datos['Nivel']      = "ModificarReserva";
				datos['idSesion']   = this.Session.Sesion.Id;
				datos['Tarjeta']    = this.Session.Pago.Tarjeta;
				datos['idReserva']  = this.Session.Operacion.IdReserva;
				datos['Butacas']    = Utils.FormatCadenaButacas ( this.Session.Operacion.Entradas );
				datos['idNivel']    = this.Session.Bloque.IdNivel;
				datos['idArea']     = this.Session.Bloque.IdArea;
				datos['idZona']     = this.Session.Bloque.IdZona;
				datos['idBloque']   = this.Session.Bloque.IdBloque;
        //atca.43840.Negocio.Procesar ModificarReserva
        if (datos['Butacas']=='')
          {
            datos['Butacas'] = this.Session.ButacasNoModal;
          }
        ///atca.43840.Negocio.Procesar ModificarReserva

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "AnularReserva" :

				var datos = new Array ( );
				datos['Nivel']      = "AnularReserva";
				datos['idReserva']  = this.Session.Operacion.IdReserva;

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "Pago" :

// alert ( "Demo SERMEPA" );

// this.Session.Pago.Tarjeta 	   = "4548812049400004";
// this.Session.Pago.Caduca 	   = "1212";
// this.Session.Pago.Cvc 		   = "123";


				datos['idSesion']   = this.Session.Sesion.Id;
				if ( this.Session.Pago.Boletines != "" )  
				{
					datos['Boletines'] = this.Session.Pago.Boletines;
				}


				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "MisCompras" :


				datos['Nivel']     = "EntradasPendientes";

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "DetalleOperacion" :

				if ( datos['HomeTicket'] )
				{
					datos['Nivel'] = "DetalleOperacionHT";
				}else
				{
					datos['Nivel'] = "DetalleOperacion";
				}
				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;
				
				break;


			case "Oficinas" :

				datos['Nivel']     = "Oficinas";

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;
			case "Imagen" :

				var datos = new Array ( );
				datos['Nivel']     = "Imagen";

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

			case "SetTicketRegalo" :

				datos['Nivel']     = "TicketRegalo";

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;

      // (fbp) valoraciones
			case "SetValoracion" :

				datos['Nivel']     = "Valoracion";

				var url = Url.Qservlet ( "Gateway.php" , datos );
				Utils.Debug ( url.Url + "\n" + url.Datos );
				rc = true;

				break;


			default :
				break;
		}

		if ( rc )
		{
			/******************/	
			/* Para Asincrono */	
			/******************/	

			XConn.DefineCallBack ( TratarContenidoServer );
			XConn.DefineWaitingCallBack ( Utils.Waiting );

			XConn.ConnectToHost ( Cfg.HOST, Cfg.PUERTO, url );

			/******************/	
			/* Para Sincrono */	
			/******************/	
			// XConn.DefineWaitingCallBack ( Utils.Waiting );
			// var contenido = XConn.ConnectToHost ( Cfg.HOST, Cfg.PUERTO, url );
			// Contenidos ( contenido );
     
     
		}
	}
	Negocio.prototype.BuscarPosicionRecinto = function ( idRecinto )
	{
		var pos = -1;
		if ( idRecinto != "" )
		{
			for ( var i=0; i < this.Contenido.Recintos.length; i++ )
			{
				if ( idRecinto == this.Contenido.Recintos[i]['Id'] )
				{
					pos = i;
					break;
				}
			}
		}
		return pos;
	}

	Negocio.prototype.BuscarPosicionEvento = function ( idRecinto , idEvento )
	{
		var pos = -1;
		var comprobarEvento = false;

		if ( ( idRecinto != "" ) || ( idEvento != "" ) )
		{
			for ( var i=0; i < this.Contenido.Eventos.length; i++ )
			{
				if ( idEvento == this.Contenido.Eventos[i]['Id'] )
				{
					var terminar = false;
					if ( idRecinto != "" )
					{
						for ( var j=0;j < this.Contenido.Eventos[i]['Recinto'].length;j++ )
						{
							if ( idRecinto == this.Contenido.Eventos[i]['Recinto'][j]['IdRecinto'] )
							{
								terminar = true;
								break;
							}
						}	
					}else
					{
						terminar = true;
					}

					if ( terminar )
					{
						pos = i;
						break;
					}
				}

			}
		}
		return pos;
	}

	Negocio.prototype.GetRecintosEvento = function ( idEvento )
	{

		var lista = new Array ( );
		var recintos = new Array ( );
		for ( var i=0; i < this.Contenido.Eventos.length; i++ )
		{
			if ( idEvento == this.Contenido.Eventos[i]['Id'] )
			{
				var recintos = this.Contenido.Eventos[i]['Recinto'];
				break;
			}
		}



		var k = 0;
		for ( var i=0; i < recintos.length; i++ )
		{
			var pos = -1;
			for ( var j=0; j < this.Contenido.Recintos.length; j++ )
			{
				if ( recintos[i]['IdRecinto'] == this.Contenido.Recintos[j]['Id'] )
				{
					lista[k] = this.Contenido.Recintos[j];
					k++;
				}
			}
		}

		return lista;
	}




}

