function onPage(page)
{
	document.location.href=g_phpFilename + "?category=" + g_category + "&page=" + page;
	return false;
}

function onTopMenuMouseOver(obj, event, tableId)
{
	menu_showPopup(-1, event, document.getElementById(tableId), obj, "bottom");
}

function onTopMenuMouseOut(obj, event, tableId)
{
	menu_exitPopupDelayed(-1, event);
}

function resizeFrame(body)
{
	iframe = document.getElementById("mainFrame");
	var mainFrameContent = document.getElementById("mainFrameContent");
	body = body.document.body;
	if (mainFrameContent)
		mainFrameContent.innerHTML = body.innerHTML;
}

var current = null;

function setFlash(which)
{
	var pageFlash = null;
	if (document.embeds && document.embeds["pageFlash1"])
	{
		pageFlash = document.embeds["pageFlash1"];
	}
	else
	{
		pageFlash = document.getElementById("pageFlash");
	}
	
	if (!pageFlash || typeof pageFlash.LoadMovie == "undefined" || pageFlash.PercentLoaded() == 0)
	{
		// flash has been disabled
		var flashDiv   = document.getElementById("flashDiv");
		var noFlashDiv = document.getElementById("noFlashDiv");
		
		flashDiv.style.display = "none";
		noFlashDiv.style.display = "";
		
		noFlashDiv.firstChild.src = which=="home" ? "images/CLF_foto_groot.jpg" : "images/CLF_foto_klein.jpg";
		return;
	}
	
	var flashDiv = document.getElementById("flashDiv");
	
	var height = 165;
	if (which!="home")
	{
		filename = "CLF_slides_klein_h100_w780.swf";
		height = 99;
	}
	else 
	{
		filename = "home.swf";
	}
	
	var backgroundPosY = 130 + height;
	var body = document.getElementsByTagName("body")[0];
	body.style.backgroundPosition = "left " + backgroundPosY + "px";
		
	if (current == null)
	{
		current = pageFlash.src ? pageFlash.src : pageFlash.movie;
	}

	if (current != "flash/" + filename)
	{
		current = "flash/" + filename;
		pageFlash.LoadMovie(0, current);
		pageFlash.height = height;
		flashDiv.style.height = height + "px";
	}
}

function setMenu(name)
{
	var menuObj = document.getElementById("menu");
	var tds = menuObj.firstChild.firstChild.firstChild.childNodes;
	var i;
	for(i=0; i<tds.length; i++)
	{
		tds[i].className = "";
	}
	
	var elt = document.getElementById("menu_" + name);
	if (elt)
	{
		elt.className = "active";
	}
}

function checkFrame(which, bodyObj)
{
	if (parent)
	{
		var topCategory = _GET("category");
		if (!topCategory)
			topCategory = _GET("category0");

		parent.setMenu(topCategory);

		parent.resizeFrame(bodyObj);
	
		parent.setFlash(which);
		
	}
}

function checkForm(form, obligatory)
{
	var regX = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/);
	
	var i;
	var success = true;
	for(i=0; i<obligatory.length; i++)
	{
		var e = form.elements[obligatory[i]];
		if (e.value == "" || (obligatory[i] == "contactEmail" && !regX.test(e.value)))
		{
			success = false;
			e.parentNode.previousSibling.className = "obligatory";
		}
		else
		{
			e.parentNode.previousSibling.className = "";
		}
	}
	
	if (!success)
	{
		alert("U heeft niet alle verplichte velden ingevuld.")
	}
	return success;;
}

function onSubmitNieuwsbrief(form)
{
	return checkForm(form, Array("naam", "email"));
}

function onSubmitContact(form)
{
	return checkForm(form, Array("naam", "email"));
}

function onSubmitComplaint(form)
{
	if (document.getElementById("missingClothes").checked || 
		document.getElementById("missingObject").checked || 
		document.getElementById("missingOtherCheck").checked)
	{
		var checkArr = Array("date_day", "date_month", "date_year", "location", "lastName", "initials", "qicNumber", "contactEmail",
							 "clothing", "clothingColor", "clothingSize", "clothingDetails", 
							 "missingSince_day", "missingSince_month", "missingSince_year");
		
		if (document.getElementById("missingOtherCheck").checked)
		{
			checkArr.push("missingOther");
		}
	}
	else
	{
		var missingCheckArr = Array("clothing", "clothingColor", "clothingSize", "clothingDetails", 
									"missingSince_day", "missingSince_month", "missingSince_year", "missingOther");
		for(i=0; i<missingCheckArr.length; i++)
		{
			var e = form.elements[missingCheckArr[i]];
			e.parentNode.previousSibling.className = "";
		}
		
		var checkArr = Array("date_day", "date_month", "date_year", "location", "lastName", "initials", "qicNumber", "contactEmail");
	}
	
	return checkForm(form, checkArr);
}

function toggleCheck(checkBox)
{
	var checkBoxes = document.getElementsByName(checkBox.name);
	
	for (var i = 0; i < checkBoxes.length; i++)
	{
		if (checkBoxes[i].checked && checkBoxes[i].value != checkBox.value)
		{
			checkBoxes[i].checked = false;
		}
	}
}

function checkNumericField(e)
{
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if (keynum == 8 || keynum == 9 || keynum == 37 || keynum == 39)
	{
		return true;
	}
	
	keychar = String.fromCharCode(keynum);

	numcheck = /[^0-9]/;
	return !numcheck.test(keychar);
}



