var i_today;
var i_fromdate;
var i_todate;
var num_pax_room = new Array();
var actual_errors = new Array();
var global_nights = 1;
var global_from;
var global_fromdate;
var global_todate;
var fromDate
var dossier='';
var reference='';
var hotel_booking;
var hotel_booking_id;
var datisis;
var global_client;
var global_agreement;
var global_book_name;
var struct_param = new Array();
var global_rooming_list = new Array();
var global_remarks_list = new Array();
var global_options_list = new Array();
var openedhotel = '';
var openedbook = false;
var openedconfirm = false;
var global_currency;
var userchosed='';
var hppage = 6;
var maxpages = 6;
var actual_page = 1;
var default_order = 'availability';
var actual_order = 'availability';
var order_changed = false;
var global_deadline;
var global_full;
var global_rooms = new Array();
var global_hotel_code;
var __previous__ = null;
var global_total;
var global_hotel_id;
var global_policies;
var global_comments;
var global_av_params;

function init()	{
	url_xml_rpc = js_global_root_url+'xml_rpc/call.php';
	form_obj = document.getElementById('input_data');
	form_doc = document.input_data;
	div_form = document.getElementById('search');
	div_loading = document.getElementById('loading');
	struct_param['header'] = new Array();
	struct_param['query'] = new Array();
	struct_param['header']['version'] = '1.0.0';
	struct_param['header']['product'] = 'hotelbooking';
	struct_param['header']['sessid'] = sessid;
	struct_param['query']['language'] = js_language;
	iso_encoding = 'utf-8';
	var i_today = to_int(new Date());
	var i_fromdate = i_today;
	var i_todate = i_today;
	num_pax_room['SGL']=1;
	num_pax_room['TSU']=1;
	num_pax_room['TWN']=2;
	num_pax_room['DBL']=2;
	num_pax_room['TRP']=3;
	num_pax_room['QUD']=4;
	num_pax_room['DBC']=3;
	num_pax_room['TWC']=3;
	num_pax_room['TRC']=4;
	setPD();
	document.body.style.display = 'none';
	document.body.style.display = 'block';
}

<!-- Traduce una data in un intero 'ordinabile'-->
function to_int(date) {
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    if(m<10) m='0'+''+m;
    var d = date.getDate();
    if(d<10) d='0'+''+d;
    return parseInt(y+''+m+''+d);
}



// Caricamento delle select per tutte le destinazioni
function display_other()	{
	
	//document.getElementById('hf_summary').style.display = 'none';
	document.getElementById('other').style.display = 'block';
	document.getElementById('list').innerHTML = ''; 
	document.getElementById('hf_cont').style.display = 'none'; 
	document.getElementById('hf_cont').style.display = 'block'; 
	document.body.style.display='none';
	document.body.style.display='block';
	document.getElementById('form_title').innerHTML = js_dic_LOCATION;
}

// Aggiorna lo staus del form
function updateStatus() {
    var elt = document.getElementById('hfs_content');
    var selCitta = document.getElementById('citta');
    if(!document.getElementById('citta')) {
    	    actual_errors[actual_errors.length] = 'CITY';
    	    return;
    }
    else if(selCitta.options)
     var nomeCitta = selCitta.options[selCitta.selectedIndex].text;
    else
     {
      var city_radio_list = document.getElementsByName('citta');
      var no_selected_city = true;
      for(var u=0; u < city_radio_list.length; u++)
      if(city_radio_list[u].checked) 
       {var ap_citta = city_radio_list[u].value.split('-');
        var nomeCitta = ap_citta[1];
        no_selected_city = false;
       }
     }
    
    actual_errors = new Array();
    
    if((selCitta.options && selCitta.options[selCitta.selectedIndex].value=='***') || (!selCitta.options && no_selected_city)) {
        actual_errors[actual_errors.length] = 'CITY';
        //document.getElementById('hf_summary').style.display = 'none';
        return;
    }
    if(document.getElementById('zone') && (document.getElementById('zone').options && document.getElementById('zone').options[document.getElementById('zone').selectedIndex].value!='***')) {
        var zone = '('+document.getElementById('zone').options[document.getElementById('zone').selectedIndex].text+') ';
    }
    else
    	var zone = '';
    var text = js_dic_SUMMARYTEXT + ' <u>' + nomeCitta + '</u> '+zone;
    
    var fromDate = global_fromdate = document.getElementById('aa').value+'-'+document.getElementById('mma').value+'-'+document.getElementById('gga').value;
    var toDate = global_todate = document.getElementById('ap').value+'-'+document.getElementById('mmp').value+'-'+document.getElementById('ggp').value;
    var category = document.getElementById('hf_hcat');
    var stars = document.getElementById('stars');
    i_fromdate=to_int(new Date(document.getElementById('aa').value,document.getElementById('mma').value-1,document.getElementById('gga').value,01,00,00));
    i_todate=to_int(new Date(document.getElementById('ap').value,document.getElementById('mmp').value-1,document.getElementById('ggp').value,01,00,00));
    var clean_fromgg = new Date(document.getElementById('aa').value,document.getElementById('mma').value-1,document.getElementById('gga').value,01,00,00).getDate();
    var clean_togg = new Date(document.getElementById('ap').value,document.getElementById('mmp').value-1,document.getElementById('ggp').value,01,00,00).getDate();
    var oggi=new Date();
    //alert(clean_fromgg+'|'+fromDate);
    //alert(clean_togg+'|'+toDate);
    if(i_fromdate>=i_todate || i_fromdate<to_int(oggi) || clean_fromgg!=document.getElementById('gga').value || clean_togg!=document.getElementById('ggp').value) 
        actual_errors[actual_errors.length] = 'DATE';
    global_from = format_data(fromDate,js_language);
    global_to = format_data(toDate,js_language);
    text += js_dic_FROM + ' <u>'+format_data(fromDate,js_language) + '</u> ' + js_dic_TODATE + ' <u>' + format_data(toDate,js_language) +'</u>';
    /*if(category.selectedIndex > 0) {
        text += ', cat. <u>' + category.options[category.selectedIndex].text + '</u>';
    } */
    //PER L'HOTEL
    if (document.getElementById('hotel_id') && document.getElementById('hotel_id').value != '***') {
        text += '<br />' + js_dic_HOTEL + ': <u>' + document.getElementById('hotel_id').options[document.getElementById('hotel_id').selectedIndex].text + '</u>';
    }
    if(stars && stars.selectedIndex > 0) {
        text += ', <u>' + stars.options[stars.selectedIndex].text + '</u>';
    } 
    text += '<br/>';

    var rC = new Array();
    	rC['SGL']=0;
	rC['TSU']=0;
	rC['TWN']=0;
	rC['DBL']=0;
	rC['TRP']=0;
	rC['QUD']=0;
	rC['DBC']=0;
	rC['TWC']=0;
	rC['TRC']=0;
    var cots = 0;
    var ebeds = 0;
    var paxes = 0;
    var areThereRooms = false;
    var roomlets=true;
    
    for(var i=1; i<5; i++) {
        var selRoom = document.getElementById('room_'+i).value;
        if(document.getElementById('numeroStanze'+i)) var numRoom = document.getElementById('numeroStanze'+i).value;       
        if(document.getElementById('culla'+i)) var cot = document.getElementById('culla'+i).value;
        if(document.getElementById('eta'+i)) 
        	{var eta = document.getElementById('eta'+i).value;
        	 var numRoom = 1;
        	}
        if(selRoom != '*') {
            areThereRooms = true;
            paxes += numRoom * num_pax_room[selRoom];
            rC[selRoom] +=Number(numRoom);
                if(document.getElementById('eta'+i)) { 
                    ebeds += 1;
                }
                if(document.getElementById('culla'+i) && document.getElementById('culla'+i).checked) {
                    cots += Number(numRoom);
                }
            }
        }
        

    if(areThereRooms) {
        text += js_dic_ROOMS + ': ';
        var written = false;

        for(room in rC) {
            var num = rC[room];
            if(num>0) { 
                if(written) text += ', ';
                else text += ' ';
                text += num + ' <u>' + eval('js_dic_'+room) + '</u>';
                written = true;
            }
        }

        if(ebeds!=0 || cots!=0) text += ' <br/>' + js_dic_EXTRA + ': ';
        if(ebeds!=0) text += ebeds + ' <u>extrabed</u>';
        if(cots!=0) { 
            if(ebeds!=0) text += ', ';
            text += cots + ' <u>'+ js_dic_COTS +'</u>';
        }
        if(paxes!=0) text += ' <br/>' + js_dic_PAXES + ': ' + paxes;
    } else actual_errors[actual_errors.length] = 'NOROOMS';

    if(paxes>9) { 
        elt.innerHTML = js_dic_MAX9;
        actual_errors[actual_errors.length] = 'TOOPAX';
    }

    if(nomeCitta.length>0) 
    {	//var class_summary=document.getElementById('hf_summary');
    	//if(class_summary.className=='') class_summary.className='summary';
    	//elt.innerHTML = text;
        //document.getElementById('hf_summary').style.display = 'block';
    }
}

<!-- Scrittura dei layer -->
function layerWrite(layerName, layerText)
{ if(document.all)
    document.all[layerName].innerHTML = layerText;
  else
  { l = document.getElementById(layerName);
    l.innerHTML = layerText;
  }
}

<!-- Imposta la select per le stanze -->
function setNumRooms(num)
{ lName = 'num_' + num + '_div';
  lString = '<SELECT name="numeroStanze'+num+'" id="numeroStanze'+num+'" onChange="updateStatus();">';
  lString = lString + '<OPTION value="1"> 1'; 
  lString = lString + '<OPTION value="2"> 2'; 
  lString = lString + '<OPTION value="3"> 3'; 
  lString = lString + '<OPTION value="4"> 4';
  lString = lString + '<OPTION value="5"> 5'; 
  lString = lString + '</SELECT>';
  layerWrite(lName, lString);
}

<!-- Imposta il checkbox per le culle -->
function askCot(num)
{ lName = 'cot_' + num + '_div';
  lString = '<INPUT type="checkbox" name="culla'+num+'" id="culla'+num+'" onChange="updateStatus();" style="border:0px;" class="checkbox">';
  layerWrite(lName, lString);
}

<!-- Elimina la select per l'età -->
function noAskAge(num)
{ lName = 'eb_' + num;
  lString = '';
  layerWrite(lName, lString);
  lName = 'eb2_' + num;
  layerWrite(lName, lString);
}

<!-- Imposta la select per l'età -->
function askAge(num)
{ lName = 'eb_' + num;
  lString = '<SELECT name="eta'+num+'" id="eta'+num+'" onChange="updateStatus();">';
  lString = lString + '<OPTION value="3"> 3</OPTION>'; 
  lString = lString + '<OPTION value="4"> 4</OPTION>';
  lString = lString + '<OPTION value="5"> 5</OPTION>'; 
  lString = lString + '<OPTION value="6"> 6</OPTION>'; 
  lString = lString + '<OPTION value="7"> 7</OPTION>'; 
  lString = lString + '<OPTION value="8"> 8</OPTION>'; 
  lString = lString + '<OPTION value="9"> 9</OPTION>'; 
  lString = lString + '<OPTION value="10"> 10</OPTION>'; 
  lString = lString + '<OPTION value="11"> 11</OPTION>'; 
  lString = lString + '<OPTION value="12"> 12</OPTION>'; 
  lString = lString + '<OPTION value="13"> 13</OPTION>'; 
  lString = lString + '<OPTION value="14"> 14</OPTION>'; 
  /*lString = lString + '<OPTION value="15"> 15'; 
  lString = lString + '<OPTION value="16"> 16'; 
  lString = lString + '<OPTION value="17"> 17'; 
  lString = lString + '<OPTION value="18"> 18'; */
  lString = lString + '</SELECT>';
  layerWrite(lName, lString);
  lName = 'eb2_' + num;
  lString = '<SELECT name="eta2'+num+'" id="eta2'+num+'" onChange="updateStatus();">';
  lString = lString + '<OPTION value=""> --</OPTION>'; 
  lString = lString + '<OPTION value="3"> 3</OPTION>'; 
  lString = lString + '<OPTION value="4"> 4</OPTION>';
  lString = lString + '<OPTION value="5"> 5</OPTION>'; 
  lString = lString + '<OPTION value="6"> 6</OPTION>'; 
  lString = lString + '<OPTION value="7"> 7</OPTION>'; 
  lString = lString + '<OPTION value="8"> 8</OPTION>'; 
  lString = lString + '<OPTION value="9"> 9</OPTION>'; 
  lString = lString + '<OPTION value="10"> 10</OPTION>'; 
  lString = lString + '<OPTION value="11"> 11</OPTION>'; 
  lString = lString + '<OPTION value="12"> 12</OPTION>'; 
  lString = lString + '<OPTION value="13"> 13</OPTION>'; 
  lString = lString + '<OPTION value="14"> 14</OPTION>'; 
  /*lString = lString + '<OPTION value="15"> 15'; 
  lString = lString + '<OPTION value="16"> 16'; 
  lString = lString + '<OPTION value="17"> 17'; 
  lString = lString + '<OPTION value="18"> 18'; */
  lString = lString + '</SELECT>';
  layerWrite(lName, lString);
}

<!-- Imposta ad uno il numero di stanze -->
function setToOne(num)
{ lName = 'num_' + num + '_div';
  lString = '1';
  layerWrite(lName, lString);
}

<!-- Elimina il checkbox per le culle -->
function setNoCot(num)
{ lName = 'cot_' + num + '_div';
  lString = '';
  layerWrite(lName, lString);
}

<!-- Elimina tutte le possibili voci -->
function setToNone(num)
{ lName = 'num_' + num + '_div';
  lString = '';
  layerWrite(lName, lString);
  lName = 'cot_' + num + '_div';
  layerWrite(lName, lString);
  lName = 'eb_' + num;
  layerWrite(lName, lString);
  lName = 'eb2_' + num;
  layerWrite(lName, lString);
}


<!-- Handler di quando viene modificato il codice di stanza -->
function changed(num)
{ nCode = document.getElementById('room_'+num).value;
  if(nCode == '*')
    { setToNone(num);
      return;
    }
  if(nCode != 'TWC' && nCode != 'DBC' && nCode != 'TRC')
    {  setNumRooms(num);
       noAskAge(num);
    } 
   else 
     { setToOne(num);
       askAge(num);
     }
  if(nCode != 'SGL' && nCode != 'QUD')
    askCot(num);
  else setNoCot(num);
  updateStatus();
}

<!-- Calcola il numero di notti -->
function nights()
{ var annoa = document.getElementById('aa').options[document.getElementById('aa').options.selectedIndex].value;
  var mesea = document.getElementById('mma').options[document.getElementById('mma').options.selectedIndex].value;
  var giornoa = document.getElementById('gga').options[document.getElementById('gga').options.selectedIndex].value;
  var annop = document.getElementById('ap').options[document.getElementById('ap').options.selectedIndex].value;
  var mesep = document.getElementById('mmp').options[document.getElementById('mmp').options.selectedIndex].value;
  var giornop = document.getElementById('ggp').options[document.getElementById('ggp').options.selectedIndex].value;

  dataa = new Date(mesea+'/'+giornoa+'/'+annoa);
  datap = new Date(mesep+'/'+giornop+'/'+annop);

  secs = Math.abs(datap.getTime() - dataa.getTime());
  secs = Math.round(secs / (24 * 60 * 60 * 1000));
  global_nights = secs;
  layerWrite('nights', secs);
}

<!-- Setta la departure Date -->
function setPD()
{ 
    var anno = document.getElementById('aa').options[document.getElementById('aa').options.selectedIndex].value;
    var mese = document.getElementById('mma').options[document.getElementById('mma').options.selectedIndex].value;
    var giorno = document.getElementById('gga').options[document.getElementById('gga').options.selectedIndex].value;
    var today = new Date(); 
    var arrivo=new Date(anno, mese-1, giorno, 1, 0, 0);
    if (__customization['startdate'] !== false) {
        var tmp = __customization['startdate'].split('-');
        var cstart = new Date(Number(tmp[0]), Number(tmp[1]) - 1, Number(tmp[2]), 1, 0, 0);
        if (arrivo < cstart) {
            document.getElementById('gga').value = tmp[2];
            document.getElementById('mma').value = tmp[1];
            document.getElementById('aa').value = tmp[0];
            arrivo = cstart;
        }
    }
    if (__customization['enddate'] !== false) {
        var tmp = __customization['enddate'].split('-');
        var cend = new Date(Number(tmp[0]), Number(tmp[1]) - 1, Number(tmp[2]) - 1, 1, 0, 0);
        if (arrivo > cend) {
            var tmpd = tmp[2] - 1;
            document.getElementById('gga').value = (tmpd < 10) ? '0'+tmpd : tmpd;
            document.getElementById('mma').value = tmp[1];
            document.getElementById('aa').value = tmp[0];
            arrivo = cend;
        }
    }
    var more = 86400000 * __customization['days'];
    var partenza=new Date(arrivo.getTime() + more);
    var month = partenza.getMonth() + 1;
    document.getElementById('mmp').value = (month < 10) ? '0' + month : month;
    document.getElementById('ggp').value = (partenza.getDate() < 10) ? '0' + partenza.getDate() : partenza.getDate();
    document.getElementById('ap').value = partenza.getFullYear();
}

//////////////////// RICERCA DI DISPONIBILITA' //////////////////////////////////
function availability_search() {
	document.getElementById('searchmessage').style.display='none';
    //sistemo status ed errori
    updateStatus();
    hide_error();
    //fisso il numero di pagina
    actual_page = 1;
    struct_param['query'] = new Array();
    //resetto la variabile controlla se sono entrato nella pagina di booking
    openedbook = false;
    //controllo se ci sono errori da notificare
	if(actual_errors.length>0) {
        print_error(eval('js_dic_ERROR'+actual_errors[0]));
        return true;
	}
    //mostro i bottoni del sommario e il flash di caricamento
    //document.getElementById('othersearch').style.display = 'block';
    document.getElementById('loading').style.display='block';
    document.getElementById('search').style.display='none';
    document.getElementById('hotels').style.display='none';
    document.getElementById('cities_list').style.display='none';
    document.getElementById('hotel').style.display='none';
    document.getElementById('others').style.display='none';
    struct_param['header']['type'] = 'availability_search';
    struct_param['query']['rewrite'] = booking_rewrite;
	//controllo su che citta' e' fatta la richiesta
    var selCitta = document.getElementById('citta');
	//se la citta' e' scelta dalla select
    if (selCitta.options)
        struct_param['query']['city'] = selCitta.options[selCitta.selectedIndex].value;
    //altrimenti e' scelta dai radiobuttons
    else {
        var city_radio_list = document.getElementsByName('citta');
        //scorro i radio finche' non trovo quello selezionato
	    for(var u=0; u < city_radio_list.length; u++) {
            if(city_radio_list[u].checked) {
                var ap_citta = city_radio_list[u].value.split('-');
                struct_param['query']['city'] = ap_citta[0];
	        }
        }
	}
    //controllo se e' richiesto un particolare hotel
    if  (document.getElementById('hotel_id'))
        struct_param['query']['hotel_id'] = parseInt(document.getElementById('hotel_id').value);
    //prelevo la valuta
    global_currency = currency = struct_param['query']['currency'] = document.getElementById('currency').value;
    //e le date
    struct_param['query']['from'] = document.getElementById('aa').value+'-'+document.getElementById('mma').value+'-'+document.getElementById('gga').value;
    struct_param['query']['to'] = document.getElementById('ap').value+'-'+document.getElementById('mmp').value+'-'+document.getElementById('ggp').value;
    //controllo se e' stato scelto un numero di stelle
    if (document.getElementById('stars').value > 1)
        struct_param['query']['stars'] = document.getElementById('stars').value;
    //controllo le notti viva
    //if (document.getElementById('vivanights').value != '***')
    //    struct_param['query']['vivanights'] = Number(document.getElementById('vivanights').value);
    //prelevo il codice del cliente
    global_client = struct_param['query']['client'] = document.getElementById('client').value;
    //controllo le stanze scorrendole
    struct_param['query']['rooms'] = new Array();
    for(var i=1; i<5; i++) {
        var selRoom = document.getElementById('room_'+i).value;
        //per ogni stanza controllo se e' impostata
        if (selRoom != '*' ) {
            //ne controllo il tipo
            if(selRoom=='DBC') selRoom='DBL';
            else if(selRoom=='TWC') selRoom='TWN';
            else if(selRoom=='TRC') selRoom='TRP';
            struct_param['query']['rooms'][i] = new Array();
            struct_param['query']['rooms'][i]['type'] = selRoom;
            //controllo il numero di stanze
            if (document.getElementById('numeroStanze'+i))
                var num_ = Number(document.getElementById('numeroStanze'+i).value);
            else
                var num_ = 1;
            struct_param['query']['rooms'][i]['num'] = num_;
            //controllo la culla
            if(document.getElementById('culla'+i) && document.getElementById('culla'+i).checked)
                struct_param['query']['rooms'][i]['cot'] = document.getElementById('culla'+i).value;
            //e l'eta' del bambino
            if(document.getElementById('eta'+i))
                struct_param['query']['rooms'][i]['age'] = Number(document.getElementById('eta'+i).value);
            if(document.getElementById('eta2'+i) && document.getElementById('eta2'+i).value!='') {
                struct_param['query']['rooms'][i]['age'] = [struct_param['query']['rooms'][i]['age']];
                struct_param['query']['rooms'][i]['age'].push(Number(document.getElementById('eta2'+i).value));
            }
	}
    }
    global_rooms = struct_param['query']['rooms'];
    //controllo se sono stati richiesti solo hotels disponibili o tutti
    if (document.getElementById('onlyavail') && document.getElementById('onlyavail').style.display != 'none' && document.getElementById('onlyavail').checked)
        struct_param['query']['onlyavail'] = true;
    else
        struct_param['query']['onlyavail'] = false;
    //codice promozionale
    if (document.getElementById('promocode') && document.getElementById('promocode').value != '')
        struct_param['query']['promocode'] = document.getElementById('promocode').value;
    //imposto il numero di hotels che voglio per pagina
    struct_param['query']['hppage'] = hppage;
    //imposto l'ordinamento di default
    actual_order = default_order;
    struct_param['query']['orderby'] = default_order;
    //invio la richiesta
    global_av_params = struct_param['query'];
    __previous__ = 'avail';
    document.getElementById('page').style.display='none';
    xml_request(struct_param,url_xml_rpc,iso_encoding,callbacks_xml_request);
}
/////////////////////////////////////////////////////////////////////////////////////

function change_page(page) {
    //se sono gia' sulla pagina non faccio nulla
    if (page == actual_page && order_changed == false) return false;
    order_changed = false;
    actual_page = page;
    document.getElementById('loading').style.display='block';
    document.getElementById('hotels').style.display='none';
    window.location = '#';
    struct_param['header']['type'] = 'availability_search';
    struct_param['query'] = new Array();
    struct_param['query']['page'] = page;
    struct_param['query']['hppage'] = hppage;
    struct_param['query']['orderby'] = actual_order;
    struct_param['query']['currency'] = currency;
    //controllo su che citta' e' fatta la richiesta
    var selCitta = document.getElementById('citta');
    //se la citta' e' scelta dalla select
    if (selCitta.options)
        struct_param['query']['city'] = selCitta.options[selCitta.selectedIndex].value;
    //altrimenti e' scelta dai radiobuttons
    else {
        var city_radio_list = document.getElementsByName('citta');
        //scorro i radio finche' non trovo quello selezionato
	    for(var u=0; u < city_radio_list.length; u++) {
            if(city_radio_list[u].checked) {
                var ap_citta = city_radio_list[u].value.split('-');
                struct_param['query']['city'] = ap_citta[0];
	        }
        }
	}
    xml_request(struct_param,url_xml_rpc,iso_encoding,callbacks_xml_request);
}

function compute_days(start,end)
{	
	var ap_s = start.split('-');
	var start_date = new Date(ap_s[0],ap_s[1]-1,ap_s[2],11,0,0);
	var start_int = ap_s[0]+''+ap_s[1]+''+ap_s[2];
	var ap_e = end.split('-');
	var end_date = new Date(ap_e[0],ap_e[1]-1,ap_e[2],11,0,0);
	var end_int = ap_e[0]+''+ap_e[1]+''+ap_e[2];
	
	var array_gg = new Array();
	
	
	var iter_date = start_date;
	while(start_int<end_int)
	 {	
	 	// ricalcolo start_int
	 	var iter_gg=iter_date.getDate();
	 	if(iter_gg<=9) iter_gg='0'+iter_gg;
	 	var iter_mm=iter_date.getMonth()+1;
	 	if(iter_mm<=9) iter_mm='0'+iter_mm;
	 	var iter_aaaa=iter_date.getFullYear();
	 	iter_date.setTime(iter_date.getTime()+86400000);
	 	var start_int = iter_aaaa+''+iter_mm+''+iter_gg;
	 	if(start_int!=end_int) array_gg[array_gg.length] = iter_aaaa+'-'+iter_mm+'-'+iter_gg;
	 	
	 }
	return array_gg;
}

// Apre la box del dettaglio dei prezzi
function show_prices(id,agreement)
{
 if (openedhotel != '') {
     id='det';
     agreement += '_det';
 }
 var intest = document.getElementById(id);
 var prezzo = document.getElementById('price_'+agreement);
// var pos = findPos(intest);
 var elt = document.getElementById('prices_details_'+agreement);
// elt.style.visibility='hidden';
 elt.style.display='block';
/* var delta = findPos(elt.offsetParent);
 elt.style.top = pos[1]-delta[1]+50;
 elt.style.left = pos[0]-delta[0];
 elt.style.visibility='visible';*/
}

// Nasconde la box del dettaglio dei prezzi
function hide_prices(id)
{ 
  if (openedhotel != '') id += '_det';
  var elt = document.getElementById('prices_details_'+id);
  elt.style.display='none';
}

function return_deadline(response, type) {
    book(global_hotel_code,global_agreement,response);
}

function book(hotel_code,agreement,ddl)	{
    global_hotel_code = hotel_code;
    openedbook = true;
    openedconfig = false;
	global_rooming_list = new Array();
	global_remarks_list = new Array();
	global_options_list = new Array();
	global_agreement = agreement;
	var hotel_id = document.getElementById('seq_id_'+hotel_code).value;
	hotel_booking_id = hotel_id;
	hotel_booking = hotels[hotel_id];
    document.getElementById('hotels').style.display='none';
    document.getElementById('listbuttons').style.display='none';
    document.getElementById('book').style.display='none';
	document.getElementById('hotel').style.display='none';
	//document.getElementById('hf_summary').style.display='none';
    //deadline hotelbeds
    if (ddl == null && agreement.split('.')[0] == 'hb2') {
        document.getElementById('loading').style.display='block';
        var agrdet = hotel_booking['agreements'][agreement];
        struct_param['header']['type'] = 'get_hotelbeds_deadline_v2';
        struct_param['query'] = new Array();
        struct_param['query']['checkin'] = global_fromdate;
        struct_param['query']['checkout'] = global_todate;
        struct_param['query']['avltoken'] = agrdet['support']['availToken'];
        struct_param['query']['hotel_info_code_text'] = agrdet['support']['hotel_info_code_text'];
        struct_param['query']['contract_list_text'] = agrdet['support']['contract_list_text'];
        struct_param['query']['hotel_info_destination_attrib'] = agrdet['support']['hotel_info_destination_attrib'];
        struct_param['query']['rooms'] = agrdet['support']['rooms'];
        struct_param['query']['accommodation'] = global_av_params['rooms'];
        struct_param['query']['agreement'] = agreement;
        xml_request(struct_param,url_xml_rpc,iso_encoding,return_deadline);
        return false;
    }
    
    //controllo deadline
    if (ddl == null) {
        var dead = hotel_booking['agreements'][agreement]['deadline'];
        var deadline = format_timestamp(hotel_booking['agreements'][agreement]['deadline'],js_language)
        var full = false;
        var policies = new Array();
        var comments = '';
    }
    else {
        if (typeof(ddl) == 'object') {
            var full = (ddl['full'] == undefined) ? false : ddl['full'];
            var policies = (ddl['policies'] == undefined) ? new Array() : ddl['policies'];
            var comments = (ddl['comments'] == undefined) ? '' : ddl['comments'];
            ddl = ddl['deadline'];
        }
        else {
            var full = false;
            var policies = new Array();
            var comments = '';
        }
        var dead = ddl;
        var deadline = format_timestamp(ddl,js_language);
    }
    global_deadline = deadline;
    global_full = full;
    global_policies = policies;
    global_comments = comments;
    
    if (openedhotel == '')
        var onclick = 'print_hotels(hotels);';
    else
        var onclick = 'print_hotel('+openedhotel+');';
    var backb = '<div id="back" style="font-weight: bold; color: #4b61ac; font-size: 16px; margin-top: 5px; text-align: center;">'
              + '<span style="cursor: pointer;" onClick="'+onclick+'">Back</span>'
              + '</div>';
	var intest = backb;
	document.getElementById('book_confirm').innerHTML!=''

    // Bottoni
	var button_bar = '<div class="align_center" style="margin-top: 5px;"><input type="button" class="button" value="'+js_dic_CONFIRM+'" onClick="if(remarks_check() && check_book()) get_book_confirm();" /></div>';
    
    //var termsdata='<div class="iframe">'+decode_e_h(termsandconditions)+'</div>'
    //             +'<div>'+js_dic_CONDITIONSACCEPT+'&nbsp;<input type="checkbox" id="check_conditions">'
    //             +'<span  id="inv_ast_check_conditions"></span></div>';
    var clink = 'http://www.italiaonline.travel/?page=voorwaarden';
    var termsdata='<a href="'+clink+'" style="font-size: 14px;" target="_blank">'+js_dic_CLICKHERETOREADTERMS+'</a>'
                 +'<div>'+js_dic_CONDITIONSACCEPT+'&nbsp;<input type="checkbox" id="check_conditions">'
                 +'<span  id="inv_ast_check_conditions"></span></div>';
	var terms = '<div class="availbg availbr">'
              + '<div class="form_title">'+ js_dic_OPERATINGPROCEDURES.toUpperCase()+ '</div>'
              + '<div class="form_box">'+termsdata+button_bar+'</div>'
              + '</div>';
	
	var resfor = '<span class="underline">'+capitalize(hotel_booking['name'])+'</span>, '+capitalize(global_city_name)+' ('+capitalize(global_country_name)+')';
	var fields = '<table cellpadding="0" cellspacing="0" width="100%">';
    
    // Scorro i prezzi per capire che stanze ci sono
	var rooms = hotel_booking['agreements'][agreement]['rooms'];
	
	var num_rooms=0;
	fields += '<tr class="text_bold">'
            + '<td>'+js_dic_ROOMTYPE+'</td>'
            + '<td style="width:240px">'+js_dic_TITLE+', '+js_dic_SURNAME+', '+js_dic_INITIAL+'</td>'
            + '<td>'+js_dic_LEADER+'</td>'
            + '</tr>'
            + '<tr style="height: 5px;"><td></td></tr>';
	var rooms_list = '';
	var row_class ='div_on';
	var temp_services = services;
	var found = 0;
	// variabile per messaggio extra e cot
	var extraandcot='';
	for(var room in rooms) {
        var num_room = 	rooms[room]['num'];
        rooms_list += num_room+' '+eval('js_dic_'+rooms[room]['type'])+' ';
        for(var r = 1; r <= num_room; r++)
        {	
            //if(row_class=='div_on') row_class='div_over';
            //else row_class='div_on';
            num_rooms++;
            var num_pax = eval('js_global_occupancy_'+rooms[room]['type']);
            var paxs = '';
            var room_desc = eval('js_dic_'+rooms[room]['type']);
            
            if(rooms[room]['cot'])   // cot       
            room_desc += ' + '+js_dic_COT;
            // Se ho un extrabed o una culla comunico che si va su richiesta
            if((rooms[room]['extrabed'] || rooms[room]['cot']) && hotel_booking['agreements'][agreement]['available'] != 'False') 
            {
                room_desc += ' *';
                extraandcot = '<div >*'+js_dic_EXTRAANDCOT+'</div>';
            }
                        
            for(var o=1; o<=num_pax; o++) {
                var surname = '';
                var initial = '';
                for(i in temp_services) {
                    for(j in temp_services[i]['accommodation']) {
                        if(temp_services[i]['accommodation'][j]['type'] == rooms[room]['type'] && temp_services[i]['accommodation'][j]['paxes'][o-1]['surname'] != '' && temp_services[i]['accommodation'][j]['paxes'][o-1]['initial'] != '') {
                            surname = temp_services[i]['accommodation'][j]['paxes'][o-1]['surname'];
                            initial = temp_services[i]['accommodation'][j]['paxes'][o-1]['initial'];
                            if(temp_services[i]['accommodation'][j]['paxes'][o-1]['title'] == 'MR') var options ='<option value="MR" selected>MR'; else var options ='<option value="MR">MR';
                            if(temp_services[i]['accommodation'][j]['paxes'][o-1]['title'] == 'MS') options = options+'<option value="MS" selected>MS'; else options = options+'<option value="MS">MS';
                            if(temp_services[i]['accommodation'][j]['paxes'][o-1]['title'] == 'MRS') options = options+'<option value="MRS" selected>MRS'; else options = options+'<option value="MRS">MRS';
                            temp_services[i]['accommodation'][j]['paxes'][o-1]['surname'] = '';
                            temp_services[i]['accommodation'][j]['paxes'][o-1]['initial'] = '';
                            temp_services[i]['accommodation'][j]['paxes'][o-1]['title'] = '';
                            found = 1;
                            break;
                        }
                        else {
                            var options ='<option value="MR">MR<option value="MS">MS<option value="MRS">MRS';
                            found = 0;
                        }
                    }
                    if(found == 1) break;
                }
                var field_nome=rooms[room]['type']+'_'+num_rooms+'_'+o;
                var field_titolo='tit_'+field_nome;
                var field_iniziale='ini_'+field_nome;
                var options ='<option value="MR">MR<option value="MS">MS<option value="MRS">MRS';
                var select = '<select name="'+field_titolo+'" id="'+field_titolo+'">'+options+'</select>';
                   
                if(o==1 && num_rooms==1) var checked='checked';
                else var checked='';
                fields += '<tr class="'+row_class+'">'+
                          '<td class="text_bold">'+room_desc+'</td>'+
                          '<td>'+select+' <input type="text" id="'+field_nome+'" name="'+field_nome+'" size="12" value="'+surname+'"><span  id="ast_'+field_nome+'"></span>&nbsp;<input type="text" name="'+field_iniziale+'" id="'+field_iniziale+'" size="1" maxlength="1" value="'+initial+'"><span  id="ast_'+field_iniziale+'"></span></td><td><input  '+checked+'  name="leader" id="leader_'+field_nome+'" value="'+field_nome+'" type="radio" style="border:0px"></td>'+
                          '</tr>';
                room_desc=''; //la stampo solo al primo pax
            }
            if(rooms[room]['extrabed'])   // extrabed       
            {
                for (var ex = 1; ex <= rooms[room]['extrabed'].length; ex++) {
                     var extra_nome=room+'_'+num_rooms+'_extra_'+ex;
                     var extra_titolo='tit_'+extra_nome;
                     var extra_iniziale='ini_'+extra_nome;	
                     var select = '<select name="'+extra_titolo+'" id="'+extra_titolo+'">'+options+'</select>';
                     fields += '<tr class="'+row_class+'">'+
                               '<td></td><td>'+select+' <input type="text" id="'+extra_nome+'" name="'+extra_nome+'" size="12" maxlength="12" value=""><span  id="ast_'+extra_nome+'"></span>&nbsp;<input type="text" name="'+extra_iniziale+'" id="'+extra_iniziale+'" size="1" maxlength="1" value=""> - '+js_dic_EXTRABED+' ('+js_dic_AGECHILD+': '+rooms[room]['extrabed'][ex - 1]+')<span  id="ast_'+extra_iniziale+'"></span></td><td></td>'+
                               '</tr>';	
                }
            }
        }
	 }
      	
	fields += '</table>'+extraandcot;
	var datipren = '<div class="availbr availbg" style="margin-top: 10px;">'
                 + '<div class="form_title">'+js_dic_RESDATA.toUpperCase()+'</div>'
                 + '<div class="form_box">' + fields + '</div>'
                 + '</div>';
	
    var tologin = '<span id="show_login" onClick="document.getElementById(\'contact_table\').style.display=\'none\';'
                                               +'document.getElementById(\'show_login\').style.display=\'none\';'
                                               +'document.getElementById(\'show_contact\').style.display=\'inline\';'
                                               +'document.getElementById(\'check_register_div\').style.display=\'none\';'
                                               +'document.getElementById(\'login_table\').style.display=\'block\';" '
                  +'class="text_bold cursor_pointer">'+js_dic_AREUREGISTERED+'</span>';
                  
    var tocontact = '<span id="show_contact" onClick="document.getElementById(\'contact_table\').style.display=\'block\';'
                                                 +'document.getElementById(\'show_login\').style.display=\'inline\';'
                                                 +'document.getElementById(\'show_contact\').style.display=\'none\';'
                                                 +'document.getElementById(\'check_register_div\').style.display=\'block\';'
                                                 +'document.getElementById(\'login_table\').style.display=\'none\';" '
                  +'class="text_bold cursor_pointer hidden">'+js_dic_AREUNOTREGISTERED+'</span>';
    
	// Dati del Contatto
    if (loggedin == true || document.getElementById('user')) var style='style="display: none;"';
    else style='';
	var fields_contact='<div '+style+'>* '+js_dic_COMPULSORY+'</div><table id="contact_table" border="0" cellpadding="3" cellspacing="0" '+style+'>'
		+'<tr>'
		+'<td>'+js_dic_TITLE+'<span>*</span> : </td>'
		+'<td>'
		+'<select id="contact_title" name="contact_title">'+options+'</select>'
		+'</td>'
        +'<td>&nbsp;</td>'
        //+'<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u>'+tologin+'</u></td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_name+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="contact_name" name="contact_name" type="text"><span  id="ast__contact_name"></span>'
		+'</td>'
		+'</tr>'
		+'<tr >'
		+'<td>'+js_dic_SURNAME+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="contact_surname"  name="contact_surname" type="text"><span  id="ast__contact_surname"></span>'
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_telephone+'<span>*</span> : </td>'
		+'<td>'
		+'<input  id="contact_telefone" name="contact_telefone" type="text"><span  id="ast__contact_telefone"></span>'
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_mobile+' : </td>'
		+'<td>'
		+'<input  id="contact_mobile" name="contact_mobile" type="text">'
		+'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td height="15">'+js_dic_fax+' : </td>'
		+'<td>'
		+'<input id="contact_fax" name="contact_fax" type="text">'
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_email+'<span>*</span> :</td>'
		+'<td>'
		+'<input  id="contact_email" name="contact_email" onselectstart="return false;" onselect="x = this.value; this.value = \'\'; this.value = x;" type="text"><span  id="ast__contact_email"></span>'
		+'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td>'+js_dic_REPEAT+' '+js_dic_email+'<span>*</span> :</td>'
		+'<td>'
		+'<input id="contact_email_repeat" name="contact_email_repeat" onselectstart="return false;" onselect="x = this.value; this.value = \'\'; this.value = x;" type="text"><span  id="ast__contact_email_repeat"></span>'
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_address+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="contact_address" name="contact_address" type="text"><span  id="ast__contact_address"></span>'
		+'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td height="18">'+js_dic_city+'<span>*</span> :</td>'
		+'<td>'
		+'<input id="contact_city" name="contact_city" type="text"><span  id="ast__contact_city"></span>'
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_zip+'<span>*</span> :</td>'
		+'<td>'
		+'<input  id="contact_zip" name="contact_zip" size="10" maxlength="10" type="text"><span  id="ast__contact_zip"></span>'
		+'</td>'
		+'</tr>'		
		+'<tr class="div_on">'
		+'<td>'+js_dic_country+'<span>*</span> :</td>'
		+'<td>'
		+'<select id="contact_country" name="contact_country">'
        +'<option value="***">- '+js_dic_SELECTCOUNTRY+' -</option>';
    for (var code in countries_list)
        fields_contact += '<option value="'+code+'">'+countries_list[code]+'</option>';
    fields_contact += '</select><span  id="inv_ast_contact_country"></span>'
		+'</td>'
		+'</tr>'
		+'</table>';
    if (loggedin == true) {
        var login = '<div id="login_table">'
                   +'<input id="contact_login" name="contact_login" type="hidden" value="'+useremail+'">'
                   +'<input id="contact_password" name="contact_password" type="hidden" value="'+userpassword+'">'
                   +'</div>';
    }
    else if (document.getElementById('user')) {
        var udatas = document.getElementById('user').value.split('||');
        var login = '<div id="login_table">'
                   +'<input id="contact_login" name="contact_login" type="hidden" value="'+udatas[0]+'">'
                   +'<input id="contact_password" name="contact_password" type="hidden" value="'+udatas[1]+'">'
                   +'</div>';
    }
    else {
        var login = '<table id="login_table" border="0" cellpadding="3" cellspacing="0" style="display: none;">'
            +'<tr>'
            +'<td>'+js_dic_email+'<span>*</span> : </td>'
            +'<td>'
            +'<input id="contact_login" name="contact_login" type="text"><span  id="ast__contact_login"></span>'
            +'</td>'
            +'<td class="div_on">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u>'+tocontact+'</u></td>'
            +'</tr>'
            +'<tr>'
            +'<td>'+js_dic_password+'<span>*</span> : </td>'
            +'<td>'
            +'<input id="contact_password"  name="contact_password" type="password"><span  id="ast__contact_password"></span>'
            +'</td>'
            +'</tr>'
            +'</table>';
    }
        
    if (true || loggedin == true || document.getElementById('user')) var style='style="display: none;"';
    else style='';
    var wishregister = '<div id="check_register_div" '+style+'>'+js_dic_WISHREGISTER+'&nbsp;'
        +'<input type="checkbox" id="check_register" name="check_register" checked></div>'
        
    var needinvoice = js_dic_WISHINVOICE+'&nbsp;'
        +'<input type="checkbox" id="check_invoice" name="check_invoice" onclick="display_invoice(this.checked);">';
    if (document.getElementById('user')) // se sono manager posso decidere se pagare o no con carta
    {
    	userchosed = '<div class="text_bold">'+document.getElementById('user').options[document.getElementById('user').selectedIndex].text+'</div>';
        var needcc = js_dic_PAYMENTCC+'&nbsp;'
        +'<input type="checkbox" id="check_cc" name="check_cc" checked>';
    }
    else
        var needcc='';

    var invoice = '<div id="contact_invoice" class="availbg availbr" style="display: none;">'
        +'<div class="form_title">'+js_dic_INVOICEDATES.toUpperCase()+'</div>'
        +'<div class="form_box">'
        +'<table border="0" cellpadding="3" cellspacing="0">'
		+'<tr>'
		+'<td>'+js_dic_CAPTION+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="invoice_caption" name="invoice_caption" type="text"><span  id="inv_ast_invoice_caption"></span>'
		+'</td>'
		+'</tr>'
        +'<tr>'
		+'<td>'+js_dic_address+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="invoice_address" name="invoice_address" type="text"><span  id="inv_ast_invoice_address"></span>'
		+'</td>'
		+'</tr>'
        +'<tr>'
		+'<td>'+js_dic_city+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="invoice_city" name="invoice_city" type="text"><span  id="inv_ast_invoice_city"></span>'
		+'</td>'
		+'</tr>'
        +'<tr>'
		+'<td>'+js_dic_zip+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="invoice_zip" name="invoice_zip" type="text"><span  id="inv_ast_invoice_zip"></span>'
		+'</td>'
		+'</tr>'
        +'<tr>'
		+'<td>'+js_dic_CFPI+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="invoice_cf" name="invoice_cf" type="text"><span  id="inv_ast_invoice_cf"></span>'
		+'</td>'
		+'</tr>'
        +'</table>'
        +'</div>'
        +'</div>';
	
	var daticontact = '<div class="availbg availbr">'
                    + '<div class="form_title">'+js_dic_CONTDATA.toUpperCase()+'</div>'
                    + '<div class="form_box">' + fields_contact+login+wishregister+userchosed+needinvoice+needcc + '</div>'
                    + '</div>'+invoice;
	// Sistemazione
	var accommodation = '<table cellpadding="3" cellspacing="0" width="99%">';
    accommodation += '<tr><td style="vertical-align: top; width: 100%;"><table cellpadding="3" cellspacing="0" width="100%">';
	accommodation += '<tr><td class="text_bold">'+js_dic_HOTEL+'</td><td>'+resfor+'</td><tr>';
	accommodation += '<tr><td class="text_bold">'+js_dic_HTLCAT+'</td><td>'+hotel_booking['classification']+'</td></tr>';
	accommodation += '<tr><td class="text_bold">'+js_dic_DAYFROM+'</td><td>'+global_from+'</td></tr>';
	accommodation += '<tr><td class="text_bold">'+js_dic_DAYTO+'</td><td>'+global_to+'</td></tr>';
	accommodation += '<tr><td class="text_bold">'+js_dic_NIGHTS+'</td><td>'+global_nights+'</td></tr>';
	accommodation += '<tr><td class="text_bold">'+js_dic_ROOMS+'</td><td>'+rooms_list+'</td></tr>';
    //accommodation += '<tr><td class="text_bold"><div style="margin-top: 10px;">'+js_dic_TOTALPRICE+'</div></td><td class="text_bold"><div style="margin-top: 10px; text-decoration: line-through;">'+format_price(hotel_booking['agreements'][agreement]['total'],js_language)+' '+ currency +'</div></td></tr>';
	accommodation += '<tr><td class="text_bold"><div style="margin-top: 10px;">'+js_dic_TOTALPRICE+'</div></td><td class="text_bold"><div style="margin-top: 10px;">'+format_price(hotel_booking['agreements'][agreement]['total'],js_language)+' '+ currency +'</div></td></tr>';
    if (document.getElementById('eurovalue_'+agreement))
        	accommodation += '<tr class="text_bold"><td>'+js_dic_EUROTOTAL+'*</td><td>'+format_price(document.getElementById('eurovalue_'+agreement).value,js_language)+' EUR<input type="hidden" value="'+document.getElementById('eurovalue_'+agreement).value+'" id="eurovalue_book"></td></tr>';
    accommodation += '</table></td>';
    accommodation += '<td style="text-align: right; vertical-align: top;">';
    if (document.getElementById('photo_'+hotel_code))
        accommodation += '<img height="90px" width="90px" class="border_photo" title="'+hotel_booking['name']+'" alt="'+hotel_booking['name']+'" src="'+document.getElementById('photo_'+hotel_code).value+'">';
    accommodation += '</td>';
    accommodation += '</tr>';
	accommodation += '</table>';
	datisis = '<div class="availbg availbr">'
            + '<div class="form_title">'+js_dic_ACCOMMODATION.toUpperCase()+'</div>'
            + '<div class="form_box">'+accommodation+'</div>'
            + '<div class="form_title">'+js_dic_ATTENTION+': '+js_dic_CANCELLATIONDEADLINE+' '+global_deadline+'</div>';
    //garanzia
    var war = '<div class="availbg availbr" style="margin-top: 10px;">'
            + '<div class="form_title">'+js_dic_INSURANCE.toUpperCase()+'</div>'
            + '<div class="form_box">'
	    + '<input type="radio" name="insurance" id="noins" checked> '+js_dic_NOINSURANCE
	    + '<br><input type="radio" name="insurance" id="baseins"> '+js_dic_CANCELLATION+': ' + format_price(hotel_booking['agreements'][agreement]['basewarranty'],js_language) + ' ' + currency
            + '<br><input type="radio" name="insurance" id="insurance"> '+js_dic_CANCANDAS+': ' + format_price(hotel_booking['agreements'][agreement]['warranty'],js_language) + ' ' + currency
            + '</div>'
            + '</div>';
    // Su richiesta
	if(hotel_booking['agreements'][agreement]['available'] == 'False')
		datisis += '<div class="form_title" style="height: auto; text-align: justify;">'+js_dic_ATTENTION+': '+js_dic_ONREQUESTMSG+'</div>';
    datisis += '</div>';
            
	var remarks ='';	
    
    var form = '<form id="booking_form">'+intest+datisis+war+datipren+daticontact+remarks+terms+'</form>';
    document.getElementById('book').innerHTML = form;
    document.getElementById('book').style.display='block';
    document.getElementById('loading').style.display='none';
    // div dei contenuti
    if(document.getElementById('city_content')) document.getElementById('city_content').style.display='none';
    if(document.getElementById('country_content')) document.getElementById('country_content').style.display='none';
    
	form_obj = document.getElementById('booking_form');
	div_form = document.getElementById('book');
    document.body.style.display='none';
    window.location = '#';
	document.body.style.display='block';
}

function display_invoice(chk) {
    if (chk == true)
        document.getElementById('contact_invoice').style.display = 'block';
    else
        document.getElementById('contact_invoice').style.display = 'none';
}

function add_remarks()	{
	document.getElementById('remarks').style.display='block';
	document.getElementById('remarks_link').style.display='none';
	document.getElementById('book').style.display='none';
	document.getElementById('book').style.display='block';
}

function hide_remarks()	{
	document.getElementById('remarks').style.display='none';
	document.getElementById('remarks_link').style.display='block';
	document.getElementById('book').style.display='none';
	document.getElementById('book').style.display='block';
}

function check_book() {
    reset_asterisk();
    hide_error();
    if (loggedin == false && !document.getElementById('user')) {
        document.getElementById('ast__contact_login').innerHTML = '';
        document.getElementById('ast__contact_password').innerHTML = '';
        document.getElementById('inv_ast_contact_country').innerHTML = '';
        document.getElementById('inv_ast_check_conditions').innerHTML = '';
        var fieldset = document.getElementById('contact_table');
        var fields = fieldset.getElementsByTagName('span');
        for (var i = 0; i < fields.length; i++) {
            if (fields[i].id.indexOf('ast__') >= 0)
                fields[i].innerHTML = '';
        }
        var fieldset = document.getElementById('contact_invoice');
        var fields = fieldset.getElementsByTagName('span');
        for (var i = 0; i < fields.length; i++) {
            if (fields[i].id.indexOf('inv_ast_') >= 0)
                fields[i].innerHTML = '';
        }
    }
    if (field_control('','nourl') == false)
        return false;
    if (document.getElementById('contact_table').style.display != 'none') {
        var fieldset_contact = document.getElementById('contact_table');
        var fields = fieldset_contact.getElementsByTagName('input');
        for (var i = 0; i < fields.length; i++) {
            if (fields[i].value == '' && document.getElementById('ast__'+fields[i].id)) {
                div_form.style.display = 'block';
                div_loading.style.display = 'none';
                document.getElementById('ast__'+fields[i].id).innerHTML = '*';
                print_error(js_dic_NOALLFIELDS,'ast__'+fields[i].id);
                return false;
            }
            if (fields[i].id.indexOf('mail')>=0 && !emailControl(fields[i].value)) {
                div_form.style.display = 'block';
                div_loading.style.display = 'none';
                document.getElementById('ast__'+fields[i].id).innerHTML = '*';
                print_error(js_dic_NOALLFIELDS,'ast__'+fields[i].id);
                return false;
            }
        }
        if (document.getElementById('contact_country').value == '***') {
            div_form.style.display = 'block';
            div_loading.style.display = 'none';
            document.getElementById('inv_ast_contact_country').innerHTML = '*';
            print_error(js_dic_NOALLFIELDS,'inv_ast_contact_country');
            return false;
        }
        var email = document.getElementById('contact_email').value;
        var repeat = document.getElementById('contact_email_repeat').value;
        if (email != repeat) {
            div_form.style.display = 'block';
            div_loading.style.display = 'none';
            document.getElementById('ast__contact_email').innerHTML = '*';
            document.getElementById('ast__contact_email_repeat').innerHTML = '*';
            print_error(js_dic_MAILERROR,'ast__contact_email');
            return false;
        }
    }
    else {
        if (document.getElementById('contact_login').value == '') {
            div_form.style.display = 'block';
            div_loading.style.display = 'none';
            document.getElementById('ast__contact_login').innerHTML = '*';
            print_error(js_dic_NOALLFIELDS,'ast__contact_login');
            return false;
        }
        if (document.getElementById('contact_password').value == '') {
            document.getElementById('ast__contact_password').innerHTML = '*';
            div_form.style.display = 'block';
            div_loading.style.display = 'none';
            print_error(js_dic_NOALLFIELDS,'ast__contact_password');
            return false;
        }
    }
    if (document.getElementById('check_invoice').checked) {
        var fieldset = document.getElementById('contact_invoice');
        var fields = fieldset.getElementsByTagName('input');
        for (var i = 0; i < fields.length; i++) {
            if (fields[i].value == '') {
                div_form.style.display = 'block';
                div_loading.style.display = 'none';
                document.getElementById('inv_ast_'+fields[i].id).innerHTML = '*';
                print_error(js_dic_NOALLFIELDS,'inv_ast_'+fields[i].id);
                return false;
            }
        }
    }
    if (document.getElementById('check_conditions').checked == false) {
        div_form.style.display = 'block';
        div_loading.style.display = 'none';
        document.getElementById('inv_ast_check_conditions').innerHTML = '*';
        print_error(js_dic_CONDITIONSERROR,'inv_ast_check_conditions');
        return false;
    }
    return true;
}

function get_book_confirm() {
    document.getElementById('loading').style.display = 'block';
    document.getElementById('book').style.display = 'none';
    if (document.getElementById('login_table').style.display != 'none') {
        struct_p = new Array();
        struct_p['header'] = new Array();
        struct_p['query'] = new Array();
        struct_p['header']['version'] = '1.0.0';
        struct_p['header']['product'] = 'buymanager';
        struct_p['header']['type'] = 'buy_login';
        struct_p['query']['user'] = document.getElementById('contact_login').value;
        struct_p['query']['password'] = document.getElementById('contact_password').value;
        struct_p['query']['get'] = true;
        xml_request(struct_p,url_xml_rpc,iso_encoding,callback_xml_function);
    }
    else
        book_confirm();
}

function book_confirm()	{
    openedconfig = true;
	var elt = document.getElementById('book_confirm');
	hide_error();
	// Back and forward
    var backb = '<div style="font-weight: bold; color: #4b61ac; font-size: 16px; margin-top: 5px; text-align: center;">'
              + '<span style="cursor: pointer;" onClick="show_book(false);">Back</span>'
              + '</div>';
	var intest = backb;
    var fields = '<table cellpadding="0" cellspacing="0" width="99%">';

	fields += '<tr class="text_bold">'
            + '<td>'+js_dic_ROOMTYPE+'</td>'
            + '<td style="width:240px">'+js_dic_TITLE+', '+js_dic_SURNAME+', '+js_dic_INITIAL+'</td>'
            + '<td>&nbsp;</td>'
            + '</tr>'
            + '<tr style="height: 5px;"><td></td></tr>';
            
	var rooms = hotel_booking['agreements'][global_agreement]['rooms'];
	var num_rooms=0;

	var rooms_list = '';
	var row_class ='div_over';
	// variabile per messaggio extra e cot
	var extraandcot='';
	for(var room in rooms) 
      	 {
		var num_room = 	rooms[room]['num'];
      	 	rooms_list += num_room+' '+eval('js_dic_'+rooms[room]['type'])+' ';
      	 	for(var r = 1; r <= num_room; r++)
      	 	{	// Dati per il booking
			var ap_rooming = new Array();
      	 		ap_rooming['type'] = rooms[room]['type'];
      	 		ap_rooming['paxes'] = new Array();
      	 		num_rooms++;
      	 		var num_pax = eval('js_global_occupancy_'+rooms[room]['type']);
      	 		var paxs = '';
      	 		var room_desc = eval('js_dic_'+rooms[room]['type']);
      	 		if(rooms[room]['cot'])   // cot       
				{room_desc += ' + '+js_dic_COT;
				 ap_rooming['cot'] = true;
				}
			// Se ho un extrabed o una culla comunico che si va su richiesta
			if((rooms[room]['extrabed'] || rooms[room]['cot']) && hotel_booking['agreements'][global_agreement]['available'] != 'False') 
				{
					room_desc += ' *';
					extraandcot = '<div >*'+js_dic_EXTRAANDCOT+'</div>';
				}
      	 		fields += '<tr class="div_on"><td class="text_bold">'+room_desc+'</td>';
      	 		for(var o=1; o<=num_pax; o++)
      	 		{
      	 			var field_nome=rooms[room]['type']+'_'+num_rooms+'_'+o;
				var field_titolo='tit_'+field_nome;
				var field_iniziale='ini_'+field_nome;
				
				var ap_paxes = new Array();
				if(document.getElementById('leader_'+field_nome) && document.getElementById('leader_'+field_nome).checked) {var isleader=js_dic_LEADER; ap_paxes['leader']=true;}
				else	var isleader='';
                if (o != 1)
                    fields += '<tr><td>&nbsp;</td>';
				fields +='<td >'+document.getElementById(field_titolo).value+'&nbsp;'+document.getElementById(field_nome).value+'&nbsp;'+document.getElementById(field_iniziale).value+'.</td><td>'+isleader+'</td>'+
				         '</tr>';
				
				ap_paxes['title'] = document.getElementById(field_titolo).value;
				ap_paxes['surname'] = document.getElementById(field_nome).value;
				ap_paxes['initial'] = document.getElementById(field_iniziale).value;
				ap_rooming['paxes'][ap_rooming['paxes'].length]=ap_paxes;
      	 		}
			if(rooms[room]['extrabed'])   {
                for (var ex = 1; ex <= rooms[room]['extrabed'].length; ex++) {
                ap_rooming['extrabed'] = true;
      	 		 var extra_nome=room+'_'+num_rooms+'_extra_' + ex;
      	 		 var extra_titolo='tit_'+extra_nome;
                 var extra_iniziale='ini_'+extra_nome;
                 fields += '<tr>'+
                            '<td>&nbsp;</td>' +
                              '<td >'+document.getElementById(extra_titolo).value+'&nbsp;'+document.getElementById(extra_nome).value+'&nbsp;'+document.getElementById(extra_iniziale).value+'. - '+js_dic_EXTRABED+' ('+js_dic_AGECHILD+': '+rooms[room]['extrabed'][ex - 1]+')</td><td></td>'+
                              '</tr>';
			 
                 var ap_paxes = new Array();
                 ap_paxes['title'] = document.getElementById(extra_titolo).value;
                 ap_paxes['surname'] = document.getElementById(extra_nome).value;
                 ap_paxes['initial'] = document.getElementById(extra_iniziale).value;	          
                 ap_paxes['age'] = Number(rooms[room]['extrabed'][ex - 1]);
                 ap_rooming['paxes'][ap_rooming['paxes'].length]=ap_paxes;
                }
			
			}	   
			global_rooming_list[num_rooms] = ap_rooming;
      	 	}
      	 	
      	 	
	 }
	
	fields += '</table>'+extraandcot;
    
	var datipren = '<div class="availbr availbg" style="margin-top: 10px;">'
                 + '<div class="form_title">'+js_dic_RESDATA.toUpperCase()+'</div>'
                 + '<div class="form_box">' + fields + '</div>'
                 + '</div>';
    
    // Dati del Contatto 
	var fields_contact='<div class="availbg availbr">'
        +'<div class="form_title">'+js_dic_CONTDATA.toUpperCase()+'</div>'
        +'<div class="form_box">'
        +'<table border="0" cellpadding="3" cellspacing="0">'
		+'<tr>'
		+'<td>'+js_dic_TITLE+' : </td>'
		+'<td>'
		+document.getElementById('contact_title').value
		+'</td>'
        +'<td rowspan="11" class="valign_top align_justify availbg" style="width: 30%; padding: 20px;">'
        +js_dic_BOOKINGEND
        +'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td>'+js_dic_name+' : </td>'
		+'<td>'
		+document.getElementById('contact_name').value
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_SURNAME+' : </td>'
		+'<td>'
		+document.getElementById('contact_surname').value
		+'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td>'+js_dic_telephone+' : </td>'
		+'<td>'
		+document.getElementById('contact_telefone').value
		+'</td>'
		+'</tr>'
        +'<tr>'
        +'<td>'+js_dic_mobile+' : </td>'
        +'<td>';
    if (document.getElementById('contact_mobile').value == '')
        fields_contact += 'n/a';
    else
        fields_contact += document.getElementById('contact_mobile').value;
    fields_contact +='</td>'
        +'</tr>'
        +'<tr class="div_on">'
        +'<td height="15">'+js_dic_fax+' : </td>'
        +'<td>';
    if (document.getElementById('contact_fax').value == '')
        fields_contact += 'n/a';
    else
        fields_contact += document.getElementById('contact_fax').value;
    fields_contact +='</td>'
        +'</tr>'
        +'<tr>'
		+'<td>'+js_dic_email+' : </td>'
		+'<td>'
        +document.getElementById('contact_email').value
		+'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td>'+js_dic_address+' : </td>'
		+'<td>'
		+document.getElementById('contact_address').value
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td height="18">'+js_dic_city+' :</td>'
		+'<td>'
		+document.getElementById('contact_city').value
		+'</td>'
		+'</tr>'
		+'<tr class="div_on">'
		+'<td>'+js_dic_zip+' :</td>'
		+'<td>'
		+document.getElementById('contact_zip').value
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_country+' :</td>'
		+'<td>'
		+document.getElementById('contact_country').options[document.getElementById('contact_country').selectedIndex].text
		+'</td>'
		+'</tr>'
		+'</table>'
        
    
    if (document.getElementById('check_invoice').checked)
        var invoice = '</div>'
            +'</div>'
            +'<div class="availbg availbr">'
            +'<div class="form_title">'+js_dic_INVOICEDATES.toUpperCase()+'</div>'
            +'<div class="form_box">'
            +'<table border="0" cellpadding="3" cellspacing="0">'
            +'<tr>'
            +'<td>'+js_dic_CAPTION+' : </td>'
            +'<td>'
            +document.getElementById('invoice_caption').value
            +'</td>'
            +'</tr>'
            +'<tr class="div_on">'
            +'<td>'+js_dic_address+' : </td>'
            +'<td>'
            +document.getElementById('invoice_address').value
            +'</td>'
            +'</tr>'
            +'<tr>'
            +'<td>'+js_dic_city+' : </td>'
            +'<td>'
            +document.getElementById('invoice_city').value
            +'</td>'
            +'</tr>'
            +'<tr class="div_on">'
            +'<td>'+js_dic_zip+' : </td>'
            +'<td>'
            +document.getElementById('invoice_zip').value
            +'</td>'
            +'</tr>'
            +'<tr>'
            +'<td>'+js_dic_CFPI+' : </td>'
            +'<td>'
            +document.getElementById('invoice_cf').value
            +'</td>'
            +'</tr>'
            +'</table>';
    else
        var invoice = '';
	
    //assicurazione
    var totadd = 0;
    if (document.getElementById('noins').checked) {
        var label = js_dic_NOINSURANCE;
    }
    else if (document.getElementById('baseins').checked) {
        var label = js_dic_CANCELLATION+': ' + format_price(hotel_booking['agreements'][global_agreement]['basewarranty'],js_language) + ' ' + currency;
        totadd = hotel_booking['agreements'][global_agreement]['basewarranty'];
    }
    else if (document.getElementById('insurance').checked) {
        var label = js_dic_CANCANDAS+': ' + format_price(hotel_booking['agreements'][global_agreement]['warranty'],js_language) + ' ' + currency;
        totadd = hotel_booking['agreements'][global_agreement]['warranty'];
    }
	var war = '<div class="availbg availbr" style="margin-top: 10px;">'
		+ '<div class="form_title">'+js_dic_INSURANCE.toUpperCase()+'</div>'
		+ '<div class="form_box">'
		+ label
		+ '</div>'
		+ '</div>';
    
    //prezzo totale
    var tot = hotel_booking['agreements'][global_agreement]['total'];
    tot += totadd;
    global_total = tot;
    var tottopay = '<div class="availbg availbr" style="margin-top: 10px;">'
                 + '<div class="form_title">TOTAL PRICE TO PAY</div>'
                 + '<div class="form_box" style="font-weight: bold; text-align: center; font-size: 14px;">'
                 + format_price(tot,js_language) + ' ' + currency
                 + '</div>'
                 + '</div>';
    
	if (document.getElementById('check_cc') && document.getElementById('check_cc').checked)
	var cc = '<div class="text_bold">'+js_dic_PAYMENTCC+': '+js_dic_YES+'<div>';
	else if(document.getElementById('check_cc'))
	var cc = '<div class="text_bold">'+js_dic_PAYMENTCC+': '+js_dic_NO+'<div>';
	else
	var cc = '';
	var remarks = '';
	
	// Bottoni
	var button_bar = '<div class="align_center" style="margin-top: 10px;"><input type="button" class="button" value="'+js_dic_CONFIRM+'" onClick="book_send();" /></div>';

	var form = '<form id="booking_form">'+intest+datisis+war+datipren+remarks+fields_contact+cc+invoice+tottopay+button_bar+'</div></div></form>';
	elt.innerHTML = form;
	div_loading.style.display='none';
	div_form.style.display='none';
	elt.style.display='block';
}

function show_book(fromlist)	{
    //document.getElementById('hf_summary').style.display='none';
    document.getElementById('listbuttons').style.display='none';
    document.getElementById('hotels').style.display='none';
    document.getElementById('hotel').style.display='none';
	document.getElementById('book_confirm').style.display='none';
	document.getElementById('book').style.display='block';
    if (openedhotel == '')
        var onc = 'print_hotels(hotels);';
	else
        var onc = 'print_hotel('+openedhotel+');';
    var backb = '<div style="font-weight: bold; color: #4b61ac; font-size: 16px; margin-top: 5px; text-align: center;">'
              + '<span style="cursor: pointer;" onClick="'+onc+'">Back</span>'
              + '</div>';
    document.getElementById('back').innerHTML = backb;
	//if (openedconfig == true) {
    //    var forward = '<input type="button" class="button forward" onClick="show_book_confirm()" onMouseOver="window.status=\' '+js_dic_FORWARD+'\'; return true;" onMouseOut="window.status=\'\'; return true;" value="'+js_dic_FORWARD+' ">';
	//    document.getElementById('back').innerHTML += forward;
    //}
	document.body.style.display='none';
	document.body.style.display='block';
}

function show_book_confirm()	{
	document.getElementById('book').style.display='none';
	document.getElementById('book_confirm').style.display='block';
	var backb = '<div style="font-weight: bold; color: #4b61ac; font-size: 16px; margin-top: 5px; text-align: center;">'
              + '<span style="cursor: pointer;" onClick="show_book(false);">Back</span>'
              + '</div>';
    document.getElementById('back').innerHTML = backb;
}

function remarks_check()	{
	return true;
}

function book_send()	{
    hide_error();
	struct_param['header']['type'] = 'hotel_adding';
    struct_param['header']['sessid'] = sessid;
	struct_param['query'] = new Array();
    //codice promozionale
    if (document.getElementById('promocode') && document.getElementById('promocode').value != '')
        struct_param['query']['promocode'] = document.getElementById('promocode').value;
	struct_param['query']['actor'] = global_client;
	struct_param['query']['hotel'] = hotel_booking['id'];
	struct_param['query']['agreement'] = global_agreement;
	struct_param['query']['configuration'] = new Array();
	struct_param['query']['configuration']['availability'] = global_availability; 
	struct_param['query']['configuration']['typeavailability'] = hotel_booking['agreements'][global_agreement]['available'];
	//struct_param['query']['configuration']['vivanights'] = hotel_booking['agreements'][global_agreement]['vivanights'];
    struct_param['query']['configuration']['language'] = js_language;
    struct_param['query']['configuration']['total'] = global_total;
    struct_param['query']['configuration']['pricerooms'] = hotel_booking['agreements'][global_agreement]['pricerooms'];
    if (document.getElementById('baseins').checked) {
        struct_param['query']['configuration']['basewarranty'] = hotel_booking['agreements'][global_agreement]['basewarranty'];
    }
    else if (document.getElementById('insurance').checked) {
        struct_param['query']['configuration']['warranty'] = hotel_booking['agreements'][global_agreement]['warranty'];
    }
    // Dati del contatto
	var contact = new Array();
    contact['title'] = document.getElementById('contact_title').value;
    contact['name'] = document.getElementById('contact_name').value;
    contact['surname'] = document.getElementById('contact_surname').value;
    contact['telephone'] = document.getElementById('contact_telefone').value;
    contact['mobile'] = document.getElementById('contact_mobile').value;
    contact['fax'] = document.getElementById('contact_fax').value;
    contact['email'] = document.getElementById('contact_email').value;
    contact['address'] = document.getElementById('contact_address').value;
    contact['city'] = document.getElementById('contact_city').value;
    contact['zip'] = document.getElementById('contact_zip').value;
    contact['country'] = document.getElementById('contact_country').value;
    contact['registration'] = document.getElementById('check_register').checked;
	struct_param['query']['configuration']['contact'] = contact;
    // Controllo se devo registrare l'utente
    if (document.getElementById('contact_table').style.display != 'none')
        struct_param['query']['register'] = true;
    else
        struct_param['query']['register'] = false;
	// Dati per la fattura
	if (document.getElementById('check_invoice').checked)
        {var invoice = new Array();
         invoice['caption'] = document.getElementById('invoice_caption').value
         invoice['address'] = document.getElementById('invoice_address').value
         invoice['city'] = document.getElementById('invoice_city').value
         invoice['zip'] = document.getElementById('invoice_zip').value
         invoice['cf'] = document.getElementById('invoice_cf').value
         struct_param['query']['configuration']['invoice'] = invoice;
        }  
	struct_param['query']['checkin'] = global_fromdate;
	struct_param['query']['checkout'] = global_todate;
	struct_param['query']['description'] = new Array();
	struct_param['query']['description']['cityname'] = global_city_name;
	struct_param['query']['description']['hotelname'] = hotel_booking['name'];
	struct_param['query']['description']['countryname'] = global_country_name;
	struct_param['query']['description']['total'] = global_total;
	struct_param['query']['description']['currency'] = currency;
	struct_param['query']['description']['arrangement'] = hotel_booking['agreements'][global_agreement]['room_basis'];
	struct_param['query']['description']['accommodation'] = hotel_booking['agreements'][global_agreement]['ctype'];
	struct_param['query']['description']['availability'] = hotel_booking['agreements'][global_agreement]['available'];
	if(hotel_booking['zone']) struct_param['query']['description']['zone'] = hotel_booking['zone'];
	// se voglio pagare senza carta di credito lo segnalo
	if (document.getElementById('check_cc') && !document.getElementById('check_cc').checked)
		struct_param['query']['description']['cc'] = false;
	else
		struct_param['query']['description']['cc'] = true;
	
	struct_param['query']['customerreference'] = '';
	struct_param['query']['accommodation'] = global_rooming_list;
	if (document.getElementById('eurovalue_book'))
        struct_param['query']['eurovalue'] = document.getElementById('eurovalue_book').value;
    else
        struct_param['query']['eurovalue'] = global_total;
	struct_param['query']['remarks'] = global_remarks_list;
	struct_param['query']['options'] = global_options_list;
	struct_param['query']['returnpoints'] = new Array();
	document.getElementById('loading').style.display='block';
	document.getElementById('book_confirm').style.display='none';
	xml_request(struct_param,url_xml_rpc,iso_encoding,book_close);
	
}

function book_close(response,type)	{
    if (response == 'ok')
        window.location = js_global_root_url+'cart.php';
    else if (response == 'directok')
        window.location = js_global_root_url+'bookings.php';
    else {
        document.getElementById('loading').style.display = 'none';
        document.getElementById('book_confirm').style.display = 'block';
        print_error('');
    }
}

function display_services(services) {
	document.getElementById('link_services').style.display = 'none';
	var content = '<table width="100%">';
	content = content+'<tr><td><b>'+js_dic_SERVICE+'</b></td>';
	content = content+'<td><b>'+js_dic_TYPE+'</b></td>';
	content = content+'<td><b>'+js_dic_LOCATION+'</b></td>';
	content = content+'<td><b>'+js_dic_DATES+'</b></td>';
	content = content+'<td><b>'+js_dic_DETAILS+'</b></td>';
	content = content+'<td><b>'+js_dic_PRICES+'</b></td></tr>';
	for(i in services) {
		content = content+'<tr><td><a href="'+js_global_root_url+'booking_manager/index.php?book_name='+services[i].name+'"><b>'+services[i].name+'</b></td>';
		content = content+'<td>'+services[i].type+'</td>';
		content = content+'<td>'+services[i].hotelname+', '+services[i].cityname+'</td>';
		content = content+'<td>'+services[i].checkin+' - '+services[i].checkout+'</td>';
		content = content+'<td>'+services[i].rooms+', '+services[i].paxes+'</td>';
		content = content+'<td>'+services[i].total+'</td></tr>';
	}
	content = content+'</table>';
	content = content+'<span onClick="hide_services();" style="cursor: pointer; font-weight: bold"><u>'+js_dic_HIDE_SERVICES+'</u></span>';
	document.getElementById('services').innerHTML = content;
	
}

function hide_services() {
	document.getElementById('link_services').style.display = 'block';
	document.getElementById('services').innerHTML = '';
}

// Apre la box del dettaglio dei remarks
function show_remarks(id,agreement)
{
 var text='';
 var intest = document.getElementById(id);
 var pos = findPos(intest);
 var elt = document.getElementById('remarks_box_'+agreement);
 elt.style.display='block';
 var delta = findPos(elt.offsetParent);
 elt.style.top = pos[1]-delta[1]+18;
 elt.style.left = pos[0]-delta[0];
}

// Nasconde la box dei remarks
function hide_remarks_h(agreement)
{ var elt = document.getElementById('remarks_box_'+agreement);
  elt.style.display='none';
}

function show_more_rooms()
{
	if(navigator.appName=='Netscape') var ap = 'table-row';
	else var ap = 'block';
	document.getElementById('show_more').style.display='none';
    document.getElementById('hide_more').style.display='block';
	document.getElementById('div_room_2').style.display=ap;
	document.getElementById('div_room_3').style.display=ap;
	document.getElementById('div_room_4').style.display=ap;
}

function hide_more_rooms()
{
	document.getElementById('hide_more').style.display='none';
    document.getElementById('show_more').style.display='block';
    document.getElementById('room_2').value='*';
	document.getElementById('room_3').value='*';
	document.getElementById('room_4').value='*';
	document.getElementById('div_room_2').style.display='none';
	document.getElementById('div_room_3').style.display='none';
	document.getElementById('div_room_4').style.display='none';
    updateStatus();
}

// mostra i dettagli dei servizi di un dossier
function open_services(dossier) {
	var rows = document.getElementsByTagName('tr');
	for (i = 0; i < rows.length; i++) {
		if(rows[i].getAttribute('id') && rows[i].getAttribute('id').match('services_'))
			rows[i].style.display = 'none';
	}
	
	document.getElementById('services_'+dossier).style.display = display_for_browser();
}

function show_voucher(id_book)
{
	url_xml_rpc = js_global_root_url+'xml_rpc/call.php';
	struct_param['header'] = new Array();
	struct_param['query'] = new Array();
	struct_param['header']['version'] = '1.0.0';
	struct_param['header']['product'] = 'bookingmanager_b2c';
	struct_param['header']['sessid'] = sessid;
	struct_param['query']['language'] = js_language;
	iso_encoding = 'utf-8';
	
	struct_param['header']['type'] = 'booking_voucher';
	struct_param['query']['filter_function'] = 'show_booking_voucher_b2c';
	struct_param['query']['name'] = id_book;
	
	var info = new Array();
	info['where'] = 'new_page';
	info['what'] = id_book;
	
	document.getElementById('voucher_button_'+id_book).style.display = 'none';
	document.getElementById('voucher_loading_'+id_book).style.display = 'inline';
	
	html_request(struct_param,url_xml_rpc,iso_encoding,callback_html_response,info);
}

function print_voucher(book_name)
{
	document.getElementById('print_button').disabled = true;
	document.getElementById('print_button').value = 'loading';
	
	url_xml_rpc = js_global_root_url+'xml_rpc/call.php';
	struct_param['header'] = new Array();
	struct_param['query'] = new Array();
	struct_param['header']['version'] = '1.0.0';
	struct_param['header']['product'] = 'bookingmanager';
	struct_param['header']['sessid'] = sessid;
	struct_param['query']['language'] = js_language;
	iso_encoding = 'utf-8';
	
	struct_param['header']['type'] = 'print_voucher';
	struct_param['query']['name'] = book_name;
	
	xml_request(struct_param,url_xml_rpc,iso_encoding,callback_xml_function);
}

function delete_booking(book_name)
{
	global_book_name = book_name;

	document.getElementById('cancel_button_'+book_name).style.display = 'none';
	document.getElementById('cancel_loading_'+book_name).style.display = 'inline';
	
	url_xml_rpc = js_global_root_url+'xml_rpc/call.php';
	struct_param['header'] = new Array();
	struct_param['query'] = new Array();
	struct_param['header']['version'] = '1.0.0';
	struct_param['header']['product'] = 'bookingmanager';
	struct_param['header']['sessid'] = sessid;
	struct_param['query']['language'] = js_language;
	iso_encoding = 'utf-8';
	
	struct_param['header']['type'] = 'delete_booking';
	struct_param['query']['name'] = book_name;

	xml_request(struct_param,url_xml_rpc,iso_encoding,callback_xml_function);	
}

function callback_html_response(response,info) {
	if(info['where'] == 'new_page') {
		book = info['what'];
		
		voucher = window.open("", "Voucher", 'height=500, width=700, menubar=yes, titlebar=no, toolbar=no, scrollbars=yes');
		voucher.document.write(response);
		voucher.document.close();
		
		document.getElementById('voucher_loading_'+book).style.display = 'none';
		document.getElementById('voucher_button_'+book).style.display = 'inline';
	}
}

function callback_xml_function(response,type) {
	switch(type)
	{
		case 'print_voucher':
			print_page();
			document.getElementById('print_button').value = 'print';
			document.getElementById('print_button').disabled = false;
		break;
		case 'delete_booking' :
		         // Chiudo la richiesta di inserimento o notifico un errore
		         if(response == 'error')
		         {
			  print_error(js_dic_ERRORTECHNICAL);
		          document.getElementById('cancel_button_'+global_book_name).style.display = 'inline';
			  document.getElementById('cancel_loading_'+global_book_name).style.display = 'none';
		         }
		         else if(response == 'failure')
		         {
			  print_error(js_dic_ERRORTECHNICAL);
		          document.getElementById('cancel_button_'+global_book_name).style.display = 'inline';
			  document.getElementById('cancel_loading_'+global_book_name).style.display = 'none';
		         }
		         else
		         { 
		          window.location = js_global_root_url+'bookings.php';
		         }
		break;
        case 'buy_login':
            if (typeof(response) == 'object') {
                document.getElementById('contact_title').value = response['configuration']['contact']['title'];
                document.getElementById('contact_name').value = response['configuration']['contact']['name'];
                document.getElementById('contact_surname').value = response['configuration']['contact']['surname'];
                document.getElementById('contact_telefone').value = response['configuration']['contact']['telephone'];
                document.getElementById('contact_mobile').value = response['configuration']['contact']['mobile'];
                document.getElementById('contact_fax').value = response['configuration']['contact']['fax'];
                document.getElementById('contact_email').value = response['email'];
                document.getElementById('contact_email_repeat').value = response['email'];
                document.getElementById('contact_address').value = response['configuration']['contact']['address'];
                document.getElementById('contact_city').value = response['configuration']['contact']['city'];
                document.getElementById('contact_zip').value = response['configuration']['contact']['zip'];
                document.getElementById('contact_country').value = response['configuration']['contact']['country'];
                book_confirm();
            }
            else {
                document.getElementById('ast__contact_login').innerHTML = '*';
                document.getElementById('ast__contact_password').innerHTML = '*';
                document.getElementById('book').style.display = 'block';
                document.getElementById('loading').style.display = 'none';
                print_error(js_dic_WRONGUSERPWD,'ast__contact_login');
            }
        break;
	}
}

function show_hotels_question() {
    selected_hotel = '';
    if (document.getElementById('hotel_fieldset')) {
        document.getElementById('hotel_fieldset').style.display = 'block';
    	document.getElementById('hotels_question').style.display = 'block';
        document.getElementById('hotel_select').style.display = 'none';
        document.getElementById('sel_hotel').innerHTML = '';
        document.getElementById('onlyavail').style.display = 'inline';
        document.getElementById('onlyavail_label').style.display = 'inline';
    }
}

function allcity_search() {
    selected_hotel = '';
    document.getElementById('hotel_id').value = '***';
    document.getElementById('hotels').style.display = 'none';
    document.getElementById('hotel').style.display = 'none';
    if(document.getElementById('onlyavail')) {
        if (!document.getElementById('introhotel'))
            document.getElementById('onlyavail').style.display = 'inline';
        if (document.getElementById('onlyavail_label'))
            document.getElementById('onlyavail_label').style.display = 'inline';
        if (document.getElementById('introhotel')) {
            if (document.getElementById('globalavailability'+hdetails).value == 'false')
                document.getElementById('onlyavail').checked = true;
            else
                document.getElementById('onlyavail').checked = false;
        }
        else
            document.getElementById('onlyavail').checked = false;
    }
    availability_search();
}

function onrequest_search() {
    document.getElementById('hotels').style.display = 'none';
    document.getElementById('onlyavail').checked = false;
    availability_search();
}

function close_service(service) {
    document.getElementById(service).style.display = 'none';
}

function set_onlyavail(val) {
    if (val == '***') {
        document.getElementById('onlyavail').style.display = 'inline';
        document.getElementById('onlyavail_label').style.display = 'inline';
    }
    else {
        document.getElementById('onlyavail').style.display = 'none';
        document.getElementById('onlyavail_label').style.display = 'none';
    }
}


function close_voucher()
{
	self.close();
}

function get_city_events(city,type) {
    document.getElementById('eventsdiv'+type).style.display = 'block';
    if (document.getElementById('eventsloading')) {
        struct_param['header']['type'] = 'get_city_events';
        struct_param['query'] = new Array();
        struct_param['query']['city'] = city;
        struct_param['query']['filter_function'] = 'show_events';
        var where = new Array();
        where[0] = type;
        where[1] = document.getElementById('eventscontent');
        html_request(struct_param,url_xml_rpc,iso_encoding,show_events,where);
    }
    else {
        if (document.getElementById('eventscontentdown'))
            document.getElementById('eventscontentdown').innerHTML = document.getElementById('eventscontent').innerHTML;
    }
}

function show_events(response,where) {
    where[1].innerHTML = response;
    if (where[0] == 'down' && document.getElementById('eventscontentdown'))
        document.getElementById('eventscontentdown').innerHTML = document.getElementById('eventscontent').innerHTML;
}

function check_vivacodes(hotel_code, agreement) {
    if (hotel_code != undefined) {
        global_hotel_code = hotel_code;
        global_agreement = agreement;
    }
    if (document.getElementById('seq_id_'+hotel_code))
        global_hotel_id = document.getElementById('seq_id_'+hotel_code).value;
    document.getElementById('hotels').style.display = 'none';
    document.getElementById('hotel').style.display = 'none';
    if (!vivacodes && document.getElementById('vcodesdiv').style.display == 'none') {
        document.getElementById('vcodesdiv').style.display = 'block';
        return;
    }
    document.getElementById('vcodesdiv').style.display = 'none';
    document.getElementById('vivacode_error').innerHTML = '';
    document.getElementById('loading').style.display = 'block';
    struct_param['header']['type'] = 'check_vivacodes';
    struct_param['query'] = new Array();
    if (!vivacodes) {
        struct_param['query']['cad'] = document.getElementById('vivacode_cad').value;
        struct_param['query']['pin'] = document.getElementById('vivacode_pin').value;
    }
	xml_request(struct_param, url_xml_rpc, iso_encoding, check_codes_result);
}

function check_codes_result(response, type) {
    if (response == 'ok') {
        vivacodes = true;
        book(global_hotel_code, global_agreement);
    }
    else {
        document.getElementById('loading').style.display = 'none';
        document.getElementById('vcodesdiv').style.display = 'block';
        document.getElementById('vivacode_error').innerHTML = 'Wrong codes!';
        vivacodes = false;
    }
}

function country_notes(country) {
	if (country == 'A') {
		document.getElementById('country_notes').innerHTML = js_dic_COANOTE;
		document.getElementById('country_notes').style.display = 'block';
	}
	else {
		document.getElementById('country_notes').style.display = 'none';
	}
}

