function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

 function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
function dateRange(date) {
var now = new Date();
//PARA QUE PERMITA SELECCIONAR EL DIA DE HOY
now.setHours(0,0,0,0);
return (date.getTime() <= now.getTime() )
}
function dateRange2(date) {
	
var now = new Date();
var dia=document.formPresupuesto.day_rtr.options[document.formPresupuesto.day_rtr.selectedIndex].value;
var numero=(document.formPresupuesto.msn_rtr.options[document.formPresupuesto.msn_rtr.selectedIndex].value);
	var mes= (numero%12);
	numero=numero-mes;
	var ano=numero/12;
if(dia==1){
	
	switch(mes){
		 
		case 0: dia=31; mes=11; ano--; break;
		case 1:case 3:case 5: case 7: case 8: case 10: dia=31;mes--;break;
		case 4: case 6: case 9: case 11: dia=30;mes--;break;
		default: mes--; 
			if((((ano%4)==0)&&((ano%100)!=0))||(ano%100==0)){
				dia=29;	
			}else {
				dia=28;
			}break;
	}
}else{dia--;}
	
now.setDate(dia);

	now.setMonth(mes);
	now.setYear(ano);

return (date.getTime() <= now.getTime() )
}
function catcalc_rtr(cal){
var date = cal.date;
document.formPresupuesto.day_rtr.options.selectedIndex=date.getDate();
document.formPresupuesto.msn_rtr.options.selectedIndex= mes_ano(date.getMonth(),date.getFullYear());
DeshabilitaPresupuesto();

x=findPosX(document.getElementById("calendario1"));
y=findPosY(document.getElementById("calendario1"));
Calendar.setup({
        inputField     :    "date_desde",      // id of the input field
//        ifFormat       :    "%Y/%m/%d %H:%M",// format of the input field
        ifFormat       :    "%Y%m%d",// format of the input field
        showsTime      :    false,            // will display a time selector
        button         :    "calendario1",   // trigger for the calendar (button ID)
		date:cal.date,
		position		: [x,y],
        singleClick    :    "right",            // single-click mode
		step           :    1,                // show all years in drop-down boxes (instead of every other year as default)
		onUpdate       :    catcalc_rtr,
		dateStatusFunc : dateRange
    });
Calendar.setup({
        inputField     :    "date_desde",      // id of the input field
//        ifFormat       :    "%Y/%m/%d %H:%M",// format of the input field
        ifFormat       :    "%Y%m%d",// format of the input field
        showsTime      :    false,            // will display a time selector
		position		: [x,y+30],
        button         :    "calendario2",   // trigger for the calendar (button ID)
		date:cal.date,
        singleClick    :    "right",            // single-click mode
		step           :    1,                // show all years in drop-down boxes (instead of every other year as default)
		onUpdate       :    catcalc_ent,
		dateStatusFunc :    dateRange2
    });
dia=date.getDate();
mes=date.getMonth();
ano=date.getFullYear();
	dia=dia+7;	
	switch(date.getMonth()){
		case 0:case 2:case 4: case 6: case 9:
			if(dia>31){ dia=dia-31;mes++;}
			break;
		case 1:
			if((((ano%4)==0)&&((ano%100)!=0))||(ano%100==0)){
				if(dia>29) {dia=dia-29;mes++;}
			}else{
				if(dia>28) {dia=dia-28;mes++;}
			}
			
			break;
		case 3:case 5: case 8: case 10: 
			if(dia>30) {dia=dia-30;mes++;}
			break;		 
		default: if(dia>31) {dia=dia-31;mes=0;ano++}
			break;		 			
	}
	document.formPresupuesto.day_ent.options.selectedIndex=dia;
	document.formPresupuesto.msn_ent.options.selectedIndex= mes_ano(mes,ano);
}

function catcalc_ent(cal){
var date = cal.date;
document.formPresupuesto.day_ent.options.selectedIndex=date.getDate();
document.formPresupuesto.msn_ent.options.selectedIndex= mes_ano(date.getMonth(),date.getFullYear());
DeshabilitaPresupuesto();
}
function mes_ano(mes,ano){
	var total=mes+(12*ano);

	for(var index = 0; 
    index < document.formPresupuesto.msn_rtr.options.length; 
    index++) {
   if(document.formPresupuesto.msn_rtr.options[index].value == total){
     return index;
   }
	}
}
function DeshabilitaPresupuesto() {

	// Lo primero se oculta el presupuesto ya antiguo
	// pero SOLO si la página no es "reserva.htm" 
	var path = location.pathname;
	if ( (path.match("reserva") != null) || (path.match("marriott") != null) ) {

		
		// Se ponen a 'none' para que no ocupen espacio
		document.getElementById('Reserva').style.display = 'none';
		document.getElementById('Reservaoffline').style.display = 'none';
/*
		str = new String(document.getElementById("Presupuesto").innerHTML);
		str = str.replace("!disabled","disabled");
		document.getElementById("Presupuesto").innerHTML = str;
*/
		document.getElementById("Presupuesto").innerHTML = '<h3>Por favor, pulse "Nuevo Presupuesto"</h3>';

		// NUEVO: Se oculta el campo del "supercodigo"
//		document.getElementById('codediv').style.display = 'none';

		// NUEVO: Se oculta el campo del "book and join"
//		document.getElementById('bookandjoin').style.display = 'none';

		// NUEVO: Se vacia el cuadro de los upgrades
		document.getElementById("Upgrade").innerHTML = '';
		
	}

}

