function showothercities(tofrom){
	Element.hide(tofrom+'link');
	Element.hide(tofrom+'select');
	Element.show(tofrom+'ajax');
	Element.show(tofrom+'_airports_link');
}

function do_submit(){
	if(validatedates() && validatecities() && validatepaxs()){
		return true;
	}else{
		$('tos').disabled=false;
		$('froms').disabled=false;
		return false;
	}
}
  
function validatepaxs(){
	if(parseInt($('infants').value)>parseInt($('adults').value)){
		show_ajax_error(Error[1]);
		return false;
	}

	if(parseInt($('infants').value)+parseInt($('adults').value) + parseInt($('children').value) > 9){
		show_ajax_error(Error[2]);
		return false;
	}
	
	return true;

}

function validatedates(){
	checkin=Date.parseDate($('departure').value,DATE_FORMAT);
	checkout=Date.parseDate($('return').value,DATE_FORMAT);
	if($('departure').value==g_default_cal_val || ($('backcal').style.display=='' && ($('return').value==g_default_cal_val || checkin.getTime()>checkout.getTime()))){
		show_ajax_error(Error[0]);
		return false;
	}else{
		$('departure').disabled = true;
		$('return').disabled = true;
		$('departure_h').disabled = false;
		$('return_h').disabled = false;
		$('departure_h').value = checkin.dateFormat('Y-m-d');
		if (checkout) 
			$('return_h').value = checkout.dateFormat('Y-m-d');
		else
			$('return_h').value = checkin.dateFormat('Y-m-d');
		//if ($('journey_2').checked) $('return_h').disabled = true;
		return true;
	}
	
} 

function validatecities(){
	if($('toajax').style.display=='none'){
		$('to').value=$('tos').value;
		
	}
	if($('fromajax').style.display=='none'){
		$('from').value=$('froms').value;
		
	}
	
	if($('to').value==''){
		show_ajax_error(Error[3]);
		return false;
	}else{
		if($('from').value==''){
			show_ajax_error(Error[4]);
			return false;
		}else{
			$('tos').disabled=true;
			$('froms').disabled=true;
			return true;
		}
	}
} 
  
  
function ClearOptions(OptionList) {
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }
}


function AddToOptionList(OptionList, OptionValue, OptionText) {
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}
  
  
function hidecalendars(){
		if($('cal_iefix')) Element.hide('cal_iefix');
		if($('cal2_iefix')) Element.hide('cal2_iefix');
		if($('cal2').style.display!='none')
			new Effect.Fade($('cal2'),{duration:.2});
		if($('cal').style.display!='none')
			new Effect.Fade($('cal'),{duration:.2});

}  
//$('container_1').onclick=hidecalendars;
var g_caltimer;
var dohide=true;
function trytohidecalendars(){
	if(dohide)
		g_caltimer=setTimeout('hidecalendars();', 50);
	dohide=true;
}

function cancelCalHide(){
//alert('cancelinam' + g_caltimer);
	dohide=false;
	clearTimeout(g_caltimer);
}

function other_on_select(o, pos) {
	if(o.value == 'other') 
	switch (pos) {
		case 0:
			showothercities('from');
			$('from').select();
			break;
		case 1:
			showothercities('to');
			$('to').select();
			break;
	} 
	
}
document.onclick=trytohidecalendars;
  
 
  //add_onload("resetDefaults();");
