$(document).ready(function(){

	$('ul.links li').ahover();

	$('input').focus(function () {
        $(this).parents('dl').addClass('dl_active');
        $(this).parents('dl').find('dt').addClass('dt_active');
    });

	$('input').blur(function () {
        $(this).parents('dl').removeClass('dl_active');
        $(this).parents('dl').find('dt').removeClass('dt_active');
    });

	$('textarea').focus(function () {
        $(this).parents('fieldset').addClass('dl_active_txtarea');
        $(this).parents('dl').find('dt').addClass('dt_active');
    });

	$('textarea').blur(function () {
        $(this).parents('fieldset').removeClass('dl_active_txtarea');
        $(this).parents('dl').find('dt').removeClass('dt_active');
    });


	// FORMS

	$('#kontakt_form').ajaxForm({
		target:'#kontakt_status',
		beforeSubmit: validate_kontakt,
		url:'/kontakt/send.html',
		clearForm: true
	});

});

var error_string = '';
var hasError = false;

function check(id,string) {

	if($(id).val() == '') {
		$(id).addClass('error_bg');
		error_string += string;
		hasError = true;
	} else {
		$(id).removeClass('error_bg');
	}

}

function validate_kontakt(){

		$(".error").hide();
		$(".success").hide();
		hasError = false;
		error_string = '';

		check('#nachname','<li>Bitte Nachnamen angeben!</li>');
		check('#vorname','<li>Bitte Vornamen angeben!</li>');
		check('#strasse','<li>Bitte Straße angeben!</li>');
		check('#plz','<li>Bitte Postleitzahl angeben!</li>');
		check('#ort','<li>Bitte Ort angeben!</li>');
		check('#telefon','<li>Bitte Telefon angeben!</li>');
		check('#mail','<li>Bitte E-Mail-Adresse angeben!</li>');
		check('#nachricht','<li>Bitte Nachricht eingeben!</li>');

		if(hasError == true) {
			$("#kontakt_error").html(error_string);
			$(".error").show();
			return false;
		} else {
			$("#kontakt_status").html('<li>Nachricht wird gesendet ...</li>');
			$(".success").show();
			return true;
		}

}

