function testEmailAndPLak(plak,email){
var rez  =$.ajax({
   type: "POST",
   url: "registration/test/ajax/1",
   data: 'plak='+plak+'&email='+email,
   success: showResponse
 });
}

function showResponse(responseText, statusText)  {

if (responseText==0) {
	$("#plak").after('<span class="error">Die PLAK existiert schon!</span>');
	$("#plak").focus();
}
if (responseText==-1) {
	$("#email").after('<span class="error">Die Email wurde bereits benutzt!</span>');
	$("#email").focus();
}
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property

    // if the ajaxForm method was passed an Options Object with the dataType
    // property set to 'xml' then the first argument to the success callback
    // is the XMLHttpRequest object's responseXML property

    // if the ajaxForm method was passed an Options Object with the dataType
    // property set to 'json' then the first argument to the success callback
    // is the json data object returned by the server
if (responseText==1) {
	$("#registrationForm").submit();
}

}
$(document).ready(function(){
	   $("#send").click(function() {
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var plakReg = /^\w+$/;

		var emailToVal = $("#email").val();
		var plakVal = $("#plak").val();
		var firstnameVal = $("#firstname").val();
		var lastnameVal = $("#lastname").val();

		if(emailToVal == '') {
			$("#email").after('<span class="error">Email bitte eintragen!</span>');
			$("#email").focus();
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {
			$("#email").after('<span class="error">Die Email ist nicht valid !</span>');
			$("#email").focus();
			hasError = true;
		}
		if(plakVal == '') {
			$("#plak").after('<span class="error">Plak bitte eintragen!</span>');
			$("#plak").focus();
			hasError = true;
		}else if(!plakReg.test(plakVal)) {
			$("#plak").after('<span class="error">Die Plak ist nicht valid  !Die Plak darf nur Buchstaben, Zahlen und Unterstriche enthalten.</span>');
			$("#plak").focus();
			hasError = true;
		}

		if(firstnameVal == '') {
			$("#firstname").after('<span class="error">Vorname bitte eintragen!</span>');
			$("#firstname").focus();
			hasError = true;
		}
		if(lastnameVal == '') {
			$("#lastname").after('<span class="error">Nachname bitte eintragen!</span>');
			$("#lastname").focus();
			hasError = true;
		}

		if (document.getElementById('terms_chk').checked == false) {
			$("#reg_after").after('<div class="error">Sie muessen die Nutzungbedingungen akzeptieren !</div>');
			$("#terms_chk").focus();
			hasError = true;
		}



		if (!hasError) {
			testEmailAndPLak(plakVal,emailToVal);
			//$("#registrationForm").submit();
		}
		return false;
	});
});