var timer = null;

$(document).ready(function() {

	$("#menu-holder div").each(function(i) {
		$(this).mouseover(function() {
			$(".submenu").hide();
			$("#sub"+this.id).show();
			clearTimeout(timer);
			$("#menu-holder div").each(function(i) {
				$("#"+this.id+" img").attr("src", "static/img/"+this.id+"-off.png");
			});
			$("#"+this.id+" img").attr("src", "static/img/"+this.id+"-on.png");
		});
		$(this).mouseout(function() {
			$(".submenu").hide();
			$("#sub"+this.id).show();
			timer = setTimeout("restoreMenu()", 500);
			//$("#"+this.id+" img").attr("src", "static/img/"+this.id+"-off.png");
		});
	});
	
	$("#correspondentie-same").click(function(i) {
		if(this.checked) {
			$("#correspondentie-adres").val($("#vestiging-adres").val());
			$("#correspondentie-adres").attr("readonly", "readonly");
			$("#correspondentie-postcode").val($("#vestiging-postcode").val());
			$("#correspondentie-postcode").attr("readonly", "readonly");
			$("#correspondentie-plaats").val($("#vestiging-plaats").val());
			$("#correspondentie-plaats").attr("readonly", "readonly");
		} else {
			$("#correspondentie-adres").attr("readonly", "");
			$("#correspondentie-postcode").attr("readonly", "");
			$("#correspondentie-plaats").attr("readonly", "");
		}
	});
	
	$(".submenu").mouseover(function(i) {
		clearTimeout(timer);
	});
	
	$(".submenu").mouseout(function(i) {
		timer = setTimeout("restoreMenu()", 500);
	});
	
	$(".faq-answer").hide();
	$(".faq-question").click(function() {
		var cid = this.id;
		if($("#"+cid.replace("q", "a")).css("display") == "none") {
			$(".faq-answer").hide();
			$("#"+cid.replace("q", "a")).show();
		} else {
			$(".faq-answer").hide();
		}
	});
	
});

function restoreMenu() {
	$(".submenu").hide();
	$("#submenu-"+$("#active-menu").val()).show();
	$("#menu-holder div").each(function(i) {
		$("#"+this.id+" img").attr("src", "static/img/"+this.id+"-off.png");
	});
	$("#menu-"+$("#active-menu").val()+" img").attr("src", "static/img/menu-"+$("#active-menu").val()+"-on.png");
}

function checkForm() {
	var a = $("#vestiging-naam").val();
	var b = $("#vestiging-adres").val();
	var c = $("#vestiging-postcode").val();
	var d = $("#vestiging-plaats").val();
	var e = $("#vestiging-telefoon").val();
	var f = $("#vestiging-btw").val();
	var g = $("#vestiging-bank").val();
	var h = $("#correspondentie-adres").val();
	var i = $("#correspondentie-postcode").val();
	var j = $("#correspondentie-plaats").val();
	var k = $("#contactpersoon-geslacht-man").attr("checked");
	var l = $("#contactpersoon-geslacht-vrouw").attr("checked");
	var m = $("#vestiging-voorletters").val();
	var n = $("#vestiging-achternaam").val();
	var o = $("#akkoord").attr("checked");
	if(a !== "" && b !== "" && c !== "" && d !== "" && e !== "" && f !== "" && g !== "" && h !== "" && i !== "" && j !== "" && (k || l) && m !== "" && n !== "" && o) {
		$("#form").submit();
	} else {
		alert("Vul eerst alle verplichte velden in.");
	}
}

function checkForm2() {
	var a = $("#companyname").val();
	var b = $("#numemployees").val();
	var c = $("#firstname").val();
	var d = $("#lastname").val();
	var e = $("#phone").val();
	var f = $("#email").val();
	if(a !== "" && b !== "" && c !== "" && d !== "" && e !== "" && f !== "") {
		$("#form").submit();
	} else {
		alert("Vul eerst alle verplichte velden in.");
	}
}

function checkForm3() {
	var a = $("#companyname").val();
	var b = $("#numemployees").val();
	var c = $("#city").val();
	var d = $("#firstname").val();
	var e = $("#lastname").val();
	var f = $("#function").val();
	var g = $("#phone").val();
	var h = $("#email").val();
	if(a !== "" && b !== "" && c !== "" && d !== "" && e !== "" && f !== "" && g !== "" && h !== "") {
		$("#form").submit();
	} else {
		alert("Vul eerst alle verplichte velden in.");
	}
}
