function showCorrectForm()
{
 
  valueDropDown = document.getElementById("Database_Code").value;
  bapDiv = document.getElementById("baptismform");
  marriageDiv = document.getElementById("marriageform");
  deathDiv = document.getElementById("deathsform");
  memorialDiv = document.getElementById("memorialsform");
  noDiv = document.getElementById("noform");
  if(valueDropDown == 0) 
  {
    // No database chosen
   noDiv.style.display="block";
   bapDiv.style.display = "none";
   marriageDiv.style.display = "none";
   deathDiv.style.display = "none";
   memorialDiv.style.display = "none";
   return;
  }
  if(valueDropDown == 1)
  {
    // Baptism form
    noDiv.style.display="none";
    bapDiv.style.display = "block";
    marriageDiv.style.display = "none";
    deathDiv.style.display = "none";
    memorialDiv.style.display = "none";
  }
  if(valueDropDown == 2)
  {
    // Marriage form
    noDiv.style.display="none";
    bapDiv.style.display = "none";
    marriageDiv.style.display = "block";
    deathDiv.style.display = "none";
    memorialDiv.style.display = "none";
  }
  if(valueDropDown == 3)
  {
    // Death form
    noDiv.style.display="none";
    bapDiv.style.display = "none";
    marriageDiv.style.display = "none";
    deathDiv.style.display = "block";
    memorialDiv.style.display = "none";
  }
  if(valueDropDown == 4)
  {
    // Death form
    noDiv.style.display="none";
    bapDiv.style.display = "none";
    marriageDiv.style.display = "none";
    deathDiv.style.display = "none";
    memorialDiv.style.display = "block";
  }

}

/* Validate the form based on which form is current
   Returns - true - tells the page is it ok to submit the form
           - false - tells the page not to submit the form
*/
function validateForm()
{
  valueDropDown = document.getElementById("Database_Code").value;
  if(valueDropDown == 0) 
  {
    // No database chosen - No point in submitting anything.
   return false;
  }
  if(valueDropDown == 1)
  {
    return validateBaptismForm();
  }
  if(valueDropDown == 2)
  {
    return validateMarriageForm();
  }
  if(valueDropDown == 3)
  {
    return validateDeathsForm();
  }
  if(valueDropDown == 4)
  {
    return validateMemorialsForm();
  }
  // Should not get here
  return false;
}

function validateBaptismForm()
{
  /* Baptism form consists of:
        <input name="sname" type="text" size="15"/>
        <input name="fname" type="text" size="15"/>
        <input name="datelo" type="text" size="4"/>
        <input name="datehi" type="text" size="4"/>
        <input name="parish" type="text" size="15"/>
  */
  var theForm = document.getElementById("baptism_id");
  if(!testDate(theForm.datelo.value) ||
     !testDate(theForm.datehi.value))
  {
    alert("Date values must be in the form yyyy");
    return false;
  }
  // OK - This will do then
  return true;
}
function validateBaptismForm()
{
  // No Validation required!
  return true;
}
function validateMarriageForm()
{
  /* Marriage form consists of:
    <input name="hsname" type="text" size="15"/>
    <input name="hfname" type="text" size="15"/>
    <input name="wsname" type="text" size="15"/>
    <input name="wfname" type="text" size="15"/>
    <input name="datelo" type="text" size="4"/>
    <input name="datehi" type="text" size="4"/>
    <input name="parish" type="text" size="15"/>
  */
  var theForm = document.getElementById("marriage_id");
  /* OK - So we got here, there's at least one value */
  if(!testDate(theForm.datelo.value) ||
     !testDate(theForm.datehi.value))
  {
    alert("Date values must be in the form yyyy");
    return false;
  }
  // OK - This will do then
  return true;
}

function validateDeathsForm()
{
  /* The deaths form consists of:
    <input name="sname" type="text" size="15"/>
    <input name="fname" type="text" size="15"/>
    <input name="datelo" type="text" size="4"/
    <input name="datehi" type="text" size="4"/>
    <input name="parish" type="text" size="15"/
  */
  var theForm = document.getElementById("death_id");
  /* OK - So we got here, there's at least one value */
  if(!testDate(theForm.datelo.value) ||
     !testDate(theForm.datehi.value))
  {
    alert("Date values must be in the form yyyy");
    return false;
  }
  // OK - This will do then
  return true;
}

function testDate(valToTest)
{
  if (valToTest == "")
  {
    // We're ok with it being empty
    return true;
  }
  return isDate(valToTest, "yyyy");
}

function setSelected(id, val)
{
  var dropdown = document.getElementById(id);
  var i = 0;
  for (i = 0 ; i < dropdown.options.length; i++)
  {
    if ( dropdown.options[i] == val )
    {
      dropdown.selectedIndex = i;
      return;
    }
  }
}
