function require(names)
{
  if (checkNames(names))
    return true;
  alert('Please fill in all required inputs!');
  return false;
}

function checkNames(names)
{
  var anArray = names.split(",");
  for (var i = 0; i < anArray.length; i++)
  {
    if (!checkName(anArray[i]))
      return false;
  }
  return true;
}

function checkName(name)
{
  if (name.length == 0)
    return true;
  var inputs = document.forms[0].elements;
  for (var i = 0; i < inputs.length; i++)
  {
    var anInput = inputs[i];
    if ( (anInput != null) && (anInput.name == name) )
    {
      if (checkInput(anInput))
        return true;
    }
  }
  return false;
}

function checkInput(anInput)
{
  var type = anInput.type;
  if ( (type == "text") || (type == "textarea") )
    return checkText(anInput);
  if (type == "radio")
    return checkRadio(anInput);
  if ( (type == "select-one") || (type == "select-multiple") )
    return checkSelect(anInput);
  alert("Unsupported type for required input: " + type);
  return false;
}

function checkText(anInput)
{
  var aString = anInput.value;
  if (aString == null)
    return false;
  return (aString.length > 0);
}

function checkRadio(anInput)
{
  var aBoolean = anInput.checked;
  if (aBoolean == null)
    return false;
  return aBoolean;
}

function checkSelect(anInput)
{
  if (anInput.selectedIndex < 0)
    return false;
  var option = anInput.options[anInput.selectedIndex];
  var aString = option.value;
  if ( (aString != null) && (aString.length > 0) )
    return true;
  aString = option.text;
  if ( (aString != null) && (aString.length > 0) )
    return true;
  return false;
}
