function ibe() {
	var bloc = $("ibe");
	if (bloc) {
		if ((bloc.style.display == 'none') || (bloc.style.display == '')){
			bloc.style.display = 'block';
			$('main').style.height = '330px';
			$('ibe').style.height = '330px';
			$('alert').style.display = 'none';
			$('alert').innerHTML = '';
		}
		else
			bloc.style.display = 'none';
	}
	var mainSingle = $('mainSingle');
	mainSingle.style.display = 'block';
}

function populateDestinations() {
	index = $("_origin").selectedIndex;
	origin =  $("_origin").options[index].value;
	destList = $("_destination").options;
	destList.length = 1;
	if (origin.length < 1) {
		destList.length = 1;
		return;
	}

	var myAjax = new Ajax.Request(
		'modules/ibe_getDest.php',
		{
			method: 'post',
			parameters: 'id=getDest&origine=' + origin, 
			onComplete: function (xhr) {
				var dests = eval('(' + xhr.responseText + ')');
				if (dests) {
					for (var i=0 ; i < dests.length ; i++) {
						var dest = dests[i];
						destList[i+1] = new Option(dest.titre);
						destList[i+1].value = 'Airport.' + dest.tri;			
					}
				}
			}
	});
	destList.selectedIndex = 0;
}

function populateOrigins() {
	destId = $("_origin");
	destList = destId.options;
	destList.length = 1;

	var myAjax = new Ajax.Request(
		'modules/ibe_getDest.php',
		{
			method: 'post',
			parameters: 'id=getDest', 
			onComplete: function (xhr) {
				var dests = eval('(' + xhr.responseText + ')');
				if (dests) {
					for (var i=0 ; i < dests.length ; i++) {
						var dest = dests[i];
						destList[i+1] = new Option(dest.titre);
						destList[i+1].value = 'Airport.' + dest.tri;
						if (dest.tri == 'PPT') destList.selectedIndex = i+1;
					}
				}
				populateDestinations();
			}
	});
}

function validate() {
	$('main').style.height = '330px';
	$('ibe').style.height = '330px';
	$('alert').style.display = 'none';
	$('alert').innerHTML = '';

	var myAjax = new Ajax.Request(
		'modules/ibe_getDest.php',
		{
			method: 'post',
			parameters: 'validate=1&_origin=' + $('_origin').value + '&_destination=' + $('_destination').value + '&_adults=' + $('_adults').value + '&_children=' + $('_children').value + '&_infants=' + $('_infants').value + '&_depdate' + $('dateKind').value + '=' + $('_depdate' + $('dateKind').value).value + '&_retdate' + $('dateKind').value + '=' + $('_retdate' + $('dateKind').value).value, 
			onComplete: function (xhr) {
				if (xhr.responseText == 'Done') {
					document.forms['formibe'].submit();
				} else {
					$('info').style.display = 'none';
					$('alert').innerHTML = xhr.responseText;
					$('alert').style.display = 'block';
					$('main').style.height = parseInt($('main').offsetHeight + $('alert').offsetHeight) + 'px';
					$('ibe').style.height = parseInt($('ibe').offsetHeight + $('alert').offsetHeight) + 'px';
				}
			}
	});
}

function showInfo() {
	$('alert').style.display = 'none';
	if ($('info').style.display == 'none') {
		$('info').style.display = 'block';
		$('main').style.height = parseInt($('main').offsetHeight + $('info').offsetHeight) + 'px';
		$('ibe').style.height = parseInt($('ibe').offsetHeight + $('info').offsetHeight) + 'px';
	}
	else {
		$('info').style.display = 'none';
		$('main').style.height = '330px';
		$('ibe').style.height = '330px';
	}
	
}

function majFromTo(kind) {
	if ($('simple').checked == true) {
		$('fromto').style.display = 'none';
		$('_retdate' + kind).value = '';
	}

	if ($('retour').checked == true)
		$('fromto').style.display = 'block';
	
}