$(window).resize(function()
{
  setMargins();
});

function initGallery()
{
  $("#galleria").galleria(
  {
    data_source: "#photos"
  });
	setTimeout("$('#galleria').show()",500);
}

function setMargins()
{
  var wheight = $(window).height();
  var dheight = $("#centerDiv").height();
  if (wheight>dheight) $("#centerDiv").css("margin-top",((wheight-dheight)/2)+"px");
	else $("#centerDiv").css("margin-top","0");
}

function toggleSlide(element,speed)
{
	if ($(element).css("display") == "none") $(element).slideDown(speed);
	else $(element).slideUp(speed);
}

function checkMsgForm()
{
  var errorMsg  = "De volgende velden zijn niet correct ingevuld:\n";
  var hasErrors = false;

  var name    = $("#name").val();
  var message = $("#message").val();
	var email   = $("#email").val();

  if (message==null || message=="")
  {
    hasErrors = true;
    errorMsg += "\n- Bericht";
  }
  if (name==null || name=="")
  {
    hasErrors = true;
    errorMsg += "\n- Naam";
  }
  if (email==null || email=="" || !checkEmail(email))
  {
    hasErrors = true;
    errorMsg += "\n- E-mailadres";
  }

  if (hasErrors) alert(errorMsg);
  else  $("#addMsgForm").submit();
}

function checkEmail(address)
{
  var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  if (filter.test(address)) return true;
  else return false;
}

function checkContactForm(id)
{
  var errorMsg  = "De volgende velden zijn niet correct ingevuld:\n";
  var hasErrors = false;

	var gender  = $("input[name=gender]:radio:checked").val();
	var fname   = $("#fname").val();
	var lname   = $("#lname").val();
	var cname   = $("#cname").val();
	var address = $("#address").val();
	var zipcode = $("#zipcode").val();
	var city    = $("#city").val();
	var phone   = $("#phone").val();
	var email   = $("#email").val();
	var info    = $("#info").val();

  if (fname==null || fname=="")
  {
    hasErrors = true;
    errorMsg += "\n- voornaam";
  }
  if (lname==null || lname=="")
  {
    hasErrors = true;
    errorMsg += "\n- achternaam";
  }
  if (address==null || address=="")
  {
    hasErrors = true;
    errorMsg += "\n- straat + huisnummer";
  }
  if (zipcode==null || zipcode=="")
  {
    hasErrors = true;
    errorMsg += "\n- postcode";
  }
  if (city==null || city=="")
  {
    hasErrors = true;
    errorMsg += "\n- woonplaats";
  }
  if (phone==null || phone=="")
  {
    hasErrors = true;
    errorMsg += "\n- telefoonnummer";
  }
  if (email!=null && email!="" && !checkEmail(email))
  {
    hasErrors = true;
    errorMsg += "\n- e-mailadres";
  }
  if (info==null || info=="")
  {
    hasErrors = true;
    errorMsg += "\n- informatie over";
  }

	if (hasErrors) alert(errorMsg);
	else 	$("#contactform"+id).submit();
}
