function checkForm() {
	if (checkMandatory()) {
		$.post("gewinnspiel/checkcaptcha.php",
		  { code: $('#captchacode').val() },
		  function(data){
		    if (data == '0'){
				$('div#introduction').html('<h1>Pferdebesitzer mitgemacht!</h1><br/><span class="error">Der eingegebene Code ist nicht korrekt!<br/><br/><br/></span>');
			} else {
				checkFormRest();
			}
		  }
		);
	}
}

function checkFormRest() {
	if ($('#disc_checkbox').attr("checked")){
		var theDisziplin = '';
		$('input[@name=disziplin]').each(function () {
			if ($(this).attr("checked"))
				theDisziplin += $(this).val() + ', ';
		});
					
		$.post("gewinnspiel/submitpost.php",
		//$.post("http://www.angie-winkler-design.de/equistro_gewinnspiel/insert_equistro.php",
		  { vorname: $('#vorname').val(), nachname: $('#name').val(),
			strasse: $('#strhnr').val(), ort: $('#plz').val()+' '+$('#ort').val(),
			email: $('#email').val(), handy: $('#handy').val(), disziplin: theDisziplin,
			kenntprodukte: $('#kennengelernt').val(), besonders: $('#besonders').val(),
			infos: $("input[@name='newsletter']:checked").val() },
		  function(data){
		  
		  }
		);
		
		$('#introduction').hide();
		$('form').hide();
		$('h1#danke').show();
		parent.animateToStep2();
	} else
		alert('Sie muessen den Nutzungsbedingungen zuerst zustimmen!');
}

function showDisclaimer() {
	$('#disc_checkbox').attr("checked","checked");
	$('#gewinnspiel_inner').hide();
	$('#disclaimer').show();
	$('img#logo').hide();
	$('img#close').unbind();
	$('img#close').click(function () {
		closeDisclaimer();
	});
	$('img#close').hover(function() {
		$(this).css("cursor","hand");
	}, function () {
		$(this).css("cursor","pointer");
	});	
}

var step=1;
function weiterlesen() {
	step++;
	$('div.step').hide();
	$('div#step'+step).show();
	if (step == 3){
		$('img#weiterlesen').attr("src","http://www.angie-winkler-design.de/equistro_gewinnspiel/images/close_nutzung.gif");
		$('img#weiterlesen').unbind();
		$('img#weiterlesen').click(function () {
			closeDisclaimer();
			$('div.step').hide();
			$('div#step1').show();
			step = 1;
			$('img#weiterlesen').attr("src","http://www.angie-winkler-design.de/equistro_gewinnspiel/images/weiterlesen.gif");
			$('img#weiterlesen').unbind();
			$('img#weiterlesen').click(function () {
				weiterlesen();
			});
		});
	}
}

function init() {
$(document).ready(function() {
	$('img#submit').click(function () {
		checkForm();
	});
	
	$('img#disclaimer_link').click(function () {
		showDisclaimer();
	});
	
	$('img#close').click(function () {
		parent.closeLayer();
	});
	
	$('img#weiterlesen').click(function () {
		weiterlesen();
	});
	
	$('img#submit').hover(function() {
		$(this).css("cursor","hand");
	}, function () {
		$(this).css("cursor","pointer");
	});
	
	$('img#close').hover(function() {
		$(this).css("cursor","hand");
	}, function () {
		$(this).css("cursor","pointer");
	});
	
	$('img#disclaimer_link').hover(function() {
		$(this).css("cursor","hand");
	}, function () {
		$(this).css("cursor","pointer");
	});
	
	$('img#weiterlesen').hover(function() {
		$(this).css("cursor","hand");
	}, function () {
		$(this).css("cursor","pointer");
	});
});
}

function closeDisclaimer() {
	$('#gewinnspiel_inner').show();
	$('#disclaimer').hide();
	$('img#logo').show();
	$('img#close').unbind();
	$('img#close').click(function () {
		parent.closeLayer();
	});
}

function checkMandatory() {
	$('.mandatory').removeClass("error");
	var error = false;
	$('.mandatory').each(function() {
		if ($(this).val() == ""){
			error = true;
			$(this).addClass("error");
		}
	});
	
	if (error) {
		$('div#introduction').html('<h1>Pferdebesitzer mitgemacht!</h1><br/><span class="error">Sie haben nicht alle erforderlichen Felder ausgef&uuml;llt!<br/><br/></span>');
		return false;
	} else
		return true;
}
