jQuery(document).ready(
    function(){
					
			//set default data types:
			//jQuery('#achternaam').alpha();
			jQuery('#voornaam').alpha();
			//jQuery('#achternaam1').alpha();
			jQuery('#postcode').numeric();
			jQuery('#postcode2').alpha();
			jQuery('#telefoon').numeric();
      // end of default data types
			
			//postcode- make sure any letters are uppercase
			jQuery('#postcode2').keyup(
					function(){ 
							this.value = this.value.toUpperCase();
					}
			);//end postcode check
           		 
			//country selection section		 
			jQuery('#land').change(
				function(){
					//Germany
					if(jQuery('#land').val() == 'Duitsland'){				
							jQuery("#postcode").attr("maxlength", "5");
							jQuery("#postcode2").removeClass("required");
							jQuery("#postcode2").hide();
							jQuery('#postcode').numeric();
												
					}//duitsland			
					//Nederland
					if(jQuery('#land').val() == 'Nederland'){
							//first remove the other fields then replace them:
							//now set them back up:
							jQuery("#postcode").attr("maxlength", "4");
							jQuery("#postcode2").attr("maxlength", "2");
							jQuery("#postcode2").removeClass("required");
							jQuery("#postcode2").addClass("required");
							jQuery('#postcode').numeric();
							jQuery('#postcode2').alpha();
							jQuery("#postcode2").show();
					}
					//Belgie
					if(jQuery('#land').val() == 'Belgie'){
							jQuery("#postcode").attr("maxlength", "4");
							jQuery('#postcode').numeric();
							jQuery("#postcode2").hide();
							jQuery("#postcode2").removeClass("required");
					} //end of belgie
				});
		  //country selection section
					
			//ajax section
				jQuery("#postcode2").change(function(){
					var pcode       = jQuery("#postcode").val();
					var pcode2      = jQuery("#postcode2").val();
					var pcode       = pcode+pcode2;
					
					//if 2nd postcode field loses focus, send request for the postcode to get rest of the user's details.
					var formdata = jQuery("#Form3").serialize();
					jQuery.ajax({
							type: "POST",
							url: "/ajax/adresXpress_form.php",
							data: formdata,
							success: function(data){
									//alert(data);
									var info        = data.split('|');
									var town        = info[0];
									var street      = info[1];
									jQuery("#adres").val(street); //street address
									jQuery("#woonplaats").val(town); //town/city
							} //success
						}) 
				});
		    //ajax section
				
	      //validate section
        jQuery("#Form3").validate
        (
            {
                onkeyup: false,
                rules:{
                        email: {
                            //required: false,
                            email: true
                        },
                        postcode:{
                            required: true,
                            minlength: 4
                        }
                },
                errorPlacement: function(error, element){},
                highlight: function(element, errorClass)
                { 
                    jQuery(element).fadeOut
                    (
                        function()
                        {
                            jQuery(element).fadeIn();
                        }
                    );
                    jQuery(element).addClass(errorClass);
                },
                unhighlight: function(element, errorClass)
                { 
                    jQuery(element).removeClass(errorClass);
                    jQuery(element).addClass("valid");
                }
            }
        );
        //validate section
			 

				
		
			  //submit section
				jQuery('#formsubmit').one(
																	'click',function(){
																	//
																	if (jQuery("#Form3").validate().form()){
																		 jQuery("#Form3").submit();
																		 //alert('Bedankt voor het aanvragen van het woonideeënboek. U krijgt zo spoedig mogelijk het boek naar u toegestuurd.');
																		//track GA
																		_gaq.push(["_trackPageview", "Analytics/registration/ideeenboek"]);
																		return false;
																	}
						return false;
				});
				//submit section	

		});
//document ready..

	//make email form obligatory when user chooses 'yes sign me up to the newsbrief:
	jQuery('#nieuwsbrief').change(function(){
		 if (jQuery('#nieuwsbrief').is(':checked')){
					jQuery('#email').addClass("required");
					 //alert('e-mail nodig is voor deze optie');
					jQuery('.req_asterisk').show();
			} else{
					jQuery('#email').removeClass("required");
					jQuery('.req_asterisk').hide();
			}
	})
