function leer(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

// This is the function that performs form verification. It is invoked
// from the onsubmit event handler. The handler should return whatever
// value this function returns.
function check(f) {
    var msg;
    var empty_fields = "";
    var errors = "";

    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
        if ((e.type == "text") && !e.optional) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || leer(e.value))	{
                empty_fields += "\n          " + e.name;
                continue;
            }
        }
		if (e.type == "text") {
			//Email testen
			if (e.name == "email")	{
				if (e.value.indexOf("@")==-1)	{
					errors += "Das @ in der Email fehlt.\n";
				}
				if (e.value.indexOf(".")==-1)	{
					errors += "Der Punkt in der Email fehlt.\n";
				}
			}
		}
		if (e.type == "checkbox") {
			if (e.checked == false)	{
				errors += "\n Stimmen Sie bitte gennanten Bedingungen zu.\n";
			}
		}
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "Einige Eingaben sind falsch. Bitte überprüfen Sie die Eingaben\n";
	msg += "und schicken Sie das Formular erneut ab.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
        msg += "Die folgenden Felder sind leer:" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

function popup(name,width,height,directories,toolbar,location,menubar,scrollbars,status,resizable,dependent,fullscreen)
{
var einstellungen;
einstellungen="width="+ width +",height="+ height +",directories=" + directories +",toolbar="+ toolbar +",location="+ location +",menubar="+ menubar +",scrollbars="+ scrollbars +",status="+ status +",resizable="+ resizable +",dependent="+ dependent +",fullscreen="+ fullscreen;
window.open('',name,einstellungen);
}