function calendar2(obj_target) {
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup = cal_popup2;
	if (!obj_target)
	return false;
	if (obj_target.value == null)
	return false;
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	this.id = calendars.length;
	calendars[this.id] = this;
}
function cal_popup2 (str_datetime) {
	this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	if (!this.dt_current) return;
	var obj_calwindow = window.open(
	'/cal2.htm?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
	'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
	',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function fCIH(){
if(!(document.FHH.inm.selectedIndex == 11 && document.FHH.ind.selectedIndex == 30 && document.FHH.iny.selectedIndex == document.FHH.iny.length - 1)){
fCDH(document.FHH.inm.options[document.FHH.inm.selectedIndex].value,document.FHH.ind.options[document.FHH.ind.selectedIndex].value, document.FHH.iny.options[document.FHH.iny.selectedIndex].value, "in");
if(fDM(document.FHH.inm.options[document.FHH.inm.selectedIndex].value,document.FHH.ind.options[document.FHH.ind.selectedIndex].value,document.FHH.iny.options[document.FHH.iny.selectedIndex].value,document.FHH.outm.options[document.FHH.outm.selectedIndex].value,document.FHH.outd.options[document.FHH.outd.selectedIndex].value, document.FHH.outy.options[document.FHH.outy.selectedIndex].value) != 2)
fSCOH(document.FHH.inm.options[document.FHH.inm.selectedIndex].value,document.FHH.ind.options[document.FHH.ind.selectedIndex].value,document.FHH.iny.options[document.FHH.iny.selectedIndex].value);}else alert("Check-In Non Valido");}
function fCOH() { if (!(document.FHH.outm.selectedIndex == 0 && document.FHH.outd.selectedIndex == 0 && document.FHH.outy.selectedIndex == 0)){
fCDH(document.FHH.outm.options[document.FHH.outm.selectedIndex].value,document.FHH.outd.options[document.FHH.outd.selectedIndex].value,document.FHH.outy.options[document.FHH.outy.selectedIndex].value,"out");
if (fDM(document.FHH.outm.options[document.FHH.outm.selectedIndex].value, document.FHH.outd.options[document.FHH.outd.selectedIndex].value, document.FHH.outy.options[document.FHH.outy.selectedIndex].value, document.FHH.inm.options[document.FHH.inm.selectedIndex].value, document.FHH.ind.options[document.FHH.ind.selectedIndex].value, document.FHH.iny.options[document.FHH.iny.selectedIndex].value) != 1)
alert("ATTENTION: Date Error!");}else alert("ATTENTION: Check-Out Error!");}
function fCDH(Mese, Giorno, Anno, S) {Mese = parseInt(Mese); Giorno = parseInt(Giorno); Anno = parseInt(Anno);
if (Giorno > 28) if (Mese == 2) {if (!(Giorno == 29 && Anno % 4 == 0)) fUGMH(Mese, Anno, S);} else	if (Giorno == 31 && (Mese == 4 || Mese == 6 || Mese == 9 || Mese == 11)) fUGMH(Mese, Anno, S);}

function fSCOH(Mese, Giorno, Anno) {Mese = parseInt(Mese); Giorno = parseInt(Giorno); Anno = parseInt(Anno);
if (Giorno <= 27) fGSH(); else if (Mese == 2) if (Giorno == 28 && Anno % 4 == 0) fGSH(); else	foutmSH(Mese); else if (Giorno == 31) foutmSH(Mese); else if (Giorno == 30 && (Mese == 4 || Mese == 6 || Mese == 9 || Mese == 11)) foutmSH(Mese); else fGSH();}

function fGSH(){document.FHH.outm.selectedIndex = document.FHH.inm.selectedIndex;document.FHH.outd.selectedIndex = document.FHH.ind.selectedIndex + 1;document.FHH.outy.selectedIndex = document.FHH.iny.selectedIndex;}
function foutmSH(Mese) { Mese = parseInt(Mese); if (Mese == 12) { document.FHH.outm.selectedIndex = 0; document.FHH.outd.selectedIndex = 0;if (document.FHH.iny.selectedIndex + 1 < document.FHH.iny.length)	document.FHH.outy.selectedIndex = document.FHH.iny.selectedIndex + 1;} else { document.FHH.outm.selectedIndex = document.FHH.inm.selectedIndex + 1;	document.FHH.outd.selectedIndex = 0;	document.FHH.outy.selectedIndex = document.FHH.iny.selectedIndex;}}

function fUGMH(Mese, Anno, S) { switch(parseInt(Mese)) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: document.FHH.elements[S + "d"].selectedIndex = 30;break;case 4: case 6: case 9: case 11: document.FHH.elements[S + "d"].selectedIndex = 29;break;case 2:	if (Anno % 4 == 0) document.FHH.elements[S + "d"].selectedIndex = 28;else document.FHH.elements[S + "d"].selectedIndex = 27;break;}}
function grillH(epoch, destination){
epoch = parseInt(epoch);
var mydate = new Date(epoch)
mm = mydate.getMonth();	
gg = mydate.getDate()-1;
var today = new Date();
aa = mydate.getFullYear() - today.getFullYear();
switch(destination) {
	case 1:
	document.FHH.inm.options[mm].selected = true;
	document.FHH.ind.options[gg].selected = true;
	document.FHH.iny.options[aa].selected = true;
	fCIH();
	break;
	case 0:
	document.FHH.outm.options[mm].selected = true;
	document.FHH.outd.options[gg].selected = true;
	document.FHH.outy.options[aa].selected = true;
	fCOH();
	break;
	default:
	return;
}
return true;
}
function C2EH(dadove){ 
switch(dadove){
	case 1:
	var today = new Date();
	CIa = document.FHH.iny.selectedIndex + today.getFullYear();
	CIm = document.FHH.inm.selectedIndex;
	CIg = document.FHH.ind.selectedIndex +1;
	var checkin = new Date();
	checkin.setFullYear(CIa,CIm,CIg);
	checkin.setHours (0,0,0,0);
	document.FHH.indate.value = checkin.getTime();
	break;
	case 0:
	var today = new Date();
	COa = document.FHH.outy.selectedIndex + today.getFullYear();
	COm = document.FHH.outm.selectedIndex;
	COg = document.FHH.outd.selectedIndex +1;
	var checkout = new Date();
	checkout.setFullYear(COa,COm,COg);
	checkout.setHours (0,0,0,0);
	document.FHH.outdate.value = checkout.getTime();
	break;
	default:
	return;
	break;
}
return true;
}


var CIH = new calendar2(document.forms['FHH'].elements['indate']);
CIH.year_scroll = false;
CIH.time_comp = false;
var COH = new calendar2(document.forms['FHH'].elements['outdate']);
COH.year_scroll = false;
COH.time_comp = false;
