var CHILDREN_SELECTS_ROW_DIV_NAME             = "children_selects_row";
var CHILDREN_SELECTS_AGE_DESCRIPTION_DIV_NAME = "child_age_description";
var CHILDREN_SELECTS_AGE_NOTE_DIV_NAME        = "child_age_note";

// Hide a select
function hideSelect(id)
{
  selectObj = document.getElementById(id);
  
  if (!selectObj) {
    //alert(id);
    return;
  }
  
  selectObj.style.visibility = 'hidden';
  //selectObj.style.display    = 'block';
}

// Show a select
function showSelect(id)
{
  selectObj = document.getElementById(id);
  
  if (!selectObj) {
    //alert(id);
    return;
  }
  
  selectObj.style.visibility = 'visible';
  //selectObj.style.display    = 'block';
}

// Show the appropriate child select boxes based on the number of children selected.
function showChildSelects(form_object) {
  number_of_children = 0;
  
  if (!form_object.cruise_child) {
    return;
  }
  
  number_of_children    = form_object.cruise_child.selectedIndex;
  total_number_children = form_object.cruise_child.options.length - 1;
  
  for (count = number_of_children; count <= total_number_children; count++) {
    hideSelect('child_age_' + count);
  }
  
  if (!number_of_children) {
       
    if (document.getElementById(CHILDREN_SELECTS_AGE_DESCRIPTION_DIV_NAME)) {
      hideDiv(CHILDREN_SELECTS_AGE_DESCRIPTION_DIV_NAME,!CHILDREN_ROW_HIDE_COMPLETE);
    }
    
    if (document.getElementById(CHILDREN_SELECTS_AGE_NOTE_DIV_NAME)) {
      hideDiv(CHILDREN_SELECTS_AGE_NOTE_DIV_NAME,!CHILDREN_ROW_HIDE_COMPLETE);
    }
    
    return;
  }
  
  for (count = 1; count <= number_of_children; count++) {
    showSelect('child_age_' + count);
  }
  
  
  if (document.getElementById(CHILDREN_SELECTS_AGE_DESCRIPTION_DIV_NAME)) {
    showDiv(CHILDREN_SELECTS_AGE_DESCRIPTION_DIV_NAME);
  }
  
  if (document.getElementById(CHILDREN_SELECTS_AGE_NOTE_DIV_NAME)) {
    showDiv(CHILDREN_SELECTS_AGE_NOTE_DIV_NAME);
  }
}

// Checks the children age selects and adds input fields to the form for submission
function childrenSelectChecks(form_object)
{
  if (!form_object.cruise_child) {
    return true;
  }
  
  // Loop over each of the child selects to verify they have valid ages selected
  for (count = 1; count <= form_object.cruise_child.selectedIndex; count++) {
    // Do the checks to make sure that each child was selected an age
    child_age_select = document.getElementById('child_age_' + count);
    if (child_age_select && !child_age_select.selectedIndex) {
      alert('Please select the age of child ' + count);
      child_age_select.focus();
      return false;
    }
  }
  
  return true;
}