function key(e)
{
  if (!e) var e = window.event;
  if (e.keyCode) return e.keyCode;
  else if (e.which) return e.which;
}

function checkInput(key,id)
{
	if (key==13)
	{
		doSearchAll(id);
		return false;
	}
}

function setHeight()
{
	$("#content_middle_text").hide(1).show(1,function(){ setHeight2(); });
}

function setHeight2()
{
  var left   = $("#content_left");
  var midc   = $("#content_middle_container");
	var middle = $("#content_middle");
  var right  = $("#content_right");

  var rightHeight = 238;
  if ($("#content_right_buttons").height()>($("#content_right_top").height()+257))
  	rightHeight += $("#content_right_buttons").height();
  else
    rightHeight += $("#content_right_top").height() + 257;

  var highest = rightHeight;
  if ($("#content_middle_text").height()+78>highest) highest = $("#content_middle_text").height()+78;

  left.height(highest);
  midc.height(highest);
	middle.height(highest);
  right.height(highest);
}

function adjustScroll(width)
{
  if (width>1025)
  {
	  var scroll = (1390-width)/2;
	  $(document).scrollLeft(scroll);
  }
  else $(document).scrollLeft(182);
}

function closePopup()
{
  $("#popup").slideUp(200);
}

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 checkForm(formName)
{
  var form = document.getElementById(formName);
  var error = false;
  var errorMsg = "De volgende velden zijn niet (correct) ingevuld:\n";
  //if (form.companyName.value == null || form.companyName.value == "") { error = true; errorMsg += "\n- bedrijfsnaam"; }
  if (form.initials.value    == null || form.initials.value    == "") { error = true; errorMsg += "\n- voorletter(s)"; }
  if (form.lastName.value    == null || form.lastName.value    == "") { error = true; errorMsg += "\n- achternaam"; }
  if (form.address.value     == null || form.address.value     == "") { error = true; errorMsg += "\n- straat + huisnummer"; }
  if (form.zipcode.value     == null || form.zipcode.value     == "") { error = true; errorMsg += "\n- postcode"; }
  if (form.city.value        == null || form.city.value        == "") { error = true; errorMsg += "\n- woonplaats"; }
  if (form.email.value       == null || form.email.value       == "" || !checkEmail(form.email.value)) { error = true; errorMsg += "\n- e-mail adres"; }
  if (form.info.value        == null || form.info.value        == "") { error = true; errorMsg += "\n- vragen/opmerkingen"; }
  if (error) alert(errorMsg);
  else document.getElementById(formName).submit();
}

function preloader() 
{
  imageObj 	 = new Image();
  images 	 = new Array();
  images[0]  = "/images/buttons/btn01.gif";
  images[1]  = "/images/buttons/btn02_active.gif";
  images[2]  = "/images/buttons/btn03_active.gif";
  images[3]  = "/images/buttons/btn04_active.gif";
  images[4]  = "/images/buttons/btn05_active.gif";
  images[5]  = "/images/buttons/btn06_active.gif";
  images[6]  = "/images/buttons/btn07_active.gif";
  images[7]  = "/images/buttons/btn08_active.gif";
  images[8]  = "/images/buttons/btn01_active.gif";
  images[9]  = "/images/buttons/btn02.gif";
  images[10] = "/images/buttons/btn03.gif";
  images[11] = "/images/buttons/btn04.gif";
  images[12] = "/images/buttons/btn05.gif";
  images[13] = "/images/buttons/btn06.gif";
  images[14] = "/images/buttons/btn07.gif";
  images[15] = "/images/buttons/btn08.gif";
  for (var i=0; i<=15; i++) { imageObj.src=images[i]; }
}

var hoverDelay = null;
function delayedSlideDown(id)
{
  if (hoverDelay!=null) clearTimeout(hoverDelay);
  hoverDelay = setTimeout("$('#"+id+"').slideDown()",500);
}

function doSearchAll(id)
{
  var params = $("#searchAllForm").serialize();
  $("#projectList").load("ajax/loadprojects.jsp?id="+ id +"&searchAll=1&"+ params,function() { $(".colorbox").colorbox();$("#loadList").hide(0,function() { setHeight(); }); });
}

function doAdvancedSearch(id)
{
	var params = $("#searchAdvancedForm").serialize();
  $("#projectList").load("ajax/loadprojects.jsp?id="+ id +"&searchAdvanced=1&"+ params,function() { $(".colorbox").colorbox();$("#loadList").hide(0,function() { setHeight(); }); });
}

function mailLogin(id)
{
	var go = confirm("Weet u zeker dat u deze gebruiker zijn/haar inloggegevens wil mailen?");
	if (go) alert("Under construction...\n\nEr worden momenteel geen e-mails verstuurd.");
}

function checkConferenceForm()
{
	var errorMsg     = "";
	var organisation = $("#organisation").val();
	var name         = $("#name").val();
	var func         = $("#function").val();
	var email        = $("#email").val();
	var buffet       = $("input:radio[name=buffet]:checked").val();

	if (organisation==null || organisation=="")         errorMsg += "\n- Organisatie";
	if (name==null || name=="")                         errorMsg += "\n- Naam";
	if (func==null || func=="")                         errorMsg += "\n- Function";
	if (email==null || email=="" || !checkEmail(email)) errorMsg += "\n- E-mailadres";
	if (buffet==null || buffet=="")                     errorMsg += "\n- Deelname buffet";

	if (errorMsg!="") alert("De volgende velden zijn niet correct ingevuld:\n" + errorMsg);
	else $("#conferenceForm").submit();
}
