$(window).resize(function()
{
  setHeight();
});

function setHeight()
{
	var left  = $("#leftContainer").height() + 93;
	var right = $("#rightContainer").height() + 93;
  if (left < $(window).height() && right < $(window).height())
	  $("#contentContainer").height($(window).height() - 93);
}

function toggleSlide(element,speed)
{
	if ($(element).css("display")=="none") $(element).slideDown(speed);
	else  $(element).slideUp(speed);
}

function checkTeacherForm()
{
  var errorMsg  = "De volgende velden zijn niet correct ingevuld:\n";
  var hasErrors = false;

  var fname         = $("#d_fname").val();
  var lname         = $("#d_lname").val();
  var email         = $("#d_email").val();
  var schoolname    = $("#d_schoolname").val();
  var schooladdress = $("#d_schooladdress").val();
  var schoolzipcode = $("#d_schoolzipcode").val();
  var schoolcity    = $("#d_schoolcity").val();
  var schooltype    = $("input[name=d_schooltype]:radio:checked").val();
  var schoolyear    = $("input[name=d_schoolyear]:radio:checked").val();
	var poemlanguage  = $("#d_poemlanguage").val();
  var nrOfStudents  = $("#d_nrOfStudents").val();

  if (fname==null || fname=="")
  {
    hasErrors = true;
    errorMsg += "\n- Voornaam";
  }
  if (lname==null || lname=="")
  {
    hasErrors = true;
    errorMsg += "\n- Achternaam";
  }
  if (email==null || email=="" || !checkEmail(email))
  {
    hasErrors = true;
    errorMsg += "\n- E-mailadres";
  }
  if (schoolname==null || schoolname=="")
  {
    hasErrors = true;
    errorMsg += "\n- Naam school";
  }
  if (schooladdress==null || schooladdress=="")
  {
    hasErrors = true;
    errorMsg += "\n- Straat + Huisnummer";
  }
  if (schoolzipcode==null || schoolzipcode=="")
  {
    hasErrors = true;
    errorMsg += "\n- Postcode";
  }
  if (schoolcity==null || schoolcity=="")
  {
    hasErrors = true;
    errorMsg += "\n- Plaats";
  }
  if (schooltype==null || schooltype=="" || schooltype=="undefined")
  {
    hasErrors = true;
    errorMsg += "\n- Schooltype";
  }
  if (schoolyear==null || schoolyear=="" || schoolyear=="undefined")
  {
    hasErrors = true;
    errorMsg += "\n- Jaar";
  }
  if (poemlanguage==null || poemlanguage=="")
  {
    hasErrors = true;
    errorMsg += "\n- Gedichttaal";
  }
  if (nrOfStudents==null || nrOfStudents=="")
  {
    hasErrors = true;
    errorMsg += "\n- Aantal leerlingen";
  }

  if (hasErrors) alert(errorMsg);
  else $("#d_applicationForm").submit();
}

function checkStudentForm()
{
  var errorMsg  = "De volgende velden zijn niet correct ingevuld:\n";
  var hasErrors = false;

  var fname         = $("#l_fname").val();
  var lname         = $("#l_lname").val();
  var address       = $("#l_address").val();
  var zipcode       = $("#l_zipcode").val();
  var city          = $("#l_city").val();
  var email         = $("#l_email").val();
  var schoolname    = $("#l_schoolname").val();
  var schooltype    = $("input[name=l_schooltype]:radio:checked").val();
  var schoolyear    = $("input[name=l_schoolyear]:radio:checked").val();
  var language      = $("#l_language1").val();
	var poemlanguage  = $("#l_poemlanguage").val();
	var age           = $("#l_age").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- Plaats";
  }
  if (email==null || email=="" || !checkEmail(email))
  {
    hasErrors = true;
    errorMsg += "\n- E-mailadres";
  }
  if (schoolname==null || schoolname=="")
  {
    hasErrors = true;
    errorMsg += "\n- Naam school";
  }
  if (schooltype==null || schooltype=="" || schooltype=="undefined")
  {
    hasErrors = true;
    errorMsg += "\n- Schooltype";
  }
  if (schoolyear==null || schoolyear=="" || schoolyear=="undefined")
  {
    hasErrors = true;
    errorMsg += "\n- Jaar";
  }
  if (language==null || language=="")
  {
    hasErrors = true;
    errorMsg += "\n- Moedertaal";
  }
  if (poemlanguage==null || poemlanguage=="")
  {
    hasErrors = true;
    errorMsg += "\n- Gedichttaal";
  }
  if (age==null || age=="")
  {
    hasErrors = true;
    errorMsg += "\n- Leeftijd";
  }

  if (hasErrors) alert(errorMsg);
  else $("#l_applicationForm").submit();
}

function checkUploadForm()
{
  var errorMsg  = "De volgende velden zijn niet correct ingevuld:\n";
  var hasErrors = false;

  var fname = $("#i_fname").val();
  var lname = $("#i_lname").val();
  var email = $("#i_email").val();
  var title = $("#i_title").val();
  var poem  = $("#i_poem").val();

  if (fname==null || fname=="")
  {
    hasErrors = true;
    errorMsg += "\n- Voornaam";
  }
  if (lname==null || lname=="")
  {
    hasErrors = true;
    errorMsg += "\n- Achternaam";
  }
  if (email==null || email=="" || !checkEmail(email))
  {
    hasErrors = true;
    errorMsg += "\n- E-mailadres";
  }
  if (title==null || title=="")
  {
    hasErrors = true;
    errorMsg += "\n- Titel van het gedicht";
  }
  if (poem==null || poem=="")
  {
    hasErrors = true;
    errorMsg += "\n- Gedicht";
  }

  if (hasErrors) alert(errorMsg);
  else $("#i_uploadForm").submit();
}

function checkMsgForm()
{
  var errorMsg  = "De volgende velden zijn niet correct ingevuld:\n";
  var hasErrors = false;

  var name    = $("#name").val();
  var email   = $("#email").val();
  var message = $("#message").val();

  if (name==null || name=="")
  {
    hasErrors = true;
    errorMsg += "\n- Naam";
  }
  if (email==null || email=="" || !checkEmail(email))
  {
    hasErrors = true;
    errorMsg += "\n- E-mailadres";
  }
  if (message==null || message=="")
  {
    hasErrors = true;
    errorMsg += "\n- Bericht";
  }

  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;
}
