$(document).ready(function() {
	$("div.panel_button").click(function(){
		$("div#panel").animate({
			height: "500px"
		})
		.animate({
			height: "400px"
		}, "fast");
		$("div.panel_button").toggle();
	
	});	
	
   $("div#hide_button").click(function(){
		$("div#panel").animate({
			height: "0px"
		}, "fast");
		
	
   });
   
   
	$("form#aanmeldenproefaccount").validate({
		rules : {
			voornaam : "required",
			achternaam : "required",
			bedrijfsnaam : "required",
			telefoon : "required",
			email : {
				required : true,
				email: true
			},
			voorwaarden: "required"
		},
		
		highlight: function(element, errorClass) {
			$(element).attr("style", "border: 2px solid #ff0000; padding:1px;");
 		},
		
		unhighlight: function(element, errorClass) {
			$(element).attr("style", "");
 		}
	});
	
	$("form#aanmeldenproefaccount img#versturen").click(function(){
		if($("form#aanmeldenproefaccount").valid()){
			var voornaam, achternaam, bedrijfsnaam, telefoon, email;
			voornaam = $("#voornaam").val();
			achternaam = $("#achternaam").val();
			bedrijfsnaam = $("#bedrijfsnaam").val();
			telefoon = $("#telefoon").val();
			email = $("#email").val();
			
			var data = "sender=trial&voornaam=" + voornaam + "&achternaam=" + achternaam + "&bedrijfsnaam=" + bedrijfsnaam + "&telefoon=" + telefoon + "&email=" + email;
			
			$.ajax({
				url : "./php/mailer.php",
				type: "POST",
				data: data,
				cache: false,
				success: function(html){
					if(html == ""){
						$("#login2").append("<span id=\"bevestiging\" style=\"display:none;\">Bedankt voor uw aanvraag. Binnen enkele werkdagen ontvangt u uw inloggegevens.</span>");
						$("form#aanmeldenproefaccount, div#velden-verplicht").fadeOut("normal", function() { 
							$("form#aanmeldenproefaccount")[0].reset();
							$("#login2 span#bevestiging").fadeIn("normal");
						});
					}else{
						alert(html);
					}
				}
			});
		}
	});
	
	$("form#logon").validate({
		rules : {
			username : "required",
			password : "required"
		},
		
		highlight: function(element, errorClass) {
			$(element).attr("style", "border: 2px solid #ff0000; padding:1px;");
 		},
		
		unhighlight: function(element, errorClass) {
			$(element).attr("style", "");
 		}
	});
	
	$("form#logon img#inloggen").click(function(){ $("form#logon").submit(); });
	
	
	$("form#contactfooter").validate({
		rules : {
			emailadres : { required : true, email: true },
			bericht : "required"
		},
		
		highlight: function(element, errorClass) {
			$(element).attr("style", "border: 2px solid #ff0000; padding:1px;");
 		},
		
		unhighlight: function(element, errorClass) {
			$(element).attr("style", "");
 		}
	});
	
	$("form#contactfooter span.btn").click(function(){
		if($("form#contactfooter").valid()){
			var email, bericht;
			email = $("#emailadres").val();
			bericht = $("#bericht").val();
			
			var data = "sender=contactfooter&email=" + email + "&bericht=" + bericht;
			
			$.ajax({
				url : "./php/mailer.php",
				type: "POST",
				data: data,
				cache: false,
				success: function(html){
					if(html == ""){
						$(".stel-ons-een-vraag").append("<div id=\"bevestiging\" style=\"display:none;\">Bedankt voor uw aanvraag. Wij proberen zo spoedig mogelijk contact met u op te nemen.</div>");
						$("form#contactfooter").fadeOut("normal", function() { 
							$("form#contactfooter")[0].reset();
							$(".stel-ons-een-vraag div#bevestiging").fadeIn("normal");
						});
						$("form#contactfooter").fadeOut();
					}else{
						alert(html);
					}
				}
			});
		}
	});
});
