//////////////////////////////////////////////////////////////////////// 
//
// fichero: logic.js
//
// version: 08
//
// Autor: Jose Manuel Estevez (josemanuel.estevez@dracena.org)
//
// Modificado por: José Antonio Martín Baena (jose.antonio.martin.baena@gmail.com)
//					en la adaptación a minicalculadora.
//
// (C) Copyright 2005 - All Rights Reserved. Jose Manuel Estevez & José Antonio Martín Baena
//
// Terminos de la Licencia:
//
// Uso Comercial: Se prohibe la modificacion, uso o distribución para fines
// comerciales sin autorización expresa de Jose Manuel Estevez,
// José Antonio Martín Baena y UNISPAIN. 
//
// Uso NO comercial: Se autoriza la modificación, uso y distribución de este
// software para fines NO comerciales siempre que no se altere
// la cabecera del fichero.
//
// Reconocimientos:
// Este software hace uso de los ficheros: calendar1.js y calendar.html conocidos
// como Tigra Calendar.
// La licencia de este software esta incluida en la cabecera de dichos ficheros.
// Para mas informacion ver: http://www.softcomplex.com/products/tigra_calendar/
//
////////////////////////////////////////////////////////////////////////
var optWait = 'wait ...';
var optNoAppl = 'N/A';
var calci; 
var calai; 
var calaf; 
var ARR_WEEKDAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
var calcOn = 'img/cal.gif' ;
var calcOff = 'img/nocal.gif' ;
var calcs = 0;
var vercs = 0;
var calas = 0;
var calae = 0;
var MINI_CALCULATOR = true;
var MonthArr = new Array ('', 'Jan','Feb','Mar','Apr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dec'); 
var MonthDays = new Array ('', 31,28,31,30,31,30,31,31,30,31,30,31);
var LevelCity = 0;
var LevelSchool = 1;
var LevelCourse = 2;
var LevelDuration = 3;
var LevelDates = 4;
var LevelAcom = 5;
var LevelPrice = 6;
var LevelSelectedDate = 7;
DateData = new Array ('');
FirstOption = new Array ("Select a City", 
"Select a School",
"Select a Course",
"Select Duration" ,
"Choose an option" ,
"Select Accommodation"); 
AcomOpts = new Array (
'',
'No accomodation needed',
'Family',
'Shared Flat');
AcomRoom = new Array (
'',
'Single',
'Double');
AcomBoard = new Array (
'',
'Half Board',
'Full Board',
' ');
DIVISOR = ", ";
AllOpts = new Array (
new Array (''),
new Array (''),
new Array (''),
new Array (''),
new Array (''), 
new Array ('')
);
AllLinks = new Array (
new Array (''),
new Array (''),
new Array (''),
new Array (''),
new Array ('')
);
var CourseExtras = 1;
var AcomExtras = 2;
var glbWeeksLimit = 36;
var PrecioCursoDuracion = new Array ('');
var PrecioCursoDuracionOff = new Array ('');
var EnrollCursoDuracion = new Array ('');
var ExtrasCursoDuracion = new Array ('');

function init_page () 
{
	init_Globals ();
	with (getLevel2Object(LevelCity)) 
	{
		for (var i = options.length - 1; 0 < i; i--) 
		{
			options[i] = null; 
		}
		options[0] = new Option(FirstOption[LevelCity], 0);
		for (var i = 1; i < AllOpts[LevelCity].length ; i++) 
		{
			options[i] = new Option(AllOpts[LevelCity][i], i); 
		}
		options[0].selected = true; 
	}
	update_data (LevelCity, LevelSchool, 1);
}

function init_Globals () 
{
	for(var i = 1; i < DatosEscuelaAlojamiento.length; i++)
	{
		if(DatosEscuelaAlojamiento[i].length <= 15)
		{
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][5]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][6]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][7]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][8]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][9]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][10]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][11]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][12]);
			DatosEscuelaAlojamiento[i].push(DatosEscuelaAlojamiento[i][13]);			
		}
	}
	AllOpts[0] = DatosCiudad;
	for (var i = 0; i < DatosEscuelas.length ; i++) 
	{
		AllOpts[1][i] = DatosEscuelas[i][1];
		if (i > 0) 
		{
			if (AllLinks[0].length <= DatosEscuelas[i][0]) {AllLinks[0].push (new Array ());}
			AllLinks[0][DatosEscuelas[i][0]].push(i);
		}
	}
	for (var i = 0; i < DatosCursos.length ; i++) 
	{
		AllOpts[2][i] = DatosCursos[i][1];
		if (i > 0) 
		{
			if (AllLinks[1].length <= DatosCursos[i][0]) {AllLinks[1].push (new Array ());}
			AllLinks[1][DatosCursos[i][0]].push(i);
			DatosCursos[i].push (0); 
			DatosCursos[i].push (0); 
		}
	}
	for (var i = 1; i < DatosDuracion.length ; i++) 
	{
		AllOpts[3][i] = DatosDuracion[i][0];
	}
	for (var i = 1; i < DatosCursoDuracion.length ; i++) 
	{
		var DatosCursoNdx = DatosCursoDuracion[i][0];
		var Duracion = DatosCursoDuracion[i][1];
		var ExtraWeeks = DatosCursoDuracion[i][7];
		var TipoTarifa = DatosCursos[DatosCursoNdx][3]; // 2 LB
		
		if (TipoTarifa == 0) 
		{
			if (Duracion <= glbWeeksLimit && ExtraWeeks > 0) 
			{
				DatosCursos[DatosCursoNdx][3] = 1; //2 LB
				DatosCursos[DatosCursoNdx][4] = Duracion; //3 LB
			} 
			else
			{
				DatosCursos[DatosCursoNdx][3] = 2; //2 LB
			}
		} 
		else if (TipoTarifa == 1) 
		{
			if ((Duracion <= glbWeeksLimit && ExtraWeeks == 0) || (Duracion > glbWeeksLimit)) 
			{
				DatosCursos[DatosCursoNdx][3] = 3; //2 LB
			}
		} 
		else if (TipoTarifa == 2) 
		{
			if (Duracion <= glbWeeksLimit && ExtraWeeks > 0) 
			{
				DatosCursos[DatosCursoNdx][3] = 3; //2 LB
				DatosCursos[DatosCursoNdx][4] = Duracion;//3 LB
			}
		}
		if (DatosCursos[DatosCursoNdx][3] == 3) //2 LB
		{
			alert ('ERROR en la configuracion de precios.'+"\n"+
			'Se han encontrado diferentes configuraciones para el curso:'+"\n"+
			DatosCursos[DatosCursoNdx][1]);
		}
		if (Duracion <= glbWeeksLimit && ExtraWeeks > 0) 
		{
			if (Duracion < DatosCursos[DatosCursoNdx][4]) //3 LB
			{
				DatosCursos[DatosCursoNdx][4] = Duracion; //3 LB
			}
		}
	}
	for (var i = 1; i < DatosCursos.length ; i++) 
	{
		AllLinks[2].push (new Array ());
	}
	for (var i = 1; i < DatosCursos.length ; i++) 
	{
		var TipoTarifa = DatosCursos[i][3]; //2 LB
		if (TipoTarifa == 1 || TipoTarifa == 3) 
		{
			var MinWeeks = DatosCursos[i][4];//3 LB
			for (var j = 1; j <= (glbWeeksLimit-MinWeeks) ; j++) 
			{
				AllLinks[2][i].push(0);
			}
		}
	}
	for (var i = 1; i < DatosCursos.length ; i++) 
	{
		PrecioCursoDuracion.push(new Array(DatosDuracion.length));
		PrecioCursoDuracionOff.push(new Array(DatosDuracion.length));
		EnrollCursoDuracion.push(new Array(DatosDuracion.length));
		ExtrasCursoDuracion.push(new Array(DatosDuracion.length));
	}
	for (var i = 1; i < DatosCursoDuracion.length ; i++) 
	{
		var DatosCursoNdx = DatosCursoDuracion[i][0];
		var TipoTarifa = DatosCursos[DatosCursoNdx][3]; //2 LB
		var MinWeeks = DatosCursos[DatosCursoNdx][4]; //3 LB
		var Duracion = DatosCursoDuracion[i][1];
		var ExtraWeeks = DatosCursoDuracion[i][7];
		var PrecioEnroll = DatosCursoDuracion[i][2];
		var PrecioBase = DatosCursoDuracion[i][3];
		var PrecioBaseOff = DatosCursoDuracion[i][4];
		var PrecioEW = DatosCursoDuracion[i][5];
		var PrecioEWOff = DatosCursoDuracion[i][6];
		var Extras = DatosCursoDuracion[i][8];
		if (PrecioBaseOff <= 0) 
		{
			PrecioBaseOff = PrecioBase;
		} 
		if (PrecioEWOff <= 0) 
		{
			PrecioEWOff = PrecioEW;
		} 
		if (TipoTarifa == 1) 
		{
			if (Duracion <= glbWeeksLimit && ExtraWeeks > 0) 
			{
				var Indice = Duracion-MinWeeks;
				for (var j = Duracion; j <= glbWeeksLimit ; j++) 
				{
					AllLinks[2][DatosCursoNdx][Indice] = j;
					PrecioCursoDuracion[DatosCursoNdx][j] = PrecioBase + ((j-Duracion) * PrecioEW);
					PrecioCursoDuracionOff[DatosCursoNdx][j] = PrecioBaseOff + ((j-Duracion) * PrecioEWOff);
					EnrollCursoDuracion[DatosCursoNdx][j] = PrecioEnroll;
					ExtrasCursoDuracion[DatosCursoNdx][j] = Extras;
					Indice++;
				} 
			} 
			else 
			{
				alert ('Error en los datos de entrada.'+"\n"+'Tarifas no validas (Error: 001).');
			}
		} 
		else if (TipoTarifa == 2) 
		{
			AllLinks[2][DatosCursoNdx].push(Duracion);
			PrecioCursoDuracion[DatosCursoNdx][Duracion] = PrecioBase;
			PrecioCursoDuracionOff[DatosCursoNdx][Duracion] = PrecioBaseOff;
			EnrollCursoDuracion[DatosCursoNdx][Duracion] = PrecioEnroll;
			ExtrasCursoDuracion[DatosCursoNdx][Duracion] = Extras;
		} 
		else 
		{
			alert ('Error en los datos de entrada.'+"\n"+'Tarifas no validas (Error: 002). ');
		}
	}
	for (var i = 1; i < DatosCursoInicio.length ; i++) 
	{
		if (DatosCursoInicio[i][2] == 1) 
		{
			AllOpts[4][i] = 'Every Monday';
		} 
		else if (DatosCursoInicio[i][3] == 1) 
		{
			AllOpts[4][i] = 'Every Second Monday';
		} 
		else
		{
			AllOpts[4][i] = DatosCursoInicio[i][4];
		}
		if (DatosCursoInicio[i][1] == 1) 
		{
			AllOpts[4][i] = AllOpts[4][i] + ' (Beginners)';
		}
	}
	for (var i = 1; i < DatosCursoInicio.length ; i++) 
	{
		if (AllLinks[3].length <= DatosCursoInicio[i][0]) {AllLinks[3].push (new Array ());}
		AllLinks[3][DatosCursoInicio[i][0]].push(i);
	}
	AllOpts[5] = AcomOpts;
	for (var i = 1; i < DatosEscuelas.length ; i++) 
	{
		AllLinks[4].push (new Array ('1'));
		for (var j = 2; j < AcomOpts.length ; j++) 
		{
			if (check_acom_type(i, j)) 
			{
				AllLinks[4][i].push(j);
			} 
		}
	}
}
function getLevel2Object (pLevel) {
var object=document.minical.accomodation;
if (pLevel == LevelCity) 
object = document.minical.city;
else if (pLevel == LevelSchool)
object = document.minical.school;
else if (pLevel == LevelCourse)
object = document.minical.course;
else if (pLevel == LevelDuration)
object = document.minical.nWeeks;
else if (pLevel == LevelDates)
object = document.minical.dateStart;
else if (pLevel == LevelSelectedDate)
object = document.minical.selectedDate;
else if (pLevel == LevelPrice)
object = document.prices;
else if (pLevel != LevelAcom)
alert("Warning: The code has a minor mistake. (getLevel2Object with unknown Level:"+pLevel+")");
return object;
}
function update_data (pLevelOrig, pLevelUpdate, pClearLevels) {
if (MINI_CALCULATOR)
update_data_mini (pLevelOrig, pLevelUpdate, pClearLevels);
else
update_data_comp (pLevelOrig, pLevelUpdate,pClearLevels);
}

function update_data_mini (pLevelOrig, pLevelUpdate, pClearLevels) 
{
	var SelectedNdx = 0;
	var Value = 0;
	var AutoNextLevel = 0;
	var Debug = false;
	if (Debug)
		alert('Orig='+pLevelOrig +' Upd='+pLevelUpdate +' Clear='+pClearLevels);
	if (pLevelOrig != null) 
	{
		SelectedNdx = getLevel2Object(pLevelOrig).selectedIndex;
		Value = getLevel2Object(pLevelOrig).options[SelectedNdx].value;
	}
	if (pClearLevels) 
	{
		if (pLevelOrig < LevelAcom && pLevelUpdate <= LevelAcom) {init_sel_acom (0, optWait)};
		if (pLevelOrig < LevelDates && pLevelUpdate <= LevelDates) {init_sel_dates (0, optWait);} 
		if (pLevelOrig < LevelDuration && pLevelUpdate <= LevelDuration) {init_sel_duracion (0, optWait);} 
		if (pLevelOrig < LevelCourse && pLevelUpdate <= LevelCourse) {init_level (LevelCourse, optWait);} 
		if (pLevelOrig < LevelSchool && pLevelUpdate <= LevelSchool) {init_level (LevelSchool, optWait);} 
	} 
	showprice ();
	if (pLevelOrig == 3 && pLevelUpdate == 4) 
	{
		alert ("actualizar inicios");
	}
	if (SelectedNdx != 0 && getLevel2Object(pLevelUpdate).options.length == 1) 
	{
		init_level (pLevelUpdate , FirstOption[pLevelUpdate]);
		if (pLevelUpdate != LevelAcom) 
		{
			with (getLevel2Object(pLevelUpdate)) 
			{
				var NumOptions = AllLinks[pLevelUpdate-1][Value].length;
				for (var i = 1; i <= NumOptions ; i++) 
				{
					OptElem = AllLinks[pLevelUpdate-1][Value][i-1];
					if (Debug) 
					{
						options[i] = new Option('i='+i + ' OptElem='+OptElem + ' -> ' + AllOpts[pLevelUpdate][OptElem], OptElem); 
					} 
					else 
					{ 
						if(pLevelUpdate == LevelAcom && i==1) //LB HACK Temporal para Universidad de Granada para obligar a elegir alojamiento
						{
							var Course = getCourse();
							if(DatosCursos[Course][2]==0)
							{
								options[i] = new Option(AllOpts[pLevelUpdate][OptElem], OptElem); 
							}
						}
						else options[i] = new Option(AllOpts[pLevelUpdate][OptElem], OptElem); 
					} 
				}
				if (NumOptions == 1) 
				{ 
					options[1].selected = true;
					AutoNextLevel = 1;
				}
			}
		} 
		else 
		{
			initAcom();
		}
	} 
	showprice ();
	if (AutoNextLevel) 
	{
		if (pLevelUpdate == LevelSchool) 
		{
			update_data (LevelSchool, LevelCourse, 1);
		} 
		else if (pLevelUpdate == LevelCourse) 
		{
			update_data (LevelCourse, LevelDuration, 1);
		} 
		else if (pLevelUpdate == LevelDuration) 
		{
			// update_data (LevelDuration, LevelDates, 1);
			update_data (LevelCourse, LevelDates, 1);
		} 
		else if (pLevelUpdate == LevelDates) 
		{
			check_dates (0, LevelSchool, LevelAcom);
		}
	}
	showprice ();
}

// Nombre: update_data_comp
// Funcion: Parece que determina la navegacion del formulario, actualizando datos cuando sea 
//          necesario o cargando o borrando opciones segun la navegacion del interfaz.

function update_data_comp (pLevelOrig, pLevelUpdate, pClearLevels) 
{
	var SelectedNdx = 0;
	var Value = 0;
	var AutoNextLevel = 0;
	var Debug = false;
	if (Debug) 
	{
		alert('Orig='+pLevelOrig +' Upd='+pLevelUpdate +' Clear='+pClearLevels);
	}
	if (pLevelOrig != null) 
	{
		SelectedNdx = document.forms[pLevelOrig].elements[0].selectedIndex;
		Value = document.forms[pLevelOrig].elements[0].options[SelectedNdx].value;
	}
	if (pClearLevels) 
	{
		// if (pLevelOrig < LevelAcom) {init_sel_acom (0, optWait)};
		// if (pLevelOrig < LevelDates) {init_sel_dates (0, optWait);} 
		// if (pLevelOrig < LevelDuration) {init_sel_duracion (0, optWait);} 
		// if (pLevelOrig < LevelCourse) {init_level (LevelCourse, optWait);} 
		// if (pLevelOrig < LevelSchool) {init_level (LevelSchool, optWait);} 
		if (pLevelOrig < LevelAcom && pLevelUpdate <= LevelAcom) {init_sel_acom (0, optWait)};
		if (pLevelOrig < LevelDates && pLevelUpdate <= LevelDates) {init_sel_dates (0, optWait);} 
		if (pLevelOrig < LevelDuration && pLevelUpdate <= LevelDuration) {init_sel_duracion (0, optWait);} 
		if (pLevelOrig < LevelCourse && pLevelUpdate <= LevelCourse) {init_level (LevelCourse, optWait);} 
		if (pLevelOrig < LevelSchool && pLevelUpdate <= LevelSchool) {init_level (LevelSchool, optWait);}
		// Para limpiar formulario cuando se modifica la duración del curso
//		if (pLevelOrig < LevelDates && pLevelUpdate <= LevelDates) {init_level (LevelDates, optWait);}  
	} 
	showprice ();
	//----------------------------------------------------------------------------------
	// Modificación para obligar a seleccionar fecha si se cambia la duración del curso
	//----------------------------------------------------------------------------------
//	if (pLevelUpdate == 4)
//	{
//		init_sel_acom (0, optWait);
//		check_dates (0, LevelSchool, LevelAcom);
//	}
	//-----------------------------------------------------------------------------------
	// Fin de modificación by Javi
	//-----------------------------------------------------------------------------------
	if (pLevelOrig == 3 && pLevelUpdate == 4) 
	{
		alert ("actualizar inicios");
	}
	if (SelectedNdx != 0 && document.forms[pLevelUpdate].elements[0].options.length == 1) 
	{
		init_level (pLevelUpdate , FirstOption[pLevelUpdate]);
		with (document.forms[pLevelUpdate].elements[0]) 
		{
			var NumOptions = AllLinks[pLevelUpdate-1][Value].length;
			for (var i = 1; i <= NumOptions ; i++) 
			{
				OptElem = AllLinks[pLevelUpdate-1][Value][i-1];
				if (Debug) 
				{
					options[i] = new Option('i='+i + ' OptElem='+OptElem + ' -> ' + AllOpts[pLevelUpdate][OptElem], OptElem); 
				} 
				else 
				{ 
					if(pLevelUpdate == LevelAcom && i==1) //LB HACK Temporal para Universidad de Granada para obligar a elegir alojamiento
					{
						var Course = getCourse();
						if(DatosCursos[Course][2]==0)
						{
							options[i] = new Option(AllOpts[pLevelUpdate][OptElem], OptElem); 
						}
					}
					else options[i] = new Option(AllOpts[pLevelUpdate][OptElem], OptElem); 

				} 
			}
			if (NumOptions == 1) 
			{
				options[1].selected = true;
				AutoNextLevel = 1;
			}
		}
	}
	showprice ();
	if (AutoNextLevel) 
	{
		if (pLevelUpdate == LevelSchool) 
		{
			update_data (LevelSchool, LevelCourse, 1);
		} 
		else if (pLevelUpdate == LevelCourse) 
		{
			update_data (LevelCourse, LevelDuration, 1);
		} 
		else if (pLevelUpdate == LevelDuration) 
		{
			// update_data (LevelDuration, LevelDates, 1);
			update_data (LevelCourse, LevelDates, 1);
		} 
		else if (pLevelUpdate == LevelDates) 
		{
			check_dates (0, LevelSchool, LevelAcom);
		}
	}
	showprice ();
}

function init_level (pLevel, pString) {
with (getLevel2Object(pLevel)) {
for (var i = options.length - 1; 0 < i; i--) {
options[i] = null; 
}
options[0] = new Option(pString, 0);
options[0].selected = true;
}
}
function init_sel_duracion (pOrigSel, pmessage) {
if (pOrigSel == 0) {
init_level (LevelDuration, pmessage);
}
}
function check_extra_weeks (pLevelStart, pLevelUpdate) {
// # alert ('extra_weeks');
with (getLevel2Object(LevelDuration)) {
var SelectedNdx = selectedIndex;
var Value = options[SelectedNdx].value;
if (Value == 0) {
init_sel_duracion (1, optNoAppl);
update_data (null, pLevelUpdate, 0);
// # } else if (DatosCursoDuracion[Value][5] > 0 && DatosCursoDuracion[Value][7]) {
// # init_sel_duracion (1, '0');
// # update_data (pLevelStart, pLevelUpdate, 0);
} else {
init_sel_duracion (1, optNoAppl);
update_data (pLevelStart, pLevelUpdate, 0);
}
}
showprice ();
}
function init_sel_dates (pOrigSel, pmessage) {
/*if (MINI_CALCULATOR)
init_sel_dates_mini (pOrigSel, pmessage);
else*/
init_sel_dates_comp (pOrigSel, pmessage);
}
function init_sel_dates_comp (pOrigSel, pmessage) {
if (pOrigSel == 0) {
init_level (LevelDates, pmessage);
}
setCourseStartDateTxt (pmessage);
document.images['cs'].src= calcOff;
calcs = 0;
vercs = 0;
}
function changeCourseInitDate () {
if (calcs) {
var ExtraNdx = getCourseExtraNdx ();
alert (AlertExtrasTxt (CourseExtras, ExtraNdx, 1));
calci.popup();
}
}
function check_dates (pOrigSel, pLevelStart, pLevelUpdate) {
if (MINI_CALCULATOR)
check_dates_mini(pOrigSel,pLevelStart,pLevelUpdate);
else
check_dates_comp(pOrigSel,pLevelStart,pLevelUpdate);
}
function check_dates_mini (pOrigSel, pLevelStart, pLevelUpdate) {
//var SelectedNdx = getLevel2Object(LevelDates).selectedIndex;
var Value = getLevel2Object(LevelDates).value;
if (Value == 0) {
init_sel_dates (1, optWait);
update_data (null, pLevelUpdate, 0);
return;
}
var ExtraNdx = getCourseExtraNdx ();
if (pOrigSel == 0) {
if (DatosCursoInicio[Value][2] || DatosCursoInicio[Value][3]) {
// with (document.forms[LevelDates]) {
if (getLevel2Object(LevelSelectedDate).value != '') {
getLevel2Object(LevelSelectedDate).value = '';
}
var FechaActual = new Date ();
var Fecha = new Date ();
Fecha.setDate (Fecha.getDate()+1);
while (Fecha.getDay() != 1) {
Fecha.setDate (Fecha.getDate()+1);
}
if (DatosCursoInicio[Value][3]) {
while (nbrMonday (Fecha) != 2) {
Fecha.setDate (Fecha.getDate()+7);
}
}
getLevel2Object(LevelSelectedDate).value = makeDateTxt (Fecha.getDate(), Fecha.getMonth()+1, Fecha.getFullYear()) 
calci = new calendar1(getLevel2Object(LevelSelectedDate));
calci.year_scroll = true;
calci.time_comp = false; 
alert (AlertExtrasTxt (CourseExtras, ExtraNdx, 1));
calci.popup();
// } 
vercs = 0;
} else {
var FechaActual = new Date ();
var Fecha = jsDate(DatosCursoInicio[Value][4]);
if (Fecha < FechaActual) {
alert (msgCourseOutdated); 
getLevel2Object(LevelDates).options[0].selected = true;
return;
} else {
setCourseStartDateTxt (DatosCursoInicio[Value][4]);
update_data (pLevelStart, pLevelUpdate, 0);
document.images['cs'].src= calcOff;
calcs = 0;
vercs = 1;
}
}
}
if (pOrigSel == 1) {
if (DatosCursoInicio[Value][2] || DatosCursoInicio[Value][3]) {
// with (document.forms[LevelDates]) {
var FechaError = 0;
var ExtraTxt = AlertExtrasTxt (CourseExtras, ExtraNdx, 0);
if (getLevel2Object(LevelSelectedDate).value == '') {
alert (msgNOInputDate+ExtraTxt);
FechaError = 1;
} else {
var FechaActual = new Date ();
var Fecha = jsDate(getLevel2Object(LevelSelectedDate).value);
if (check_closed (CourseExtras, ExtraNdx, Fecha)) {
alert (msgSchoolIsClosed+ExtraTxt);
FechaError = 1;
} else if (Fecha < FechaActual) {
alert (msgDatePast+ExtraTxt); 
FechaError = 1;
} else if (DatosCursoInicio[Value][3] && nbrMonday (Fecha) != 2) {
alert (msgNotSecondMon +ExtraTxt);
FechaError = 1; 
} else if (Fecha.getDay() != 1) {
alert (msgnotMonday+ExtraTxt);
FechaError = 1;
}
}
if (FechaError == 1) {
calcs = 0;
vercs = 0;
calci.popup();
} else {
document.images['cs'].src= calcOn;
calcs = 1;
vercs = 1;
update_data (pLevelStart, pLevelUpdate, 0);
} 
// } 
}
}
showprice (); 
}
function check_dates_comp (pOrigSel, pLevelStart, pLevelUpdate) {
alert('check_dates_comp cannot be used in minicalculator mode!');
/* var SelectedNdx = getLevel2Object(LevelDates).selectedIndex;
var Value = getLevel2Object(LevelDates).options[SelectedNdx].value;
if (Value == 0) {
init_sel_dates (1, optWait);
update_data (null, pLevelUpdate, 0);
return;
}
var ExtraNdx = getCourseExtraNdx ();
if (pOrigSel == 0) {
if (DatosCursoInicio[Value][2] || DatosCursoInicio[Value][3]) {
with (document.forms[LevelDates]) {
if (elements[1].value != '') {
elements[1].value = '';
}
var FechaActual = new Date ();
var Fecha = new Date ();
Fecha.setDate (Fecha.getDate()+1);
while (Fecha.getDay() != 1) {
Fecha.setDate (Fecha.getDate()+1);
}
if (DatosCursoInicio[Value][3]) {
while (nbrMonday (Fecha) != 2) {
Fecha.setDate (Fecha.getDate()+7);
}
}
elements[1].value = makeDateTxt (Fecha.getDate(), Fecha.getMonth()+1, Fecha.getFullYear()) 
calci = new calendar1(elements[1]);
calci.year_scroll = true;
calci.time_comp = false; 
alert (AlertExtrasTxt (CourseExtras, ExtraNdx, 1));
calci.popup();
} 
vercs = 0;
} else {
var FechaActual = new Date ();
var Fecha = jsDate(DatosCursoInicio[Value][4]);
if (Fecha < FechaActual) {
alert (msgCourseOutdated); 
getLevel2Object(LevelDates).options[0].selected = true;
return;
} else {
setCourseStartDateTxt (DatosCursoInicio[Value][4]);
update_data (pLevelStart, pLevelUpdate, 0);
document.images['cs'].src= calcOff;
calcs = 0;
vercs = 1;
}
}
}
if (pOrigSel == 1) {
if (DatosCursoInicio[Value][2] || DatosCursoInicio[Value][3]) {
with (document.forms[LevelDates]) {
var FechaError = 0;
var ExtraTxt = AlertExtrasTxt (CourseExtras, ExtraNdx, 0);
if (elements[1].value == '') {
alert (msgNOInputDate+ExtraTxt);
FechaError = 1;
} else {
var FechaActual = new Date ();
var Fecha = jsDate(elements[1].value);
if (check_closed (CourseExtras, ExtraNdx, Fecha)) {
alert (msgSchoolIsClosed+ExtraTxt);
FechaError = 1;
} else if (Fecha < FechaActual) {
alert (msgDatePast+ExtraTxt); 
FechaError = 1;
} else if (DatosCursoInicio[Value][3] && nbrMonday (Fecha) != 2) {
alert (msgNotSecondMon +ExtraTxt);
FechaError = 1; 
} else if (Fecha.getDay() != 1) {
alert (msgnotMonday+ExtraTxt);
FechaError = 1;
}
}
if (FechaError == 1) {
calcs = 0;
vercs = 0;
calci.popup();
} else {
document.images['cs'].src= calcOn;
calcs = 1;
vercs = 1;
update_data (pLevelStart, pLevelUpdate, 0);
} 
} 
}
}
showprice (); */
}
function initAcom() {
with (getLevel2Object(LevelAcom)) {
for (i=options.length-1;i>0;i--)
options[i]=null;
//var count = 0;
options[1]=new Option(AcomOpts[1],new Array(0,optNoAppl,optNoAppl));
// We look for those entries of accomodation in the school already selected.
for (i=0;i<DatosEscuelaAlojamiento.length; i++){
// Those entries fitting the school selected.
if (DatosEscuelaAlojamiento[i][0] == getEscuela()) {
//count++;
iType = DatosEscuelaAlojamiento[i][1];
iRoom = DatosEscuelaAlojamiento[i][2];
iBoard= DatosEscuelaAlojamiento[i][3];
newOption = AcomOpts[iType] + DIVISOR;
newOption += AcomRoom[iRoom] + DIVISOR;
newOption += AcomBoard[iBoard];
indexes=new Array(iType,iRoom,iBoard);
options[options.length]=new Option(newOption,indexes,false,false);
}
}
return options.length-1;
}
}
function init_sel_acom (pOrigSel, pmessage) {
if (MINI_CALCULATOR)
init_sel_acom_mini (pOrigSel, pmessage);
else
init_sel_acom_comp (pOrigSel, pmessage);
}
function init_sel_acom_mini (pOrigSel, pmessage) {
if (pOrigSel == 0) {
init_level (LevelAcom, pmessage);
// document.forms[LevelAcom].elements[3].value = pmessage;
// document.images['as'].src= calcOff;
calas = 0;
// document.forms[LevelAcom].elements[4].value = pmessage;
// document.images['ae'].src= calcOff;
calae = 0;
}
}
function init_sel_acom_comp (pOrigSel, pmessage) {
alert('init_sel_acom_comp cannot be used in minicalculator mode!');
/*if (pOrigSel == 0) {
init_level (LevelAcom, pmessage);
document.forms[LevelAcom].elements[3].value = pmessage;
document.images['as'].src= calcOff;
calas = 0;
document.forms[LevelAcom].elements[4].value = pmessage;
document.images['ae'].src= calcOff;
calae = 0;
}
for (var j = 1; j <= 2; j++) {
if (j >= pOrigSel ) {
with (document.forms[LevelAcom].elements[j]) {
for (var i = options.length - 1; 0 < i; i--) {
options[i] = null; 
}
options[0] = new Option(pmessage, 0); 
options[0].selected = true; 
}
}
}
*/
}
function changeAcomStartDate () {
if (calas) {
calai.popup();
}
}
function changeAcomEndDate () {
if (calae) {
calaf.popup();
}
}
function check_acom_type (Escuela, Tipo) {
for (var i = 1; i < DatosEscuelaAlojamiento.length ; i++) {
if (DatosEscuelaAlojamiento[i][0] == Escuela && DatosEscuelaAlojamiento[i][1] == Tipo) {
return 1;
}
}
return 0;
}
function check_acom_room (Escuela, Tipo, Room) {
for (var i = 1; i < DatosEscuelaAlojamiento.length ; i++) {
if (DatosEscuelaAlojamiento[i][0] == Escuela && DatosEscuelaAlojamiento[i][1] == Tipo && DatosEscuelaAlojamiento[i][2] == Room) {
return 1;
}
}
return 0;
}
function check_acom_board (Escuela, Tipo, Room, Board) {
for (var i = 1; i < DatosEscuelaAlojamiento.length ; i++) {
if (DatosEscuelaAlojamiento[i][0] == Escuela && DatosEscuelaAlojamiento[i][1] == Tipo && DatosEscuelaAlojamiento[i][2] == Room && DatosEscuelaAlojamiento[i][3] == Board) {
return 1;
}
}
return 0;
}
function check_acom_data (pOrigSel) {
if (MINI_CALCULATOR)
check_acom_data_mini (pOrigSel);
else
check_acom_data_comp (pOrigSel);
}
function check_acom_data_mini (pOrigSel) {
showprice();
}
function check_acom_data_comp (pOrigSel) {
alert('check_acom_data_comp cannot be used in minicalculator mode!');
/* if (pOrigSel <= 3) {
init_sel_acom (pOrigSel, optWait);
var Value = 0;
if (pOrigSel) {
with (document.forms[LevelAcom].elements[pOrigSel-1]) {
Value = options[selectedIndex].value;
}
} 
if (Value == 0) {
showprice ();
return;
}
}
var Escuela = getEscuela ();
var Tipo = 0;
var Room = 0;
var Board = 0;
if (Escuela == 0) {
showprice ();
return;
}
with (document.forms[LevelAcom]) {
Tipo = elements[0].options[elements[0].selectedIndex].value;
if (Tipo == 0) {
showprice ();
return;
} else if (Tipo == 1) {
init_sel_acom (pOrigSel, optNoAppl);
elements[3].value = optNoAppl;
elements[4].value = optNoAppl;
showprice ();
return;
}
if (elements[3].value == optNoAppl) {
elements[3].value = optWait;
elements[4].value = optWait;
}
elements[1].options[0].text = 'Select Room Type';
if (pOrigSel == 1) { 
var nextOpt = 1;
for (var Room = 1; Room <= AcomRoom.length; Room++) {
if (check_acom_room (Escuela, Tipo, Room) ) {
elements[1].options[nextOpt] = new Option(AcomRoom[Room], Room);
nextOpt ++;
}
}
elements[1].options[0].selected = true; 
if (elements[1].options.length == 2) {
elements[1].options[1].selected = true;
pOrigSel++;
}
}
Room = getRoom ();
if (Room == 0) {
showprice ();
return;
}
elements[2].options[0].text = 'Select Board Type';
if (pOrigSel == 2) {
var nextOpt = 1;
for (var Board = 1; Board <= AcomBoard.length; Board++) {
if (check_acom_board (Escuela, Tipo, Room, Board) ) {
elements[2].options[nextOpt] = new Option(AcomBoard[Board], Board);
nextOpt ++;
}
} 
elements[2].options[0].selected = true;
if (elements[2].options.length == 2) {
elements[2].options[1].selected = true;
pOrigSel++;
}
}
Board = getBoard ();
if (Board == 0) {
showprice ();
return;
}
if (pOrigSel == 3 || pOrigSel == 4 || pOrigSel == 5) {
getAcomDates (pOrigSel); 
}
}
showprice ();
*/
}
function getAcomDates (pOrigSel) {
alert('getAcomDates cannot be used in minicalculator mode!');
/* var ExtraNdx = getCourseExtraNdx ();
with (document.forms[LevelAcom]) {
if (elements[3].value == optWait || elements[3].value == optNoAppl) {
var FechaStart = jsDate(getCourseStartDateTxt ());
var dia = FechaStart.getDate() - 1;
FechaStart.setDate(dia);
var anio = FechaStart.getFullYear();
var mes = FechaStart.getMonth() + 1;
dia = FechaStart.getDate();
elements[3].value = makeDateTxt (dia, mes, anio);
calai = new calendar1(elements[3]);
calai.year_scroll = true;
calai.time_comp = false;
alert (AlertExtrasTxt (AcomExtras, 0, 2));
calai.popup();
return;
}
if (elements[4].value == optWait || elements[4].value == optNoAppl) {
var Days = getCouseDays ();
var FechaStart = jsDate(getCourseStartDateTxt ());
var dia = FechaStart.getDate() + Days - 2;
FechaStart.setDate(dia);
var anio = FechaStart.getFullYear();
var mes = FechaStart.getMonth() + 1;
dia = FechaStart.getDate();
elements[4].value = makeDateTxt (dia, mes, anio);
calaf = new calendar1(elements[4]);
calaf.year_scroll = true;
calaf.time_comp = false;
alert (AlertExtrasTxt (AcomExtras, 0, 3));
// calaf.popup();---------------------------------- Modificado por José Antonio Martín Baena
return;
}
}*/
}
function makeDateTxt (pDia, pMes, pAnio) {
if (pDia < 1 || pDia > 31 || pMes < 1 || pMes > 12 || pAnio < 2001 || pAnio > 9999) {
return '01-01-2001';
}
var DateTxt = (pDia > 9)? pDia+'-' : '0'+pDia+'-';
DateTxt += (pMes > 9)? pMes+'-' : '0'+pMes+'-';
DateTxt += pAnio;
return DateTxt;
} 
function checkAcomDate (pArrivalDate) {
alert('checkAcomDate cannot be used in minicalculator mode!');
/* with (document.forms[LevelAcom]) {
if (elements[0].selectedIndex < 2) {return;} 
}
var msgInitial = 0;
var Element = 0;
var OrigLevel = 0;
var iconImg = '';
if (pArrivalDate) {
msgInitial = 2;
Element = 3;
OrigLevel = 4;
iconImg = 'as';
} else { 
msgInitial = 3;
Element = 4;
OrigLevel = 5;
iconImg = 'ae';
}
with (document.forms[LevelAcom]) {
if (elements[Element].value == optWait || elements[Element].value == optNoAppl) {
return;
}
var ExtraNdx = getCourseExtraNdx ();
ExtraTxt = AlertExtrasTxt (AcomExtras, ExtraNdx, msgInitial);
var FechaError = 0;
if (elements[Element].value == '') {
alert (msgNOInputDate + ExtraTxt);
FechaError = 1;
} else {
var FechaActual = new Date ();
var Fecha = jsDate(elements[Element].value);
if (Fecha < FechaActual) {
alert (msgDatePast+ExtraTxt); 
FechaError = 1;
} else if (pArrivalDate == 0) {
var FechaInicial = jsDate(elements[Element-1].value);
var Days = calcDaysBtwDates (FechaInicial, Fecha);
var AcomPricesNdx = getAcomPricesNdx (getEscuela (), getAcomType (), getRoom (), getBoard ()); 
if (Days <= 0) {
elements[4].value = elements[3].value;
alert (msgBadStartEndPeriod+"\n"+ExtraTxt); 
FechaError = 1;
} else if (AcomPricesNdx) {
var minDays = DatosEscuelaAlojamiento[AcomPricesNdx][4] - 1;
if (minDays && Days < minDays) {
alert (msgBadAcomMinDays+minDays+' days.'+"\n"+ExtraTxt); 
FechaError = 1;
} 
} 
}
}
if (FechaError == 1) {
document.images[iconImg].src= calcOff;
if (pArrivalDate) {
calas = 0;
showprice ();
calai.popup();
} else { 
calae = 0;
showprice ();
calaf.popup();
}
} else {
document.images[iconImg].src= calcOn;
if (pArrivalDate) {
calas = 1;
} else { 
calae = 1;
}
check_acom_data (OrigLevel); 
}
}
if (pArrivalDate && FechaError == 0) {
checkAcomDate (0);
}*/
}
function showprice () {
if (MINI_CALCULATOR)
ret = showprice_mini();
else
ret = showprice_comp();
return ret;
}

function showprice_mini () 
{
	var coursePrice = null;
	var acomPrice = null;
	var totalPrice = null;
	var totalOffPrice = null;
	var DescuentoExtra = 0;

	if (checkCoursePrice()) 
	{
		coursePrice = showCoursePrice();
	} 
	else 
	{
		clearCoursePrice();
	}
	
	if (checkAcomPrice()) 
	{
		if(coursePrice!=null)
		{
			DescuentoExtra = coursePrice[2];
		}
		else DescuentoExtra = 0;
		
		acomPrice = showAcomPrice(DescuentoExtra);
	} 
	else 
	{
		clearAcomPrice();
	}
//	alert('Prices are = '+coursePrice+' - '+acomPrice);

	if (coursePrice != null && coursePrice[0] > 0 && acomPrice != null)
	{
		totalPrice = coursePrice[0] + acomPrice[0];
		getLevel2Object(LevelPrice).elements[5].value = totalPrice +"\u20AC";
	}
	//else getLevel2Object(LevelPrice).elements[5].value = optWait;

	if (coursePrice != null && coursePrice[1] > 0 && acomPrice != null)
	{
		totalOffPrice = coursePrice[1] + acomPrice[1];
		getLevel2Object(LevelPrice).elements[4].value = totalOffPrice +"\u20AC";
	}
//	else getLevel2Object(LevelPrice).elements[4].value = optWait;

/*
	if (coursePrice != null && coursePrice[0] > 0 && acomPrice != null) 
	{
		totalPrice = coursePrice[0] + acomPrice;
		totalOfficialPrice = coursePrice[1] + acomPrice;
		document.forms[LevelPrice].elements[5].value = totalPrice +"\u20AC";
		document.forms[LevelPrice].elements[4].value = totalOfficialPrice +"\u20AC";
	}
*/
	return totalPrice;
}

function showprice_comp () 
{
	var coursePrice = null;
	var acomPrice = null;
	var totalPrice = null;
	var totalOffPrice = null;
	var DescuentoExtra = 0;
	
	if (checkCoursePrice()) 
	{
		coursePrice = showCoursePrice();
	} 
	else 
	{
		clearCoursePrice();
	}
	if (checkAcomPrice()) 
	{
		if(coursePrice!=null)
		{
			DescuentoExtra = coursePrice[2];
		}
		else DescuentoExtra = 0;
		
		acomPrice = showAcomPrice(DescuentoExtra);
	} 
	else 
	{
		clearAcomPrice();
	}
//	alert('Prices are = '+coursePrice+' - '+acomPrice);

	if (coursePrice != null && coursePrice[0] > 0 && acomPrice != null)
	{
		totalPrice = coursePrice[0] + acomPrice[0];
		document.forms[LevelPrice].elements[6].value = totalPrice +"\u20AC"; //	LB	document.forms[LevelPrice].elements[5].value = totalPrice +"\u20AC";
	}
	else document.forms[LevelPrice].elements[6].value = optWait;

	if (coursePrice != null && coursePrice[1] > 0 && acomPrice != null)
	{
		totalOffPrice = coursePrice[1] + acomPrice[1];
		document.forms[LevelPrice].elements[7].value = totalOffPrice +"\u20AC"; // LB		document.forms[LevelPrice].elements[4].value = totalOfficialPrice +"\u20AC";
	}
	else document.forms[LevelPrice].elements[7].value = optWait;

	return totalPrice;
}

function checkInitPrice() {
if (getLevel2Object(LevelCity).selectedIndex == 0) {return 0;} 
if (getLevel2Object(LevelSchool).selectedIndex == 0) {return 0;} 
if (getLevel2Object(LevelCourse).selectedIndex == 0) {return 0;} 
}
function checkCoursePrice() {
if (checkInitPrice() == 0) {return 0;}
if (getLevel2Object(LevelDuration).selectedIndex == 0) {return 0;}
if (getLevel2Object(LevelDates).selectedIndex == 0) {return 0;}
if (vercs == 0) {return 0;}
return 1;
}
function checkAcomPrice() {
if (MINI_CALCULATOR)
ret = checkAcomPrice_mini();
else
ret = checkAcomPrice_comp();
return ret;
}
function checkAcomPrice_mini() {
return (getLevel2Object(LevelAcom).selectedIndex != 0);
}
function checkAcomPrice_comp() 
{
	alert('checkAcomPrice_comp cannot be used in minicalculator mode!');
	/*
	if (checkInitPrice() == 0) {return 0;}
	if (getAcomType () == 0) {return 0;}
	if (getAcomType () == 1) {return 1;}
	if (getRoom () == 0) {return 0;}
	if (getBoard () == 0) {return 0;}
	with (document.forms[LevelAcom]) 
	{
		if (elements[3].value == optWait || elements[3].value == optNoAppl) {return 0;}
		if (elements[4].value == optWait || elements[4].value == optNoAppl) {return 0;}
	}
	if (calas == 0 || calae == 0) {return 0;}
	return 1;
	*/
}

function clearCoursePrice() {
if (MINI_CALCULATOR){
clearCoursePrice_comp();
getLevel2Object(LevelPrice).elements[5].value = optWait;
} else
clearCoursePrice_comp();
}

function clearCoursePrice_comp() 
{
	/*
	with (getLevel2Object(LevelPrice))
	{
		elements[0].value = optWait;
		elements[1].value = optWait;
		elements[2].value = optWait;
		elements[3].value = optWait; // LB
		elements[6].value = optWait; //	LB	elements[4].value = optWait;
		elements[7].value = optWait; // LB
	}
   */
}

function clearAcomPrice() 
{
	with (getLevel2Object(LevelPrice)) 
	{
		elements[3].value = optWait;
		elements[4].value = optWait;
	}
}

function showCoursePrice() {
if (MINI_CALCULATOR)
ret = showCoursePrice_mini();
else 
ret = showCoursePrice_comp()
return ret;
}

function showCoursePrice_mini() 
{
	var Price = 0;
	var PriceOff = 0;
	var PriceExtras = 0;
	var Course = getCourse ();
	var Duracion = getDuracion ();
	Price = PrecioCursoDuracion[Course][Duracion];
	PriceOff = PrecioCursoDuracionOff[Course][Duracion];
	Enrollment = EnrollCursoDuracion[Course][Duracion];
	var Days = getCouseDays ();
	var ExtraNdx = getCourseExtraNdx();
	var StartDate = getCourseStartDateTxt ();
	var DescuentoExtra = 0;
	
	if (ExtraNdx) 
	{
		PriceExtras = calcSeasonExtra (CourseExtras, ExtraNdx, StartDate, Days); 
	}
	Price += PriceExtras;
	PriceOff += PriceExtras;
	var Escuela = getEscuela();
	if(DatosEscuelas[Escuela][3]==1) //Hay que enmascarar
	{
		DescuentoExtra = PriceOff - Price;
		Price = PriceOff;
	}
	
	with (getLevel2Object(LevelPrice)) 
	{
		elements[0].value = Price + "\u20AC";
		elements[1].value = PriceOff + "\u20AC";
		if (Enrollment) 
		{ 
			elements[2].value = Enrollment+"\u20AC";
		} 
		else 
		{
			elements[2].value = optNoAppl;
		}
	}
	return new Array(Price + Enrollment,PriceOff + Enrollment, DescuentoExtra);
}

function showCoursePrice_comp() 
{
	var Price = 0;
	var PriceOff = 0;
	var PriceExtras = 0;
	var Course = getCourse ();
	var Duracion = getDuracion ();
	Price = PrecioCursoDuracion[Course][Duracion];
	PriceOff = PrecioCursoDuracionOff[Course][Duracion];
	Enrollment = EnrollCursoDuracion[Course][Duracion];
	var Days = getCouseDays ();
	var ExtraNdx = getCourseExtraNdx();
	var StartDate = getCourseStartDateTxt ();
	var DescuentoExtra = 0;
	if (ExtraNdx) 
	{
		PriceExtras = calcSeasonExtra (CourseExtras, ExtraNdx, StartDate, Days); 
	}
	Price += PriceExtras;
	PriceOff += PriceExtras;
	var Escuela = getEscuela();
	if(DatosEscuelas[Escuela][3]==1) //Hay que enmascarar
	{
		DescuentoExtra = PriceOff - Price;
		Price = PriceOff;
	}
	with (document.forms[LevelPrice]) 
	{
		elements[0].value = Price + "\u20AC";
		elements[1].value = PriceOff + "\u20AC";
		
		if (Enrollment) 
		{ 
			elements[2].value = Enrollment+"\u20AC";
			elements[3].value = Enrollment+"\u20AC"; // LB
		} 
		else 
		{
			elements[2].value = optNoAppl;
			elements[3].value = optNoAppl; // LB			
		}
	}
	return new Array(Price + Enrollment,PriceOff + Enrollment, DescuentoExtra);// LB return Price + Enrollment;
}
function getCourseFinishDate() {
with (getLevel2Object(LevelDuration)) {
duration=options[selectedIndex].value;
duration=duration*604800000-86400;
fecha = jsDate(getCourseStartDateTxt());
//alert('Antigua :'+fecha.toString()+' + '+duration);
fecha.setTime(fecha.getTime()+duration);
//alert('La fecha de fin es '+fecha.toString());
return fecha;
}	
}

function showAcomPrice(DescuentoExtra) 
{
	if (MINI_CALCULATOR)
		ret = showAcomPrice_mini(DescuentoExtra);
	else
		ret = showAcomPrice_comp(DescuentoExtra);
	return ret;
}

function showAcomPrice_mini(DescuentoExtra) 
{
	var index = getLevel2Object(LevelAcom).selectedIndex;
	var values = getLevel2Object(LevelAcom).options[index].value.split(',');
	var Escuela = getEscuela();
	var AcomType = values[0];
	var Room = values[1];
	var Board = values[2];
	var StartDate = getCourseStartDateTxt();
	var FechaStart = jsDate(StartDate);
	var FechaEnd = getCourseFinishDate();
	var Price = 0;
	var OffPrice = 0;
	var PriceExtras = 0;
	var AcomPricesNdx = getAcomPricesNdx (Escuela, AcomType, Room, Board);
	var Days = calcDaysBtwDates (FechaStart, FechaEnd);
	if (AcomType == 2) 
	{
		Price = calcFamilyPrice (AcomPricesNdx, FechaStart, Days);
		OffPrice = calcOffFamilyPrice(AcomPricesNdx, FechaStart, Days); // LB
	} 
	if (AcomType == 3) 
	{
		if (DatosEscuelas[Escuela][2] == 0) 
		{
			Price = calcApartmentPrice (AcomPricesNdx, FechaStart, Days); //temp
			OffPrice = calcOffApartmentPrice(AcomPricesNdx, FechaStart, Days); // LB
		} 
		else 
		{
			Price = calcFamilyPrice (AcomPricesNdx, FechaStart, Days); //temp
			OffPrice = calcOffFamilyPrice(AcomPricesNdx, FechaStart, Days); // LB
		}
	}
	var ExtraNdx = getAcomExtraNdx (AcomPricesNdx);
	if (ExtraNdx) 
	{
		PriceExtras = calcSeasonExtra (AcomExtras, ExtraNdx, StartDate, Days); 
	}
	Price += PriceExtras;
	OffPrice += PriceExtras; // LB
	
	if(DatosEscuelas[Escuela][3]==1)
	{
		Price-=DescuentoExtra; //Aplicar un descuento para casos como don Quijote en que hay que 'enmascarar'
	}
	
	with (getLevel2Object(LevelPrice)) 
	{
		if (Price != null) 
		{
			elements[3].value = Price + "\u20AC";
		} 
		else 
		{
			elements[3].value = optNoAppl;
			Price = 0;
		}
	}
	return new Array(Price, OffPrice);
}

function showAcomPrice_comp() {
alert('showAcomPrice_comp cannot be used in minicalculator mode!');
/*
var AcomType = getAcomType ();
if (AcomType.selectedIndex == 1) {
with (getLevel2Object(LevelPrice)) {
elements[4].value = optNoAppl;
elements[5].value = optNoAppl;
}
return 0;
}
var Escuela = getEscuela ();
with (document.forms[LevelAcom]) {
var Room = getRoom ();
var Board = getBoard ();
var StartDate = elements[3].value;
var FechaStart = jsDate(StartDate);
var FechaEnd = jsDate(elements[4].value);
}
var Price = 0;
var PriceExtras = 0;
var AcomPricesNdx = getAcomPricesNdx (Escuela, AcomType, Room, Board);
var Days = calcDaysBtwDates (FechaStart, FechaEnd);
if (AcomType == 2) {
Price = calcFamilyPrice (AcomPricesNdx, FechaStart, Days);
} 
if (AcomType == 3) {
if (DatosEscuelas[Escuela][2] == 0) { 
Price = calcApartmentPrice (AcomPricesNdx, FechaStart, Days);
} else {
Price = calcFamilyPrice (AcomPricesNdx, FechaStart, Days);
}
}
var ExtraNdx = getAcomExtraNdx (AcomPricesNdx);
if (ExtraNdx) {
PriceExtras = calcSeasonExtra (AcomExtras, ExtraNdx, StartDate, Days); 
}
Price += PriceExtras;
with (getLevel2Object(LevelPrice)) {
if (Price != null) {
elements[3].value = Price + "\u20AC";
} else {
elements[3].value = optNoAppl;
Price = 0;
}
}
return Price;*/
}
function getAcomPricesNdx (pEscuela, pTipo, pRoom, pBoard) {
for (var i = 1; i < DatosEscuelaAlojamiento.length ; i++) {
if (DatosEscuelaAlojamiento[i][0] == pEscuela && DatosEscuelaAlojamiento[i][1] == pTipo && DatosEscuelaAlojamiento[i][2] == pRoom && DatosEscuelaAlojamiento[i][3] == pBoard) {
return i;
}
}
return 0;
}
function calcFamilyPrice (pPricesNdx, pFechaStart, pDays) {
var Months = 0;
var EMDays = 0;
var DaysAux = pDays;
var DaysInMonth = 0;
while (DaysAux > 0) {
var FechaStartAux = new Date (pFechaStart.getFullYear(), pFechaStart.getMonth(), pFechaStart.getDate(), 0 ,0 ,0);
DaysInMonth = getMonthDays (FechaStartAux.getFullYear(), FechaStartAux.getMonth()+1 + Months);
if (DaysInMonth > DaysAux) {
EMDays = 0 + DaysAux;
DaysAux = 0; 
} else {
DaysAux -= DaysInMonth;
Months++; 
}
}
var MonthlyPrice = getMonthlyPrice (pPricesNdx, Months);
var WeeklyPrice = getWeeklyPrice (pPricesNdx);
var ExtraWeekPrice = getExtraWeekPrice (pPricesNdx);
var ExtraDayPrice = getExtraDayPrice (pPricesNdx);
var EDWeeks = 0;
var Weeks = 0; 
var SistemaPrecios;
if (MonthlyPrice) {
SistemaPrecios = 'Host Mensual';
} else {
SistemaPrecios = 'Host Semanal';
EDWeeks = (pDays + 1) % 7;
Weeks = ((pDays + 1) - EDWeeks) / 7;
}
var Price = 0;
var ExtraDaysPrice = 0;
if (MonthlyPrice) {
Price = Months * MonthlyPrice;
if (EMDays) {
MonthlyPriceNext = getMonthlyPrice (pPricesNdx, Months+1); 
ExtraDaysPrice = calcExtraDays (EMDays, ExtraWeekPrice, ExtraDayPrice);
if (ExtraDaysPrice == 0 || ExtraDaysPrice >= MonthlyPriceNext) {
Price = (Months + 1) * MonthlyPriceNext;
ExtraDaysPrice = 0; 
}
} 
} else if (WeeklyPrice && ExtraWeekPrice) {
if (Weeks >= 1) {
Price = WeeklyPrice + (Weeks - 1) * ExtraWeekPrice;
if (EDWeeks) {
ExtraDaysPrice = EDWeeks * ExtraDayPrice;
if (ExtraDaysPrice == 0 || ExtraDaysPrice > ExtraWeekPrice) {
Price += ExtraWeekPrice;
ExtraDaysPrice = 0;
}
}
} else {
Price = EDWeeks * ExtraDayPrice;
} 
} else {
alert (msgNoAcomPrices);
}
return Price + ExtraDaysPrice;
}

function calcOffFamilyPrice (pPricesNdx, pFechaStart, pDays) 
{
	var Months = 0;
	var EMDays = 0;
	var DaysAux = pDays;
	var DaysInMonth = 0;
	while (DaysAux > 0) 
	{
		var FechaStartAux = new Date (pFechaStart.getFullYear(), pFechaStart.getMonth(), pFechaStart.getDate(), 0 ,0 ,0);
		DaysInMonth = getMonthDays (FechaStartAux.getFullYear(), FechaStartAux.getMonth()+1 + Months);
		if (DaysInMonth > DaysAux) 
		{
			EMDays = 0 + DaysAux;
			DaysAux = 0; 
		} 
		else 
		{
			DaysAux -= DaysInMonth;
			Months++; 
		}
	}
	var MonthlyPrice = getOffMonthlyPrice (pPricesNdx, Months);
	var WeeklyPrice = getOffWeeklyPrice (pPricesNdx);
	var ExtraWeekPrice = getOffExtraWeekPrice (pPricesNdx);
	var ExtraDayPrice = getOffExtraDayPrice (pPricesNdx);
	var EDWeeks = 0;
	var Weeks = 0; 
	var SistemaPrecios;
	if (MonthlyPrice) 
	{
		SistemaPrecios = 'Host Mensual';
	} 
	else 
	{
		SistemaPrecios = 'Host Semanal';
		EDWeeks = (pDays + 1) % 7;
		Weeks = ((pDays + 1) - EDWeeks) / 7;
	}
	var Price = 0;
	var ExtraDaysPrice = 0;
	if (MonthlyPrice) 
	{
		Price = Months * MonthlyPrice;
		if (EMDays) 
		{
			MonthlyPriceNext = getOffMonthlyPrice (pPricesNdx, Months+1); 
			ExtraDaysPrice = calcExtraDays (EMDays, ExtraWeekPrice, ExtraDayPrice);
			if (ExtraDaysPrice == 0 || ExtraDaysPrice >= MonthlyPriceNext) 
			{
				Price = (Months + 1) * MonthlyPriceNext;
				ExtraDaysPrice = 0; 
			}
		} 
	} 
	else if (WeeklyPrice && ExtraWeekPrice) 
	{
		if (Weeks >= 1) 
		{
			Price = WeeklyPrice + (Weeks - 1) * ExtraWeekPrice;
			if (EDWeeks) 
			{
				ExtraDaysPrice = EDWeeks * ExtraDayPrice;
				if (ExtraDaysPrice == 0 || ExtraDaysPrice > ExtraWeekPrice) 
				{
					Price += ExtraWeekPrice;
					ExtraDaysPrice = 0;
				}
			}
		} 
		else 
		{
			Price = EDWeeks * ExtraDayPrice;
		} 
	} 
	else 
	{
		alert (msgNoAcomPrices);
	}
	return Price + ExtraDaysPrice;
}

function calcApartmentPrice (pPricesNdx, pFechaStart, pDays) {
var FechaEnd = new Date (pFechaStart.getFullYear(), pFechaStart.getMonth(), pFechaStart.getDate()+pDays, 0 ,0 ,0);
var EiniDays = 0;
var Months = 0;
var EfinDays = 0;
var FechaMonthStart = sameDate (pFechaStart);
if (pFechaStart.getDate() > 1) {
FechaMonthStart.setDate(1);
FechaMonthStart.setMonth(FechaMonthStart.getMonth()+1);
EiniDays = calcDaysBtwDates (pFechaStart, FechaMonthStart); 
}
var DaysAux = pDays-EiniDays+1;
var DaysInMonth = 0;
var FechaStartAux = sameDate (FechaMonthStart);
while (DaysAux > 0) {
DaysInMonth = getMonthDays (FechaStartAux.getFullYear(), FechaStartAux.getMonth()+1);
if (DaysAux >= DaysInMonth) {
DaysAux -= DaysInMonth;
Months++;
FechaStartAux.setDate (FechaStartAux.getDate()+DaysInMonth);
} else {
EfinDays = DaysAux;
DaysAux = 0;
}
}
var MonthlyPrice = getMonthlyPrice (pPricesNdx, Months);
var ExtraWeekPrice = getExtraWeekPrice (pPricesNdx);
var ExtraDayPrice = getExtraDayPrice (pPricesNdx);
var ExtraIniDaysPrice = calcExtraDays (EiniDays, ExtraWeekPrice, ExtraDayPrice);
var ExtraFinDaysPrice = calcExtraDays (EfinDays, ExtraWeekPrice, ExtraDayPrice);
if (EiniDays && ExtraIniDaysPrice == 0) {
EiniDays = 0;
Months++;
}
if (EfinDays && ExtraFinDaysPrice == 0) {
EfinDays = 0;
Months++;
} 
MonthlyPrice = getMonthlyPrice (pPricesNdx, Months);
if (EiniDays && EfinDays) {
if (ExtraIniDaysPrice > MonthlyPrice || ExtraFinDaysPrice > MonthlyPrice) {
MonthlyPrice = getMonthlyPrice (pPricesNdx, Months+1);
}
if (ExtraIniDaysPrice > MonthlyPrice) {
EiniDays = 0;
ExtraIniDaysPrice = 0;
Months++;
}
if (ExtraFinDaysPrice > MonthlyPrice) {
EfinDays = 0;
ExtraFinDaysPrice = 0;
Months++;
}
MonthlyPrice = getMonthlyPrice (pPricesNdx, Months);
} else if (EiniDays && ExtraIniDaysPrice > MonthlyPrice) {
EiniDays = 0;
ExtraIniDaysPrice = 0;
Months++;
} else if (EfinDays && ExtraFinDaysPrice > MonthlyPrice) {
EfinDays = 0;
ExtraFinDaysPrice = 0;
Months++;
}
MonthlyPrice = getMonthlyPrice (pPricesNdx, Months);
if (MonthlyPrice == 0) {
alert (msgNoAcomPrices);
return null;
}
var Price = ExtraIniDaysPrice + (MonthlyPrice * Months) + ExtraFinDaysPrice;
return Price;
}

function calcOffApartmentPrice (pPricesNdx, pFechaStart, pDays) 
{
	var FechaEnd = new Date (pFechaStart.getFullYear(), pFechaStart.getMonth(), pFechaStart.getDate()+pDays, 0 ,0 ,0);
	var EiniDays = 0;
	var Months = 0;
	var EfinDays = 0;
	var FechaMonthStart = sameDate (pFechaStart);
	if (pFechaStart.getDate() > 1) 
	{
		FechaMonthStart.setDate(1);
		FechaMonthStart.setMonth(FechaMonthStart.getMonth()+1);
		EiniDays = calcDaysBtwDates (pFechaStart, FechaMonthStart); 
	}
	var DaysAux = pDays-EiniDays+1;
	var DaysInMonth = 0;
	var FechaStartAux = sameDate (FechaMonthStart);
	while (DaysAux > 0) 
	{
		DaysInMonth = getMonthDays (FechaStartAux.getFullYear(), FechaStartAux.getMonth()+1);
		if (DaysAux >= DaysInMonth) 
		{
			DaysAux -= DaysInMonth;
			Months++;
			FechaStartAux.setDate (FechaStartAux.getDate()+DaysInMonth);
		} 
		else 
		{
			EfinDays = DaysAux;
			DaysAux = 0;
		}
	}
	var MonthlyPrice = getOffMonthlyPrice (pPricesNdx, Months);
	var ExtraWeekPrice = getOffExtraWeekPrice (pPricesNdx);
	var ExtraDayPrice = getOffExtraDayPrice (pPricesNdx);
	var ExtraIniDaysPrice = calcExtraDays (EiniDays, ExtraWeekPrice, ExtraDayPrice);
	var ExtraFinDaysPrice = calcExtraDays (EfinDays, ExtraWeekPrice, ExtraDayPrice);
	if (EiniDays && ExtraIniDaysPrice == 0) 
	{
		EiniDays = 0;
		Months++;
	}
	if (EfinDays && ExtraFinDaysPrice == 0) 
	{
		EfinDays = 0;
		Months++;
	} 
	MonthlyPrice = getOffMonthlyPrice (pPricesNdx, Months);
	if (EiniDays && EfinDays) 
	{
		if (ExtraIniDaysPrice > MonthlyPrice || ExtraFinDaysPrice > MonthlyPrice) 
		{
			MonthlyPrice = getOffMonthlyPrice (pPricesNdx, Months+1);
		}
		if (ExtraIniDaysPrice > MonthlyPrice) 
		{
			EiniDays = 0;
			ExtraIniDaysPrice = 0;
			Months++;
		}
		if (ExtraFinDaysPrice > MonthlyPrice) 
		{
			EfinDays = 0;
			ExtraFinDaysPrice = 0;
			Months++;
		}
		MonthlyPrice = getOffMonthlyPrice (pPricesNdx, Months);
	} 
	else if (EiniDays && ExtraIniDaysPrice > MonthlyPrice) 
	{
		EiniDays = 0;
		ExtraIniDaysPrice = 0;
		Months++;
	} 
	else if (EfinDays && ExtraFinDaysPrice > MonthlyPrice) 
	{
		EfinDays = 0;
		ExtraFinDaysPrice = 0;
		Months++;
	}
	MonthlyPrice = getOffMonthlyPrice (pPricesNdx, Months);
	if (MonthlyPrice == 0) 
	{
		alert (msgNoAcomPrices);
		return null;
	}
	var Price = ExtraIniDaysPrice + (MonthlyPrice * Months) + ExtraFinDaysPrice;
	return Price;
}

function calcExtraDays (pExtraDays, pExtraWeekPrice, pExtraDayPrice) {
var ExtraPrice = 0;
var NbrDays = pExtraDays % 7;
var NbrWeeks = (pExtraDays - NbrDays) / 7;
if (pExtraWeekPrice) {
if (pExtraDayPrice) {
ExtraPrice = NbrWeeks * pExtraWeekPrice; 
if (pExtraWeekPrice < NbrDays * pExtraDayPrice) {
ExtraPrice += pExtraWeekPrice;
} else {
ExtraPrice += NbrDays * pExtraDayPrice;
} 
} else {
ExtraPrice = (NbrWeeks + 1) * pExtraWeekPrice;
}
} else if (pExtraDayPrice) {
ExtraPrice = pExtraDays * pExtraDayPrice;
}
return ExtraPrice; 
} 

function getWeeklyPrice (pPricesNdx) 
{
	return DatosEscuelaAlojamiento[pPricesNdx][7];
}

function getExtraWeekPrice (pPricesNdx) 
{
	return DatosEscuelaAlojamiento[pPricesNdx][6];
}

function getExtraDayPrice (pPricesNdx) 
{
	return DatosEscuelaAlojamiento[pPricesNdx][5];
}

function getMonthlyPrice (pPricesNdx, pMonths) 
{
	var PriceData = DatosEscuelaAlojamiento[pPricesNdx];
	var BestMonth = 7+pMonths;
	if (BestMonth < 8 ) 
	{
		BestMonth = 8;
	} 
	else if (BestMonth > 13 ) 
	{
		BestMonth = 13;
	}
	var MonthlyPrice = PriceData[8];
	for (var i = BestMonth; i > 8; i--) 
	{
		if ((MonthlyPrice == 0) || (MonthlyPrice > 0 && PriceData[i] > 0 && PriceData[i] < MonthlyPrice) ) 
		{
			MonthlyPrice = PriceData[i];
		}
	}
	return MonthlyPrice;
}

function getOffWeeklyPrice (pPricesNdx) 
{
	return DatosEscuelaAlojamiento[pPricesNdx][17];
}

function getOffExtraWeekPrice (pPricesNdx) 
{
	return DatosEscuelaAlojamiento[pPricesNdx][16];
}

function getOffExtraDayPrice (pPricesNdx) 
{
	return DatosEscuelaAlojamiento[pPricesNdx][15];
}

function getOffMonthlyPrice (pPricesNdx, pMonths) 
{
	var PriceData = DatosEscuelaAlojamiento[pPricesNdx];
	var BestMonth = 17+pMonths;
	if (BestMonth < 18 ) 
	{
		BestMonth = 18;
	} 
	else if (BestMonth > 23 ) 
	{
		BestMonth = 23;
	}
	var OffMonthlyPrice = PriceData[18];
	for (var i = BestMonth; i > 18; i--) 
	{
		if ((OffMonthlyPrice == 0) || (OffMonthlyPrice > 0 && PriceData[i] > 0 && PriceData[i] < OffMonthlyPrice) ) 
		{
			OffMonthlyPrice = PriceData[i];
		}
	}
	return OffMonthlyPrice;
}

function getCourseExtraNdx () 
{
	var Course = getCourse ();
	var Duracion = getDuracion ();
	if (Course < 1 || Duracion < 1) 
	{
		return 0;
	} 
	return ExtrasCursoDuracion[Course][Duracion];
}

function getAcomExtraNdx (pAcomPricesNdx) 
{
	return DatosEscuelaAlojamiento[pAcomPricesNdx][14];
}

function makeSeasonText (pArrdata, pText) {
if (pArrdata[7] == 0 || pArrdata[8] > 0) {
return pText;
}
if (pText == '') {
pText = "\n\nATENTION: This School has a Seasonal surcharge between: \n";
}
return pText + ' -> ' + MonthArr[pArrdata[3]] + ' ' + pArrdata[4]
+ ' and ' + MonthArr[pArrdata[5]] + ' ' + pArrdata[6]
+ ' of ' + pArrdata[7] + "\u20AC/Week"+ ".\n"; 
}
function makeClosedText (pArrdata, pText) {
if (pArrdata[8] == 0) {
return pText;
}
if (pText == '') {
pText = "\n\nATENTION: This School is closed between: \n";
}
return pText + ' -> ' + MonthArr[pArrdata[3]] + ' ' + pArrdata[4]
+ ' and ' + MonthArr[pArrdata[5]] + ' ' + pArrdata[6] + ".\n"; 
}
function check_closed (pTypeExtras, ExtraNdx, Fecha) { 
if (ExtraNdx == 0) {
return 0; 
}
var isClosed = 0;
var mes = Fecha.getMonth() + 1;
var dia = Fecha.getDate();
for (var Extra = 1; Extra < DatosExtra.length; Extra++) {
if (DatosExtra[Extra][0] == ExtraNdx && DatosExtra[Extra][pTypeExtras] && DatosExtra[Extra][8]) {
var m1 = DatosExtra[Extra][3];
var d1 = DatosExtra[Extra][4];
var m2 = DatosExtra[Extra][5];
var d2 = DatosExtra[Extra][6];
if ( (m1 < m2) || (m1 == m2 && d1 <= d2) ) {
if ( (mes > m1 || (mes == m1 && dia >= d1)) && (mes < m2 || (mes == m2 && dia <= d2)) ) {
isClosed = 1;
} 
} else { 
if ( mes > m1 || (mes == m1 && dia >= d1) || mes < m2 || (mes == m2 && dia <= d2) ) {
isClosed = 1;
} 
}
} 
}
return isClosed;
}
function AlertExtrasTxt (pTypeExtras, pExtraNdx, pFirstMsg) {
/*if (MINI_CALCULATOR)
text = AlertExtrasTxt_mini (pTypeExtras, pExtraNdx, pFirstMsg);
else*/
text = AlertExtrasTxt_comp (pTypeExtras, pExtraNdx, pFirstMsg);
return text;
}
/*function AlertExtrasTxt_mini (pTypeExtras, pExtraNdx, pFirstMsg) {
// var DatesNdx = getLevel2Object(LevelDates).selectedIndex;
var Dates = getLevel2Object(LevelDates).value;
var ClosedTxt = '';
var SeasonTxt = '';
var ExtraTxt = '';
if (pExtraNdx) {
for (var Extra = 1; Extra < DatosExtra.length; Extra++) {
if (DatosExtra[Extra][0] == pExtraNdx && DatosExtra[Extra][pTypeExtras]) {
ClosedTxt = makeClosedText (DatosExtra[Extra], ClosedTxt);
SeasonTxt = makeSeasonText (DatosExtra[Extra], SeasonTxt);
}
}
}
ExtraTxt = ClosedTxt + SeasonTxt;
if (pFirstMsg == 1) {
if (DatosCursoInicio[Dates][2]) {
ExtraTxt = msgSelectMonday + ExtraTxt;
} else if (DatosCursoInicio[Dates][3]) {
ExtraTxt = msgSelectSecondMonday + ExtraTxt;
}
} else if (pFirstMsg == 2) {
ExtraTxt = msgArrivalDate + ExtraTxt;
} else if (pFirstMsg == 3) {
ExtraTxt = msgDepartureDate + ExtraTxt;
}
return ExtraTxt;
}*/
function AlertExtrasTxt_comp (pTypeExtras, pExtraNdx, pFirstMsg) {
var DatesNdx = getLevel2Object(LevelDates).selectedIndex;
var Dates = getLevel2Object(LevelDates).options[DatesNdx].value;
var ClosedTxt = '';
var SeasonTxt = '';
var ExtraTxt = '';
if (pExtraNdx) {
for (var Extra = 1; Extra < DatosExtra.length; Extra++) {
if (DatosExtra[Extra][0] == pExtraNdx && DatosExtra[Extra][pTypeExtras]) {
ClosedTxt = makeClosedText (DatosExtra[Extra], ClosedTxt);
SeasonTxt = makeSeasonText (DatosExtra[Extra], SeasonTxt);
}
}
}
ExtraTxt = ClosedTxt + SeasonTxt;
if (pFirstMsg == 1) {
if (DatosCursoInicio[Dates][2]) {
ExtraTxt = msgSelectMonday + ExtraTxt;
} else if (DatosCursoInicio[Dates][3]) {
ExtraTxt = msgSelectSecondMonday + ExtraTxt;
}
} else if (pFirstMsg == 2) {
ExtraTxt = msgArrivalDate + ExtraTxt;
} else if (pFirstMsg == 3) {
ExtraTxt = msgDepartureDate + ExtraTxt;
}
return ExtraTxt;
} 
function calcSeasonExtra (pTypeExtras, pExtraNdx, pStartDate, pDays) { 
if (pExtraNdx == 0) {
return 0; 
}
var FechaStart = jsDate(pStartDate);
var FechaCheck = FechaStart;
var mes = FechaStart.getMonth() + 1;
var dia = FechaStart.getDate();
var ExtraPrice = 0; 
for (var Extra = 1; Extra < DatosExtra.length; Extra++) {
if (DatosExtra[Extra][0] == pExtraNdx && DatosExtra[Extra][pTypeExtras] && DatosExtra[Extra][7]) {
var m1 = DatosExtra[Extra][3];
var d1 = DatosExtra[Extra][4];
var m2 = DatosExtra[Extra][5];
var d2 = DatosExtra[Extra][6];
var FechaCheck = jsDate(pStartDate);
for (var i=0; i<pDays; i++) {
dia = FechaCheck.getDate() + 1;
FechaCheck.setDate(dia);
mes = FechaCheck.getMonth() + 1;
dia = FechaCheck.getDate();
var ApplyExtra = 0;
if ( (m1 < m2) || (m1 == m2 && d1 <= d2) ) {
if ( (mes > m1 || (mes == m1 && dia >= d1)) && (mes < m2 || (mes == m2 && dia <= d2)) ) {
ApplyExtra = 1;
} 
} else { 
if ( mes > m1 || (mes == m1 && dia >= d1) || mes < m2 || (mes == m2 && dia <= d2) ) {
ApplyExtra = 1;
} 
}
if (ApplyExtra) {
ExtraPrice += DatosExtra[Extra][7];
i += 6; 
}
}
} 
}
return ExtraPrice;
}
function sameDate (pDate) {
return new Date (pDate.getFullYear(), pDate.getMonth(), pDate.getDate(), 0 ,0 ,0);
}
function calcDaysBtwDates (pDateStart, pDateEnd) {
var Days = pDateEnd.getTime()-pDateStart.getTime();
Days -= (Days % 86400000);
return Days / 86400000;
}
function jsDate (pString) {
var dia = pString.slice(0,2);
var mes = pString.slice(3,5);
var anio = pString.slice(6,10);
var Fecha = new Date (anio, mes-1, dia, 0 , 0, 0);
return Fecha;
}
function nbrMonday (pFecha) {
var MyDay = pFecha.getDate();
if (MyDay <= 6 || MyDay == 31) {
return 1;
} else if (MyDay <= 13) {
return 2;
} else if (MyDay <= 20) {
return 3;
} else if (MyDay <= 27) {
return 4;
} else {
return 5;
} 
}
function getMonthDays (pYear, pMonth) {
while (pMonth > 12) {
pYear++;
pMonth = pMonth - 12; 
}
var Days = MonthDays[pMonth];
if (pMonth == 2 && pYear % 4 == 0) {
Days++;
}
return Days;
}
function getEscuela () {
with (getLevel2Object(LevelSchool)) {
return options[selectedIndex].value;
}
}
function getCourse () {
with (getLevel2Object(LevelCourse)) {
return options[selectedIndex].value;
}
}
function getDuracion () {
with (getLevel2Object(LevelDuration)) {
return options[selectedIndex].value;
}
}
function getCouseDays () {
return DatosDuracion[getDuracion ()][1];
}
function getAcomType () {
if (MINI_CALCULATOR)
alert('Error! getAcomType() called in mini-calculator mode!');
with (getLevel2Object(LevelAcom)) {
return options[selectedIndex].value; 
}
}
function getRoom () {
if (MINI_CALCULATOR)
alert('Error! getRoom() called in mini-calculator mode!');
with (document.forms[LevelAcom].elements[1]) {
return options[selectedIndex].value; 
}
}
function getBoard () {
if (MINI_CALCULATOR)
alert('Error! getBoard() called in mini-calculator mode!');
with (document.forms[LevelAcom].elements[2]) {
return options[selectedIndex].value;
} 
}
function getCourseStartDateTxt () {
return getLevel2Object(LevelSelectedDate).value;
}
function setCourseStartDateTxt (pDateTxt) {
getLevel2Object(LevelSelectedDate).value = pDateTxt;
}
