function checkForm (whichForm) {

	var error=false;

	// Wenn es eine verstecke Variable "required" im dem Formular "whichForm" gibt, 
	// den Inhalt auslesen und die einzelnen Pflichtfelder extrahieren:

	var  requiredField=whichForm.required.value.split(",");

	// Fuer jedes der Pflichtfelder feststellen, ob Eingabe/Auswahl gemacht wurde:

	for (var i = 0; i < requiredField.length; i++)   {
	   	if (!checkName(whichForm,eraseBlanks(requiredField[i]) ) ) error=true;	
	}

	if (error) {

		//var myURL=document.location.toString();     

		alert ("Missing fields! \nPlease fill in all fields marked with a *.\n\nThank you!");
		return false;
	} else {
		return true;
	}
}

function eraseBlanks (strText) { 
	// entfernt Leerzeichen aus "myString" und gibt das Ergebnis zurueck

    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);

   return strText;
}


function checkName(FormName,name) {
  if (name.length == 0)
    return true;
  var inputs = FormName.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 == "checkbox")
    return checkCheckbox(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) || (aString == "")) 
    return false;
  return true; 
// (aString.length > 0);
}

function checkRadio(anInput)
{
  var aBoolean = anInput.checked;
  if (aBoolean == null)
    return false;
  return aBoolean;
}

function checkCheckbox(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;
//  aString2 = option.text;
//  if ( (aString2 != null) && (aString2.length > 0) && (aString != "") ) {
//		alert ("true");
//    return true;
//	}
  return false;
}

