//*****************************************************************************
// FUNCTION SORT_RECORDS
//*****************************************************************************
  function sort_records(sort_order) {
    document.getElementById('data_sort_order').value = sort_order;  
    document.forms[0].submit();
  }
// END FUNCTION SORT_RECORDS
//*****************************************************************************


//*****************************************************************************
// FUNCTION EDIT_SHIP
//*****************************************************************************

function edit_ship(entity_id) {
  document.location.href = 'index.php?action=edit_ship&entity_id='
                           + entity_id;
}
//
// END FUNCTION UPDATE_SHIP
//*****************************************************************************


//*****************************************************************************
// FUNCTION CREATE_SHIP
//*****************************************************************************

function create_ship() {
  document.location.href = 'index.php?action=create_ship';
}
//
// END FUNCTION CREATE_SHIP
//*****************************************************************************


//*****************************************************************************
// FUNCTION UPDATE_SHIP
//*****************************************************************************

function update_ship() {
  document.getElementById('data_action').value = "update_ship";
  document.forms[0].submit();
}
// 
// END FUNCTION UPDATE_SHIP
//*****************************************************************************


//*****************************************************************************
// FUNCTION VIEW_SHIP
//*****************************************************************************

function view_ship(entity_id) {
  document.location.href = 'index.php?action=view_ship&entity_id=' 
                              + entity_id; 
}
//
// END FUNCTION VIEW_SHIP
//*****************************************************************************


//*****************************************************************************
// FUNCTION LIST_SHIPS
//*****************************************************************************

function list_ships() {
  document.location.href = 'index.php?action=list_ships';
}
//
// END FUNCTION LIST_SHIPS
//*****************************************************************************


//*****************************************************************************
// FUNCTION DELETE_SHIP
//*****************************************************************************
 
function delete_ship(entity_id) {
  document.location.href = 'index.php?action=delete_ship&entity_id=' + entity_id;                                 
}
//
// END FUNCTION DELETE_SHIP
//*****************************************************************************


//*****************************************************************************
// FUNCTION UNDELETE_SHIP
//*****************************************************************************
                              
function undelete_ship(entity_id) {
  document.location.href = 'index.php?action=undelete_ship&entity_id=' + entity_id;
}
//
// END FUNCTION UNDELETE_SHIP     
//*****************************************************************************


//*****************************************************************************
// FUNCTION DELETESHIPRATING
//*****************************************************************************

function deleteShipRating(r) {
  document.getElementById('data_ship_0_ship_rating_' + r + '_delete').value = 'Y';
  document.getElementById('ship_rating_row_' + r).style.display = 'none';
}
//
// END FUNCTION DELETESHIPRATING
//*****************************************************************************


//*****************************************************************************
// FUNCTION ADDSHIPRATING
//*****************************************************************************
  
function addShipRating() {  

  // tbody containing contact rows
  var ship_ratings = document.getElementById('ship_ratings');  

  var ship_id = document.getElementById('data_entity_id').value;

  var num_ship_rating = document.getElementById('num_ship_rating');

  var n = num_ship_rating.value * 1;
  num_ship_rating.value = n + 1;

  var ship_rating_html = 
  "<tr id=\"ship_rating_row_" + n + "\"  >\n"
  + "<td>"
  + "<img src=\"static_images/content/icon_delete.gif\" alt=\"delete contact\" title=\"delete ship rating\" "
  + " onclick=\"deleteShipRating(" + n + ")\" />\n"  
  + "<input type=\"hidden\" name=\"data[ship][0][ship_rating][" + n + "][delete]\" "
  + " id=\"data_ship_0_ship_rating_" + n + "_delete\" value=\"\" />\n"
  + "<input type=\"hidden\" name=\"data[ship][0][ship_rating][" + n + "][entity_id]\" " 
  + " id=\"data_ship_0_ship_rating_" + n + "_entity_id\" value=\"\" />\n"
  + "<input type=\"hidden\" name=\"data[ship][0][ship_rating][" + n + "][ship_id]\" "
  + " id=\"data_ship_0_ship_rating_" + n + "_ship_id\" value=\"" + ship_id + "\" />\n"
  + "</td>\n"
  + "<td class=\"small\"><select name=\"data[ship][0][ship_rating][" + n + "][rating_type_id]\" "   
  + " id=\"data_ship_0_ship_rating_" + n + "_rating_type_id\" >\n" 
  + " <option  selected  value=\"1\">Pilot</option>\n" 
  + " <option  value=\"2\">Bombadier</option>\n"
  + "</select>\n"    
  + "</td>\n"
  + "<td class=\"small\" ><input type=\"text\" name=\"data[ship][0][ship_rating][" + n + "][start_date]\" " 
  + " id=\"data_ship_0_ship_rating_" + n + "_start_date\" value=\"\"  size=\"14\"  maxlength=\"10\"  />\n"
  + "</td>\n"
  + "<td class=\"small\" ><input type=\"text\" name=\"data[ship][0][ship_rating][" + n + "][end_date]\" " 
  + " id=\"data_ship_0_ship_rating_" + n + "_end_date\"  value=\"\"  size=\"14\"  maxlength=\"10\"  />\n"
  + "</td>\n"
  + "<td class=\"small\" ><input type=\"text\" name=\"data[ship][0][ship_rating][" + n + "][thrust_rating]\" " 
  + " id=\"data_ship_0_ship_rating_" + n + "_thrust_rating\" value=\"\"  size=\"10\"  maxlength=\"10\"  />\n"
  + "</td>\n"
  + "<td class=\"small\" ><input type=\"text\" name=\"data[ship][0][ship_rating][" + n + "][handling_rating]\" "
  + " id=\"data_ship_0_ship_rating_" + n + "_handling_rating\" value=\"\"  size=\"10\"  maxlength=\"10\"  />\n"
  + "</td>\n"
  + "<td class=\"small\" ><input type=\"text\" name=\"data[ship][0][ship_rating][" + n + "][overall_difficulty_rating]\" "
  + " id=\"data_ship_0_ship_rating_" + n + "_overall_difficulty_rating\" value=\"\"  size=\"10\"  maxlength=\"10\"  />\n"
  + "</td>\n"
  + "</tr>\n";

  //alert(ship_rating_html);
  ship_ratings.innerHTML = ship_ratings.innerHTML + ship_rating_html;

}
//
// END FUNCTION ADDSHIPRATING
//*****************************************************************************


//*****************************************************************************
// FUNCTION CHANGESHIPCONFIGURATION
//*****************************************************************************

function changeShipConfiguration() {
 
  var ship_configuration_menu = document.getElementById('data_ship_0_ship_configuration_id');
  var selectedIndex = ship_configuration_menu.selectedIndex; 
  var ship_configuration = ship_configuration_menu.options[selectedIndex].text;
  var num_ship_rating = document.getElementById('num_ship_rating').value;
  var bomber_display;
  var r;
  if (ship_configuration == "Bomber") {
    bomber_display = "";
  }
  else {
    bomber_display = "none";
  }
  
  for (r = 0; r < num_ship_rating; r++) {
    if (document.getElementById('data_ship_0_ship_rating_' + r + '_rating_type_id').value == 2) {
      document.getElementById('ship_rating_row_' + r).style.display = bomber_display;
    }
  }

  //alert(ship_configuration);
}
// END FUNCTION CHANGESHIPCONFIGURATION
//*****************************************************************************










