﻿$(document).ready(function() {
	var error = document.createElement("span");
	error.className = "errorMessage";
	
	function addError($elem, message) {
		if($elem.closest("div").hasClass("errorRow"))
			$elem.closest("div").addClass("errorRow2")
		else $elem.closest("div").addClass("errorRow")
 
		error.innerHTML = message;
		$elem.closest("div").children().end().append(message);
	}
	
	function removeError($elem, message) {
	if($elem.closest("div").hasClass("errorRow"))
			$elem.parent().removeClass("errorRow");
	else $elem.closest("div").removeClass("errorRow2");
		$elem.remove();
	}
 
	var validationsDefaults= {
			errorElement: "span",
			errorPlacement: function(error, element) {
	     			addError(element, error);
	   			},
	   		success: function(label) {
	   			removeError(label);
     		}
     }
     
    jQuery.validator.addMethod("notEmptySelect", function(value, element) {
     	  		return element.value != "";
	});
		
	jQuery.validator.addMethod("customnumber", function(value, element) {
		return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?(?:,\d+)?$/.test(value);
	});
	
	jQuery.validator.addMethod("zipcode", function(value, element) {
		return this.optional(element) || /^[0-9]{4}[a-zA-Z]{2}$/.test(value) || $('#frmCountry').attr('value') != "Nederland";
	});
	
	jQuery.validator.addMethod("emailCorrect", function(value, element) {
		return this.optional(element) || /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i.test(value);
	});
 
		
	jQuery.validator.addMethod("stap1", function(value, element) {
				var checked = false;
				$(".checkBoxes > .formRow input").each(function(){
					var innerChecked = false
					if(this.checked) {
						
						$(this).closest("div.formRow").next().find("input").each(function(){
							if(this.checked) {
								 innerChecked = true;
							}
						});
						
						if(innerChecked == true) {
							checked = true
						} else {
						 checked = false;
						 return false;
						}
					}
										
				});
     	  		return checked;
	});
	
	
	$('form a.bigButton').click(function() {
		$(this).parents('form:first').submit();
		return false;
	});
 
	if($(".homepage").length > 0) {
		$('#logos a').mouseenter(function() {
			var $src = $(this).children('img').attr("src");
			 $src = $src.replace('color','alt');
			 $(this).children('img').attr("src",$src);
 
		});
		
		$('#logos a').mouseleave(function() {
			var $src = $(this).children('img').attr("src");
			 $src = $src.replace('alt','color');
			 $(this).children('img').attr("src",$src);
		});
 
	}
	
	if($(".resultspage").length > 0) {
		$(".detailsLink").toggle(function() {
			var IE7 = false /*@cc_on || @_jscript_version <= 5.7 @*/;
			var $currentRow = $(this).closest("tr");
			var $next = $currentRow.next();
			if($currentRow.hasClass("even"))
				$next.addClass("even")
			else $next.addClass("odd");
			if(IE7) {
				$next.css("display","block");
			} else {
				$next.css("display","table-row");
			}
			return false;
			
		},function() {
			$(this).closest("tr").next().css("display","none");
			return false;
		});
	}
 
	if($(".requestinfo").length > 0) {
		var validated = false;
		$('.initials').keyup(function(){
			this.value=this.value.replace(/,/g,'.');
 
			this.value=this.value.replace(/[^a-zA-Z‘ÆÐƎƏƐƔĲŊŒẞÞǷȜæðǝəɛɣĳŋœĸſßþƿȝĄƁÇĐƊĘĦĮƘŁØƠŞȘŢȚŦŲƯY̨Ƴąɓçđɗęħįƙłøơşșţțŧųưy̨ƴÁÀÂÄǍĂĀÃÅǺĄÆǼǢƁĆĊĈČÇĎḌĐƊÐÉÈĖÊËĚĔĒĘẸƎƏƐĠĜǦĞĢƔáàâäǎăāãåǻąæǽǣɓćċĉčçďḍđɗðéèėêëěĕēęẹǝəɛġĝǧğģɣĤḤĦIÍÌİÎÏǏĬĪĨĮỊĲĴĶƘĹĻŁĽĿʼNŃN̈ŇÑŅŊÓÒÔÖǑŎŌÕŐỌØǾƠŒĥḥħıíìiîïǐĭīĩįịĳĵķƙĸĺļłľŀŉńn̈ňñņŋóòôöǒŏōõőọøǿơœŔŘŖŚŜŠŞȘṢẞŤŢṬŦÞÚÙÛÜǓŬŪŨŰŮŲỤƯẂẀŴẄǷÝỲŶŸȲỸƳŹŻŽẒŕřŗſśŝšşșṣßťţṭŧþúùûüǔŭūũűůųụưẃẁŵẅƿýỳŷÿȳỹƴźżžẓ\.]/g,'');
		});
		
		$('.words').keyup(function(){
			this.value=this.value.replace(/[^a-zA-Z\-‘ÆÐƎƏƐƔĲŊŒẞÞǷȜæðǝəɛɣĳŋœĸſßþƿȝĄƁÇĐƊĘĦĮƘŁØƠŞȘŢȚŦŲƯY̨Ƴąɓçđɗęħįƙłøơşșţțŧųưy̨ƴÁÀÂÄǍĂĀÃÅǺĄÆǼǢƁĆĊĈČÇĎḌĐƊÐÉÈĖÊËĚĔĒĘẸƎƏƐĠĜǦĞĢƔáàâäǎăāãåǻąæǽǣɓćċĉčçďḍđɗðéèėêëěĕēęẹǝəɛġĝǧğģɣĤḤĦIÍÌİÎÏǏĬĪĨĮỊĲĴĶƘĹĻŁĽĿʼNŃN̈ŇÑŅŊÓÒÔÖǑŎŌÕŐỌØǾƠŒĥḥħıíìiîïǐĭīĩįịĳĵķƙĸĺļłľŀŉńn̈ňñņŋóòôöǒŏōõőọøǿơœŔŘŖŚŜŠŞȘṢẞŤŢṬŦÞÚÙÛÜǓŬŪŨŰŮŲỤƯẂẀŴẄǷÝỲŶŸȲỸƳŹŻŽẒŕřŗſśŝšşșṣßťţṭŧþúùûüǔŭūũűůųụưẃẁŵẅƿýỳŷÿȳỹƴźżžẓ\s,\']/g,'');
		});
		
		$('.wordsnumbers').keyup(function() {
			this.value=this.value.replace(/[^0-9a-zA-Z\-‘ÆÐƎƏƐƔĲŊŒẞÞǷȜæðǝəɛɣĳŋœĸſßþƿȝĄƁÇĐƊĘĦĮƘŁØƠŞȘŢȚŦŲƯY̨Ƴąɓçđɗęħįƙłøơşșţțŧųưy̨ƴÁÀÂÄǍĂĀÃÅǺĄÆǼǢƁĆĊĈČÇĎḌĐƊÐÉÈĖÊËĚĔĒĘẸƎƏƐĠĜǦĞĢƔáàâäǎăāãåǻąæǽǣɓćċĉčçďḍđɗðéèėêëěĕēęẹǝəɛġĝǧğģɣĤḤĦIÍÌİÎÏǏĬĪĨĮỊĲĴĶƘĹĻŁĽĿʼNŃN̈ŇÑŅŊÓÒÔÖǑŎŌÕŐỌØǾƠŒĥḥħıíìiîïǐĭīĩįịĳĵķƙĸĺļłľŀŉńn̈ňñņŋóòôöǒŏōõőọøǿơœŔŘŖŚŜŠŞȘṢẞŤŢṬŦÞÚÙÛÜǓŬŪŨŰŮŲỤƯẂẀŴẄǷÝỲŶŸȲỸƳŹŻŽẒŕřŗſśŝšşșṣßťţṭŧþúùûüǔŭūũűůųụưẃẁŵẅƿýỳŷÿȳỹƴźżžẓ\s,\']/g,'');
		});
		$('.postalcode').keyup(function() {
			this.value=this.value.replace(/[^0-9a-zA-Z‘ÆÐƎƏƐƔĲŊŒẞÞǷȜæðǝəɛɣĳŋœĸſßþƿȝĄƁÇĐƊĘĦĮƘŁØƠŞȘŢȚŦŲƯY̨Ƴąɓçđɗęħįƙłøơşșţțŧųưy̨ƴÁÀÂÄǍĂĀÃÅǺĄÆǼǢƁĆĊĈČÇĎḌĐƊÐÉÈĖÊËĚĔĒĘẸƎƏƐĠĜǦĞĢƔáàâäǎăāãåǻąæǽǣɓćċĉčçďḍđɗðéèėêëěĕēęẹǝəɛġĝǧğģɣĤḤĦIÍÌİÎÏǏĬĪĨĮỊĲĴĶƘĹĻŁĽĿʼNŃN̈ŇÑŅŊÓÒÔÖǑŎŌÕŐỌØǾƠŒĥḥħıíìiîïǐĭīĩįịĳĵķƙĸĺļłľŀŉńn̈ňñņŋóòôöǒŏōõőọøǿơœŔŘŖŚŜŠŞȘṢẞŤŢṬŦÞÚÙÛÜǓŬŪŨŰŮŲỤƯẂẀŴẄǷÝỲŶŸȲỸƳŹŻŽẒŕřŗſśŝšşșṣßťţṭŧþúùûüǔŭūũűůųụưẃẁŵẅƿýỳŷÿȳỹƴźżžẓ]/g,'');
		});
		$('.telephone').keyup(function() {
			this.value=this.value.replace(/[^0-9+()\-]/g,'');
		});
		$('.email').keyup(function() {
			this.value=this.value.replace(/[^0-9a-zA-Z@_\.\-]/g,'');
		});
 
		$("form").validate(validationsDefaults);
		$("form").submit(function() {validated = true});
		// berichten
		$("input.fieldsetform ").each(function() {
				$(this).rules("add",{
						required: true,
						messages: {required:"Dit veld is verplicht"}
				});		
		});
		
		$("input[name='frmEmail']").rules("add",{
				emailCorrect: true,
	   	   		messages: {required:"Graag uw emailadres nog invoeren.",emailCorrect:"Uw email is niet correct.",email:"Uw email is niet correct."}
	   	});
 
		$("input[name='frmZipcode']").rules("add",{
				zipcode: true,
	   	   		messages: {required:"Graag uw postcode nog invoeren.",zipcode:"Uw postcode is geen geldige Nederlands postcode."}
	   	});
		$("input[name='frmPhonenumber']").rules("add",{
				minlength: 10,
	   	   		messages: {required:"Graag uw telefoonnummer nog invoeren.",minlength:"uw telefoonnummer dient minimaal tien nummers te bevatten"}
	   	});
		
		$("input[name='frmInitials']").rules("add",{
	   	   		messages: {required:"Graag uw voorletters nog invoeren."}
	   	});
		$("input[name='frmLastname']").rules("add",{
	   	   		messages: {required:"Graag uw achternaam nog invoeren."}
	   	});
 
		$("input[name='frmStreet']").rules("add",{
	   	   		messages: {required:"Graag uw straat nog invoeren."}
	   	});
		$("input[name='frmNumber']").rules("add",{
	   	   		messages: {required:"Graag uw huisnummer nog invoeren."}
	   	});
		$("input[name='frmCity']").rules("add",{
	   	   		messages: {required:"Graag uw stad nog invoeren."}
	   	});
		$("input[name='frmCountry']").rules("add",{
	   	   		messages: {required:"Graag uw land  nog invoeren."}
	   	});
		
		$("input[name='frmCountry']").keyup(function(){ if(validated)$('form').valid();});
		
	}
 
 
	if($(".step1page").length > 0) {
	
		// stap1 validations
		$("form").validate( {
		 invalidHandler: function(e, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                $("div.errorcontainer").show();
            } else {
                $("div.errorcontainer").hide();
            }
        }
		});
	   	$("input").rules("add",{
	   		stap1:true,
	   		messages: {stap1:""}
	   	});
	   
	
		$(".countries").click(function() {
			if($(this).siblings().slice(1).css("display") == "none") {
				$(this).html("Meer landen verbergen");
				$(this).siblings().css("display","block");
			} else {
				$(this).html("Meer landen tonen");
				$(this).siblings().slice(1).css("display","none");
			}	
			return false;
		});
		
		$(".option").each(function() {
			if(this.checked)
				$(this).parent().parent().next().css("display","block");
		});
		
		$(".option").click(function() {
			if(this.checked) {
				$(this).parent().parent().next().css("display","block");
			} else {
				$(this).parent().parent().next().css("display","none");
			}
		});
	}
	
	if($(".step2page").length > 0) {
	
		// stap2 validations
		$("form").validate(validationsDefaults);
	   	
	   	$("input").each(function(){	   		
	   		$(this).rules("add",{
	   		    customnumber: true,
	   			digits: true,
		   		required:true,
		   		messages: {
						customnumber: "U kunt uitsluitend getallen invoeren.",
		   				digits: "U kunt uw getal afronden. Er zijn alleen gehele getallen toegestaan.",
	   					required: "U heeft hier nog geen getal ingevoerd."
	   					}
   			});
   		});
			
		$(".formRow img").each(function() {
			var c = $(this).next().html();
			if(c != null) {
				$(this).qtip({
				   content: c,
				   style: {'padding':0, width: 174, 'border':0}
				});
			}
		});
		
		$(".transactions").blur(function(){
			var value = Math.round(this.value/2);
			$(this).parent().nextAll().find("input.aantal_regels:first").attr("value",value);
		});
		
		$(".details").click(function() {
			if($(this).parent().next().css("display") == "none") {
				$(this).parent().next().css("display","block");
			} else {
				$(this).parent().next().css("display","none");
			}
			
			return false;
		});
		
	};
	
	if($(".step3page").length > 0) {
	
		// stap3 validations
		//$("form").validate( validationsDefaults);
 
		$(".sliderReplacement").each(function() { 
			var v = parseInt($(this).next().html());
			
			$(this).slider({ 
				step: 1,
				min:1,
				max:10,
				value:v,
				slide: function(event, ui) { 
					$(this).next().html(ui.value);
					$(this).nextAll()[1].value = ui.value;
				}
			});
		});
		
		$("select[name=selBroker]").change(function() {
			if(this.value > 0) {
				$('.opinion').css("display","Block");
			} else {
				$('.opinion').css("display","None");
 
			}
		});
	}
});
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
 
/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
 
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
