

min_stay = 5;


function agg_zero2 (c) {
r = "";
if (c < 10) {
r = "0";
} // fine if (c < 10)
return r;
} // fine function agg_zero2



function update_sel_dates(id) {
var sel_opt=document.getElementById("id_sdp"+id);
var other_id = id;
if (Math.ceil(id/2) != Math.floor(id/2)) other_id++;
else other_id--;
other_sel_opt = document.getElementById("id_sdp"+other_id);
var num_sel = sel_opt.selectedIndex;
var other_num_sel = other_sel_opt.selectedIndex;
if (other_sel_opt.options[other_sel_opt.selectedIndex].text != "----") {
var add_ns = 0;
var o_add_ns = 0;
if (sel_opt.options[0].text == "----") add_ns = 1;
if (other_sel_opt.options[0].text == "----") o_add_ns = 1;
var sel_date_str = sel_opt.options[sel_opt.selectedIndex].value;
if (other_id > id) {
var fut_date = new Date(sel_date_str.substr(0,4),(sel_date_str.substr(5,2) - 1),(sel_date_str.substr(8,2) - 0 + min_stay));
fut_date = fut_date.getFullYear()+'-'+agg_zero2(fut_date.getMonth() - 0 + 1)+(fut_date.getMonth() - 0 + 1)+'-'+agg_zero2(fut_date.getDate())+fut_date.getDate();
for (n1 = num_sel ; n1 <= sel_opt.length ; n1++) {
if (sel_opt.options[n1].value < fut_date) num_sel = n1;
else break;
} // fine for n1
if ((num_sel - add_ns) >= (other_num_sel - o_add_ns)) var new_sel_opt = num_sel - add_ns + o_add_ns + 1;
} // fine if (other_id > id)
if (other_id < id) {
var pas_date = new Date(sel_date_str.substr(0,4),(sel_date_str.substr(5,2) - 1),(sel_date_str.substr(8,2) - min_stay));
pas_date = pas_date.getFullYear()+'-'+agg_zero2(pas_date.getMonth() - 0 + 1)+(pas_date.getMonth() - 0 + 1)+'-'+agg_zero2(pas_date.getDate())+pas_date.getDate();
for (n1 = num_sel ; n1 > 0 ; n1--) {
if (sel_opt.options[n1].value > pas_date) num_sel = n1;
else break;
} // fine for n1
if ((num_sel - add_ns) <= (other_num_sel - o_add_ns)) var new_sel_opt = num_sel - add_ns + o_add_ns - 1;
} // fine if (other_id < id)
if (new_sel_opt >= 0) other_sel_opt.selectedIndex = new_sel_opt;
} // fine if (other_sel_opt.options[other_sel_opt.selectedIndex].text != "----")
} // fine function update_sel_dates



function crea_date () {
giorni = new Array(" Su"," Mo"," Tu"," We"," Th"," Fr"," Sa");
mesi = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
opz = "";
var oggi = new Date();
var m_oggi = oggi.getMonth();
var g_oggi = oggi.getDate();
var a_oggi = oggi.getFullYear();
var data_oggi = a_oggi+"-"+agg_zero2((m_oggi + 1))+(m_oggi + 1)+"-"+agg_zero2(g_oggi)+g_oggi;

for (n1 = 1 ; n1 <= 2 ; n1++) {
g_oggi = g_oggi + 1;
d = new Date(a_oggi,m_oggi,g_oggi);
a_oggi = d.getMonth();
g_oggi = d.getDate();
a_oggi = d.getFullYear();
data_oggi = a_oggi+"-"+agg_zero2((m_oggi + 1))+(m_oggi + 1)+"-"+agg_zero2(g_oggi)+g_oggi;
} // fine for n1

giorno = 7;
mese = 2;
anno = 2009;

for (n1 = 1 ; n1 <= 77 ; n1++) {
d = new Date(anno,mese,giorno);
mese = d.getMonth();
giorno = d.getDate();
anno = d.getFullYear();
data_corr = anno+"-"+agg_zero2((mese + 1))+(mese + 1)+"-"+agg_zero2(giorno)+giorno;
if (data_corr > data_oggi) {
opz += "<option value=\""+data_corr+"\">"+mesi[mese]+" "+agg_zero2(giorno)+giorno+", "+anno+"</option>";
} // fine if (data_corr >= data_oggi)
giorno = giorno + 1;
} // fine for n1

for (n1 = 1 ; n1 <= 17 ; n1++) {
d = new Date(anno,mese,giorno);
mese = d.getMonth();
giorno = d.getDate();
anno = d.getFullYear();
data_corr = anno+"-"+agg_zero2((mese + 1))+(mese + 1)+"-"+agg_zero2(giorno)+giorno;
if (data_corr > data_oggi) {
opz += "<option value=\""+data_corr+"\">"+mesi[mese]+" "+agg_zero2(giorno)+giorno+", "+anno+"</option>";
} // fine if (data_corr >= data_oggi)
giorno = giorno + 7;
} // fine for n1

for (n1 = 1 ; n1 <= 43 ; n1++) {
d = new Date(anno,mese,giorno);
mese = d.getMonth();
giorno = d.getDate();
anno = d.getFullYear();
data_corr = anno+"-"+agg_zero2((mese + 1))+(mese + 1)+"-"+agg_zero2(giorno)+giorno;
if (data_corr > data_oggi) {
opz += "<option value=\""+data_corr+"\">"+mesi[mese]+" "+agg_zero2(giorno)+giorno+", "+anno+"</option>";
} // fine if (data_corr >= data_oggi)
giorno = giorno + 1;
} // fine for n1

var giorno = 6;
var mese = 2;
var anno = 2010;

for (n1 = 1 ; n1 <= 77 ; n1++) {
d = new Date(anno,mese,giorno);
mese = d.getMonth();
giorno = d.getDate();
anno = d.getFullYear();
data_corr = anno+"-"+agg_zero2((mese + 1))+(mese + 1)+"-"+agg_zero2(giorno)+giorno;
if (data_corr > data_oggi) {
opz += "<option value=\""+data_corr+"\">"+mesi[mese]+" "+agg_zero2(giorno)+giorno+", "+anno+"</option>";
} // fine if (data_corr >= data_oggi)
giorno = giorno + 1;
} // fine for n1

for (n1 = 1 ; n1 <= 17 ; n1++) {
d = new Date(anno,mese,giorno);
mese = d.getMonth();
giorno = d.getDate();
anno = d.getFullYear();
data_corr = anno+"-"+agg_zero2((mese + 1))+(mese + 1)+"-"+agg_zero2(giorno)+giorno;
if (data_corr > data_oggi) {
opz += "<option value=\""+data_corr+"\">"+mesi[mese]+" "+agg_zero2(giorno)+giorno+", "+anno+"</option>";
} // fine if (data_corr >= data_oggi)
giorno = giorno + 7;
} // fine for n1

for (n1 = 1 ; n1 <= 43 ; n1++) {
d = new Date(anno,mese,giorno);
mese = d.getMonth();
giorno = d.getDate();
anno = d.getFullYear();
data_corr = anno+"-"+agg_zero2((mese + 1))+(mese + 1)+"-"+agg_zero2(giorno)+giorno;
if (data_corr > data_oggi) {
opz += "<option value=\""+data_corr+"\">"+mesi[mese]+" "+agg_zero2(giorno)+giorno+", "+anno+"</option>";
} // fine if (data_corr >= data_oggi)
giorno = giorno + 1;
} // fine for n1


} // fine function crea_date



function nasc_cal2 (ncal) {
var lcal=document.getElementById('calp'+ncal);
lcal.style.visibility='hidden';
} // fine function nasc_cal2



function mos_cal2 (ncal) {
var lcal = document.getElementById('calp'+ncal);
var elementoid=document.getElementById('bcalp'+ncal);
var elementi = elementoid;
var iTop = 0;
var prova = lcal.style.visibility;
if (prova != 'visible') {
while(elementi.tagName != 'BODY') {
iTop += elementi.offsetTop;
elementi = elementi.offsetParent;
}
elementi = elementoid;
var iLeft = 0;
while(elementi.tagName != 'BODY') {
iLeft += elementi.offsetLeft;
elementi = elementi.offsetParent;
}
lcal.style.left=(iLeft + 2) + 'px';
lcal.style.top=(iTop + elementoid.offsetHeight + 2) + 'px';
var ind_data = 0;
var data_sel = document.getElementById('id_sdp'+ncal);
if (!data_sel.selectedIndex) ind_data = 2;
else ind_data = data_sel.selectedIndex;
data_sel = data_sel.options[ind_data].value;
mese = (data_sel.substring(5,7) - 1);
anno = data_sel.substring(0,4);
crea_cal_mese2(ncal,mese,anno);
lcal.style.visibility='visible';
}
if (prova == 'visible') {
nasc_cal2(ncal);
}
} // fine function mos_cal2



function rendi_link2 (val_cal,n_lista_d,lista_d,ncal) {
var elem = document.getElementById('d'+val_cal+ncal)
if (!elem) return;
elem.bgColor = '#eeeeee';
elem.onmouseover = function() {
this.bgColor = '#dddddd';
}
elem.onmouseout = function() {
this.bgColor = '#eeeeee';
}
elem.onmousedown = function() {
lista_d.selectedIndex = n_lista_d;
update_sel_dates(ncal);
nasc_cal2(ncal);
}
} // fine function rendi_link2



function crea_cal_mese2 (ncal,mese,anno) {
var n_giorni_l = 0;
var giorni_l = new Array();
var n1 = 0;
d = new Date(anno,mese,1);
anno = d.getFullYear();
mese = d.getMonth();
giorno = d.getDay() * -1;
giorno = giorno + 2;
if (giorno > 1) giorno = giorno - 7;
var mese_orig = mese;
var anno_orig = anno;
var testo_cal = ' '+mesi[mese]+' '+anno+'<br>\
 <input type="button" class= "calbutton"onclick="crea_cal_mese2(\''+ncal+'\',\''+mese+'\',\''+(anno - 1)+'\')" value="&lt;&lt;" style="font-size: 9px; padding: 0 3px 0 3px; border-color: #333333; border-width: 1px;">\
 <input type="button" class= "calbutton" onclick="crea_cal_mese2(\''+ncal+'\',\''+(mese - 1)+'\',\''+anno+'\')" value="&lt;" style="font-size: 9px; padding: 0 3px 0 3px; border-color: #333333; border-width: 1px;">\
 <input type="button" class= "calbutton" onclick="crea_cal_mese2(\''+ncal+'\',\''+(mese + 1)+'\',\''+anno+'\')" value="&gt;" style="font-size: 9px; padding: 0 3px 0 3px; border-color: #333333; border-width: 1px;">\
 <input type="button" class= "calbutton" onclick="crea_cal_mese2(\''+ncal+'\',\''+mese+'\',\''+(anno + 1)+'\')" value="&gt;&gt;" style="font-size: 9px; padding: 0 3px 0 3px; border-color: #333333; border-width: 1px;"><br>\
<table style="border-collapse: collapse; font-size: 10px; margin-left: 1%; margin-right: 1%; cursor: default; text-align: center; padding: 2px">\
<tr><td>'+giorni['1']+'<'+'/td><td>'+giorni['2']+'<'+'/td><td>'+giorni['3']+'<'+'/td><td>'+giorni['4']+'<'+'/td><td>'+giorni['5']+'<'+'/td><td>'+giorni['6']+'<'+'/td><td>'+giorni['0']+'<'+'/td><'+'/tr>';
d = new Date(anno,mese,giorno);
mese = d.getMonth();
anno = d.getFullYear();
giorno = d.getDate();
while (mese_orig == mese || n1 == 0) {
testo_cal += '<tr>';
for (n1 = 1 ; n1 <= 7 ; n1++) {
if (mese == mese_orig) {
testo_cal += '<td id="d'+anno+'-'+agg_zero2((mese + 1))+(mese + 1)+'-'+agg_zero2(giorno)+giorno+ncal+'">'+giorno+'<'+'/td>';
n_giorni_l = n_giorni_l + 1;
}
else testo_cal += '<td><'+'/td>';
giorno = giorno + 1;
d = new Date(anno,mese,giorno);
mese = d.getMonth();
anno = d.getFullYear();
giorno = d.getDate();
}
testo_cal += '<'+'/tr>';
}
testo_cal += '<'+'/table><div style="padding: 3px 0 0 0">\
<input type="button" class= "calbutton" onclick="nasc_cal2(\''+ncal+'\')" value="Close" style="font-size: 9px; padding: 0 3px 0 3px; border-color: #333333; border-width: 1px;"><'+'/div>';
document.getElementById('calp'+ncal).innerHTML = testo_cal;
var lista_d = document.getElementById('id_sdp'+ncal);
var num_opz = lista_d.length;
var val_cal = 0;
var val_comp = anno_orig+'-'+agg_zero2(mese_orig + 1)+(mese_orig + 1);
for (n1 = 0 ; n1 < num_opz ; n1++) {
val_cal = lista_d.options[n1].value;
if (val_cal.substring(0,7) == val_comp) {
rendi_link2(val_cal,n1,lista_d,ncal);
}
}
} // fine function crea_cal_mese2



function aggiorna_data_iniziale () {
sel2_opt=document.getElementById("id_sdp2");
var num_sel = sel1_opt.selectedIndex;
var add_ns = 0;
var o_add_ns = 0;
if (sel1_opt.options[0].text == "----") add_ns = 1;
if (sel2_opt.options[0].text == "----") o_add_ns = 1;
var sel_date_str = sel1_opt.options[sel1_opt.selectedIndex].value;
var fut_date = new Date(sel_date_str.substr(0,4),(sel_date_str.substr(5,2) - 1),(sel_date_str.substr(8,2) - 0 + min_stay));
fut_date = fut_date.getFullYear()+'-'+agg_zero2(fut_date.getMonth() - 0 + 1)+(fut_date.getMonth() - 0 + 1)+'-'+agg_zero2(fut_date.getDate())+fut_date.getDate();
for (n1 = num_sel ; n1 <= sel1_opt.length ; n1++) {
if (sel1_opt.options[n1].value < fut_date) num_sel = n1;
else break;
} // fine for n1
sel2_opt.selectedIndex = num_sel - add_ns + o_add_ns + 1;
} // fine function aggiorna_data_iniziale


