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 = 10;
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;

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['header']['dialect'] = 'json';
	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';
}

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;
}

function change_city(obj) {
	if (obj.value == '---')
		obj.options.selectedIndex += 1;
}

// Aggiorna lo staus del form
function updateStatus() {
    var elt = document.getElementById('hfs_content');
    var selCitta = document.getElementById('citta');
    if(!document.getElementById('citta')) return;
    else if(selCitta.options)
     var nomeCitta = selCitta.options[selCitta.selectedIndex].text;
    else
     {
      var city_radio_list = document.input_data.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 = document.getElementById('aa').value+'-'+document.getElementById('mma').value+'-'+document.getElementById('gga').value;
    var 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';
    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+'_1')) { 
            var numRoom =1;
        }
        if(selRoom != '*') {
            areThereRooms = true;
            paxes += numRoom * num_pax_room[selRoom];
            rC[selRoom] +=Number(numRoom);
                if(document.getElementById('eta'+i+'_1')) { 
                    ebeds += 1;
                }
                if(document.getElementById('eta'+i+'_2') && document.getElementById('eta'+i+'_2').value!='') { 
                    ebeds += 1;
                    paxes += 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';
    }
}

function layerWrite(layerName, layerText)
{ if(document.all)
    document.all[layerName].innerHTML = layerText;
  else
  { l = document.getElementById(layerName);
    l.innerHTML = layerText;
  }
}

function setNumRooms(num)
{ lName = 'num_' + num + '_div';
  lString = '<SELECT name="numeroStanze'+num+'" id="numeroStanze'+num+'" onChange="updateStatus();">';
  for (var i = 1; i <= 20; i++) {
  lString = lString + '<OPTION value="'+i+'">'+i+'</option>'; 
  }
  lString = lString + '</SELECT>';
  layerWrite(lName, lString);
}

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);
}

function noAskAge(num)
{ lName = 'eb_' + num + '_1';
  lString = '';
  layerWrite(lName, lString);
  lName = 'eb_' + num + '_2';
  lString = '';
  layerWrite(lName, lString);
}

function askAge(num) {
  lName = 'eb_' + num + '_1';
  lString = '<SELECT name="eta'+num+'" id="eta'+num+'_1" onChange="updateStatus();">';
  /*
  lString = lString + '<OPTION value="3"> 3'; 
  lString = lString + '<OPTION value="4"> 4';
  lString = lString + '<OPTION value="5"> 5'; 
  lString = lString + '<OPTION value="6"> 6'; 
  lString = lString + '<OPTION value="7"> 7'; 
  lString = lString + '<OPTION value="8"> 8'; 
  lString = lString + '<OPTION value="9"> 9'; 
  lString = lString + '<OPTION value="10"> 10'; 
  lString = lString + '<OPTION value="11"> 11'; 
  lString = lString + '<OPTION value="12"> 12'; 
  lString = lString + '<OPTION value="13"> 13'; 
  lString = lString + '<OPTION value="14"> 14';
  */
  for(var age=min_age; age<=max_age; age++) {
      lString = lString + '<OPTION value="'+age+'"> '+age+'</option>';
  }
  lString = lString + '</SELECT>';
  layerWrite(lName, lString);
  lName = 'eb_' + num + '_2';
  lString = '<SELECT name="eta'+num+'" id="eta'+num+'_2" onChange="updateStatus();">';
  lString += '<OPTION value=""> - </option>';
  /*
  lString = lString + '<OPTION value="3"> 3'; 
  lString = lString + '<OPTION value="4"> 4';
  lString = lString + '<OPTION value="5"> 5'; 
  lString = lString + '<OPTION value="6"> 6'; 
  lString = lString + '<OPTION value="7"> 7'; 
  lString = lString + '<OPTION value="8"> 8'; 
  lString = lString + '<OPTION value="9"> 9'; 
  lString = lString + '<OPTION value="10"> 10'; 
  lString = lString + '<OPTION value="11"> 11'; 
  lString = lString + '<OPTION value="12"> 12'; 
  lString = lString + '<OPTION value="13"> 13'; 
  lString = lString + '<OPTION value="14"> 14';
  */
  for(var age=min_age; age<=max_age; age++) {
      lString = lString + '<OPTION value="'+age+'"> '+age+'</option>';
  }
  lString = lString + '</SELECT>';
  layerWrite(lName, lString);
}

function setToOne(num)
{ lName = 'num_' + num + '_div';
  lString = '1';
  layerWrite(lName, lString);
}

function setNoCot(num)
{ lName = 'cot_' + num + '_div';
  lString = '';
  layerWrite(lName, lString);
}

function setToNone(num)
{ lName = 'num_' + num + '_div';
  lString = '';
  layerWrite(lName, lString);
  lName = 'cot_' + num + '_div';
  layerWrite(lName, lString);
  lName = 'eb_' + num;
  layerWrite(lName, lString);
}


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();
}

function nights()
{ var annoa = document.input_data.aa.options[document.input_data.aa.options.selectedIndex].value;
  var mesea = document.input_data.mma.options[document.input_data.mma.options.selectedIndex].value;
  var giornoa = document.input_data.gga.options[document.input_data.gga.options.selectedIndex].value;
  var annop = document.input_data.ap.options[document.input_data.ap.options.selectedIndex].value;
  var mesep = document.input_data.mmp.options[document.input_data.mmp.options.selectedIndex].value;
  var giornop = document.input_data.ggp.options[document.input_data.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);
}

function setPD()
{ 
    var anno = document.input_data.aa.options[document.input_data.aa.options.selectedIndex].value;
    var mese = document.input_data.mma.options[document.input_data.mma.options.selectedIndex].value;
    var giorno = document.input_data.gga.options[document.input_data.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.input_data.gga.value = tmp[2];
            document.input_data.mma.value = tmp[1];
            document.input_data.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.input_data.gga.value = (tmpd < 10) ? '0'+tmpd : tmpd;
            document.input_data.mma.value = tmp[1];
            document.input_data.aa.value = tmp[0];
            arrivo = cend;
        }
    }
    var more = 86400000 * __customization['days'];
    var partenza=new Date(arrivo.getTime() + more);
    var month = partenza.getMonth() + 1;
    document.input_data.mmp.value = (month < 10) ? '0' + month : month;
    document.input_data.ggp.value = (partenza.getDate() < 10) ? '0' + partenza.getDate() : partenza.getDate();
    document.input_data.ap.value = partenza.getFullYear();
}

//////////////////// RICERCA DI DISPONIBILITA' //////////////////////////////////
function availability_search() {
    //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';
    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.input_data.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'] = global_fromdate = document.getElementById('aa').value+'-'+document.getElementById('mma').value+'-'+document.getElementById('gga').value;
    struct_param['query']['to'] = global_todate = document.getElementById('ap').value+'-'+document.getElementById('mmp').value+'-'+document.getElementById('ggp').value;
    global_from = format_data(global_fromdate,js_language);
    global_to = format_data(global_todate,js_language);
    //controllo se e' stato scelto un numero di stelle
    if (document.getElementById('stars').value > 1)
        struct_param['query']['stars'] = document.getElementById('stars').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
            var tmp = new Array();
            if(document.getElementById('eta'+i+'_1'))
                tmp.push(Number(document.getElementById('eta'+i+'_1').value));
            if(document.getElementById('eta'+i+'_2') && document.getElementById('eta'+i+'_2').value!='')
                tmp.push(Number(document.getElementById('eta'+i+'_2').value));
            if(tmp.length>0)
                struct_param['query']['rooms'][i]['age'] = tmp;
        }
    }
    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;
    //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
    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.input_data.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];

}

// Apre la box del dettaglio dei prezzi
function show_rembox(agreement) {
    if (openedhotel != '') agreement += '_det';
    document.getElementById('remarks'+agreement).style.display='block';
}
function hide_rembox(agreement) {
    if (openedhotel != '') agreement += '_det';
    document.getElementById('remarks'+agreement).style.display='none';
}

// 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);
}

var global_penalties = '';

function return_deadlines(response, type) {
    if (response.length > 0) {
        global_penalties = '<div class="availbg availbr">'
                         + '<div class="form_title">' + js_dic_CANCELLATIONPENALTIES + '</div>'
                         + '<div class="form_box">'
                         + '<table style="width: 100%;">'
                         + '<tr>'
                         + '<td style="font-weight: bold;">' + capitalize(js_dic_FROM) + '</td>'
                         + '<td style="font-weight: bold;">' + capitalize(js_dic_TO) + '</td>'
                         + '<td style="font-weight: bold;">' + js_dic_PENALTY + '</td>'
                         + '</tr>';
        for (var i = 0; i < response.length; i++) {
            var penalty = '';
            switch (response[i]['type']) {
                case 'P':
                    penalty = response[i]['penalty'] + '% ' + js_dic_OFTHESTAY;
                    break;
                case 'C':
                    penalty = response[i]['penalty'] + '&euro; per ';
                    if (response[i]['target'] == 'pax')
                        penalty += js_dic_PERSON;
                    else
                        penalty += js_dic_ROOM;
                    if (response[i]['period'] == 'night')
                        penalty += ' per ' + js_dic_NIGHT;
                    break;
                case 'N':
                    if (response[i]['penalty'] == 1)
                        penalty = js_dic_FIRSTNIGHT;
                    else
                        penalty = js_dic_FIRSTXNIGHTS.replace('%n', response[i]['penalty']);
                    break;
            }
            global_penalties += '<tr>'
                              + '<td>' + format_timestamp(response[i]['start']) + '</td>'
                              + '<td>' + format_timestamp(response[i]['end']) + '</td>'
                              + '<td>' + penalty + '</td>'
                              + '</tr>';
        }
        global_penalties += '</table>'
                          + '</div>';
    }
    book(global_hotel_code,global_agreement,'');
}

var __check_pay_form__ = false;

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('book').style.display='none';
	document.getElementById('hotel').style.display='none';
    document.getElementById('hotels').style.display='none';
    document.getElementById('listbuttons').style.display='none';
	document.getElementById('hf_summary').style.display='none';
    
    //deadline albatravel
	if (ddl == null && agreement.split('.')[0].toLowerCase() == 'albatravel') {
		document.getElementById('book').style.display='none';
		document.getElementById('loading').style.display='block';
		struct_param['header']['type'] = 'get_albatravel_deadline';
		struct_param['query'] = new Array();
		struct_param['query']['agreement'] = agreement;
		struct_param['query']['hotel'] = Number(hotel_booking['id']);
		xml_request(struct_param,url_xml_rpc,iso_encoding,return_deadline);
		return false;
	}
    
    if (ddl == null && agreement.split('.')[0] == 'LCL') {
        global_penalties = '';
        document.getElementById('loading').style.display='block';
        struct_param['header']['type'] = 'get_deadlines';
        struct_param['query'] = new Array();
        struct_param['query']['date'] = global_fromdate;
        struct_param['query']['contract'] = agreement.split('.')[1];
        xml_request(struct_param,url_xml_rpc,iso_encoding,return_deadlines);
        return false;
    }
    if (ddl == null || ddl == '') {
        var dead = hotel_booking['agreements'][agreement]['deadline'];
        var deadline = format_data(hotel_booking['agreements'][agreement]['deadline'],js_language)+' 12:00';
    }
    else {
        if (typeof(ddl) == 'object') {
            var full = ddl['full'];
            ddl = ddl['deadline'];
        }
        else
            var full = false;
        var dead = ddl;
        var deadline = format_data(ddl,js_language)+' 18:00';
    }
    global_deadline = deadline;
    global_full = full;
    if (openedhotel == '')
        var onclick = 'print_hotels(hotels);';
    else
        var onclick = 'print_hotel('+openedhotel+');';
	var intest = '<div id="back" width="100%" class="align_right"><input type="button" class="button back" onClick="'+onclick+'" onMouseOver="window.status=\' '+js_dic_BACK+'\'; return true;" onMouseOut="window.status=\'\'; return true;" value="'+js_dic_BACK+'"></div>';
	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 = js_global_root_url + 'generals_' + js_language + '.html';
    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" style="font-size: 16px; color: f00;" ></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="99%">';
    
    // 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='';
				if (!__customization['nopaxes']) {
				    var sp1 = '<span  style="font-size: 16px; color: f00;"  id="ast_'+field_nome+'"></span>';
				    var sp2 = '<span  style="font-size: 16px; color: f00;"  id="ast_'+field_iniziale+'"></span>';
				}
				else {
				    var sp1 = '';
				    var sp2 = '';
				}
				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+'">'+sp1+'&nbsp;<input type="text" name="'+field_iniziale+'" id="'+field_iniziale+'" size="1" maxlength="1" value="'+initial+'">'+sp2+'</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       
			{
			    if (typeof(rooms[room]['extrabed']) != 'object')
			        var xbs = [rooms[room]['extrabed']];
			    else
			        var xbs = rooms[room]['extrabed'];
			    for (var ex = 0; ex < xbs.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>';
      	 		 if (!__customization['nopaxes']) {
				    var sp1 = '<span  id="ast_'+extra_nome+'" style="font-size: 16px; color: f00;" ></span>';
				    var sp2 = '<span style="font-size: 16px; color: f00;"   id="ast_'+extra_iniziale+'"></span>';
				}
				else {
				    var sp1 = '';
				    var sp2 = '';
				}
      	 		 fields +='<tr class="'+row_class+'">'+
      	 		          '<td></td><td>'+select+' <input type="text" id="'+extra_nome+'" name="'+extra_nome+'" size="12" maxlength="12" value="">'+sp1+'&nbsp;<input type="text" name="'+extra_iniziale+'" id="'+extra_iniziale+'" size="1" maxlength="1" value=""> - '+js_dic_EXTRABED+' ('+js_dic_AGECHILD+': '+xbs[ex]+')'+sp2+'</td><td></td>'+
      	 		          '</tr>';
			    }
			}	
			
      	 	}
      	 	
      	 	
	 }
      	
	fields += '</table>'+extraandcot;
	if (__customization['nopaxes']) {
	    var dsp = 'display: none;';
	    var mrg = 'style="margin-top: 10px;"';
	}
	else {
	    var dsp = '';
	    var mrg = '';
	}
	var datipren = '<div id="paxes_form" class="availbr availbg" style="margin-top: 10px;'+dsp+'">'
                 + '<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;&nbsp;&nbsp;&nbsp;&nbsp;</td>'
		+'</tr>'
		+'<tr>'
		+'<td>'+js_dic_name+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="contact_name" name="contact_name" type="text"><span  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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" onChange="setContactCf(this.value);">'
        +'<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  style="font-size: 16px; color: f00;"  id="inv_ast_contact_country"></span>'
		+'</td>'
		+'</tr>'
        +'<tr id="contact_cf_row" style="display: none;">'
		+'<td>'+js_dic_CF+'<span>*</span> : </td>'
		+'<td>'
		+'<input id="contact_cf" name="contact_cf" type="text"><span  style="font-size: 16px; color: f00;"  id="ast__contact_cf"></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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  id="ast__contact_password"></span>'
            +'</td>'
            +'</tr>'
            +'</table>';
    }
        
    if (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"></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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  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  style="font-size: 16px; color: f00;"  id="inv_ast_invoice_cf"></span>'
		+'</td>'
		+'</tr>'
        +'</table>'
        +'</div>'
        +'</div>';
	
	var daticontact = '<div class="availbg availbr" '+mrg+'>'
                    + '<div class="form_title">'+js_dic_CONTDATA.toUpperCase()+'</div>'
                    + '<div class="form_box">' + fields_contact+login+userchosed+needinvoice+needcc + '</div>'
                    + '</div>'+invoice;
    //dati carta per il pagamento in hotel
    if (hotel_booking['agreements'][agreement]['__pay_hotel__'] != undefined) {
        //select mesi
        var ms = '<select id="payhotel_month">';
        for (var i = 1; i <= 12; i++) {
            var m = (i < 10) ? '0' + i : i;
            ms += '<option value="' + m +'">' + m + '</option>';
        }
        ms += '</select>';
        //select anni
        var ys = '<select id="payhotel_year">';
        var year = Number((new Date()).getFullYear());
        for (var i = year; i <= year + 10; i++) {
            ys += '<option value="' + i +'">' + i + '</option>';
        }
        ys += '</select>';
        //imposto se controllare i dati inseriti nel form
        if (hotel_booking['agreements'][agreement]['available']) {
            __check_pay_form__ = true;
            var phstyle = '';
        }
        else {
            __check_pay_form__ = false;
            var phstyle = 'style="display: none;"';
        }
        var payhotel = '<div id="payhotel_form" class="availbg availbr" ' + phstyle + '>'
                      +'<div class="form_title">' + js_dic_CCDETAILS.toUpperCase() + '</div>'
                      +'<div class="form_box">'
                      +'<div style="margin-top: 10px; margin-bottom: 20px; margin-right: 5px; text-align: justify;">' + js_dic_PHNOTICE + '</div>'
                      +'<div style="float: left;">'
                      +'<table border="0" cellpadding="3" cellspacing="0">'
                      +'<tr>'
                      +'<td>' + js_dic_CARDHOLDER + '<span>*</span> : </td>'
                      +'<td><input id="payhotel_int" name="payhotel_int" type="text"><span  style="font-size: 16px; color: f00;"  id="ph_ast_payhotel_int"></span></td>'
                      +'</tr>'
                      +'<tr>'
                      +'<td>' + js_dic_CARDNUMBER + '<span>*</span> : </td>'
                      +'<td><input id="payhotel_num" name="payhotel_num" type="text"><span  style="font-size: 16px; color: f00;"  id="ph_ast_payhotel_num"></span></td>'
                      +'</tr>'
                      +'<tr>'
                      +'<td>' + js_dic_EXPIRATION + '<span>*</span> : </td>'
                      +'<td>' + ms + '&nbsp;' + ys + '</td>'
                      +'</tr>'
                      +'<tr>'
                      +'<td>' + js_dic_CVV + '<span>*</span> : </td>'
                      +'<td><input id="payhotel_cvv" name="payhotel_cvv" type="text" size="3" maxlength="3"><span  style="font-size: 16px; color: f00;"  id="ph_ast_payhotel_cvv"></span></td>'
                      +'</tr>'
                      +'</table>'
                      +'</div>'
                      +'<div style="float: right; margin-right: 10px;">'
                      +'<iframe width="80" height="80" frameborder="0" scrolling="no" src="https://www.bookingvenice.eu/thawtelogo.php" marginwidth="0" marginheight="0"></iframe>'
                      +'</div>'
                      +'<div style="clear: both;"></div>'
                      +'</div>'
                      +'</div>';
    }
    else var payhotel = '';
	// 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 class="text_bold"><td>'+js_dic_HOTEL+'</td><td>'+resfor+'</td><tr>';
	accommodation += '<tr><td>'+js_dic_HTLCAT+'</td><td>'+hotel_booking['classification']/*eval('js_dic_'+hotel_booking['classification']+'_')*/+'</td></tr>';
	accommodation += '<tr class="text_bold"><td>'+js_dic_DAYFROM+'</td><td>'+global_from+'</td></tr>';
	accommodation += '<tr class="text_bold"><td>'+js_dic_DAYTO+'</td><td>'+global_to+'</td></tr>';
	accommodation += '<tr class="text_bold"><td>'+js_dic_NIGHTS+'</td><td>'+global_nights+'</td></tr>';
	accommodation += '<tr><td>'+js_dic_ROOMS+'</td><td>'+rooms_list+'</td></tr>';
	accommodation += '<tr class="text_bold"><td>'+js_dic_TOTALPRICE+'</td><td>'+format_price(hotel_booking['agreements'][agreement]['total'],js_language)+' '+ currency +'</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;">';
    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>';
    if (hotel_booking['agreements'][global_agreement]['__pay_hotel__'] == undefined || __check_pay_form__)
            datisis += '<div class="form_title">'+js_dic_ATTENTION+': '+js_dic_CANCELLATIONDEADLINE+' '+global_deadline+'</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>';
    datisis += global_penalties;

    //remarks
	var remarks ='';
    if (hotel_booking['agreements'][agreement]['remarks'].length > 0) {
        remarks = '<div class="availbg availbr" style="margin-top: 10px;">'
                + '<div class="form_title">'+js_dic_REMARKS.toUpperCase()+'</div>'
                + '<div class="form_box">';
                for (var i = 0; i < hotel_booking['agreements'][agreement]['remarks'].length; i++) {
                    var r = hotel_booking['agreements'][agreement]['remarks'][i];
                    remarks += '<div class="text_bold align_center" style="margin-top: 5px">'+js_dic_FROM+'&nbsp;'+r['startdate']+'&nbsp;'+js_dic_TO+'&nbsp;'+r['enddate']+'</div>'
                             + '<div class="align_center" style="margin-top: 5px">'+r['text']+'</div>';
                }
        remarks += '</div></div>';
    }
    
    //note
    notes = '<div class="availbg availbr">'
          + '<div class="form_title">'+js_dic_NOTES.toUpperCase()+'</div>'
          + '<div class="form_box"><textarea id="textnotes" rows="4" style="width: 99%;"></textarea></div>'
          + '</div>';
    
    var form = '<form id="booking_form">'+intest+datisis+remarks+datipren+daticontact+payhotel+notes+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 (document.getElementById('payhotel_form')) {
        var fieldset = document.getElementById('payhotel_form');
        var fields = fieldset.getElementsByTagName('span');
        for (var i = 0; i < fields.length; i++) {
            if (fields[i].id.indexOf('ph_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].id != 'contact_cf' && 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;
        }
        if (document.getElementById('contact_cf_row').style.display!='none' && document.getElementById('contact_cf').value == '') {
            div_form.style.display = 'block';
            div_loading.style.display = 'none';
            document.getElementById('ast__contact_cf').innerHTML = '*';
            print_error(js_dic_NOALLFIELDS,'ast__contact_cf');
            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('payhotel_form') && __check_pay_form__) {
        var fieldset = document.getElementById('payhotel_form');
        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('ph_ast_'+fields[i].id).innerHTML = '*';
                print_error(js_dic_NOALLFIELDS,'ph_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 intest = '<div id="back" class="align_right" width="100%"><input type="button" class="button back" onClick="show_book(false);" onMouseOver="window.status=\' '+js_dic_BACK+'\'; return true;" onMouseOut="window.status=\'\'; return true;" value="'+js_dic_BACK+'"></div>';
    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'])   // extrabed       
			{
			    if (typeof(rooms[room]['extrabed']) != 'object')
			        var xbs = [rooms[room]['extrabed']];
			    else
			        var xbs = rooms[room]['extrabed'];
			    for (var ex = 0; ex < xbs.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 class="'+row_class+'">'+
                 '<td >'+document.getElementById(extra_titolo).value+'&nbsp;'+document.getElementById(extra_nome).value+'&nbsp;'+document.getElementById(extra_iniziale).value+'. - '+js_dic_EXTRABED+' ('+js_dic_AGECHILD+': '+xbs[ex]+')</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']);
                 ap_rooming['paxes'][ap_rooming['paxes'].length]=ap_paxes;
                }
			}	   
			global_rooming_list[num_rooms] = ap_rooming;
      	 	}
      	 	
      	 	
	 }
	
	fields += '</table>'+extraandcot;
    if (__customization['nopaxes']) {
	    var dsp = 'display: none;';
	    var mrg = 'style="margin-top: 10px;"';
	}
	else {
	    var dsp = '';
	    var mrg = '';
	}
	var datipren = '<div class="availbr availbg" style="margin-top: 10px;'+dsp+'">'
                 + '<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" '+mrg+'>'
        +'<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;">';
    if (!document.getElementById('payhotel_form'))
        fields_contact += js_dic_BOOKINGEND;
    fields_contact += '</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>';
    if (document.getElementById('contact_cf_row').style.display!='none')
        fields_contact += '<tr class="div_on">'
                        +'<td>'+js_dic_CF+' : </td>'
                        +'<td>'
                        +document.getElementById('contact_cf').value
                        +'</td>'
                        +'</tr>';
	fields_contact+='</table>';
        
    
    if (document.getElementById('check_invoice').checked)
        var invoice = +'</div>'
            +'</div>'
            +'<div class="availbg availbr" style="border">'
            +'<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 = '';
	
	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 = '';
	
    //dati carta per il pagamento in hotel
    if (hotel_booking['agreements'][global_agreement]['__pay_hotel__'] != undefined && __check_pay_form__) {
        var payhotel = '</div>'
                      +'</div>'
                      +'<div class="availbg availbr">'
                      +'<div class="form_title">Dati della carta di credito</div>'
                      +'<div class="form_box">'
                      +'<div style="float: left;">'
                      +'<table border="0" cellpadding="3" cellspacing="0">'
                      +'<tr>'
                      +'<td>' + js_dic_CARDHOLDER + ': </td>'
                      +'<td>' + document.getElementById('payhotel_int').value + '</td>'
                      +'</tr>'
                      +'<tr>'
                      +'<td>' + js_dic_CARDNUMBER + ': </td>'
                      +'<td>' + document.getElementById('payhotel_num').value + '</td>'
                      +'</tr>'
                      +'<tr>'
                      +'<td>' + js_dic_EXPIRATION + ': </td>'
                      +'<td>' + document.getElementById('payhotel_month').value + '/' + document.getElementById('payhotel_year').value + '</td>'
                      +'</tr>'
                      +'<tr>'
                      +'<td>' + js_dic_CVV + ': </td>'
                      +'<td>' + document.getElementById('payhotel_cvv').value + '</td>'
                      +'</tr>'
                      +'</table>'
                      +'</div>'
                      +'<div style="float: right; margin-right: 10px;">'
                      +'<iframe width="80" height="80" frameborder="0" scrolling="no" src="https://www.bookingvenice.eu/thawtelogo.php" marginwidth="0" marginheight="0"></iframe>'
                      +'</div>'
                      +'<div style="clear: both;"></div>';
    }
    else var payhotel = '';
    
    //remarks
	var remarks ='';
    if (hotel_booking['agreements'][global_agreement]['remarks'].length > 0) {
        remarks = '<div class="availbg availbr" style="margin-top: 10px;">'
                + '<div class="form_title">'+js_dic_REMARKS.toUpperCase()+'</div>'
                + '<div class="form_box">';
                for (var i = 0; i < hotel_booking['agreements'][global_agreement]['remarks'].length; i++) {
                    var r = hotel_booking['agreements'][global_agreement]['remarks'][i];
                    remarks += '<div class="text_bold align_center" style="margin-top: 5px">'+js_dic_FROM+'&nbsp;'+r['startdate']+'&nbsp;'+js_dic_TO+'&nbsp;'+r['enddate']+'</div>'
                             + '<div class="align_center" style="margin-top: 5px">'+r['text']+'</div>';
                }
        remarks += '</div></div>';
    }
    
    //note
    var notes = '';
    var tmp = document.getElementById('textnotes').value;
    if (tmp != '') {
        tmp = tmp.replace(/\n/g, '<br>');
        tmp = tmp.replace(/\r/g, '');
        tmp = tmp.replace(/\s/g, '&nbsp;');
        notes = '</div></div><div class="availbg availbr">'
              + '<div class="form_title">'+js_dic_NOTES.toUpperCase()+'</div>'
              + '<div class="form_box">'+tmp;
    }
	
	// 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+remarks+datipren+fields_contact+cc+invoice+payhotel+notes+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 back = '<input type="button" class="button back" onClick="print_hotels(hotels)" onMouseOver="window.status=\' '+js_dic_BACK+'\'; return true;" onMouseOut="window.status=\'\'; return true;" value="'+js_dic_BACK+'">';
	else
        var back = '<input type="button" class="button back" onClick="print_hotel('+openedhotel+')" onMouseOver="window.status=\' '+js_dic_BACK+'\'; return true;" onMouseOut="window.status=\'\'; return true;" value="'+js_dic_BACK+'">';
    document.getElementById('back').innerHTML = back;
	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 back = '<input type="button" class="button back" onClick="show_book(false)" onMouseOver="window.status=\' '+js_dic_BACK+'\'; return true;" onMouseOut="window.status=\'\'; return true;" value="'+js_dic_BACK+'">';
	document.getElementById('back').innerHTML = back;
}

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();
	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']['language'] = js_language;
	if (hotel_booking['agreements'][global_agreement]['__pay_hotel__'] != undefined)
	    struct_param['query']['configuration']['payhotel'] = true;
    // 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;
    if (document.getElementById('contact_cf_row').style.display!='none')
        contact['cf'] = document.getElementById('contact_cf').value;
    //contact['registration'] = document.getElementById('check_register').checked;
    contact['registration'] = false;
	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'] = hotel_booking['agreements'][global_agreement]['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'] = hotel_booking['agreements'][global_agreement]['total'];
	struct_param['query']['remarks'] = global_remarks_list;
    //note
    if (document.getElementById('textnotes').value != '') {
        var tmp = document.getElementById('textnotes').value;
        tmp = tmp.replace(/\n/g, '<br>');
        tmp = tmp.replace(/\r/g, '');
        tmp = tmp.replace(/\s/g, '&nbsp;');
        var nr = new Array();
        nr['code'] = null; 
        nr['text'] = tmp;
        nr['checked'] = true;
        nr['visibility'] = new Array();
        nr['visibility'].push('customers');
        struct_param['query']['remarks'].push(nr);
    }
    //imposto i dati del pay in hotel se necessario
    if (document.getElementById('payhotel_form')) {
        struct_param['query']['payhotel'] = new Array();
        struct_param['query']['payhotel']['intestatario'] = document.getElementById('payhotel_int').value;
        struct_param['query']['payhotel']['numero'] = document.getElementById('payhotel_num').value;
        struct_param['query']['payhotel']['scadenza'] = document.getElementById('payhotel_month').value + '/' + document.getElementById('payhotel_year').value;
        struct_param['query']['payhotel']['cvv'] = document.getElementById('payhotel_cvv').value;
    }
	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') {
	    if (document.getElementById('payhotel_form') && __check_pay_form__)
	        window.location = 'https://www.bookingvenice.eu/cart.php?PHPSESSID='+sessid;
	    else
	        window.location = js_global_root_url+'cart.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'];
                if (response['configuration']['contact']['cf'] != undefined)
                    document.getElementById('contact_cf').value = response['configuration']['contact']['cf'];
                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 setContactCf(country) {
    if (country == 'I')
        document.getElementById('contact_cf_row').style.display=display_for_browser();
    else
        document.getElementById('contact_cf_row').style.display='none';
}
