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);
//OFERTA BANNER FOCUS
/*if (document.getElementById("oferta_banner")!=null && document.getElementById("oferta_banner").value==1){
	return (date.getTime() <= now.getTime() || (date.getMonth()<9&&date.getMonth()!=10&&(date.getMonth()==11&&date.getDate()>15))||date.getFullYear()!=2010);
}
else{
	return (date.getTime() <= now.getTime() );
}*/
//FIN OFERTA BANNER FOCUS
//OFERTA BANNER GPS
/*if (document.getElementById("oferta_banner_gps")!=null && document.getElementById("oferta_banner_gps").value==1){
	return (date.getTime() <= now.getTime() || (date.getMonth()<11&&date.getFullYear()==2010)||(date.getMonth()==11&&date.getFullYear()==2010&&(date.getDate()<3||date.getDate()>8))||date.getFullYear()>2010);
}
else{
	return (date.getTime() <= now.getTime() );
}*/
//FIN OFERTA BANNER GPS
return (date.getTime() < now.getTime() );
}
function dateRange2(date) {
	
var now = new Date();
var dia=document.formPresupuesto.day_rtr.value;
var numero=document.formPresupuesto.msn_rtr.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);
//OFERTA BANNER GPS
/*if (document.getElementById("oferta_banner_gps")!=null && document.getElementById("oferta_banner_gps").value==1){
	return ((date.getTime()<=now.getTime())||(date.getFullYear()==2010 && date.getMonth()<11)||(date.getFullYear()==2011&&date.getMonth()>0)||(date.getMonth()==12 && date.getFullYear()==2010&&date.getDate()<3));
}
else{
return (date.getTime() <= now.getTime() )
}*/
//FIN OFERTA BANNER GPS
return (date.getTime() <= now.getTime() );
}

function catcalc_rtr(cal){
var date = cal.date;
document.formPresupuesto.day_rtr.value = date.getDate();
document.formPresupuesto.msn_rtr.value = mes_ano(date.getMonth(),date.getFullYear());
document.formPresupuesto.fecha_rtr.value = date.getDate()+ " " + NombreMeses(date.getMonth()+1) + " " + date.getFullYear();

if (document.formPresupuesto_2!=null){

document.formPresupuesto_2.day_rtr.value = date.getDate();
document.formPresupuesto_2.msn_rtr.value = mes_ano(date.getMonth(),date.getFullYear());
document.formPresupuesto_2.fecha_rtr.value = date.getDate()+ " " + NombreMeses(date.getMonth()+1) + " " + date.getFullYear();	
	
}

DeshabilitaPresupuesto();

if (findPosX(document.getElementById("calendario2"))!=0){
	x=findPosX(document.getElementById("calendario1"));
	y=findPosY(document.getElementById("calendario1"));
}
else{
	x=findPosX(document.getElementById("calendario1_c"));
	y=findPosY(document.getElementById("calendario1_c"));
}
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,
		electric		: false,
		dateStatusFunc : dateRange
    });
if (document.formPresupuesto_2!=null){
	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_c",   // 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,
		electric		: false,
		dateStatusFunc : dateRange
    });
}
dia=date.getDate();
mes=date.getMonth();
ano=date.getFullYear();
	dia=dia+7;	
	switch(date.getMonth()){
		case 0:case 2:case 4: case 6: case 7: 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.value = (dia);
	document.formPresupuesto.msn_ent.value = mes_ano_ent(mes,ano);
	document.formPresupuesto.fecha_ent.value = dia + " " + NombreMeses(mes+1) + " " + ano;
	if (document.formPresupuesto_2!=null){
		document.formPresupuesto_2.day_ent.value = (dia);
		document.formPresupuesto_2.msn_ent.value = mes_ano_ent(mes,ano);
		document.formPresupuesto_2.fecha_ent.value = dia + " " + NombreMeses(mes+1) + " " + ano;
	}
	var fecha=new Date(ano,mes,dia);
	Calendar.setup({
        inputField     :    "date_desde2",      // 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:fecha,
        singleClick    :    "right",            // single-click mode
		step           :    1,                // show all years in drop-down boxes (instead of every other year as default)
		onUpdate       :    catcalc_ent,
		electric		: false,
		dateStatusFunc :    dateRange2
    });
	if (document.formPresupuesto_2!=null){
		Calendar.setup({
        inputField     :    "date_desde2",      // 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_c",   // trigger for the calendar (button ID)
		date:fecha,
        singleClick    :    "right",            // single-click mode
		step           :    1,                // show all years in drop-down boxes (instead of every other year as default)
		onUpdate       :    catcalc_ent,
		electric		: false,
		dateStatusFunc :    dateRange2
    });
	}
}


function catcalc_ent(cal){	
var date = cal.date;
document.formPresupuesto.day_ent.value=date.getDate();
document.formPresupuesto.msn_ent.value= mes_ano_ent(date.getMonth(),date.getFullYear());
document.formPresupuesto.fecha_ent.value = date.getDate()+ " " + NombreMeses(date.getMonth()+1) + " " + date.getFullYear();
if (document.formPresupuesto_2!=null){
	document.formPresupuesto_2.day_ent.value=date.getDate();
	document.formPresupuesto_2.msn_ent.value= mes_ano_ent(date.getMonth(),date.getFullYear());
	document.formPresupuesto_2.fecha_ent.value = date.getDate()+ " " + NombreMeses(date.getMonth()+1) + " " + date.getFullYear();
}
if (findPosX(document.getElementById("calendario2"))!=0){
	x=findPosX(document.getElementById("calendario2"));
	y=findPosY(document.getElementById("calendario2"));
}
else{
	x=findPosX(document.getElementById("calendario2_c"));
	y=findPosY(document.getElementById("calendario2_c"));
}
Calendar.setup({
        inputField     :    "date_desde2",      // 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,
		electric		: false,
		dateStatusFunc :    dateRange2
    });

if (document.formPresupuesto_2!=null){
Calendar.setup({
        inputField     :    "date_desde2",      // 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],
        button         :    "calendario2_c",   // 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,
		electric		: false,
		dateStatusFunc :    dateRange2
    });
}
DeshabilitaPresupuesto();
}

function mes_ano(mes,ano){
	var total=mes+(12*ano);
	return total;
}
function mes_ano_ent(mes,ano){
	var total=mes+(12*ano);
	return total;
}

function indice_dia(dia){
	for(var index = 0; index < document.formPresupuesto.day_rtr.options.length; index++) {
	   if(document.formPresupuesto.day_rtr.options[index].value == dia){
		 return index;
	   }
	}	
}
function indice_dia_ent(dia){
	for(var index = 0; index < document.formPresupuesto.day_ent.options.length; index++) {
	   if(document.formPresupuesto.day_ent.options[index].value == dia){
		 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>Please press "New quote"</h3>';

		//xmlhttp.abort();
		
		// 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 = '';
		
	}

}

function MostrarFormYaCliente(){
	document.getElementById("cliente_nuevo").style.display="none";
	document.getElementById("ya_cliente").style.display="block";
}

function MostrarFormNoCliente(){
	document.getElementById("cliente_nuevo").style.display="block";
	document.getElementById("ya_cliente").style.display="none";
}

function HacerClickCalendario1(){
	document.getElementById("calendario1").click();	
}

function HacerClickCalendario2(){
	document.getElementById("calendario2").click();	
}

function HacerClickCalendario1c(){
	document.getElementById("calendario1_c").click();	
}

function HacerClickCalendario2c(){
	document.getElementById("calendario2_c").click();	
}

function NombreMeses(numero){
	var meses=new Array();
	meses[1]="January";
	meses[2]="February";
	meses[3]="March";
	meses[4]="April";
	meses[5]="May";
	meses[6]="June";
	meses[7]="July";
	meses[8]="August";
	meses[9]="September";
	meses[10]="October";
	meses[11]="November";
	meses[12]="December";	
	return meses[numero];
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
	} while (obj = obj.offsetParent);
	array=new Array();
	array[0]=curleft;
	array[1]=curtop;
	return array;
}
}
