var aux_link;
var nMonths = 12;

/*dia en el q estamos*/
var today = new Date();
var thisDay = today.getDay();	/*indica el numero de la semana en q estamos*/
var day = today.getDate();		/*indica q dia es el seleccionado*/
var month = today.getMonth();	/*indica el mes en q nos encontramos*/
var yYear = today.getYear();	/*indica el año actual*/
var hours = today.getHours();	/*indica la hora actual*/
if (yYear < 2000) { yYear += 1900; }

/*Nuevo Angel*/
var monthOld;
var dayOld;
/*FIN Nuevo Angel*/

/* Fecha actual en milisegundos */
var fecMilis = 0;

/*fecha limite q se puede operar*/
var fLimite= new Date (today.getTime()+(nDays*3600*24*1000));
var dayLimite = fLimite.getDate();		/*es el dia limite q se puede asignar*/
var monthLimite = fLimite.getMonth();	/*es el mes limite q se puede asignar*/
var yearLimite = fLimite.getYear();		/*es el año limite maximo */
if (yearLimite < 2000) { yearLimite += 1900; }

var qDiaEsHoy = parseInt(day,10);

/*se muestra un listado de ciudades en otros destinos*/
var tDestinos;
var vWindow = null;
function otherDestinies(opSel,tSel,url)
{	var valor = "OD";
	//var url = "/ibcomv3/jsp/common/listaCiudades.html";
	if (opSel == valor)
	{	tDestinos = tSel;
		vWindow = eval(url);
	}
}

/*el codigo que se lanza desde la ventana no esta en la lista del combo*/
function noExiste(cod)
{	var encontrado = 0;
	var endCity = document.getElementById(tDestinos);
	for (var ind=0;ind<endCity.length;ind++)
	{	if (cod == endCity[ind].value) encontrado = 1; }
	if (encontrado) return true;
	else
		return false;
}

/*se añade items al combo de DESTINO*/
var indCmb_beginCity = 0;		/*incremento del combo de begin city*/
var indCmb_endCity = 0;			/*incremento del combo de end city*/
function anadirCmb(cod,city)
{	var endCity = document.getElementById(tDestinos);
	/*hay q comprobar q el item no existe*/
	if (!noExiste(cod))
	{	var option = new Option(city,cod);
		if (tDestinos == "BEGIN_CITY_01")
		{	endCity.options[indCmb_beginCity] = option;
			endCity.options[indCmb_beginCity].selected = true;
			indCmb_beginCity++;
		}
		else
		{	endCity.options[indCmb_endCity] = option;
			endCity.options[indCmb_endCity].selected = true;
			indCmb_endCity++;
		}
	}
}

/*Proceso de bloqueo del RETURN DAY*/
function bloqueoRD(Opc)
{	var enlace;
	var end_day = document.getElementById("END_DAY_01");
	var end_month  = document.getElementById("END_MONTH_01");
	var objLink = document.getElementById("ahReg");
	qOpc = parseInt(Opc,10);
	switch (qOpc)
	{	case 2: typeOp = false; enlace = aux_link;
				break;
		case 1: typeOp = true; enlace = "#";
				break;
	}
	objLink.href = enlace;
	end_day.disabled = typeOp;
	end_month.disabled = typeOp;
}

/* FUNCIONES CONTROL DE FECHAS */
function generarDate(yYear,aux_month,aux_day)
{	var aux_fecha = new Date(yYear,aux_month,aux_day);
	var txtDate = aux_fecha.getDay();
	txtDate -= 1;
	if (txtDate==(-1)) { txtDate = 6; }
	return txtDate;
}

function compDays(opSelected)
{	/*se capturan los años respectivos a salida y regreso */
		var anio_begin = document.getElementById("BEGIN_YEAR_01");
		var anio_end = document.getElementById("END_YEAR_01");
	/*se capturan los meses respectivos de salida y regreso */
		var mes_begin = document.getElementById("BEGIN_MONTH_01");
		var mes_end = document.getElementById("END_MONTH_01");

	/*se captura el dia seleccionado */
		var dia_begin = opSelected;
		var aux_dia_begin = parseInt(opSelected,10)+1;

	/*años identicos*/
		if (parseInt(anio_begin.value,10) == parseInt(anio_end.value,10))
		{	/*comprobar si los meses son identicos*/
			if ( (parseInt(mes_end.options.selectedIndex,10)) == (parseInt(mes_begin.options.selectedIndex,10)) )
			{	/* el dia seleccionado es mayor o igual al actual*/
				if ((parseInt(mes_begin.options.selectedIndex,10)) > month)
				{	/* el mes seleccionado es mayor que el mes en q nos encontramos actualmete*/
					return true;
				}
				else
				{	/* el mes seleccionado es igual al mes actual*/
					if (aux_dia_begin >= qDiaEsHoy)
					{	/*quiere significar q el dia puede cambiarse ya q esta en el limite correcto*/
						return true;
					}
				}
			}
			else
			{	if ( (parseInt(mes_end.options.selectedIndex,10)) > (parseInt(mes_begin.options.selectedIndex,10)) )
				{	return true; }
			}
			return false;
		}
}
function dentroLimite(opSelected,typeSel){
	var aux_diaSalida = parseInt(""+document.getElementById("BEGIN_DAY_01").options[document.getElementById("BEGIN_DAY_01").selectedIndex].value.toString(),10);
	var aux_diaRegreso = parseInt(""+document.getElementById("END_DAY_01").options[document.getElementById("END_DAY_01").selectedIndex].value.toString(),10);
	var aux_mesSalida = parseInt(""+document.getElementById("BEGIN_MONTH_01").options[document.getElementById("BEGIN_MONTH_01").selectedIndex].value.toString(),10);
	var aux_mesRegreso = parseInt(""+document.getElementById("END_MONTH_01").options[document.getElementById("END_MONTH_01").selectedIndex].value.toString(),10);

	var anioMesLimite;
	var aux_monthLimite = monthLimite+1;
	if(aux_monthLimite<10)
		anioMesLimite = parseInt((""+yearLimite+"0"+aux_monthLimite),10);
	else
		anioMesLimite = parseInt((""+yearLimite+""+aux_monthLimite),10);

	if(typeSel){
		if(aux_mesSalida > anioMesLimite){
			var posicion=0;
			var tama = document.getElementById("BEGIN_MONTH_01").length;
			for (var i=0; i < tama; i++){
				if(document.getElementById("BEGIN_MONTH_01").options[i].value==anioMesLimite){
					posicion=i;
					break;
				}
			}
			document.getElementById("BEGIN_MONTH_01").selectedIndex=posicion;
			document.getElementById("BEGIN_DAY_01").selectedIndex=(dayLimite-1);
			document.getElementById("END_MONTH_01").selectedIndex=posicion;
			document.getElementById("END_DAY_01").selectedIndex=(dayLimite-1);
			return false;
		}else if(aux_mesSalida == anioMesLimite){
			if(aux_diaSalida>dayLimite){
				document.getElementById("BEGIN_DAY_01").selectedIndex=(dayLimite-1);
				document.getElementById("END_DAY_01").selectedIndex=(dayLimite-1);
				return false;
			}
			else return true;
		}else return true;
	}else{
		if(aux_mesRegreso > anioMesLimite){
			var posicion=0;
			var tama = document.getElementById("END_MONTH_01").length;
			for (var i=0; i < tama; i++){
				if(document.getElementById("END_MONTH_01").options[i].value==anioMesLimite){
					posicion=i;
					break;
				}
			}
			document.getElementById("END_MONTH_01").selectedIndex=posicion;
			document.getElementById("END_DAY_01").selectedIndex=(dayLimite-1);

			return false;

		}else if(aux_mesRegreso == anioMesLimite){
			if(aux_diaRegreso>dayLimite){
				document.getElementById("END_DAY_01").selectedIndex=(dayLimite-1);
				return false;

			}
			else return true;
		}else return true;
	}
}




function ChangeDay(opSelected,typeSel)
{
		if(!dentroLimite(opSelected,typeSel)) return;
		var dia_begin = document.getElementById("BEGIN_DAY_01");
		var aux_dia_begin = dia_begin.options[dia_begin.selectedIndex].value

		var mes_begin = document.getElementById("BEGIN_MONTH_01");
		aux_mes_begin = mes_begin.options.selectedIndex;
		var aux_numeroMesBegin =document.getElementById("BEGIN_MONTH_01").options[document.getElementById("BEGIN_MONTH_01").selectedIndex].value;
        var numeroMesBegin = parseInt(aux_numeroMesBegin.substring(aux_numeroMesBegin.length-2,aux_numeroMesBegin.length),10)-1;

		var dia_end = document.getElementById("END_DAY_01");
		var mes_end = document.getElementById("END_MONTH_01");
		aux_mes_end = mes_end.options.selectedIndex;
		var aux_numeroMesEnd =document.getElementById("END_MONTH_01").options[document.getElementById("END_MONTH_01").selectedIndex].value;
		var numeroMesEnd = parseInt(aux_numeroMesEnd.substring(aux_numeroMesEnd.length-2,aux_numeroMesEnd.length),10)-1;

		if(aux_mes_begin == aux_mes_end){
			if((dia_begin.selectedIndex > dia_end.selectedIndex) &&(mes_begin.selectedIndex == mes_end.selectedIndex)){

				dia_end.selectedIndex = opSelected;
				//dia_end.selectedIndex = dia_begin.selectedIndex;

				//si el dia de salida es mayor que el de regreso pasamos al mes siguiente
				if(!typeSel){mes_end.selectedIndex = aux_mes_begin+1}
			}
		}

		//control de dia anterior al actual
		if((aux_dia_begin < qDiaEsHoy) && (numeroMesBegin == month)){
			mes_begin.selectedIndex = aux_mes_begin+1
			mes_end.selectedIndex = aux_mes_begin+1
		}


		var dDay = parseInt(opSelected,10)+1;
		if(typeSel){
		    if(aux_mes_begin == 0){
					if(opSelected < (qDiaEsHoy-1)){
	    			dia_end.selectedIndex = (qDiaEsHoy-1);
	    			//dia_begin.selectedIndex = (qDiaEsHoy-1); //comentado para permitir coger un dia anterior al actual
	    		}
	    	}

			if (dDay > tMonth[numeroMesBegin]){
			    dia_begin.selectedIndex = tMonth[numeroMesBegin]-1;
			}
		}else{
            if (dDay > tMonth[numeroMesEnd]){
                dia_end.selectedIndex = tMonth[numeroMesEnd]-1;
            }
		}

		pintaTextoDiaSemanaServ(fecMilis); //pintaTextoDiaSemana();
}

function ChangeMonth(opSelected,typeSel)
{
	if(!dentroLimite(opSelected,typeSel)){
		pintaTextoDiaSemanaServ(fecMilis); //pintaTextoDiaSemana();
		return;
	}
	var mes_begin = document.getElementById("BEGIN_MONTH_01");
	var mes_end = document.getElementById("END_MONTH_01");
	var aqDiaVoy = document.getElementById("BEGIN_DAY_01");
	var qDiaVuelvo = document.getElementById("END_DAY_01");
	aux_aqDiaVoy = aqDiaVoy.options.selectedIndex;
	aux_qDiaVuelvo = qDiaVuelvo.options.selectedIndex;

	if(typeSel){// Cambio el mes de salida.
		if(opSelected > mes_end.options.selectedIndex){//Si el nuevo mes de salida es mayor que el de vuelta cambio este ultimo
			mes_end.options.selectedIndex=opSelected;
			if(aux_qDiaVuelvo <	aux_aqDiaVoy) qDiaVuelvo.options.selectedIndex=aux_aqDiaVoy;
		}else if(opSelected == mes_end.options.selectedIndex){ // Si los meses de ida y vuelta son los mismos tengo que cambiar los dias si es necesario
			if(aux_qDiaVuelvo <	aux_aqDiaVoy) qDiaVuelvo.options.selectedIndex=aux_aqDiaVoy;
		}
		ChangeDay(aux_aqDiaVoy,typeSel);
	}else{
		if(opSelected <= mes_begin.options.selectedIndex){
			mes_end.options.selectedIndex=mes_begin.options.selectedIndex;
			if(aux_qDiaVuelvo <	aux_aqDiaVoy) qDiaVuelvo.options.selectedIndex=aux_aqDiaVoy;
		}else{
			mes_end.options.selectedIndex=opSelected;
		}
		ChangeDay(aux_qDiaVuelvo,typeSel);
	}

	pintaTextoDiaSemanaServ(fecMilis); //pintaTextoDiaSemana();

}

function pintaTextoDiaSemana(){
	var today = new Date();
	var thisDay = today.getDay();	/*indica el numero de la semana en q estamos*/
	var day = today.getDate();		/*indica q dia es el seleccionado*/
	var month = today.getMonth();	/*indica el mes en q nos encontramos*/
	var yYear = today.getYear();	/*indica el año actual*/
	var hours = today.getHours();	/*indica la hora actual*/
	if (yYear < 2000) { yYear += 1900; }

	var mes_begin = document.getElementById("BEGIN_MONTH_01");
	var mes_end = document.getElementById("END_MONTH_01");
	var aqDiaVoy = document.getElementById("BEGIN_DAY_01");
	var qDiaVuelvo = document.getElementById("END_DAY_01");
	aux_aqDiaVoy = aqDiaVoy.options.selectedIndex;
	aux_qDiaVuelvo = qDiaVuelvo.options.selectedIndex;


	var aux_qMesVoy = document.getElementById("BEGIN_MONTH_01").options[document.getElementById("BEGIN_MONTH_01").selectedIndex].value;
	var qMesVoy = parseInt(aux_qMesVoy.substring(aux_qMesVoy.length-2,aux_qMesVoy.length),10);
	var qAnioVoy = parseInt(aux_qMesVoy.substring(0,aux_qMesVoy.length-2),10);

	var aux_qMesRegreso = document.getElementById("END_MONTH_01").options[document.getElementById("END_MONTH_01").selectedIndex].value;
	var qMesRegreso = parseInt(aux_qMesRegreso.substring(aux_qMesRegreso.length-2,aux_qMesRegreso.length),10);
	var qAnioRegreso = parseInt(aux_qMesRegreso.substring(0,aux_qMesRegreso.length-2),10);

	var diaFormatoBuenoIda = parseInt(aux_aqDiaVoy,10)+1;
	var mesFormatoBuenoIda = parseInt(qMesVoy,10)-1;
	var diaFormatoBuenoReg = parseInt(qDiaVuelvo.options.selectedIndex,10)+1;
	var mesFormatoBuenoReg = parseInt(qMesRegreso,10)-1;

	var gDateIda = generarDate(qAnioVoy,mesFormatoBuenoIda,diaFormatoBuenoIda);
	var gDateVuelta = generarDate(qAnioRegreso,mesFormatoBuenoReg,diaFormatoBuenoReg);

	//condiciones de llamada a iniBooking()
	//si el dia de salida es menor que la fecha actual llamamos a iniBooking()
	var mes
	mes = month+1
	mes = mes.toString()
	if(mes.length<2) mes="0"+mes
	var fecha_actual = yYear+""+mes+""+day
	var fecha_voy = mes_begin.options[mes_begin.selectedIndex].value+""+aqDiaVoy.options[aqDiaVoy.selectedIndex].value

	fecha_actual = parseInt(fecha_actual,10)
	fecha_voy = parseInt(fecha_voy,10)

	if(fecha_voy<fecha_actual){iniBooking()}

	if (booking) {
		document.getElementById("TXT_BEGIN_DAY_01").value =  tDay_ext[gDateIda];
		document.getElementById("TXT_END_DAY_01").value =  tDay_ext[gDateVuelta];
	}

	else{
		document.getElementById("TXT_BEGIN_DAY_01").value =  tDayLong[gDateIda];
		document.getElementById("TXT_END_DAY_01").value =  tDayLong[gDateVuelta];
	}

}
/* FUNCIONES CONTROL DE FECHAS */

function openCalendar(dayC,monthC,yYearC,opSel,tipo,modificar_horizontal)
{	var lLayer = "lCalendar";
	var cDay = document.getElementById(dayC).value;
	var cMonth = document.getElementById(monthC).value;

	var cyYear = document.getElementById(yYearC).value;
	cMonth = cMonth-1;
	var aux = ""+cMonth;
	var diferencia = 0;
	if (cDay <= tMonth[parseInt(aux.substring(aux.length-2,aux.length),10)])
	{	var obj = "calendar"+opSel;
		if (tipo == 'R') { diferencia = 25; }
		
		var obj_aux = document.images[obj];
		var MiX = getRealLeft(obj_aux);
		var MiY = getRealTop(obj_aux);
		if (modificar_horizontal != 0) //retocamos la posicion para que aparezca en la obtenida
		{document.getElementById(lLayer).style.left = MiX+modificar_horizontal-127;}
		else{document.getElementById(lLayer).style.left = MiX+5-127;}
		
		if ((IE) && (mac)) { diferencia += qdiferencia; }
		if (modificar_horizontal == 0) //retocamos la posicion para que aparezca en la obtenida
		{document.getElementById(lLayer).style.top = (MiY+diferencia-90);}
		else
		{document.getElementById(lLayer).style.top = (MiY-90);}
		dibujar(qDiaEsHoy,month,cDay,parseInt(aux.substring(aux.length-2,aux.length),10),parseInt(aux.substring(0,aux.length-2),10),opSel,tipo);
		//dibujar(qDiaEsHoy,qMesEsHoy,diaSel,mes,aYear,opCion,qType)
		
		ocultar = (document.getElementById(lLayer).style.visibility == "hidden")? "visible":"hidden";
		
		document.getElementById(lLayer).style.visibility = ocultar;		
	}
}

/* se inicializan las fechas de BOOKING*/
function iniBooking(){
	/*ver el numero de elemento q hay en el combo de destino*/
	//monthOld = month;
	var monthInicio = 0
	if (document.getElementById("BEGIN_CITY_01") != null)
	{	var beginCity = document.getElementById("BEGIN_CITY_01");	indCmb_beginCity = beginCity.length;
		var endCity = document.getElementById("END_CITY_01");		indCmb_endCity = endCity.length;
		/*se inicializa el link de la pagina*/
		aux_link = document.getElementById("ahReg").href;
	}
	var dif_day = 0; var dif_month = 0;
	if(periodoHours > 23) {
		dif_day = parseInt((periodoHours/24),10); //numero de dias
		hour_difDay = periodoHours%24 ; //numero de horas
		if((hours+hour_difDay) > 23) dif_day+= 1;
	}
	else{	if((hours+periodoHours) > 23) {dif_day = 1;}else{dif_day = 0;}}
	
	/*comprobamos si el año es bisiesto*/
		if (isBisiesto(yYear)) tMonth[1]+=1;
	/*se inicializa el dia de SALIDA*/
		var begin_day = document.getElementById("BEGIN_DAY_01");
		var aux_begin_day = (day-1);
		/*se calcula la diferencia horas*/
		aux_begin_day += dif_day;

		if((month==0)||(month==2)||(month==4)||(month==6)||(month==7)||(month==9)||(month==11))
		{
			 if(aux_begin_day == 31) { aux_begin_day = 0; month+=1; monthInicio += 1; qDiaEsHoy = 1}
			 if(aux_begin_day > 31) { aux_begin_day = aux_begin_day-31; month+=1; monthInicio += 1; qDiaEsHoy = aux_begin_day+1}
			 if (aux_begin_day < 31 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
		}
		if((month==3)||(month==5)||(month==8)||(month==10))
		{
			 if(aux_begin_day == 30) { aux_begin_day = 0; month+=1; monthInicio += 1; qDiaEsHoy = 1}
			 if(aux_begin_day > 30) { aux_begin_day = aux_begin_day-30; month+=1; monthInicio += 1; qDiaEsHoy = aux_begin_day}
			 if (aux_begin_day < 30 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
		}
		
		if(month==1){
				if (isBisiesto(yYear)){
					if(aux_begin_day == 29) { aux_begin_day = 0; month+=1; monthInicio += 1; qDiaEsHoy = 1}
					if(aux_begin_day > 29) { aux_begin_day = aux_begin_day-29; month+=1; monthInicio += 1; qDiaEsHoy = aux_begin_day}
					if (aux_begin_day < 29 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
				}
				else{
					if(aux_begin_day == 28) { aux_begin_day = 0; month+=1; monthInicio += 1; qDiaEsHoy = 1}
					if(aux_begin_day > 28) { aux_begin_day = aux_begin_day-28; month+=1; monthInicio += 1; qDiaEsHoy = aux_begin_day}
					if (aux_begin_day < 28 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
				}
		}

		
		//qDiaEsHoy += dif_day;
		begin_day.selectedIndex = aux_begin_day;

	/*se inicializa el dia (en texto) de SALIDA*/
		var txt_begin_day = document.getElementById("TXT_BEGIN_DAY_01");
		/*para indicar el texto corto o largo*/

		var newTxtBeginDay = (thisDay+dif_day)-1 ;

    /*Esta comprobación se hace para que no falle los domingos o cualquier posicion fuera del array tDay o tDayLong*/
		if (newTxtBeginDay == -1){ newTxtBeginDay = 6}
		if (newTxtBeginDay > 6){ newTxtBeginDay = 0}
		if (booking){
			txt_begin_day.value = tDay_ext[newTxtBeginDay]; /*q dia se ha capturado mas la diferencia en horas menos uno para situarlo*/
		} else {
			txt_begin_day.value = tDayLong[newTxtBeginDay]; /*q dia se ha capturado mas la diferencia en horas menos uno para situarlo*/
		}
		/*se inicializa el mes de SALIDA*/
		var begin_month = document.getElementById("BEGIN_MONTH_01");
		//controla el mes en q estoy para poner index de meses a 0
		var aux_begin_month = monthInicio;
	
		begin_month.options.selectedIndex = aux_begin_month;
		document.getElementById("BEGIN_YEAR_01").value = yYear;
	
	/*se inicializa el dia de REGRESO*/
		var end_day = document.getElementById("END_DAY_01");
		end_day.options.selectedIndex = begin_day.options.selectedIndex;
	/*se inicializa el dia (en texto) de REGRESO*/
		var txt_end_day = document.getElementById("TXT_END_DAY_01");
		txt_end_day.value = txt_begin_day.value;
	/*se inicializa el mes de REGRESO*/
		var end_month = document.getElementById("END_MONTH_01");
		end_month.options.selectedIndex = begin_month.options.selectedIndex;
		document.getElementById("END_YEAR_01").value = yYear;

		document.getElementById("TXT_BEGIN_DAY_01").value=''
		document.getElementById("TXT_END_DAY_01").value=''

}

function iniBookingServ(fecha_miliseg){
    fecMilis = fecha_miliseg; //así tenemos guardada la fecha para las funciones changeDay y changeMonth
	today = new Date(fecha_miliseg);
	thisDay = today.getDay();	/*indica el numero de la semana en q estamos*/
	day = today.getDate();		/*indica q dia es el seleccionado*/
	month = today.getMonth();	/*indica el mes en q nos encontramos*/
	yYear = today.getYear();	/*indica el año actual*/
	hours = today.getHours();	/*indica la hora actual*/
	if (yYear < 2000) { yYear += 1900; }
	fLimite= new Date (today.getTime()+(nDays*3600*24*1000));
    dayLimite = fLimite.getDate();		/*es el dia limite q se puede asignar*/
    monthLimite = fLimite.getMonth();	/*es el mes limite q se puede asignar*/
    yearLimite = fLimite.getYear();		/*es el año limite maximo */
    if (yearLimite < 2000) { yearLimite += 1900; }
    qDiaEsHoy = parseInt(day,10);
	
	iniBooking();
}

function pintaTextoDiaSemanaServ(fecha_miliseg){
    	
	var today = new Date(fecha_miliseg);
    fecMilis = fecha_miliseg; //así tenemos guardada la fecha para las funciones changeDay y changeMonth
	var dif_day = 0;
	if(periodoHours > 23) {
		dif_day = parseInt((periodoHours/24),10); //numero de dias
		hour_difDay = periodoHours%24 ; //numero de horas
		if((hours+hour_difDay) > 23) dif_day+= 1;
	}
	else{	if((today.getHours()+periodoHours) > 23) dif_day = 1;}
    if (dif_day > 0)
	    today = new Date(fecha_miliseg + dif_day * 86400 * 1000);
	
	var thisDay = today.getDay();	/*indica el numero de la semana en q estamos*/
	var day = today.getDate();		/*indica q dia es el seleccionado*/
	var month = today.getMonth();	/*indica el mes en q nos encontramos*/
	var yYear = today.getYear();	/*indica el año actual*/
	var hours = today.getHours();	/*indica la hora actual*/
	if (yYear < 2000) { yYear += 1900; }

	var mes_begin = document.getElementById("BEGIN_MONTH_01");
	var mes_end = document.getElementById("END_MONTH_01");
	var aqDiaVoy = document.getElementById("BEGIN_DAY_01");
	var qDiaVuelvo = document.getElementById("END_DAY_01");
	aux_aqDiaVoy = aqDiaVoy.options.selectedIndex;
	aux_qDiaVuelvo = qDiaVuelvo.options.selectedIndex;


	var aux_qMesVoy = document.getElementById("BEGIN_MONTH_01").options[document.getElementById("BEGIN_MONTH_01").selectedIndex].value;
	var qMesVoy = parseInt(aux_qMesVoy.substring(aux_qMesVoy.length-2,aux_qMesVoy.length),10);
	var qAnioVoy = parseInt(aux_qMesVoy.substring(0,aux_qMesVoy.length-2),10);

	var aux_qMesRegreso = document.getElementById("END_MONTH_01").options[document.getElementById("END_MONTH_01").selectedIndex].value;
	var qMesRegreso = parseInt(aux_qMesRegreso.substring(aux_qMesRegreso.length-2,aux_qMesRegreso.length),10);
	var qAnioRegreso = parseInt(aux_qMesRegreso.substring(0,aux_qMesRegreso.length-2),10);

	var diaFormatoBuenoIda = parseInt(aux_aqDiaVoy,10)+1;
	var mesFormatoBuenoIda = parseInt(qMesVoy,10)-1;
	var diaFormatoBuenoReg = parseInt(qDiaVuelvo.options.selectedIndex,10)+1;
	var mesFormatoBuenoReg = parseInt(qMesRegreso,10)-1;

	var gDateIda = generarDate(qAnioVoy,mesFormatoBuenoIda,diaFormatoBuenoIda);
	var gDateVuelta = generarDate(qAnioRegreso,mesFormatoBuenoReg,diaFormatoBuenoReg);

	//condiciones de llamada a iniBooking()
	//si el dia de salida es menor que la fecha actual llamamos a iniBooking()
	var mes
	mes = month+1
	mes = mes.toString()
	if(mes.length<2) mes="0"+mes
	day = day.toString()
	if(day.length<2) day="0"+day
	var fecha_actual = yYear+""+mes+""+day
	var fecha_voy = mes_begin.options[mes_begin.selectedIndex].value+""+aqDiaVoy.options[aqDiaVoy.selectedIndex].value
	fecha_actual = parseInt(fecha_actual,10)
	fecha_voy = parseInt(fecha_voy,10)
	var aux_begin_day = (day-1);
	aux_begin_day += dif_day;
    if((month==0)||(month==2)||(month==4)||(month==6)||(month==7)||(month==9)||(month==11))
	{
		if(aux_begin_day == 31) { qDiaEsHoy = 1}
		if(aux_begin_day > 31) { aux_begin_day = aux_begin_day-31; qDiaEsHoy = aux_begin_day+1}
		if (aux_begin_day < 31 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
	}
	if((month==3)||(month==5)||(month==8)||(month==10))
	{
		if(aux_begin_day == 30) { qDiaEsHoy = 1}
		if(aux_begin_day > 30) { aux_begin_day = aux_begin_day-30; qDiaEsHoy = aux_begin_day}
		if (aux_begin_day < 30 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
	}
	if(month==1){
		if (isBisiesto(yYear)){
			if(aux_begin_day == 29) { qDiaEsHoy = 1}
			if(aux_begin_day > 29) { aux_begin_day = aux_begin_day-29; qDiaEsHoy = aux_begin_day}
			if (aux_begin_day < 29 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
		}
		else{
			if(aux_begin_day == 28) { qDiaEsHoy = 1}
			if(aux_begin_day > 28) { aux_begin_day = aux_begin_day-28; qDiaEsHoy = aux_begin_day}
			if (aux_begin_day < 28 && dif_day > 0 && periodoHours <= 23) qDiaEsHoy += dif_day
		}
	}
    //qDiaEsHoy = day

	//if(fecha_voy<fecha_actual){iniBooking()}

	if(fecha_voy<fecha_actual){iniBookingServ(fecha_miliseg)}

	if (booking) {
		document.getElementById("TXT_BEGIN_DAY_01").value =  tDay_ext[gDateIda];
		document.getElementById("TXT_END_DAY_01").value =  tDay_ext[gDateVuelta];
	}

	else{
		document.getElementById("TXT_BEGIN_DAY_01").value =  tDayLong[gDateIda];
		document.getElementById("TXT_END_DAY_01").value =  tDayLong[gDateVuelta];
	}

}

function closeCalendar(){
	var lLayer = "lCalendar";
	ocultar = (document.getElementById(lLayer).style.visibility == "hidden")? "visible":"hidden";
	document.getElementById(lLayer).style.visibility = ocultar;		

}

if (vWindow != null) { window.onblur=vWindow.focus(); }