// Se č attivo il cookie di ricerca esegue questo codice
// crea le select delle camere in base al numero scelto
function ncamsearch(num_camere){
var camere = num_camere;

  if(camere==0){
  document.getElementById('camera1').style.display ='none';
  document.getElementById('camera2').style.display ='none';
  document.getElementById('camera3').style.display ='none';
  document.getElementById('p_cam1').style.display ='none';
  document.getElementById('p_cam2').style.display ='none';
  document.getElementById('p_cam3').style.display ='none';
  }
  if(camere==1){
  document.getElementById('camera1').style.display ='block';
  document.getElementById('camera1').style.backgroundColor = '#C4FFC4';
  document.getElementById('camera2').style.display ='none';
  document.getElementById('camera3').style.display ='none';
  document.getElementById('p_cam2').style.display ='none';
  document.getElementById('p_cam3').style.display ='none';
  }
  if(camere==2){
  document.getElementById('camera1').style.display ='block';
  document.getElementById('camera1').style.backgroundColor = '#C4FFC4';
  document.getElementById('camera2').style.display ='block';
  document.getElementById('camera2').style.backgroundColor = '#C4FFC4';
  document.getElementById('camera3').style.display ='none';
  document.getElementById('p_cam3').style.display ='none';
  }
  if(camere==3){
  document.getElementById('camera1').style.display ='block';
  document.getElementById('camera1').style.backgroundColor = '#C4FFC4';
  document.getElementById('camera2').style.display ='block';
  document.getElementById('camera2').style.backgroundColor = '#C4FFC4';
  document.getElementById('camera3').style.display ='block';
  document.getElementById('camera3').style.backgroundColor = '#C4FFC4';
  }
}
// crea le select in base al numero di persone sccelte
function npers_search(camera, persone, adult, childs){
var n_persone = document.getElementById('camera' + camera).value;
var select_bambini = '';
var select_adulti = '<select name="adulti' + camera +'" id="adulti' + camera +'" value="" onChange="javascript:disableba(' + camera + ',' + n_persone + ')">';
var select_persone = '<select name="adulti' + camera +'" id="adulti' + camera +'" value="">';
var n_bambini = n_persone - 2;
var sel_childs = childs.split('-');
var ad_select = '';
var child_selected = '';
if(n_persone>0){
	if(n_persone==1){
		select_adulti += '<option value="1">Adulti: 1</option>';
		select_persone += '<option value="1">Adulti: 1</option>';
	}else if(n_persone==2){
		select_adulti += '<option value="2">Adulti: 2</option>';
		select_persone += '<option value="2">Adulti: 2</option>';
	}
		for(n=2;n<=n_persone;n++){
			if(n_persone>2){
				if(n == adult){
				ad_select = 'selected';	
				pers_select = 'selected';	
				}else{
				ad_select = '';	
				pers_select = '';	
				}
				select_adulti += '<option value="' + n + '" ' + ad_select + '>Adulti: ' + n + '</option>';
				select_persone += '<option value="' + n + '" ' + pers_select + '>Persone: ' + n + '</option>';
			}
		}
		for(n=3;n<=n_persone;n++){
			select_bambini += '<select name="bambini' + camera + '_' + (n-2) + '" id="bambini' + camera + '_' + (n-2) + '"><option value="">-- Ba --</option>';
			for(a=0;a<=16;a++){
				if(sel_childs[n-3] == a){
					child_selected ='selected';
				}else{
					child_selected ='';
				}
				select_bambini += '<option value="'+ a +'" ' + child_selected + '>'+ a +' anni</option>';	
			}
			select_bambini += '</select>';
		}

select_adulti += '</select>';
select_persone += '</select>';
document.getElementById('p_cam' + camera).style.display = 'block';
if(document.getElementById("type").value == 'Hotel'){
	document.getElementById('p_cam' + camera).innerHTML = select_adulti + select_bambini;
}else{
	document.getElementById('p_cam' + camera).innerHTML = select_persone;
}

if(n_persone>2 && document.getElementById("type").value == 'Hotel'){
document.getElementById('adulti' + camera).style.width ='76px';
document.getElementById('adulti' + camera).style.marginRight ='6px';
for(n=3;n<=n_persone;n++){
document.getElementById('bambini' + camera + '_' + (n-2)).style.marginRight ='6px';
document.getElementById('bambini' + camera + '_' + (n-2)).style.width ='76px';
}
}

}
}
// disabilita le select dei bambini in conseguenza della scelta del numero di adulti
function disablebasearch(camera, persone){
var n_adulti = document.getElementById('adulti' + camera).value;
var bambini = Number(persone) - Number(n_adulti);
//alert(bambini + ' - ' + n_adulti + ' - ' + persone);
	for(n=1;n<=persone;n++){
		if(n<=bambini){
		document.getElementById('bambini' + camera + '_' + n).disabled = false;
		}else{
		if(document.getElementById('bambini' + camera + '_' + n)){
		document.getElementById('bambini' + camera + '_' + n).disabled = true;
		document.getElementById('bambini' + camera + '_' + n).style.backgroundColor = '#FFFFFF';
		}
		}
	}
}
// Se NON č attivo il cookie di ricerca esegue questo codice
// crea le select delle camere in base al numero scelto
function ncam(){
var camere = document.getElementById('n_camere').value;

if(camere==0){
  document.getElementById('camera1').style.display ='none';
  document.getElementById('camera2').style.display ='none';
  document.getElementById('camera3').style.display ='none';
  document.getElementById('p_cam1').style.display ='none';
  document.getElementById('p_cam2').style.display ='none';
  document.getElementById('p_cam3').style.display ='none';
  }
  if(camere==1){
  document.getElementById('camera1').style.display ='block';
  document.getElementById('camera2').style.display ='none';
  document.getElementById('camera3').style.display ='none';
  document.getElementById('p_cam2').style.display ='none';
  document.getElementById('p_cam3').style.display ='none';
  }
  if(camere==2){
  document.getElementById('camera1').style.display ='block';
  document.getElementById('camera2').style.display ='block';
  document.getElementById('camera3').style.display ='none';
  document.getElementById('p_cam3').style.display ='none';
  }
  if(camere==3){
  document.getElementById('camera1').style.display ='block';
  document.getElementById('camera2').style.display ='block';
  document.getElementById('camera3').style.display ='block';
  }
}

function ncam_hotel(){
var camere = document.getElementById('n_camere_hotel').value;

if(camere==0){
  document.getElementById('camera1_hotel').style.display ='none';
  document.getElementById('camera2_hotel').style.display ='none';
  document.getElementById('camera3_hotel').style.display ='none';
  document.getElementById('p_cam1_hotel').style.display ='none';
  document.getElementById('p_cam2_hotel').style.display ='none';
  document.getElementById('p_cam3_hotel').style.display ='none';
  }
  if(camere==1){
  document.getElementById('camera1_hotel').style.display ='block';
  document.getElementById('camera2_hotel').style.display ='none';
  document.getElementById('camera3_hotel').style.display ='none';
  document.getElementById('p_cam2_hotel').style.display ='none';
  document.getElementById('p_cam3_hotel').style.display ='none';
  }
  if(camere==2){
  document.getElementById('camera1_hotel').style.display ='block';
  document.getElementById('camera2_hotel').style.display ='block';
  document.getElementById('camera3_hotel').style.display ='none';
  document.getElementById('p_cam3_hotel').style.display ='none';
  }
  if(camere==3){
  document.getElementById('camera1_hotel').style.display ='block';
  document.getElementById('camera2_hotel').style.display ='block';
  document.getElementById('camera3_hotel').style.display ='block';
  }
}
// crea le select in base al numero di persone scelte
function npers(camera, persone, adult, childs){
var n_persone = document.getElementById('camera' + camera).value;
var select_bambini = '';
var select_adulti = '<select name="adulti' + camera +'" id="adulti' + camera +'" value="" onChange="javascript:disableba(' + camera + ',' + n_persone + ')">';
var input_bambini = '';
var n_bambini = n_persone - 2;
var select_persone = '<input name="adulti' + camera +'" type="hidden" id="adulti' + camera + '" value="' + n_persone + '" />';

if(n_persone>0){
	if(n_persone==1){
		select_adulti += '<option value="1">Adulti: 1</option>';
	}else if(n_persone==2){
		select_adulti += '<option value="2">Adulti: 2</option>';
	}
		for(n=2;n<=n_persone;n++){
			if(n_persone>2){
				select_adulti += '<option value="' + n + '">Adulti: ' + n + '</option>';
			}
	}
		for(n=3;n<=n_persone;n++){
				select_bambini += '<select name="bambini' + camera + '_' + (n-2) + '" id="bambini' + camera + '_' + (n-2) + '"><option value="">-- Ba --</option><option value="0">0 anni</option><option value="1">1 anno</option><option value="2">2 anni</option><option value="3">3 anni</option><option value="4">4 anni</option><option value="5">5 anni</option><option value="6">6 anni</option><option value="7">7 anni</option><option value="8">8 anni</option><option value="9">9 anni</option><option value="10">10 anni</option><option value="11">11 anni</option><option value="12">12 anni</option><option value="13">13 anni</option><option value="14">14 anni</option><option value="15">15 anni</option><option value="16">16 anni</option></select>';
				input_bambini += '<input name="bambini' + camera + '_' + (n-2) + '" type="hidden" id="bambini' + camera + '_' + (n-2) + '" value="" />';
}

select_adulti += '</select>';
document.getElementById('p_cam' + camera).style.display = 'block';
if(document.getElementById("type").value == 'Hotel'){
	document.getElementById('p_cam' + camera).innerHTML = select_adulti + select_bambini;
}else{
	document.getElementById('p_cam' + camera).innerHTML = select_persone + input_bambini;
}

if(n_persone>2 && document.getElementById("type").value == 'Hotel'){
document.getElementById('adulti' + camera).style.width ='76px';
document.getElementById('adulti' + camera).style.marginRight ='6px';
for(n=3;n<=n_persone;n++){
document.getElementById('bambini' + camera + '_' + (n-2)).style.marginRight ='6px';
document.getElementById('bambini' + camera + '_' + (n-2)).style.width ='76px';
}
}

}
}

function npers_hotel(camera, persone, adult, childs){
var n_persone = document.getElementById('camera' + camera + '_hotel').value;
var select_bambini = '';
var select_adulti = '<select name="adulti' + camera + '_hotel' +'" id="adulti' + camera + '_hotel' +'" value="" onChange="javascript:disableba_hotel(' + camera + ',' + n_persone + ')">';
var n_bambini = n_persone - 2;

if(n_persone>0){
	if(n_persone==1){
		select_adulti += '<option value="1">Adulti: 1</option>';
	}else if(n_persone==2){
		select_adulti += '<option value="2">Adulti: 2</option>';
	}
		for(n=2;n<=n_persone;n++){
			if(n_persone>2){
				select_adulti += '<option value="' + n + '">Adulti: ' + n + '</option>';
			}
	}
		for(n=3;n<=n_persone;n++){
				select_bambini += '<select name="bambini' + camera + '_' + (n-2) + '_hotel' + '" id="bambini' + camera + '_' + (n-2) + '_hotel' + '"><option value="">-- Ba --</option><option value="0">0 anni</option><option value="1">1 anno</option><option value="2">2 anni</option><option value="3">3 anni</option><option value="4">4 anni</option><option value="5">5 anni</option><option value="6">6 anni</option><option value="7">7 anni</option><option value="8">8 anni</option><option value="9">9 anni</option><option value="10">10 anni</option><option value="11">11 anni</option><option value="12">12 anni</option><option value="13">13 anni</option><option value="14">14 anni</option><option value="15">15 anni</option><option value="16">16 anni</option></select>';
	}

select_adulti += '</select>';
document.getElementById('p_cam' + camera + '_hotel').style.display = 'block';
document.getElementById('p_cam' + camera + '_hotel').innerHTML = select_adulti + select_bambini;

if(n_persone>2){
document.getElementById('adulti' + camera + '_hotel').style.width ='76px';
document.getElementById('adulti' + camera + '_hotel').style.marginRight ='6px';
for(n=3;n<=n_persone;n++){
document.getElementById('bambini' + camera + '_' + (n-2) + '_hotel').style.marginRight ='6px';
document.getElementById('bambini' + camera + '_' + (n-2) + '_hotel').style.width ='76px';
}
}

}
}
// disabilita le select dei bambini in conseguenza della scelta del numero di adulti
function disableba(camera, persone){
var n_adulti = document.getElementById('adulti' + camera).value;
var bambini = Number(persone) - Number(n_adulti);
//alert(bambini + ' - ' + n_adulti + ' - ' + persone);
	for(n=1;n<=persone;n++){
		if(n<=bambini){
		document.getElementById('bambini' + camera + '_' + n).disabled = false;
		}else{
		document.getElementById('bambini' + camera + '_' + n).disabled = true;
		document.getElementById('bambini' + camera + '_' + n).style.backgroundColor = '#FFFFFF';
		}
	}
}
function disableba_hotel(camera, persone){
var n_adulti = document.getElementById('adulti' + camera + '_hotel').value;
var bambini = Number(persone) - Number(n_adulti);
//alert(bambini + ' - ' + n_adulti + ' - ' + persone);
	for(n=1;n<=persone;n++){
		if(n<=bambini){
		document.getElementById('bambini' + camera + '_' + n + '_hotel').disabled = false;
		}else{
		document.getElementById('bambini' + camera + '_' + n + '_hotel').disabled = true;
		document.getElementById('bambini' + camera + '_' + n + '_hotel').style.backgroundColor = '#FFFFFF';
		}
	}
}

// eventi on submit del form di ricerca
function submitform(){
if(document.getElementById('language').value=='it'){
	var lang = '';
}else{
	var lang =  '/' + document.getElementById('language').value;
}

var destination = document.getElementById('destinations').value;
/*if(document.getElementById('theme').value){
var theme = document.getElementById('theme').value;
}else{
var theme = '';
}*/
var theme = '';
var type = document.getElementById('type').value;
var controllo = '';
var cam1='';
var cam2='';
var cam3='';
var ad1='';
var ad2='';
var ad3='';

	if(type != ''){
		type += '/';
	}
	if(theme != ''){
		theme += '/';
	}

if (document.getElementById('checkIn_date').value != "" && document.getElementById('checkOut_date').value != ""){
var check_in = document.getElementById('checkIn_date').value;
var check_out = document.getElementById('checkOut_date').value;

var checkin_day = check_in.substring(0,2);
var checkin_month = check_in.substring(3,5);
var checkin_year = check_in.substring(8,10);
var checkout_day = check_out.substring(0,2);
var checkout_month = check_out.substring(3,5);
var checkout_year = check_out.substring(8,10);

var one_day=1000*60*60*24;

var checkin = new Date(checkin_year,checkin_month,checkin_day);
var checkout = new Date(checkout_year,checkout_month,checkout_day);

	if((Math.ceil(checkout.getTime()-checkin.getTime())/one_day)>30){
		controllo = "- Il numero di giorni selezionabile non puo\' essere superiore a 30!\n";
	}

	if((Math.ceil(checkout.getTime()-checkin.getTime())/one_day)<0){
		controllo = "- La data di checkout non puņ essere minore della data di checkin!\n";
	}
}

document.getElementById('checkIn_date').style.backgroundColor = '#FFFFFF';
if (document.getElementById('checkIn_date').value == "" )
{
controllo = "- Selezionare la data di checkin!\n";
document.getElementById('checkIn_date').style.backgroundColor = '#FFD7D7';
}

document.getElementById('checkOut_date').style.backgroundColor = '#FFFFFF';
if (document.getElementById('checkOut_date').value == "" )
{
controllo += "- Selezionare la data di checkout!\n";
document.getElementById('checkOut_date').style.backgroundColor = '#FFD7D7';
}

document.getElementById('type').style.backgroundColor = '#FFFFFF';
if (document.getElementById('type').value == "" )
{
controllo += "- Scegliere la tipologia di struttura!\n";
document.getElementById('type').style.backgroundColor = '#FFD7D7';
}
document.getElementById('n_camere').style.backgroundColor = '#FFFFFF';
if (document.getElementById('n_camere').value == "0" )
{
controllo += "- Scegliere il numero di camere!\n";
document.getElementById('n_camere').style.backgroundColor = '#FFD7D7';
}
// controllo che gli occupanti della prima camera siano tutti selezionati
if (document.getElementById('camera1').style.display !='none' && document.getElementById('camera1').value == "" )
{
controllo += "- Scegliere il numero di persone per la prima camera!\n";
document.getElementById('camera1').style.backgroundColor = '#FFD7D7';
}else{
document.getElementById('camera1').style.backgroundColor = '#FFFFFF';
if(document.getElementById('adulti1')){
ad1 = document.getElementById('adulti1').value;
cam1 = document.getElementById('camera1').value;
var n_bambini = document.getElementById('camera1').value - document.getElementById('adulti1').value;
var ba1 = new Array();
if(n_bambini>=1){
	//alert(document.getElementById('camera1').value + ' ' + document.getElementById('adulti1').value);
	for(b=1;b<=n_bambini;b++){
		if(document.getElementById('bambini1_' + b).value == "" && document.getElementById("type").value == 'Hotel'){
			controllo += "- Selezionare l'eta' del bambino num. " + b + " per la prima camera!\n";
			document.getElementById('bambini1_' + b).style.backgroundColor = '#FFD7D7';
		}else{
			ba1[b] = document.getElementById('bambini1_' + b).value;
			document.getElementById('bambini1_' + b).style.backgroundColor = '#FFFFFF';
		}
	}
}
}
}

// controllo che gli occupanti della seconda camera siano tutti selezionati
if (document.getElementById('camera2').style.display !='none' && document.getElementById('camera2').value == "" )
{
controllo += "- Scegliere il numero di persone per la seconda camera!\n";
document.getElementById('camera2').style.backgroundColor = '#FFD7D7';
}else{
document.getElementById('camera2').style.backgroundColor = '#FFFFFF';
if(document.getElementById('adulti2')){
ad2 = document.getElementById('adulti2').value;
cam2 = document.getElementById('camera2').value;
var n_bambini = document.getElementById('camera2').value - document.getElementById('adulti2').value;
var ba2 = new Array();
if(n_bambini>=1){
	//alert(document.getElementById('camera1').value + ' ' + document.getElementById('adulti1').value);
	for(b=1;b<=n_bambini;b++){
		if(document.getElementById('bambini2_' + b).value == "" && document.getElementById("type").value == 'Hotel'){
			controllo += "- Selezionare l'eta' del bambino num. " + b + " per la seconda camera!\n";
			document.getElementById('bambini2_' + b).style.backgroundColor = '#FFD7D7';
		}else{
			ba2[b] = document.getElementById('bambini2_' + b).value;
			document.getElementById('bambini2_' + b).style.backgroundColor = '#FFFFFF';
		}
	}
}
}
}

// controllo che gli occupanti della terza camera siano tutti selezionati
if (document.getElementById('camera3').style.display !='none' && document.getElementById('camera3').value == "" )
{
controllo += "- Scegliere il numero di persone per la terza camera!\n";
document.getElementById('camera3').style.backgroundColor = '#FFD7D7';
}else{
document.getElementById('camera3').style.backgroundColor = '#FFFFFF';
if(document.getElementById('adulti3')){
ad3 = document.getElementById('adulti3').value;
cam3 = document.getElementById('camera3').value;
var n_bambini = document.getElementById('camera3').value - document.getElementById('adulti3').value;
var ba3 = new Array();
if(n_bambini>=1){
	//alert(document.getElementById('camera1').value + ' ' + document.getElementById('adulti1').value);
	for(b=1;b<=n_bambini;b++){
		if(document.getElementById('bambini3_' + b).value == "" && document.getElementById("type").value == 'Hotel'){
			controllo += "- Selezionare l'eta' del bambino num. " + b + " per la terza camera!\n";
			document.getElementById('bambini3_' + b).style.backgroundColor = '#FFD7D7';
		}else{
			ba3[b] = document.getElementById('bambini3_' + b).value;
			document.getElementById('bambini3_' + b).style.backgroundColor = '#FFFFFF';
		}
	}
}
}
}

if(controllo != ''){
alert(controllo);
}else{
if(document.getElementById('language').value=='it'){
	var lang = '';
}else{
	var lang =  '/' + document.getElementById('language').value;
}
var destination = document.getElementById('destinations').value;
var expiredate = new Date();
expiredate.setDate(expiredate.getDate()+1);
var cookietodate = expiredate.toGMTString();

if(destination.substring(0,1) != '['){
destination = document.getElementById('destinations').value;
}else{
destination = '';
}
// setto il cookie per i parametri di ricerca
var bambini1 = '';
for(c=1;c<=10;c++){
	if(ba1){
		if(ba1[c]){
		bambini1 += ba1[c] + '|';
	}else{
		bambini1 += '|';
	}
	}else{
		bambini1 += '|';
	}
}
var bambini2 = '';
for(c=1;c<=10;c++){
	if(ba2){
		if(ba2[c]){
		bambini2 += ba2[c] + '|';
	}else{
		bambini2 += '|';
	}
	}else{
		bambini2 += '|';
	}
}
var bambini3 = '';
for(c=1;c<=10;c++){
	if(ba3){
		if(ba3[c]){
		bambini3 += ba3[c] + '|';
	}else{
		bambini3 += '|';
	}
	}else{
		bambini3 += '|';
	}
}

//alert(bambini1);
document.cookie = 'ps-search='+ destination +'|'+ document.getElementById('type').value +'|'+ theme +'|'+ document.getElementById('checkIn_date').value +'|'+ document.getElementById('checkOut_date').value +'|'+ document.getElementById('n_camere').value +'|'+ cam1 +'|'+ ad1 +'|'+ bambini1 + cam2 +'|'+ ad2 +'|'+ bambini2 + cam3 +'|'+ ad3 +'|'+ bambini3 + '; path=/';

if(destination != ''){
destination += '/';
}
document.getElementById('wait').style.display = 'block';

window.location = 'http://www.portalesardegna.com' + lang + '/search/' + destination + type + theme;
}
}

function submitform_hotel(){
if(document.getElementById('language').value=='it'){
	var lang = '';
}else{
	var lang =  '/' + document.getElementById('language').value;
}
var destination = document.getElementById('destinations_hotel').value;
/*if(document.getElementById('theme').value){
var theme = document.getElementById('theme').value;
}else{
var theme = '';
}*/
var theme = '';
var type = '';
var controllo = '';
var cam1='';
var cam2='';
var cam3='';
var ad1='';
var ad2='';
var ad3='';

	if(type != ''){
		type += '/';
	}
	if(theme != ''){
		theme += '/';
	}

if (document.getElementById('checkIn_date_hotel').value != "" && document.getElementById('checkOut_date_hotel').value != ""){
var check_in = document.getElementById('checkIn_date_hotel').value;
var check_out = document.getElementById('checkOut_date_hotel').value;

var checkin_day = check_in.substring(0,2);
var checkin_month = check_in.substring(3,5);
var checkin_year = check_in.substring(8,10);
var checkout_day = check_out.substring(0,2);
var checkout_month = check_out.substring(3,5);
var checkout_year = check_out.substring(8,10);

var one_day=1000*60*60*24;

var checkin = new Date(checkin_year,checkin_month,checkin_day);
var checkout = new Date(checkout_year,checkout_month,checkout_day);

	if((Math.ceil(checkout.getTime()-checkin.getTime())/one_day)>30){
		controllo = "- Il numero di giorni selezionabile non puo\' essere superiore a 30!\n";
	}

	if((Math.ceil(checkout.getTime()-checkin.getTime())/one_day)<0){
		controllo = "- La data di checkout non puņ essere minore della data di checkin!\n";
	}
}

document.getElementById('checkIn_date_hotel').style.backgroundColor = '#FFFFFF';
if (document.getElementById('checkIn_date_hotel').value == "" )
{
controllo = "- Selezionare la data di checkin!\n";
document.getElementById('checkIn_date_hotel').style.backgroundColor = '#FFD7D7';
}

document.getElementById('checkOut_date_hotel').style.backgroundColor = '#FFFFFF';
if (document.getElementById('checkOut_date_hotel').value == "" )
{
controllo += "- Selezionare la data di checkout!\n";
document.getElementById('checkOut_date_hotel').style.backgroundColor = '#FFD7D7';
}
document.getElementById('n_camere_hotel').style.backgroundColor = '#FFFFFF';
if (document.getElementById('n_camere_hotel').value == "0" )
{
controllo += "- Scegliere il numero di camere!\n";
document.getElementById('n_camere_hotel').style.backgroundColor = '#FFD7D7';
}
// controllo che gli occupanti della prima camera siano tutti selezionati
if (document.getElementById('camera1_hotel').style.display !='none' && document.getElementById('camera1_hotel').value == "" )
{
controllo += "- Scegliere il numero di persone per la prima camera!\n";
document.getElementById('camera1_hotel').style.backgroundColor = '#FFD7D7';
}else{
document.getElementById('camera1_hotel').style.backgroundColor = '#FFFFFF';
if(document.getElementById('adulti1_hotel')){
ad1 = document.getElementById('adulti1_hotel').value;
cam1 = document.getElementById('camera1_hotel').value;
var n_bambini = document.getElementById('camera1_hotel').value - document.getElementById('adulti1_hotel').value;
var ba1 = new Array();
if(n_bambini>=1){
	//alert(document.getElementById('camera1').value + ' ' + document.getElementById('adulti1').value);
	for(b=1;b<=n_bambini;b++){
		if(document.getElementById('bambini1_' + b + '_hotel').value == ""){
			controllo += "- Selezionare l'eta' del bambino num. " + b + " per la prima camera!\n";
			document.getElementById('bambini1_' + b + '_hotel').style.backgroundColor = '#FFD7D7';
		}else{
			ba1[b] = document.getElementById('bambini1_' + b + '_hotel').value;
			document.getElementById('bambini1_' + b + '_hotel').style.backgroundColor = '#FFFFFF';
		}
	}
}
}
}

// controllo che gli occupanti della seconda camera siano tutti selezionati
if (document.getElementById('camera2_hotel').style.display !='none' && document.getElementById('camera2_hotel').value == "" )
{
controllo += "- Scegliere il numero di persone per la seconda camera!\n";
document.getElementById('camera2_hotel').style.backgroundColor = '#FFD7D7';
}else{
document.getElementById('camera2_hotel').style.backgroundColor = '#FFFFFF';
if(document.getElementById('adulti2_hotel')){
ad2 = document.getElementById('adulti2_hotel').value;
cam2 = document.getElementById('camera2_hotel').value;
var n_bambini = document.getElementById('camera2_hotel').value - document.getElementById('adulti2_hotel').value;

var ba2 = new Array();
if(n_bambini>=1){
	//alert(document.getElementById('camera1').value + ' ' + document.getElementById('adulti1').value);
	for(b=1;b<=n_bambini;b++){
		if(document.getElementById('bambini2_' + b + '_hotel').value == ""){
			controllo += "- Selezionare l'eta' del bambino num. " + b + " per la seconda camera!\n";
			document.getElementById('bambini2_' + b + '_hotel').style.backgroundColor = '#FFD7D7';
		}else{
			ba2[b] = document.getElementById('bambini2_' + b + '_hotel').value;
			document.getElementById('bambini2_' + b + '_hotel').style.backgroundColor = '#FFFFFF';
		}
	}
}
}
}

// controllo che gli occupanti della terza camera siano tutti selezionati
if (document.getElementById('camera3_hotel').style.display !='none' && document.getElementById('camera3_hotel').value == "" )
{
controllo += "- Scegliere il numero di persone per la terza camera!\n";
document.getElementById('camera3_hotel').style.backgroundColor = '#FFD7D7';
}else{
document.getElementById('camera3_hotel').style.backgroundColor = '#FFFFFF';
if(document.getElementById('adulti3_hotel')){
ad3 = document.getElementById('adulti3_hotel').value;
cam3 = document.getElementById('camera3_hotel').value;
var n_bambini = document.getElementById('camera3_hotel').value - document.getElementById('adulti3_hotel').value;
var ba3 = new Array();
if(n_bambini>=1){
	//alert(document.getElementById('camera1').value + ' ' + document.getElementById('adulti1').value);
	for(b=1;b<=n_bambini;b++){
		if(document.getElementById('bambini3_' + b + '_hotel').value == ""){
			controllo += "- Selezionare l'eta' del bambino num. " + b + " per la terza camera!\n";
			document.getElementById('bambini3_' + b + '_hotel').style.backgroundColor = '#FFD7D7';
		}else{
			ba3[b] = document.getElementById('bambini3_' + b + '_hotel').value;
			document.getElementById('bambini3_' + b + '_hotel').style.backgroundColor = '#FFFFFF';
		}
	}
}
}
}

if(controllo != ''){
alert(controllo);
}else{
var destination = document.getElementById('destinations_hotel').value;
var expiredate = new Date();
expiredate.setDate(expiredate.getDate()+1);
var cookietodate = expiredate.toGMTString();

// setto il cookie per i parametri di ricerca
var bambini1 = '';
for(c=1;c<=10;c++){
	if(ba1){
		if(ba1[c]){
		bambini1 += ba1[c] + '|';
	}else{
		bambini1 += '|';
	}
	}else{
		bambini1 += '|';
	}
}
var bambini2 = '';
for(c=1;c<=10;c++){
	if(ba2){
		if(ba2[c]){
		bambini2 += ba2[c] + '|';
	}else{
		bambini2 += '|';
	}
	}else{
		bambini2 += '|';
	}
}
var bambini3 = '';
for(c=1;c<=10;c++){
	if(ba3){
		if(ba3[c]){
		bambini3 += ba3[c] + '|';
	}else{
		bambini3 += '|';
	}
	}else{
		bambini3 += '|';
	}
}

//alert(bambini1);
document.cookie = 'ps-search='+ destination +'|||'+ document.getElementById('checkIn_date_hotel').value +'|'+ document.getElementById('checkOut_date_hotel').value +'|'+ document.getElementById('n_camere_hotel').value +'|'+ cam1 +'|'+ ad1 +'|'+ bambini1 + cam2 +'|'+ ad2 +'|'+ bambini2 + cam3 +'|'+ ad3 +'|'+ bambini3 + '; path=/';

if(destination != ''){
destination += '/';
}

document.getElementById('wait').style.display = 'block';
window.location = 'http://www.portalesardegna.com' + lang + '/search/' + destination + type;
}
}