function color_nuevo(nuevo)
{
	/* COMMENT BY MANU FOR FIREFOR ERRROR
	source=event.srcElement
	if(source){ 
			if (source.tagName=="TR"||source.tagName=="TABLE")
			return
			while(source.tagName!="TD")
			source=source.parentElement
			//alert(source.parentElement);
			if (nuevo == 1) {nuevo = "#003467";}
			if (source.style.backgroundColor!=nuevo&&source.id!="ignore")
			{source.style.backgroundColor=nuevo;}
	}
	*/
}


function color_antiguo(viejo)
{
	/*
	if (source)	{
		if (event.toElement!=source){
			if (viejo == 1) {viejo = "#999A9C";}
			if (viejo == 2) {viejo = "#E9F3FB";}
			source.style.backgroundColor=viejo
		}
	}
	*/
}

function cambia_color_texto(indice,color)
{
	/* COMMENT BY MANU FOR FIREFOR ERRROR
		if (color == 1) {color = "#E9F3FB";}
		if (color == 2) {color = "#003467";}
		eval("link"+indice+".style.color='"+color+"'");
	*/
}


var qDiaEsHoyC;			/*indica el dia q estamos actualmente*/
var qMesEsHoyC;
var dia_pulsado;		/*indica el dia en q ese ha pulsado*/
var mes_today;			/*indica el mes q estamos actualmente*/
var anio_today;			/*indica el ao en el q nos encontramos*/
var anioSel;
var opSel;				/*indica el numero de calendario seleccionado*/
var qTipo;				/*indica el campo a rellenar*/

//pinta la fila que contiene los dias de las semanas
var wCeldas = parseInt((196/7),10);
var tDias = "<table width=100% border=0 cellpadding=0 cellspacing=0 class=calendar>";
    tDias += "<tr bgcolor=#DBE7FF><td width=10></td>"
	for (var ind=0;ind<tDay.length;ind++){tDias += "<td class=txtDay align=center width="+wCeldas+" height=20>" + tDay[ind] + "</td>"; }
    tDias += "<td width=10></td></tr></table>";

function posInicio(mes,anio_today){	/* calcular la posicion q debe de comenzar el mes*/
	var posIni = new Date(anio_today,mes,1);
	//var iFor = parseInt(posIni.getDay(),10) + 1;
	var iFor = parseInt(posIni.getDay(),10);
	return iFor;
}

function pintarMes(mes){	
	aux_mes = mes.toString()
	if(aux_mes.length < 2){aux_mes="0"+aux_mes}

	aux_monthLimite = monthLimite.toString()
	if(aux_monthLimite.length < 2){aux_monthLimite="0"+aux_monthLimite}
					
	var dateCald = anio_today +""+ aux_mes
	var dateCaldLimit = yearLimite +""+ aux_monthLimite
	
	dateCald = parseInt(dateCald,10)
	dateCaldLimit = parseInt(dateCaldLimit,10)		
	//pinta la cabecera que contiene el mes y el ao del calendario
	var avance = "<table width=100% cellspacing=0 cellpadding=0 border=0 class=calendar>";
	avance += "<tr bgcolor=#B2D5E9>";
	avance += "<td width=20%>&nbsp;</td>";
	if (mes > month) {
		avance += "<td><a href='javascript:redibujar("+(mes-1)+")'><img src=/img/arrow_back.gif border=0></a></td>";
	}
	else{
		if (anio_today > yYear)	{	avance += "<td><a href='javascript:redibujar("+(mes-1)+")'><img src=/img/arrow_back.gif border=0></a></td>"; }
	}
	avance += "<td width=60% height=24 align=center class=cabecera_calendario>"+tMeses[mes] +", "+ deE +" "+ anio_today +"</td>";
	if (dateCald < dateCaldLimit){
		avance += "<td><a href='javascript:redibujar("+(mes+1)+")'><img src=/img/arrow_fwd.gif border=0></a></td>";
	}
	avance += "<td width=18% align=right><a href='javascript:closeCalendar()'><img src=/img/close.gif alt='Cerrar' title='Cerrar' border=0></a></td>";
	avance += "<td width=2%>&nbsp;</td>";
	avance += "</tr>";
	avance += "</table>";
	return avance;
}


/*pintar la tabla de dias*/
//Pinta el pie del calendario
function tOK(){	
	var objCalendar = "<table width=100% cellspacing=0 cellpadding=0 border=0 bgcolor=#E9F3FB>";
		objCalendar += "<tr bgcolor=#B2D5E9><td colspan=2 height=5><spacer type=block height=10></td></tr>";
		objCalendar += "<tr bgcolor=#B2D5E9><td align=right height=5></td><td width=10><spacer type=block width=10></td></tr>";
	objCalendar += "</table>";
	return objCalendar;
}

function dibujar(qDiaEsHoy,qMesEsHoy,diaSel,mes,aYear,opCion,qType){	
	qDiaEsHoyC = qDiaEsHoy;
	qMesEsHoyC = qMesEsHoy;
	dia_pulsado = diaSel; mes_today = mes; anioSel = aYear; anio_today = anioSel;
	opSel = opCion; qTipo = qType;
	redibujar(mes);
}

var nVeces;
var source;
function redibujar(mes){
	tMonth[1] = 28;	
	if (mes > 11) { anio_today++; mes = 0; }
	if (mes < 0) { anio_today--; mes = 11; }
	
	var iFor = posInicio(mes,anio_today);
	pMes = pintarMes(mes);
	if (isBisiesto(anio_today)) tMonth[1]+=1;

	var nfilas = parseInt((tMonth[mes]/7),10); /*numero d filas a dibujar*/
	var rfilas = parseInt((tMonth[mes]%7),10); /*numero restante d filas a pintar*/
	if (rfilas > 0) { nfilas +=rfilas; }
	nfilas++;

	/*numero de veces q se tiene q repetir*/
	nVeces = (nfilas*7);	
	var cCalendar = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=calendar bgcolor=#E9F3FB>";
	cCalendar += "<tr bgcolor=#E9F3FB><td width=10><spacer type=block width=10></td>";
	var cDias = 1;

	//alert("tMonth:::"+tMonth[mes]);
	//alert("nfilas::::"+nfilas);

	if (iFor == 0){ iFor= 7;}
	for (var ind=1;ind<=nVeces;ind++){
		if(cDias > tMonth[mes]){break;}	
		CssClass = "days";
		cCalendar += "<td  id='cell"+ind+"' align=center width="+wCeldas
		if ( (ind >= iFor) && (cDias <= tMonth[mes]) ){	/*pinto el dia en cuestion*/
			if ( (parseInt(cDias,10)==parseInt(dia_pulsado,10)) && (mes==mes_today) && (anio_today==anioSel))
			{	cCalendar+=" onMouseover='color_nuevo(1);cambia_color_texto("+ind+",1);' onMouseout=\"color_antiguo(1);\" bgcolor=#999A9C class=daysSel style=\"text-decoration:none\" height=20 "; CssClass = "daysSel"; }
			else
			{	
				if ( (mes==monthLimite) && (anio_today==yearLimite) )
				{	if (cDias > dayLimite)
					{}
					else
					{	cCalendar+=" onMouseover='color_nuevo(1);cambia_color_texto("+ind+",1);' onMouseout='color_antiguo(2);cambia_color_texto("+ind+",2);' height=20 "; }
				}
				else
				{	if ((mes > monthLimite) && (anio_today >= yearLimite))
					{}
					else
					{	if ( (parseInt(cDias,10)<parseInt(qDiaEsHoyC,10)) && (mes==qMesEsHoyC) && (anio_today==yYear))
						{ }
						else
						{	cCalendar+=" onMouseover='color_nuevo(1);cambia_color_texto("+ind+",1);' onMouseout='color_antiguo(2);cambia_color_texto("+ind+",2);' height=20 "; }
					}
				}
			
			 }
			if ( (mes==monthLimite) && (anio_today==yearLimite) )
			{	if (cDias > dayLimite)
				{	cCalendar += " height=20 ><span class=nodaysSel style=\"text-decoration:none\" ><s>"+ cDias +"</s></span>"; }
				else
				{	cCalendar += " onclick='javascript:recogerDays("+ cDias +","+ mes +","+ anio_today +","+ind+");indicarFecha()' style='cursor:hand'><a href='javascript:void(0);' style=\"text-decoration:none\" class="+CssClass+" id='link"+ind+"'>"+cDias+"</a>"; } /*javascript:recogerDays("+ cDias +","+ mes +","+ anio_today +","+ind+");indicarFecha()*/
			}
			else
			{	if ((mes > monthLimite) && (anio_today >= yearLimite))
				{	cCalendar += " height=20><span class=nodaysSel style=\"text-decoration:none\" id='link"+ind+"' ><s>"+ cDias +"</s></span>"; }
				else
				{	if ( (parseInt(cDias,10)<parseInt(qDiaEsHoyC,10)) && (mes==qMesEsHoyC) && (anio_today==yYear))
					{	cCalendar += " height=20><span class=nodaysSel style=\"text-decoration:none\" id='link"+ind+"' ><s>"+ cDias +"</s></span>"; }
					else {	
						if ( (parseInt(cDias,10)==parseInt(qDiaEsHoyC,10)) && (mes==qMesEsHoyC) && (anio_today==yYear)){
							if (hora_actual >= 0)
							{cCalendar += " height=20><a style=\"text-decoration:none\" class="+CssClass+" id='link"+ind+"'>"+cDias+"</a>";}
							else
							{cCalendar += "onclick='javascript:recogerDays("+ cDias +","+ mes +","+ anio_today +","+ind+");indicarFecha()' style='cursor:hand'><a style=\"text-decoration:none\" class="+CssClass+" id='link"+ind+"' href='javascript:void(0);'>"+cDias+"</a>";} /*javascript:recogerDays("+ cDias +","+ mes +","+ anio_today +","+ind+");indicarFecha()*/
						}else{
							cCalendar += "onclick='javascript:recogerDays("+ cDias +","+ mes +","+ anio_today +","+ind+");indicarFecha()' style='cursor:hand'><a style=\"text-decoration:none\" href='javascript:void(0);' class="+CssClass+" id='link"+ind+"'>"+cDias+"</a>";  /*javascript:recogerDays("+ cDias +","+ mes +","+ anio_today +","+ind+");indicarFecha()*/
						}
					}
				}
			}
			cDias++;
		}		
		else
		{	
			cCalendar +=" onMouseout=color_antiguo('#E9F3FB');><spacer type=block width=1 height=1>"; 
		}
		cCalendar +="</td>";

		if ((ind%7) == 0)
		{	/*cierro el tr*/
			//cCalendar +="<td width=10><spacer type=block width=10></td></tr><tr bgcolor=#E9F3FB><td width=10><spacer type=block width=10></td>";
			cCalendar +="<td width=10><spacer type=block width=10></td></tr>";
			if(cDias <= tMonth[mes]){
				cCalendar +="<tr bgcolor=#E9F3FB><td width=10><spacer type=block width=10></td>";
			}
			
		}
	}	
	cCalendar += "</tr>";
	cCalendar += "</table>";
	
//	cCalendar += "<table width=100% border=0 cellpadding=0 cellspacing=0><tr bgcolor=#ffffff><td height=11><spacer type=block height=11></td></tr></table>";
	var oCalendar = tOK();
	var qMuestro = pMes;

	var lLayer = "lCalendar";
	var qMuestro = pMes+tDias+cCalendar+oCalendar;
	document.getElementById("lCalendar").innerHTML = qMuestro;
}

var aux_dia;		/*indica el dia q hemos seleccionado*/
var aux_mes;		/*indica el mes seleccionado*/
var aux_anio;		/*indica el ano seleccionado*/
var vDays; var vMonths; var vtxtDays; var vYears;

function recogerDays(dia,mes,anio,ind){
	var opSel_aux = opSel + 1;
	switch (qTipo){
		case 'S':
					limpiaEstilos();
					vDays = "BEGIN_DAY_0"+opSel_aux;
					vtxtDays = "TXT_BEGIN_DAY_0"+opSel_aux;
					vMonths = "BEGIN_MONTH_0"+opSel_aux;
					vYears = "BEGIN_YEAR_0"+opSel_aux;
					document.getElementById("cell"+ind).style.backgroundColor = "#858485"; 
					document.getElementById("link"+ind).className = "daysSel"
					break;

		case 'R':
					limpiaEstilos();
					vDays = "END_DAY_0"+opSel_aux;
					vtxtDays = "TXT_END_DAY_0"+opSel_aux;
					vMonths = "END_MONTH_0"+opSel_aux;
					vYears = "END_YEAR_0"+opSel_aux;
					document.getElementById("cell"+ind).style.backgroundColor = "#858485"; 
					document.getElementById("link"+ind).className = "daysSel"
					break;
	}
	aux_dia = dia; aux_mes = mes; aux_anio = anio;
}

function limpiaEstilos(){	
	for (var ind=0;ind<nVeces;ind++){		
		if(document.getElementById("link"+ind)!=null){
			document.getElementById("cell"+ind).style.backgroundColor = "#ffffff"; 
			document.getElementById("link"+ind).className = "days"
		}
	}
}


function indicarFecha(){	
	var lLayer = "lCalendar";
	/*comprobar q la fecha esta entre los rangos*/
	if (aux_anio<2000){	aux_anio += 1900; }
	var fechaSel = new Date(aux_anio,aux_mes,aux_dia);


	if ( (fechaSel <= fLimite) ){
		jkk = parseInt(fechaSel.getDay(),10)-1;
		if (jkk == (-1)){ jkk = 6; }

		var auxiliar_dia = aux_dia - 1;
		/*para indicar el texto corto o largo*/
		if (booking){
			document.getElementById(vtxtDays).value = tDay_ext[jkk];
		}
		else{
			document.getElementById(vtxtDays).value = tDayLong[jkk];
		}
			
		
		aux_mes=aux_mes+1;
		if((""+aux_mes).length <2)aux_mes="0"+aux_mes;
		var indiceCombo = ""+aux_anio+aux_mes;
		var posicion=0;
		var tama = document.getElementById(vMonths).length;
		for (var i=0; i < tama; i++){			
			if(document.getElementById(vMonths).options[i].value==indiceCombo){
				posicion=i;
				break;
			}
		}
		document.getElementById(vDays).options.selectedIndex = auxiliar_dia;
		document.getElementById(vMonths).options.selectedIndex = posicion; 
		document.getElementById(vYears).value = aux_anio;

		/*este if determina si se tiene que cambiar varios combos de SALIDA*/
		if (swChangeDate){
			var opSel_aux = opSel + 1;
			aux_begin_day = auxiliar_dia;
			aux_begin_month = aux_mes;
			aux_yYear = aux_anio;
			cambioLasFechas(aux_mes,opSel_aux)
			//llamar a una funcion de la pagina de abajo
		}

		/*comprobar si el objeto de regreso seleccionado existe */
		//alert(qTipo)		
		if (qTipo == 'S'){	
			var opSel_aux = opSel + 1;
			var objDay = "END_DAY_0"+(opSel_aux);

			if (document.getElementById(objDay) != null){
				//document.getElementById(objDay).options.selectedIndex = document.getElementById(vDays).options.selectedIndex;
				var objtxt = "TXT_END_DAY_0"+opSel_aux;
				document.getElementById(objtxt).value = document.getElementById(vtxtDays).value;
				var objMonth = "END_MONTH_0"+(opSel_aux);
				var objYear = "END_YEAR_0"+(opSel_aux);
				//si el ao de regreso es menor mostramos la advertencia y lo establecemos al mismo que de salida
				if(document.getElementById(objYear).value < document.getElementById(vYears).value){
					document.getElementById(objDay).options.selectedIndex = document.getElementById(vDays).options.selectedIndex;
					document.getElementById(objMonth).options.selectedIndex = document.getElementById(vMonths).options.selectedIndex;
					document.getElementById(objYear).value = document.getElementById(vYears).value;
				}
				//en caso de que el ao sea mayor o igual comprobamos los meses y los dias
				else
				{
					//en caso de que el ao sea el mismo
					if(document.getElementById(objYear).value == document.getElementById(vYears).value){
						
						//comprobamos si el mes de regreso es menor que el de salida, en ese caso procedemos a establecer el mes de regreso
						//para que sea el mismo que el de salida y mostramos la advertencia
						if(document.getElementById(objMonth).options.selectedIndex < document.getElementById(vMonths).options.selectedIndex){
							document.getElementById(objDay).options.selectedIndex = document.getElementById(vDays).options.selectedIndex;
							document.getElementById(objMonth).options.selectedIndex = document.getElementById(vMonths).options.selectedIndex;							
						}
						//en caso de que el mes de regreso sea mayor o igual que el de salida comprobamos el dia seleccionado
						else
						{							
							//si el mes de regreso es igual al de salida comprobamos el dia seleccionado y le mostramos la advertencia
							if(document.getElementById(objMonth).options.selectedIndex == document.getElementById(vMonths).options.selectedIndex){
								
								if(document.getElementById(objDay).options.selectedIndex < document.getElementById(vDays).options.selectedIndex){
									document.getElementById(objDay).options.selectedIndex = document.getElementById(vDays).options.selectedIndex;									
								}
							}
						}
					}
				}
			}			

	    }
		pintaTextoDiaSemana();		
		
		/* Para la pgina v3.RECCL2*/
        if((document.getElementById("dcon_02")!=null) && (document.getElementById("dcon_03")!=null))
        {
            var fecha = (auxiliar_dia + 1) + "/" + (aux_mes) + "/" + aux_anio;


			if (qTipo == 'S')
            {
                document.getElementById("dcon_02").value = fecha;
            }else
            {  			
                document.getElementById("dcon_03").value = fecha;
            }
        }

	}
	document.getElementById(lLayer).style.visibility = "hidden";
	if (document.getElementById("lCalendarIframe1"))
		document.getElementById("lCalendarIframe1").style.visibility = "hidden";

	cargar_fechas_finales();
	actualizar_dia();
}

//////////////////////////////////MECANICA DEL CALENDARIO////////////////////////////////////////
function diferencia_dias(tipo){
	formulario1 = document.getElementById("bookingForm");
	formulario2 = document.getElementById("formulario");
	
	
	
	var fecha_tmp_inicio_or = formulario1.fecha_entrada.value;
	var fecha_tmp_salida_or = formulario1.fecha_salida.value;
	
//	alert(fecha_tmp_inicio_or+" <a> "+fecha_tmp_salida_or);
	
	var fecha_tmp_inicio, fecha_tmp_salida;
	
	fecha_tmp_inicio = String(fecha_tmp_inicio_or);
//	alert("01._ "+fecha_tmp_inicio);
	fecha_tmp_inicio = fecha_tmp_inicio.split("/");		
	fecha_tmp_inicio = new Date(fecha_tmp_inicio[2],fecha_tmp_inicio[1]-1,fecha_tmp_inicio[0]);

	fecha_tmp_salida = String(fecha_tmp_salida_or);
//	alert("02._ "+fecha_tmp_salida);
	fecha_tmp_salida = fecha_tmp_salida.split("/");		
	fecha_tmp_salida = new Date(fecha_tmp_salida[2],fecha_tmp_salida[1]-1,fecha_tmp_salida[0]);

	/*dias_entre_fechas = Math.ceil((fecha_tmp_inicio-fecha_tmp_salida)/86400000);
	if (tipo == "abs")	{dias_entre_fechas = Math.abs(dias_entre_fechas);}	*/
	
	/* modificacion jar */
	horas_entre_fechas = Math.ceil((fecha_tmp_inicio-fecha_tmp_salida)/3600000);
	
	
	if (horas_entre_fechas%24==23){
		horas_entre_fechas++;
	}
	if (horas_entre_fechas%24==-23){
		horas_entre_fechas--;
	}
	dias_entre_fechas = Math.floor(horas_entre_fechas/24)
	if (tipo == "abs")	{dias_entre_fechas = Math.abs(dias_entre_fechas);}	
	/* fin modificacion jar */
	return dias_entre_fechas;
}

function cargar_fechas_finales(){
		var formulario1 = document.getElementById("bookingForm");
		//datos de los combos
		var dia_ini = document.getElementById("BEGIN_DAY_01").value;
		var mes_ini = document.getElementById("BEGIN_MONTH_01").value;
		var mes_ini = mes_ini.substr(4,2);
		var anio_ini = document.getElementById("BEGIN_YEAR_01").value;
		//para el input
		fecha_inicial = dia_ini + "/" + mes_ini + "/" + anio_ini; 
		//alert("fecha_inicial:" + fecha_inicial)		

		//para la comparacion de fechas		
		//var f_ini_comp = new Date(parseInt(anio_ini,10),parseInt(mes_ini,10),parseInt(dia_ini,10));		
		//f_ini_comp = f_ini_comp.getTime();
							
		//datos de los combos
		var dia_fin = document.getElementById("END_DAY_01").value;
		var mes_fin = document.getElementById("END_MONTH_01").value;
		var mes_fin = mes_fin.substr(4,2);		
		var anio_fin = document.getElementById("END_YEAR_01").value;
		//para el input
		fecha_final = dia_fin + "/" + mes_fin + "/" + anio_fin;
				
		//para la comparacion de fechas
		//var f_fin_comp = new Date(parseInt(anio_fin,10),parseInt(mes_fin,10),parseInt(dia_fin,10));
		//f_fin_comp = f_fin_comp.getTime();
				
		//comparacion de fechas
		if(fecha_inicial == fecha_final){
			//alert("IGUALES")																																							
			formulario1.fecha_entrada.value = fecha_inicial;			
			actualizar_date_fin(dia_fin,mes_fin,anio_fin);
		}
		else if( (parseInt(anio_fin,10) < parseInt(anio_ini,10)) || 
				 ((parseInt(anio_fin,10) == parseInt(anio_ini,10)) && (parseInt(mes_fin,10) < parseInt(mes_ini,10))) || 
				 ((parseInt(anio_fin,10) == parseInt(anio_ini,10)) && (parseInt(mes_fin,10) == parseInt(mes_ini,10)) && (parseInt(dia_fin,10) < parseInt(dia_ini,10)))){  //ini mayor que fin
			//alert("INIT MAYOR")	
			formulario1.fecha_salida.value = fecha_final;			
			actualizar_date_ini(dia_fin,mes_fin,anio_fin);
		}
		else{ //fin mayor que ini
			//alert("FIN MAYOR")	
			formulario1.fecha_entrada.value = fecha_inicial;
			formulario1.fecha_salida.value = fecha_final;
		}
	
											
		/*							
		dif_entre_fechas = Math.ceil(f_ini_comp - f_fin_comp);
		alert(dif_entre_fechas)
		//if(f_ini_comp == f_fin_comp) //1er caso: las fechas son iguales (al entrar)
		if(dif_entre_fechas==0)
		{
			alert("IGUALES")																																							
			formulario1.fecha_entrada.value = fecha_inicial;					
			actualizar_date_fin(dia_fin,mes_fin,anio_fin);			
		}							
		//else if(f_ini_comp > f_fin_comp)
		else if(dif_entre_fechas > 0)
		{
			alert("INIT MAYOR")			
			formulario1.fecha_salida.value = fecha_final;			
			actualizar_date_ini(dia_fin,mes_fin,anio_fin);
		}
		//else if(f_ini_comp < f_fin_comp)
		else if(dif_entre_fechas < 0)
		{
			alert("FIN MAYOR")	
			formulario1.fecha_entrada.value = fecha_inicial;
			formulario1.fecha_salida.value = fecha_final;
		}
		*/
		//COMMENT BY MANU: actualizar_diferencia_dias();
		
}

/* COMMENT BY MANU
function actualizar_diferencia_dias()
{
	dias_entre_fechas = diferencia_dias('');
		
		if (dias_entre_fechas > 0){
			var begin_day = document.getElementById("BEGIN_DAY_01");
			var end_day = document.getElementById("END_DAY_01");
			begin_day.options.selectedIndex = end_day.options.selectedIndex;
			
			var begin_month = document.getElementById("BEGIN_MONTH_01");
			var end_month = document.getElementById("END_MONTH_01");
			begin_month.options.selectedIndex = end_month.options.selectedIndex;
			
			var begin_year = document.getElementById("BEGIN_YEAR_01");
			var end_year = document.getElementById("END_YEAR_01");
			document.getElementById("BEGIN_YEAR_01").value =document.getElementById("END_YEAR_01").value;
			
			//COMMENT BY MANU pa que chute de una puta vez recargar_fechas_finales()
		}
}

function recargar_fechas_finales(){
		dia_ini = document.getElementById("BEGIN_DAY_01").value;
		mes_ini = document.getElementById("BEGIN_MONTH_01").value;
		mes_ini = mes_ini.substr(4,2);
		anio_ini = document.getElementById("BEGIN_YEAR_01").value;
		
		dia_fin = document.getElementById("END_DAY_01").value;
		mes_fin = document.getElementById("END_MONTH_01").value;
		mes_fin = mes_fin.substr(4,2)
		anio_fin = document.getElementById("END_YEAR_01").value;
						
		fecha_inicial = dia_ini + "/" + mes_ini + "/" + anio_ini;
		fecha_final = dia_fin + "/" + mes_fin + "/" + anio_fin;
		
	//	alert("recargar_fechas_finales: "+ fecha_inicial+"  - "+fecha_final);
		
		formulario1 = document.getElementById("bookingForm");
		
		formulario1.fecha_entrada.value = fecha_inicial;
		formulario1.fecha_salida.value = fecha_final;

}
*/

function inicializar_calendario(){
		formulario1 = document.getElementById("bookingForm");
		
		var fecha_tmp_inicio_or = String(formulario1.fecha_entrada.value);
		var fecha_tmp_salida_or = String(formulario1.fecha_salida.value);
		
		if (fecha_tmp_inicio_or != 'dd/mm/aaaa' && fecha_tmp_salida_or != 'dd/mm/aaaa' && fecha_tmp_inicio_or != 'dd/mm/yyyy' && fecha_tmp_salida_or != 'dd/mm/yyyy') {
			
			var fecha_tmp_inicio = fecha_tmp_inicio_or.split("/");
			var fecha_tmp_salida = fecha_tmp_salida_or.split("/");
			
		/* alert(fecha_tmp_inicio[0]+" -- "+Number(fecha_tmp_inicio[1])+" -- "+fecha_tmp_inicio[2]); */
			
			document.getElementById("BEGIN_DAY_01").value = fecha_tmp_inicio[0];
			document.getElementById("BEGIN_MONTH_01").value = fecha_tmp_inicio[2]+fecha_tmp_inicio[1];
			document.getElementById("BEGIN_YEAR_01").value = fecha_tmp_inicio[2];
			
		/*alert(document.getElementById("BEGIN_DAY_01").value+" - "+document.getElementById("BEGIN_MONTH_01").value+" - "+document.getElementById("BEGIN_YEAR_01").value);*/
			
			document.getElementById("END_DAY_01").value = fecha_tmp_salida[0];
			document.getElementById("END_MONTH_01").value = fecha_tmp_salida[2]+fecha_tmp_salida[1];
			document.getElementById("END_YEAR_01").value = fecha_tmp_salida[2];
			
		}
		else
			iniBooking();
}

//ADD BY MANU FOR INITIALIZING CALENDAR COMBOS 28/01/2008

function init_combos_calendar(f_ini,f_fin){
	//inicializacion de los combos 	si hay fechas introducidas
	if(f_ini!="" && f_fin!=""){
		
		var fecha_tmp_inicio_or = String(f_ini);		
		var fecha_tmp_salida_or = String(f_fin);		
		var fecha_tmp_inicio = fecha_tmp_inicio_or.split("/");		
		var fecha_tmp_salida = fecha_tmp_salida_or.split("/");
	}
	//inicializacion de los combos si NO hay fechas introducidas
	else if(f_ini=="" && f_fin=="") {

		today = new Date();
		day = today.getDate();		/*indica q dia es el seleccionado*/
		month = today.getMonth();	/*indica el mes en q nos encontramos*/
		yYear = today.getFullYear();	/*indica el aņo actual*/
	
		if(day < 10){ day = "0"+day; }
		if(month < 10){ month = "0"+month; }			

		var fecha_tmp_inicio_or = day+"/"+month +"/"+yYear ;	
		var fecha_tmp_salida_or = day+"/"+month +"/"+yYear ;			
		var fecha_tmp_inicio = fecha_tmp_inicio_or.split("/");		
		var fecha_tmp_salida = fecha_tmp_salida_or.split("/");
		
	}
		
	//alert("DIA:::::" + fecha_tmp_inicio[0] + "MES:::::::" + fecha_tmp_inicio[1] +"ANO::::::" + fecha_tmp_inicio[2]);
	
	//INICIO 
	
	dia_ini_selected = parseInt(fecha_tmp_inicio[0],10)-1; 
	mes_ini_selected = String(fecha_tmp_inicio[2]) + String(fecha_tmp_inicio[1]);

	//refresco el dia seleccionado
	document.getElementById("BEGIN_DAY_01").options.selectedIndex   = dia_ini_selected;

	//refresco del mes seleccionado
	var tama = document.getElementById("BEGIN_MONTH_01").length;
	for (var i=0; i < tama; i++){
		if(document.getElementById("BEGIN_MONTH_01").options[i].value==mes_ini_selected)
		{
			document.getElementById("BEGIN_MONTH_01").options[i].selected = true;
			var sel_ind = document.getElementById("BEGIN_MONTH_01").options[i].selectedIndex;
			break;
		}
	}

	//FIN
	dia_fin_selected = parseInt(fecha_tmp_salida[0],10)-1;
	mes_fin_selected = String(fecha_tmp_salida[2]) + String(fecha_tmp_salida[1])

	//refresco el dia seleccionado
	document.getElementById("END_DAY_01").options.selectedIndex   = dia_fin_selected;

	//refresco del mes seleccionado
	var tama = document.getElementById("END_MONTH_01").length;
	for (var i=0; i < tama; i++){			
		if(document.getElementById("END_MONTH_01").options[i].value==mes_fin_selected)
		{
			document.getElementById("END_MONTH_01").options[i].selected = true;
			var sel_ind = document.getElementById("END_MONTH_01").options[i].selectedIndex;
			break;
		}
	}			
	//else return false; 
}



//ADD BY MANU 
function actualizar_date_ini(dia,mes,ano){
	//alert("INI::::" + dia + "---" + mes + "---" + ano)

	dia_ini = parseInt(dia,10);
	mes_ini = parseInt(mes,10);
	anio_ini = parseInt(ano,10);

	//aplicamos algoritmo de comprobacion de fechas	
 	if((mes_ini==1)||(mes_ini==3)||(mes_ini==5)||(mes_ini==7)||(mes_ini==8)||(mes_ini==10)||(mes_ini==12)){
			if(dia_ini==1){								
					if(mes_ini==1) //cambio de aņo 
					{
						mes_ini  = 12; 
						anio_ini = parseInt(anio_ini,10) - 1;
						dia_ini=31;
					}
					else if(mes_ini==3){ //febrero
						if(isBisiesto(anio_ini)) { dia_ini = 29;}
						else {dia_ini = 28;}
						mes_ini = 2;
					}
					else if(mes_ini==8){ //agosto
						mes_ini = parseInt(mes_ini,10) - 1;
						dia_ini=31;
					}
					else //eoc 
					{
						mes_ini = parseInt(mes_ini,10) - 1;
						dia_ini=30;					
					}		
			}
			else{
				dia_ini = dia_ini - 1;
			}
	}
	else if((!isBisiesto(anio_fin) && (mes_ini==2))||(mes_ini==4)||(mes_ini==6)||(mes_ini==9)||(mes_ini==11)){
			if(dia_ini==1){
				dia_ini = 31;				
				mes_ini = parseInt(mes_ini,10) - 1; 
			}
			else{
				dia_ini = parseInt(dia_ini,10) - 1;
			}											
	}	

	if(dia_ini < 10){ dia_ini = "0"+dia_ini; }
	if(mes_ini < 10){ mes_ini = "0"+mes_ini; }
	
	dia_ini_selected = parseInt(dia_ini,10) - 1;
	mes_ini_selected = String(anio_ini) + String(mes_ini);
	
	//alert("mes_ini_selected:::::" + mes_ini_selected)

	fecha_inicial = dia_ini + "/" + mes_ini + "/" + anio_ini;
	//alert("F_INI::::::::::" + fecha_inicial);
	
	//refresco el dia seleccionado
	document.getElementById("BEGIN_DAY_01").options.selectedIndex   = dia_ini_selected;
	//refresco el mes seleccionado							
	
	var tama = document.getElementById("BEGIN_MONTH_01").length;
	for (var i=0; i < tama; i++){
		if(document.getElementById("BEGIN_MONTH_01").options[i].value==mes_ini_selected)
		{
			document.getElementById("BEGIN_MONTH_01").options[i].selected = true;
			var sel_ind = document.getElementById("BEGIN_MONTH_01").options[i].selectedIndex;
			break;
		}
	}
	
	var formulario1 = document.getElementById("bookingForm");
	formulario1.fecha_entrada.value = fecha_inicial;		

	//refresco el dia de la semana	
	ChangeDay(sel_ind,0);

}

//ADD BY MANU 
function actualizar_date_fin(dia,mes,ano)
{	
	//alert("FIN::::" + dia + "---" + mes + "---" + ano)		
	dia_fin = parseInt(dia,10);
	mes_fin = parseInt(mes,10);
	anio_fin = parseInt(ano,10);
	
	//aplicamos algoritmo de comprobacion de fechas	
	//alert(mes_fin);
 	if((mes_fin==1)||(mes_fin==3)||(mes_fin==5)||(mes_fin==7)||(mes_fin==8)||(mes_fin==10)||(mes_fin==12))
	{
			if(dia_fin >=31){
					dia_fin = 1;
					if(mes_fin==12) 
					{
						mes_fin = 1; 
						anio_fin = parseInt(anio_fin,10) + 1;
					}
					else 
					{						
						mes_fin = parseInt(mes_fin,10) + 1; 						
					}
			}
			else{
				dia_fin = parseInt(dia_fin,10) + 1;
			}
			
	}
	else if((mes_fin==4)||(mes_fin==6)||(mes_fin==9)||(mes_fin==11)){
			if(dia_fin >= 30){
					dia_fin = 1;
					mes_fin = parseInt(mes_fin,10) + 1; 
					
			}
			else{
				dia_fin = parseInt(dia_fin,10) + 1;
			}						 
	}
	else if(mes_fin==2){			
			//alert("disfin -> "+dia_fin+"/ bisiesto"+isBisiesto(anio_fin));
			if(isBisiesto(anio_fin) && dia_fin >= 29){
				dia_fin = 1; 
				mes_fin = parseInt(mes_fin,10) + 1; 
			}
			else if(isBisiesto(anio_fin) && dia_fin >= 28){
				dia_fin = parseInt(dia_fin,10) + 1;				
			}
			else{
				if(dia_fin >= 28)
				{
					dia_fin = parseInt(1,10);
					mes_fin = parseInt(mes_fin,10) + 1; 
				}
				else
				{dia_fin = parseInt(dia_fin,10) + 1;}
			} 			
	}

	if(dia_fin < 10){ dia_fin = "0" + dia_fin; }
	if(mes_fin < 10){ mes_fin = "0" + mes_fin; }			
	
	dia_fin_selected = parseInt(dia_fin,10) - 1;
	mes_fin_selected = String(anio_fin) + String(mes_fin)
		
	fecha_final = dia_fin + "/" + mes_fin + "/" + anio_fin;
	//alert("FECHA_FINAL:::::" + fecha_final);
		
	
	//refresco el dia seleccionado
	document.getElementById("END_DAY_01").options.selectedIndex   = dia_fin_selected;
	
	var tama = document.getElementById("END_MONTH_01").length;
	for (var i=0; i < tama; i++){			
		if(document.getElementById("END_MONTH_01").options[i].value==mes_fin_selected)
		{
			document.getElementById("END_MONTH_01").options[i].selected = true;
			var sel_ind = document.getElementById("END_MONTH_01").options[i].selectedIndex;
			break;
		}
	}
	//actualizo fecha en el input
	var formulario1 = document.getElementById("bookingForm");
	formulario1.fecha_salida.value = fecha_final;		
	
	//alert("FECHA_FINAL final :::::" + formulario1.fecha_salida.value);
	
	//refresco el dia de la semana	
	ChangeDay(sel_ind,0);			
}