(function($){

	$.extend($.validator.messages, {
		required: "Dit is een verplicht veld.",
		email: "Vul hier een geldig email adres in."
	});	
	
	$(".modal").click(function(){
		$.modal($("#modal"), {
			onShow: function(dialog){
				textBlur($("input#sEmail"));
				textBlur($("input#sLastname"));
				
				$("#sBranche").customSelect();
				
				$(".step-1, .step-3").hide();
				
				$(".close button").click($.modal.close);	
				
				/* Validate stuff */
				$("form").validate({
					"errorPlacement": function(er, el){
						if(el.attr("name")=="iAgree"){
							el.closest('p').append(er);
						}else{
							el.parent().find('label').prepend(er);
						}
					},
					"submitHandler": function(form){
						var fields = $("form").serialize();
						$.post("/remote/submit.php", fields, function(data){
							if(data == "1"){
								$("#email-holder").html($("#sEmail").val());
								$(".step-2").hide();
								$(".step-3").show();
							}else{
								alert("Er is een fout opgetreden tijdens het opslaan, probeer het aub opnieuw");
							}
						});

					}
				});
				
				/* ie6 hovers */
				if (typeof document.body.style.maxHeight == "undefined"){ // IE6 only! document.all targets both ie6 & ie7
					$("button").hover(function(){$(this).addClass("hover");}, function(){$(this).removeClass("hover");});
				}

			}
		});
	});
	
	/* TextBlur, for focus,blurring  */
	function textBlur($el){
		if($el.size() > 0){
			var t = $el.val();
			$el.focus(function(){
					if(this.value == t){
						this.value = '';
					}
				})
				.blur(function(){
					if(this.value == '' || this.value == t){
						this.value = t;
					}
				});
		}
	}
	
})(jQuery);
