﻿
var DatosGenerales = {

	Desde		: "",
	Hasta		: "",
	Noches		: "",

	Nombre		: "",
	Apellido1	: "",
	Apellido2	: "",
	Dni			: "",
	Telefono	: "",
	Direccion	: "",
	Poblacion	: "",
	Postal		: "",
	Mail		: "",
	Observaciones: "",	
		
	Adultos		: 0,
	Nenes		: 0,

	VReservas	: new Array(),
	VServicios	: new Array(),

	Reserva : function(){
		//Campos de la Reserva.	
		IdHabitacion	: 0;
		Habitacion		: "";
		IdRegimen		: 0;
		Regimen			: "";
		Adultos			: 0;
		Nenes			: 0;
		Precio			: 0;
		IdContrato		: 0;
		EsContrato		: 1;
	},

	Servicio : function(){
		//Campos del Servicio.
		IdServicio		: 0;
		Servicio		: "";
		Cantidad		: 0;
		Precio			: 0;
		PorPax			: 0;
	},
	
	NReservas : function(){
		return this.VReservas.length;
	},

	NServicios : function(){
		return this.VServicios.length;
	},

	PuntoComa : function(m_numero){
		m_PuntoComa = ((1/2)+"").substring(1,2);

		return parseFloat(m_numero.replace(".",m_PuntoComa).replace(",",m_PuntoComa));
	},	

	BCesta : function(){
		Bcesta = false;
		if ((this.VReservas.length + this.VServicios.length) > 0){
			Bcesta = true;	
		}
		return Bcesta;
	},

	UsoTotal : function(){
		nUso = 0;
		for(i=0;i<this.NReservas();i++)
		{
			nUso += (this.VReservas[i].Adultos-0 + this.VReservas[i].Nenes-0);
		}		
		return nUso;
	},

	PrecioTotal : function(){
		nTotal = 0;
		for(i=0;i<this.NReservas();i++)
		{
			nTotal += this.PuntoComa(this.VReservas[i].Precio.toString());
		}		
		for(i=0;i<this.NServicios();i++)
		{
			nTotal += (this.VServicios[i].Cantidad * this.PuntoComa(this.VServicios[i].Precio.toString()));
		}
		
		return nTotal.toFixed(2);
	},

	PrecioBase : function(){
		nTotal = 0;
		for(i=0;i<this.NReservas();i++)
		{
			nTotal += this.PuntoComa(this.VReservas[i].Precio.toString());
		}		
		for(i=0;i<this.NServicios();i++)
		{
			nTotal += (this.VServicios[i].Cantidad * this.PuntoComa(this.VServicios[i].Precio.toString()));
		}
		
		return ((nTotal *100) / 107).toFixed(2);
	},

	PrecioIva : function(){
		nTotal = 0;
		for(i=0;i<this.NReservas();i++)
		{
			nTotal += this.PuntoComa(this.VReservas[i].Precio.toString());
		}		
		for(i=0;i<this.NServicios();i++)
		{
			nTotal += (this.VServicios[i].Cantidad * this.PuntoComa(this.VServicios[i].Precio.toString()));
		}
		
		return (nTotal - ((nTotal *100) / 107)).toFixed(2);
	},

	AdultosTotal : function(){
		aTotal = 0;
		for(i=0;i<this.NReservas();i++)
			aTotal += this.VReservas[i].Adultos - 0;
		
		return aTotal;
	},

	NenesTotal : function(){
		aTotal = 0;
		for(i=0;i<this.NReservas();i++)
			aTotal += this.VReservas[i].Nenes - 0;
		
		return aTotal;
	},

	Prepago : function(){
		return 	((this.PrecioTotal()/100)*20).toFixed(2);
	},

	Resto : function(){
		return (this.PrecioTotal() - this.Prepago()).toFixed(2);
	},

	AddReserva : function(m_Reserva){
		nCant = this.NReservas();
		this.VReservas[nCant] = m_Reserva;
	},
	
	AddServicio : function(m_Servicio){
		nCant = this.NServicios();
		this.VServicios[nCant] = m_Servicio;
	},
	
	MontaCesta : function(bEdit){

		n_rows = 0;
		s_resultado = "<table cellspacing='0' cellpadding='0' border='0' width='100%'>";
		
		for(i=0;i<this.NReservas();i++)
		{
			if (i==0)
				s_resultado = s_resultado + "<tr><td class='tiulorojo'>HABITACIÓN</td></tr>";

			if(n_rows%2 == 0){
				s_resultado = s_resultado + "<tr class='gRow1'><td style='height:70px'><table cellspacing='3' cellpadding='0' border='0' width='100%'>";
			}
			else{
				s_resultado = s_resultado + "<tr><td style='height:70px'><table cellspacing='3' cellpadding='0' border='0' width='100%'>";
			}
			s_resultado = s_resultado + "<tr><td colspan='5' class='lb' align='right' >Precio: <b>" + this.VReservas[i].Precio + " €</td></tr>"; 
			s_resultado = s_resultado + "<tr><td style='width:60px' class='lb' align='right'>Tipo:</td><td colspan='3' class='lbbold'>" + this.VReservas[i].Habitacion + "</td><td rowspan='3' align='right'>" + (bEdit ? "<img style='cursor:pointer;' src='../_Images/delBasket.gif' alt='Eliminar Habitación' onclick='javascript:EliminaReserva(true,"+ i+ ");'>" : "") + "</td></tr>";
			s_resultado = s_resultado + "<tr><td style='width:60px' class='lb' align='right'>Regimén:</td><td class='lbbold' colspan='3'>" + this.VReservas[i].Regimen + "</td></tr>"; 	
			s_resultado = s_resultado + "<tr><td style='width:60px' class='lb' align='right'>Adultos:</td><td class='lbbold' style='width:20px'>" + this.VReservas[i].Adultos + "</b></td><td class='lb' style='width:30px'>Niños:</td><td class='lbbold' align='left' width='100%'>" + this.VReservas[i].Nenes + "</td></tr></table></td><td></td></tr>"; 	

			n_rows = n_rows + 1;
		}		

		for(i=0;i<this.NServicios();i++)
		{
			if (i==0)
				s_resultado = s_resultado + "<tr><td class='tiulorojo'>SERVICIOS EXTRAS</td></tr>";
	
			if(n_rows%2 == 0){
				s_resultado = s_resultado + "<tr class='gRow1'><td style='height:60px'><table cellspacing='3' cellpadding='0' border='0' width='100%'>";
			}
			else{
				s_resultado = s_resultado + "<tr><td style='height:60px'><table cellspacing='3' cellpadding='0' border='0' width='100%'>";
			}
			
			s_resultado = s_resultado + "<tr><td colspan='3' class='lb' align='right'>Precio: <b>" + this.VServicios[i].Precio + " €</td></tr>"; 
			s_resultado = s_resultado + "<tr><td style='width:60px' class='lb' align='right'>Servicio: </td><td class='lbbold'>" + this.VServicios[i].Servicio + "</td><td align='right' rowspan='2'>" + (bEdit ? "<img style='cursor:pointer;' src='../_Images/delBasket.gif' alt='Eliminar Servicio Extra' onclick='javascript:EliminaReserva(false,"+ i+ ");'>":"") + "</td></tr>";
			s_resultado = s_resultado + "<tr><td style='width:60px' class='lb' align='right'>Cantidad: </td><td class='lbbold'>" + this.VServicios[i].Cantidad+ "</td></tr></table></td></tr>"; 	

			n_rows = n_rows + 1;
		}

		s_resultado = s_resultado + "</table>";

		return s_resultado;
		
	},

	DelVector : function(bServicio,n_Indice){
		
		if (bServicio)
			this.VReservas.splice(n_Indice,1);
		else
			this.VServicios.splice(n_Indice,1);
		
	},
	
	Reset : function(){
		
		this.VReservas.splice(0,this.VReservas.length);
		this.VServicios.splice(0,this.VServicios.length);
	}
}


