
function validateFormOnSubmit(theForm) {
  var reason = "";
  
  reason += validateEmpty(theForm.vorname);
  reason += validateEmpty(theForm.nachname);
  reason += validateEmpty(theForm.strasse);
  reason += validateEmpty(theForm.plz);
  reason += validateEmpty(theForm.ort);
  reason += validateEmail(theForm.email);
  reason += validateCheckbox_d(theForm.agbg);
  
   if (reason != "") {
    alert(unescape("Bitte versichern Sie sich, dass Sie alle Felder ausgef%FCllt im Formular haben!\n" /*+ reason*/));
    return false;
  }
}
function validateRecommendForm(theForm){
	var reason = "";
  
  reason += validateEmpty(theForm.from);
    reason += validateEmpty(theForm.from_name);
	 reason += validateEmpty(theForm.to);
	  reason += validateEmpty(theForm.to_name);
  

   if (reason != "") {
    alert("Bitte versichern Sie sich, dass Sie alle Felder im Formular ausgef%FCllt haben!\n" /*+ reason*/);
    return false;
  }
	
	}


function validateCheckbox_e (fld){
 var error = "";
 
if ( !fld.checked)
    {
		fld.style.background = '#ccc';
        alert("Please make sure you have read and understood the terms and conditions.\n");
		 return false;
    }

return error;

}
function validateCheckbox_d (fld){
 var error = "";
 
if ( !fld.checked)
    {
		fld.style.background = '#ccc';
        alert("Bitte versichern Sie sich, dass Sie die AGBG gelesen und akzeptiert haben.\n");
		 return false;
    }

return error;

}
/*
function validateCheckbox(fld){ 
    if ( fld.checked == false )
    {
        error = "Please check the Terms & Conditions box.";
        return error;
    }
}*/


function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#ccc'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);            // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#ccc';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ccc';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ccc';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
