image_tb3_on = new Image();
image_tb3_on.src = "http://map.aeroplanner.com/images/mp_start_on.gif";
image_tb3_off = new Image();
image_tb3_off.src = "http://map.aeroplanner.com/images/mp_start_off.gif";
image_tb4_on = new Image();
image_tb4_on.src = "http://map.aeroplanner.com/images/mp_options_on.gif";
image_tb4_off = new Image();
image_tb4_off.src = "http://map.aeroplanner.com/images/mp_options_off.gif";

function SwapTable2(tbl_on) {
  if(tbl_on == 'table3'){
    tbl_off = 'table4';
    document.getElementById('tbl3').src=image_tb3_on.src;
    document.getElementById('tbl4').src=image_tb4_off.src;
  }else{
    tbl_off = 'table3';
    document.getElementById('tbl3').src=image_tb3_off.src;
    document.getElementById('tbl4').src=image_tb4_on.src;
  }
  document.getElementById(tbl_on).style.display = 'block';
  document.getElementById(tbl_off).style.display = 'none';
}

function _CF_onError(form_object, input_object, object_value, error_message){
	alert(error_message);
  return false;	
}

function _CF_hasValue(obj, obj_type){
  if (obj_type == "TEXT" || obj_type == "PASSWORD"){
    if (obj.value.length == 0) 
      return false;
    else 
      return true;
  }else if (obj_type == "SELECT"){
    for (i=0; i < obj.length; i++){
		  if (obj.options[i].selected)
			  return true;
		}
    return false;	
	}else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX"){
		if (obj.checked)
			return true;
		else
      return false;	
	}else if (obj_type == "RADIO" || obj_type == "CHECKBOX"){
    for (i=0; i < obj.length; i++){
		  if (obj[i].checked)
			  return true;
		}
    return false;	
	}
}

function _CF_checknumber(object_value){
    //Returns true if value is a number or is NULL
    //otherwise returns false	

  if (object_value.length == 0)
    return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
    decimal = true;
	else if (check_char < 1)
		return false;
        
	  //Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++){
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1){
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}else if (check_char == 0){
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks
		}else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
  //All tests passed, so...
  return true
}
    
function  _CF_checkCFForm_1(_CF_this){
  if  (!_CF_hasValue(_CF_this.AirportFrom, "TEXT" )) {
    if  (!_CF_onError(_CF_this, _CF_this.AirportFrom, _CF_this.AirportFrom.value, "Please enter a Departure Airport.")){
      return false; 
    }
  }
  if  (!_CF_hasValue(_CF_this.AirportTo, "TEXT" )) {
    if  (!_CF_onError(_CF_this, _CF_this.AirportTo, _CF_this.AirportTo.value, "Please enter a Destination Airport.")){
      return false; 
    }
  }
  if  (!_CF_checknumber(_CF_this.Alt.value)){
    if  (!_CF_onError(_CF_this, _CF_this.Alt, _CF_this.Alt.value, "Please enter Altitude as a number.")){
      return false; 
    }
  }
  if  (!_CF_checknumber(_CF_this.spd.value)){
    if  (!_CF_onError(_CF_this, _CF_this.spd, _CF_this.spd.value, "Please enter Speed as a number.")){
      return false; 
    }
  }
  if  (!_CF_checknumber(_CF_this.Fuel.value)){
    if  (!_CF_onError(_CF_this, _CF_this.Fuel, _CF_this.Fuel.value, "Please enter Fuel Burn as a number.")){
      return false; 
    }
  }
  return true;
}