function onChangeReturnCity(self)
{
	var fare = document.getElementById("flight-search-method-calendar-fare");
	var date = document.getElementById("flight-search-method-calendar-date");
	var depart = document.getElementById("departCity");

	if(((self.options[self.selectedIndex].value == "POS") && (depart.options[depart.selectedIndex].value == "TAB")) || ((self.options[self.selectedIndex].value == "TAB") && (depart.options[depart.selectedIndex].value == "POS"))){
		
		document.getElementById("by-Fare").checked=true;
		date.style.visibility = "hidden";
		fare.style.visibility = "visible";
		
	}else{
		document.getElementById("by-Date").checked=true;
		date.style.visibility = "visible";
		fare.style.visibility = "visible";
	
		if(self.options[self.selectedIndex].value == "TAB" || depart.options[depart.selectedIndex].value == "TAB"){
			if(fare != null) {
				if(depart.options[depart.selectedIndex].value == "TAB" && self.options[self.selectedIndex].value != "POS") {
					document.getElementById("by-Date").checked=true;
					date.style.visibility = "visible";
					fare.style.visibility = "hidden";
				}
				if(depart.options[depart.selectedIndex].value != "POS" && self.options[self.selectedIndex].value == "TAB") {
					document.getElementById("by-Date").checked=true;
					date.style.visibility = "visible";
					fare.style.visibility = "hidden";
				}
			}
		}
	}
	document.forms[1].hidDepartCity.value=document.forms[1].returnCity.options[document.forms[1].returnCity.selectedIndex].value;

}

function onChangeOneWay(radio)
{
	

	if(radio.checked) {
		var label = document.getElementById("return-date-label");
		var day = document.getElementById("return-date-day");
		var time = document.getElementById("return-date-time");
		label.style.display = day.style.display = time.style.display = "none";
	}
}
function onChangeReturn(radio)
{
	if(radio.checked) {
		var label = document.getElementById("return-date-label");
		var day = document.getElementById("return-date-day");
		var time = document.getElementById("return-date-time");
		label.style.display = day.style.display = time.style.display = "block";
	}
}
function repaintDest(depart_name, return_name) {
	
  depart_city=document.forms[1].elements[depart_name];
  return_city=document.forms[1].elements[return_name];
  
  	sel_ndx = depart_city.selectedIndex;
	var date = document.getElementById("flight-search-method-calendar-date");
	var fare = document.getElementById("flight-search-method-calendar-fare");
	
	date.style.visibility = "visible";
	fare.style.visibility = "visible";
	
	if(date != null) {
		
   		if(depart_city.options[depart_city.selectedIndex].value == "TAB" && return_city.options[return_city.selectedIndex].value != "POS") {
			document.getElementById("by-Date").checked=true;
   			date.style.visibility = "visible";
			fare.style.visibility = "hidden";
   		}
   		if(depart_city.options[depart_city.selectedIndex].value == "TAB" && return_city.options[return_city.selectedIndex].value == "POS") {
			document.getElementById("by-Fare").checked=true;
   			date.style.visibility = "hidden";
			fare.style.visibility = "visible";
   		}
		if(depart_city.options[depart_city.selectedIndex].value != "POS" && return_city.options[return_city.selectedIndex].value == "TAB") {
			document.getElementById("by-Date").checked=true;
   			date.style.visibility = "visible";
			fare.style.visibility = "hidden";
   		}
		if(depart_city.options[depart_city.selectedIndex].value == "POS" && return_city.options[return_city.selectedIndex].value == "TAB") {
			document.getElementById("by-Fare").checked=true;
   			date.style.visibility = "hidden";
			fare.style.visibility = "visible";
   		}
		
	}
	
   
   
  if(document.getElementById("hidReturnCity") != null){
    ret_sel_val= document.forms[1].hidReturnCity.value;
  }
  else{
    ret_sel_val = return_city.options[return_city.selectedIndex].value;
  }

  if (sel_ndx > 0 && sel_ndx <= dest_array.length) {
    valid_destinations = getValidDest(depart_city.options[sel_ndx].value);

    if (valid_destinations == null || valid_destinations == "") {
      allDestCities(depart_name, return_name);
    }
    else {
      return_city.options.length=depart_city.options.length;
      for (j=1,entries=0; j < depart_city.options.length; j++) {
        if (isValid(depart_city.options[j].value, valid_destinations)) {
          return_city.options[entries+1].value=depart_city.options[j].value;
          return_city.options[entries+1].text=depart_city.options[j].text;
          entries++;
        }
      }
      for (j=entries+1; j < depart_city.options.length; j++) {
        return_city.options[j].value="";
        return_city.options[j].text="";
      }
      return_city.options.length=entries+1;

      if(ret_sel_val != null && ret_sel_val != "") {
      	setReturnSelectedIndex(ret_sel_val, return_name);
      }
    }
  }
  else {
    allDestCities(depart_name, return_name);
  }
}

function isValid(city_code, valid_destinations) {
  valid_array = valid_destinations.split(',');
  for (i=0; i < valid_array.length; i++) {
    if (city_code == valid_array[i])
      return true;
  }
  return false;
}

function setReturnSelectedIndex(ret_sel_val, return_name) {
	return_city=document.forms[1].elements[return_name];
	for (i=1; i < return_city.options.length; i++) {
		if( return_city.options[i].value == ret_sel_val) {
			return_city.options[i].selected = "selected";
		}
	}
}

function allDestCities(depart_name, return_name) {
  depart_city=document.forms[1].elements[depart_name];
  return_city=document.forms[1].elements[return_name];
  return_city.options.length=depart_city.options.length;
  for (j=0; j < depart_city.options.length; j++) {
    return_city.options[j].value=depart_city.options[j].value;
    return_city.options[j].text=depart_city.options[j].text;
  }
}

function getValidDest(city_code) {
  for (j=0; j < city_array.length; j++) {
    if (city_code == city_array[j])
      return dest_array[j];
  }
  return "";
}
