$(document).ready(function(){
	$("#input_search").focus(function(){
		clearBox($(this), 'zoeken');
	});
	$("#input_search").blur(function(){
		fillBox($(this),'zoeken');
	});
	$("#call_name").focus(function(){
		clearBox($(this), 'uw naam');
	});
	$("#call_name").blur(function(){
		fillBox($(this),'uw naam');
	});
	$("#call_phone").focus(function(){
		clearBox($(this), 'uw telefoonnummer');
	});
	$("#call_phone").blur(function(){
		fillBox($(this),'uw telefoonnummer');
	});
	$(".par_home").mouseover(function(){
		$(this).addClass('active');
	});
	$(".par_home").mouseout(function(){
		$(this).removeClass('active');
	});
	
	$("#googlemaps_from").focus(function(){
		clearBox($(this), 'uw adres');
	});
	$("#googlemaps_from").blur(function(){
		fillBox($(this),'uw adres');
	});
	
	$("#contact_name").focus(function(){
		clearBox($(this), 'Naam');
	});
	$("#contact_name").blur(function(){
		fillBox($(this),'Naam');
	});
	
	$("#contact_email").focus(function(){
		clearBox($(this), 'E-mail of telefoonnummer');
	});
	$("#contact_email").blur(function(){
		fillBox($(this),'E-mail of telefoonnummer');
	});
	
	$("#contact_subject").focus(function(){
		clearBox($(this), 'Onderwerp');
	});
	$("#contact_subject").blur(function(){
		fillBox($(this),'Onderwerp');
	});
	
	$("#contact_question").focus(function(){
		clearBox($(this), 'Vraag');
	});
	$("#contact_question").blur(function(){
		fillBox($(this),'Vraag');
	});
	
	focusoptions();
	$("#math_contact").click(function(){
		document.location.href = '/contact/';
	});
	$(".par_home").click(function(){
		var id = $(this).attr('id');
		if(id == 'par_home_1'){
			document.location.href = '/verzekeringen/';
		}else if(id == 'par_home_2'){
			document.location.href = '/hypotheken/';
		}else if(id == 'par_home_3'){
			document.location.href = '/bancaire-diensten/';
		}
	});
	
	$(".topitem").click(function(){
		var id = $(this).attr('id');
		if(id == 'topitem_1'){
			document.location.href = '/verzekeringen/';
		}else if(id == 'topitem_2'){
			document.location.href = '/hypotheken/';
		}else if(id == 'topitem_3'){
			document.location.href = '/bancaire-diensten/';
		}
	});
	
	$('#mailoverlay').hover(function() {
		var offset = $("#mailoverlay").offset();
		if(offset.left == -180){
			$("#mailoverlay").stop().animate({"left": "+=180px"}, "slow");
		}
	}, function(){
		window.setTimeout(function() {
			var offset = $("#mailoverlay").offset();
			if(offset.left == 0){
				$("#mailoverlay").stop().animate({"left": "-=180px"}, "slow");
			}
		}, 4000);
	});
	
	window.setTimeout(function() {
		$("#mailoverlay").animate({"left": "-=180px"}, "slow");
	}, 4000);
	
	
	
	$("#contact_button").click(function(){
		mail();
	});
	
	$(":input[@name='partner']").change(function(){
		if ($(":input[@name='rdio']:checked").val() == 'y'){
			$("#specialcontainer #math_age2, #specialcontainer #math_2").css({ 'display' : 'inline' });
		}else{
			$("#specialcontainer #math_age2, #specialcontainer #math_2").css({ 'display' : 'none' });
		}
	});
	
	$("#overlay_close").click(function(){
		closeoverlay();
	});
	
	$(".newsimage").click(function(){
		var id = $(this).attr('id');
		$("#overlay_bg").css({ 'display' : 'block' });
		$("#overlay").html('<img src="/media/basic/images/plugins/news/resize_'+id+'" border="0" alt="" />');
		$("#overlay").css({ 'display' : 'block' });
		$("#overlay_close").css({ 'display' : 'block' });
	});
});

function closeoverlay(){
	$("#overlay_bg").css({ 'display' : 'none' });
	$("#overlay").css({ 'display' : 'none' });
	$("#overlay_close").css({ 'display' : 'none' });
}

function focusoptions(){
	$("#math_age").focus(function(){
		clearBox($(this), 'uw leeftijd');
	});
	$("#math_age").blur(function(){
		fillBox($(this),'uw leeftijd');
	});
	$("#math_1").focus(function(){
		clearBox($(this), 'uw bruto jaarinkomen');
	});
	$("#math_1").blur(function(){
		fillBox($(this),'uw bruto jaarinkomen');
	});
	$("#math_age2").focus(function(){
		clearBox($(this), 'leeftijd partner');
	});
	$("#math_age2").blur(function(){
		fillBox($(this),'leeftijd partner');
	});
	$("#math_2").focus(function(){
		clearBox($(this), 'bruto jaarinkomen partner');
	});
	$("#math_2").blur(function(){
		fillBox($(this),'bruto jaarinkomen partner');
	});
}
function mathform(){
	$("#specialcontainer").html('<form name="" action="" method="post" onsubmit="math_hypotheek();return false;"><table cellpadding="0" cellspacing="0" border="0"><tr><td valign="top" colspan="2" style="padding-bottom: 20px;"><h3>Bereken Hypotheek</h3></td></tr><tr><td valign="top" colspan="2" id="errormelding"></td></tr><tr><td valign="top" style="padding-bottom: 10px;"><input type="text" name="math_age" id="math_age" value="uw leeftijd" /></td><td valign="top"><input type="text" name="math_1" id="math_1" value="uw bruto jaarinkomen" /></td></tr><tr><td valign="top" colspan="2" style="padding-bottom: 10px;">Partner met inkomen: <input type="radio" name="partner" id="partner_y" value="y" checked="checked" /> Ja <input type="radio" name="partner" id="partner_n" value="n" /> Nee</td></tr><tr><td valign="top" style="padding-bottom: 10px;"><input type="text" name="math_age2" id="math_age2" value="leeftijd partner" /></td><td valign="top"><input type="text" name="math_2" id="math_2" value="bruto jaarinkomen partner" /></td></tr><tr><td valign="top" align="right" colspan="2"><input type="submit" value="Berekenen" /></td></tr></table></form>');
	focusoptions();
}
function clearBox(box, string) {
	if(box.val()==string) {
		box.val('');
	}
}
function fillBox(box, string) {
	if(box.val()=="") {
		box.val(string);
	}
}
function search(){	
	var keywords = $('#input_search').val();
	location.href='/zoeken/'+keywords;
	return false;
}

function math_hypotheek(){
	var item1 = $("#math_1").val().replace('.','').replace(',','');
	var item2 = $("#math_2").val().replace('.','').replace(',','');
	if(item1 == parseFloat(item1) && item2 == parseFloat(item2)){
		var c = Math.round((parseInt(item1) + parseInt(item2)) * 4.6);
		$("#specialcontainer").html("<h3>Bereken Hypotheek</h3><br /><br /><span style=\"font-size: 15px;\">uw geschatte hypotheek komt neer op:<br /><br /><span style=\"font-size: 48px;\">&euro; "+c+"</span></span><br /><br /><a href='javascript:mathform();' style='color: #ffffff;'>Opnieuw berekenen</a><br /><br /><input type='submit' id='math_contact' value='contact opnemen' style='position: relative; float: right;' />" );
		$("#math_contact").click(function(){
			document.location.href = '/contact/';
		});
	}else if(item1 == parseFloat(item1)){
		var c = Math.round((parseInt(item1)) * 4.6);
		$("#specialcontainer").html("<h3>Bereken Hypotheek</h3><br /><br /><span style=\"font-size: 15px;\">uw geschatte hypotheek komt neer op:<br /><br /><span style=\"font-size: 48px;\">&euro; "+c+"</span></span><br /><br /><a href='javascript:mathform();' style='color: #ffffff;'>Opnieuw berekenen</a><br /><br /><input type='submit' id='math_contact' value='contact opnemen' style='position: relative; float: right;' />" );
		$("#math_contact").click(function(){
			document.location.href = '/contact/';
		});
	}else{
		$("#specialcontainer #errormelding").html("u heeft geen geldig bruto jaarinkomen opgegeven.");
	}
	
}

function mail(){
	var name = $("#contact_name").val();
	var subject = $("#contact_subject").val();
	var email = $("#contact_email").val();
	var message = $("#contact_question").val();
	if((name != 'Naam' && name != '') && (email != 'E-mail of telefoonnummer' && email != '') && (message != 'Vraag' && message != '')){
		$.post('../media/basic/ajax/mail.php',{
			action : 'mail',
			name : name,
			subject: subject,
			email: email,
			message : message
		},function(data){
			if(data == "SUCCESS"){
				//$("#contact_container").fadeOut('slow', function() {
					$("#contactcontainer").html("<div style=\"padding-right: 25px;\"><br /><h3>Bedankt</h3><br />Wij hebben uw gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.</div>");
				//	$("#contact_container").fadeIn('slow');
				//});
			}
			return false;
		});
	}if((name == 'Naam' || name == '')){
		$("#contact_name").addClass('error');
	}else{
		$("#contact_name").removeClass('error');
	}
	if((email == 'E-mail of telefoonnummer' || email == '')){
		$("#contact_email").addClass('error');
	}else{
		$("#contact_email").removeClass('error');
	}
	if((message == 'Vraag' || message == '')){
		$("#contact_question").addClass('error');
	}else{
		$("#contact_question").removeClass('error');
	}
}
function call(){
	var name = $("#call_name").val();
	var phonenumber = $("#call_phone").val();
	if((name != 'uw naam' && name != '') && (phonenumber != 'uw telefoonnummer' && phonenumber != '')){
		$.post('../media/basic/ajax/mail.php',{
			action : 'call',
			name : name,
			phonenumber: phonenumber
		},function(data){
			if(data == "SUCCESS"){
				//$("#contact_container").fadeOut('slow', function() {
					$("#callfromresult").html("<div style=\"padding-right: 25px; margin-top: -10px; position: relative;\"><br /><h2 style=\"float: left; position: relative;\">Bedankt</h2><div  style=\"float: left; position: relative; padding-top: 8px;\">Wij hebben uw gegevens ontvangen en zullen u zo spoedig mogelijk terugbellen.</div></div>");
				//	$("#contact_container").fadeIn('slow');
				//});
			}
			return false;
		});
	}if((name == 'uw naam' || name == '')){
		$("#call_name").addClass('error');
	}else{
		$("#call_name").removeClass('error');
	}
	if((phonenumber == 'uw telefoonnummer' || phonenumber == '')){
		$("#call_phone").addClass('error');
	}else{
		$("#call_phone").removeClass('error');
	}
}
function validateMail(email){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
		return false;
	}else{
		return true;
	}
}
