function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateFornavn(theForm.a_fornavn);
 	reason += validateEfternavn(theForm.b_efternavn);
	reason += validateAdresse(theForm.c_adresse);
	reason += validatePostnr(theForm.d_postnr);
	reason += validateBy(theForm.e_by);
  reason += validateland(theForm.f_land);



      
  if (reason != "") {
    alert("Einige Felder sind nicht ausgefüllt:\n" + reason);
    return false;
  }
  return true;
}
function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "Ein Feld ist nicht ausgefüllt.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateFornavn(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Bitte geben Sie den Vornamen an.\n";
    } else if ((fld.value.length < 1) || (fld.value.length > 25)) {
        fld.style.background = 'Yellow'; 
        error = "Der Vorname hat die verkehrte Länge.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateEfternavn(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Bitte geben Sie den Nachnamen an.\n";
    } else if ((fld.value.length < 1) || (fld.value.length > 25)) {
        fld.style.background = 'Yellow'; 
        error = "Der Nachname hat die verkehrte Länge.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateAdresse(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Bitte geben Sie die Adresse an-Strasse und Hausnr.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePostnr(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Bitte geben Sie die Postnummer an.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 8)) {
        fld.style.background = 'Yellow'; 
        error = "Die Postnummer ist falsch.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateBy(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Bitte geben Sie den Ort an.\n";
    } else if ((fld.value.length < 1) || (fld.value.length > 25)) {
        fld.style.background = 'Yellow'; 
        error = "Der Ortsname ist verkehrt.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateland(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Bitte geben Sie die land an.\n";
    } else if ((fld.value.length < 1) || (fld.value.length > 25)) {
        fld.style.background = 'Yellow'; 
        error = "Die land ist verkehrt.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

