function hoverProducts() {
	$('.item a.link').hover(function() {
		$(this).parent('.item').find('.title').css('color','#000').css('background-image','url(images/template/arrow_roll.gif)');								 
	}, function() {
		$(this).parent('.item').find('.title').css('color','#fc9a17').css('background-image','url(images/template/arrow.gif)');								 
	});
}

function hoverHypotheken() {
	$('#links .item').hover(function() {
		$(this).children('a').css('color','#000').css('background-image','url(images/template/arrow_hypotheken_roll.png)');								 
	}, function() {
		$(this).children('a').css('color','#fff').css('background-image','url(images/template/arrow_hypotheken.png)');								 
	});
}

function customSelect(){
	$("select").each(function(){
		$(this).wrap("<div class='selector'></div>");
		var firstText = $(this).find('option.fake').val();
		var span = "<span class='select'>" + firstText + "</span>";
		
		$(this).find('option.fake').hide();							 
		
		$(this).before(span)
		.fadeTo(1, 0)
		.focus(function(){
			$(this).parents(".selector").addClass("focus");
		})
		.change(function(){
			$(this).siblings("span").text($(this).children(":selected").text());
		}).click ( function (){
			$(this).siblings("span").text($(this).children(":selected").text());		
		}) 
		.blur(function(){
			$(this).parents(".selector").removeClass("focus");
		});	
	});
	$('select').trigger("change");
}

function pageSelect() {
	$('#choice').change(function() {
		var sOption = $(this).val();	
		var sLocation = '';
		
		switch(sOption) {
			case 'first':
				sLocation = aLocations['first'];
			break;
			case 'move':
				sLocation = aLocations['move'];
			break;
			case 'edit':
				sLocation = aLocations['edit'];
			break;
			case 'info':
				sLocation = aLocations['info'];
			break;
			case 'calculate':
				sLocation = aLocations['calculate'];
			break;
			case 'apk':
				sLocation = aLocations['apk'];
			break;
		}

		window.location.href = sLocation;
	});
}


function orderForm() {
	
	$('#sStaat').change(function() {
		var sStaat = $(this).val();
		
		if(sStaat == 'Gehuwd' || sStaat == 'Samenwonend') {
			$('#partner').show();
			$('#partner').find('input.partner').addClass('required');
		} else {
			$('#partner').hide();
			$('#partner').find('input.partner').removeClass('required');
		}
	});

	$('#sHypotheek').change(function() {
		var sHypotheek = $(this).val();
		
		if(sHypotheek == 'Kopen bestaande woning' || sHypotheek == 'Kopen nieuwbouwwoning') {
			$('#hypotheek1').show();
			$('#hypotheek1').find('input.partner').addClass('required');
		} else {
			$('#hypotheek1').hide();
			$('#hypotheek1').find('input.partner').removeClass('required');
		}
		
		if(sHypotheek == 'Kopen bestaande woning' || sHypotheek == 'Kopen nieuwbouwwoning') {
			$('#hypotheek2').show();
			$('#hypotheek2').find('input.partner').addClass('required');
		} else {
			$('#hypotheek2').hide();
			$('#hypotheek2').find('input.partner').removeClass('required');
		}
		
/*		if(sHypotheek == 'Verhogen hypotheek') {
			$('#hypotheek3').show();
			$('#hypotheek3').find('input.partner').addClass('required');
		} else {
			$('#hypotheek3').hide();
			$('#hypotheek3').find('input.partner').removeClass('required');
		}*/
		
		if(sHypotheek == 'Oversluiten hypotheek' || sHypotheek == 'Einde rentevastperiode' || sHypotheek == 'Verhogen hypotheek') {
			$('#hypotheek4').show();
			$('#hypotheek4').find('input.partner').addClass('required');
		} else {
			$('#hypotheek4').hide();
			$('#hypotheek4').find('input.partner').removeClass('required');
		}
		
	});
	
	$('#sKoopproces').change(function() {
		var sKoopproces = $(this).val();
	if(sKoopproces == 'Woning gekocht') {
			$('#hypotheek2_2').show();
			$('#hypotheek2_2').find('input.partner').addClass('required');
		} else {
			$('#hypotheek2_2').hide();
			$('#hypotheek2_2').find('input.partner').removeClass('required');
		}
	});	
	
	$('#sKoopproces').change(function() {
		var sKoopproces = $(this).val();
	if(sKoopproces == 'Woningzoekende' || sKoopproces == 'In onderhandeling') {
			$('#hypotheek2_1').show();
			$('#hypotheek2_1').find('input.partner').addClass('required');
		} else {
			$('#hypotheek2_1').hide();
			$('#hypotheek2_1').find('input.partner').removeClass('required');
		}
	});
	
	$('#sLening').change(function() {
		var sLening = $(this).val();
	if(sLening == 'Ja') {
			$('#hypotheek5').show();
			$('#hypotheek5').find('input.partner').addClass('required');
		} else {
			$('#hypotheek5').hide();
			$('#hypotheek5').find('input.partner').removeClass('required');
		}
	});
		
}


function popup() {
	$('.iframe').hover(function(){
		$('.iframe').css('text-decoration','underline');							
	},function(){
		$('.iframe').css('text-decoration','none');							
	});
	$('.iframe, .rentetarieven').click(function(){
		$('#layer').fadeTo(0,0.8);						
		$('#layer').fadeIn('fast');		
		setTimeout('$("#layer_content").show();',350);						
	});
	$('#sluiten').click(function(){
		$('#layer').hide();	
		$('#layer_content').hide();		
	});
	$('#layer').click(function(){
		$('#layer').hide();	
		$('#layer_content').hide();		
	});
}

function initCheckbox() {
	$('.selectbox-wrapper').click(function(){
		submitForm();
	});
	$('.btn1').click(function(){
		$('.btn1').removeClass('checked');
		$(this).addClass('checked');
		$('#sVraag1').attr('value', $(this).attr('title'));
		submitForm();
	});
	$('.btn2').click(function(){
		$('.btn2').removeClass('checked');
		$(this).addClass('checked');
		$('#sVraag2').attr('value', $(this).attr('title'));
		submitForm();
	});
	$('.btn4').click(function(){
		$('.btn4').removeClass('checked');
		$(this).addClass('checked');
		$('#sVraag4').attr('value', $(this).attr('title'));
		submitForm();
	});
	$('.btn5').click(function(){
		$('.btn5').removeClass('checked');
		$(this).addClass('checked');
		$('#sVraag5').attr('value', $(this).attr('title'));
		submitForm();
	});
	$('.btn6').click(function(){
		$('.btn6').removeClass('checked');
		$(this).addClass('checked');
		$('#sVraag6').attr('value', $(this).attr('title'));
		submitForm();
	});
}

function submitForm(){
	sVraag1 = $('#sVraag1').val();
	sVraag2 = $('#sVraag2').val();
	sVraag3 = $('#select-nationaliteit_input').val();
	sVraag4 = $('#sVraag4').val();
	sVraag5 = $('#sVraag5').val();
	sVraag6 = $('#sVraag6').val();

	if(
		sVraag1 != '' && 
		sVraag2 != '' && 
		sVraag3 != 'Selecteer uw nationaliteit' &&
		sVraag4 != '' && 
		sVraag5 != '' && 
		sVraag6 != ''
	) {
		$.ajax({
			url: "requests/vragenlijst.req.php",
			type: "POST",
			data: "vraag1="+sVraag1+"&vraag2="+sVraag2+"&vraag3="+sVraag3+"&vraag4="+sVraag4+"&vraag5="+sVraag5+"&vraag6="+sVraag6,
			success: function(data){
				
				$('#uitkomst_wrapper').html(data);
			},
			error: function(message){
				alert('error'+message);
			}
		});
		return false;
	
	} else {

	}

}

function saveForm(form) {
	var options = {
		url: "requests/vragenlijst.req.php",
		type: "POST",
		success: function(data) {
			sRequest = data;
			aRequest = sRequest.split('|');
			if(aRequest[0] == 'success') {
				$('#message').html(aRequest[1]);
				$(form).remove();
			} else {
				$('#message').html(aRequest[1]);
			}
			$('#message').show();
		}
	}
	$(form).ajaxSubmit(options);
}

function validateForm(p_sForm) {
	var rules = {};
	var messages = {};
	if(p_sForm == 'orderform') {
		rules[aFields[1]] = {
			required: true
		};
		rules[aFields[2]] = {
			required: false
		};
		rules[aFields[3]] = {
			required: true,
			minlength: 2
		};
		rules[aFields[4]] = {
			required: true
		};
		rules[aFields[14]] = {
			required: true
		};
		rules[aFields[5]] = {
			required: true
		};
		rules[aFields[6]] = {
			required: true
		};
		rules[aFields[7]] = {
			required : true,
			maxlength: 14
		};
		rules[aFields[8]] = {
		};
		rules[aFields[9]] = {
			required: true,
			email: true
		};
		rules[aFields[10]] = {
			required: true
		};
		rules[aFields[11]] = {
			required: true
		};
		rules[aFields[21]] = {
			required: false
		};
		rules[aFields[17]] = {
			required: false
		};
		rules[aFields[19]] = {
			required: false
		};
		
		messages[aFields[1]] = {
			required: 'Vul uw voorletter(s) in'
		};
		messages[aFields[2]] = {
			required: ''
		};
		messages[aFields[3]] = {
			required: 'Vul uw achternaam in',
			minlength: 'Vul een geldige achternaam in'
		};
		messages[aFields[4]] = {
			required: 'Vul uw straatnaam in'
		};
		messages[aFields[14]] = {
			required: 'Vul uw huisnummer in'
		};
		messages[aFields[5]] = {
			required: 'Vul uw postcode in'
		};
		messages[aFields[6]] = {
			required: 'Vul uw woonplaats in'
		};
		messages[aFields[7]] = {
			required: 'Vul uw telefoonnummer in',
			maxlength: 'Vul een geldig telefoonnummer in'
		};
		messages[aFields[8]] = {
		};
		messages[aFields[9]] = {
			required: 'Vul uw e-mailadres in',
			email: 'Vul een geldig e-mailadres in'
		};
		messages[aFields[10]] = {
			required: 'Vul uw geboortedatum in'
		};
		messages[aFields[11]] = {
			required: 'Vul uw bruto jaarinkomen in'
		};
		messages[aFields[21]] = {
			required: ''
		};
		messages[aFields[17]] = {
			required: 'Vul uw gewenste hypotheek in'
		};
		messages[aFields[19]] = {
			required: 'Vul uw huidige hypotheek in'
		};
		
	}
	
	$('#'+p_sForm).validate({
		rules: rules,
		messages: messages,
		errorPlacement: function(error, element) {
			console.log(error);
			var obj = element.parents('.field');
			error.insertAfter(obj);
		},
		success: function(label) {
			label.remove();
		},
		submitHandler: function(form) {
			form.trigger('submit');
		}
	});	
}

function validateInschrijven() {
	var aMessage = new Array();
	aMessage[0] = 'Vul uw naam in.';
	aMessage[1] = 'Vul uw e-mailadres in.';
	aMessage[2] = 'Geen geldig e-mailadres.';

	$('#nieuwsbrief').validate({
		rules: {
			sNaam: {
				required: true
			},
			sEmail: {
				required: true,
				email: true
			}
		},
		messages: {
			sNaam: {
				required: aMessage[0]
			},
			sEmail: {
				required: aMessage[1],
				email: aMessage[2]
			}
		},
		errorPlacement: function(error, element) {
			error.insertAfter(element.parents('.field'));
		},
		success: function(label) {
			label.remove();
		},
		submitHandler: function(form) {
			var sDiv = '';
			var options = {
				url: 'inc/inschrijven.inc.php',
				type: 'POST',
				success: function(sData) {
					var aResponse = sData.split('|');
					if(aResponse[0] == 0){
						$('#nieuwsbrief').fadeOut(500, function(){
							$(this).remove();						 
						});
						
						sDiv += '<div class="succes">';
						sDiv += aResponse[1];
						sDiv += '</div>';
						
					} else if(aResponse[0] == 1){

						sDiv += '<div class="succes">';
						sDiv += aResponse[1];
						sDiv += '</div>';
					}
					$('div.melding').html(sDiv);
		
					setTimeout("$('.melding').fadeIn(700)", 499);
					
				}
			}
			$(form).ajaxSubmit(options);
			return false;
		}
	});	
}

function vergelijkerCycle() {
	$('#vergelijker').cycle({
		fx:			'scrollHorz',
		next:		'#next',
		prev:		'#prev',
		timeout:	0,
		easing:  	'backinout'
	});
}
