﻿function initMenu() {
	var objContainer = document.getElementById("cellMenu");
	if (objContainer) {
		var menuClasses = "#menuItem#, #menuItemSelect#, #subMenuItem#, #subMenuItemSelect#, #menuItemBlue#, #menuItemBlueSelect#";
		var arrDiv = objContainer.getElementsByTagName("DIV");
		var i, countDiv = arrDiv.length;
		var objGroupSelect = null;
		for (i=0; i < countDiv; i++) {
			if (arrDiv[i].className == "menuItemSelect") {
				var arrAnchor = arrDiv[i].getElementsByTagName("A");
				if (arrAnchor.length == 0) {
					objGroupSelect = arrDiv[i];
					break;
				}
			}
		}
		var objCurrSelect = objGroupSelect;
		for (i=0; i < countDiv; i++) {
			if (menuClasses.indexOf("#" + arrDiv[i].className + "#") > -1) {
				arrDiv[i].onclick = function() {
					var arrAnchor = this.getElementsByTagName("A");
					if (arrAnchor.length == 0) {
						var objDiv = document.getElementById("sub" + this.id);
						if (objDiv) {
							objDiv.style.display = objDiv.style.display == "block" ? "none" : "block";
							this.className = objDiv.style.display == "block" || this == objGroupSelect ? "menuItemSelect" : "menuItem";
							if (objCurrSelect && objCurrSelect != this) {
								objDiv = document.getElementById("sub" + objCurrSelect.id);
								if (objDiv) objDiv.style.display = "none";
								if (objCurrSelect != objGroupSelect) objCurrSelect.className = "menuItem";	
							}
							if (this.className == "menuItemSelect") objCurrSelect = this;
							else if (objCurrSelect == this) objCurrSelect = null;
						}
					}
					else if (arrAnchor[0].target == "_blank") {
						window.open(arrAnchor[0].href);
					}
					else {
						document.location = arrAnchor[0].href;
					}
					return false;
				};
				if (arrDiv[i].className.indexOf("Select") == -1) {
					arrDiv[i].onmouseover = function() {
						if (this.className.indexOf("Select") == -1) this.className = this.className + "Select";
					};
					arrDiv[i].onmouseout = function() {
						if (this.className == "menuItemSelect") {
							var objDiv = document.getElementById("sub" + this.id);
							if (objDiv && objDiv.style.display == "block") return;
						}
						var idx = this.className.indexOf("Select");
						if (idx > -1) this.className = this.className.substring(0, idx);
					};
				}
			}
		}
	}
}
function trimString(str) {
    return str.replace(/^\s+/g,'').replace(/\s+$/g,'');
}
function validateForm(objFrm) {
    var test = trimString(objFrm.elements["achternaam"].value);
    if (test.length == 0) {
        alert("achternaam is verplicht");
        objFrm.elements["achternaam"].focus();
        return false;
    }
    test = trimString(objFrm.elements["emailadres"].value);
    if (test.length == 0) {
        alert("emailadres is verplicht");
        objFrm.elements["emailadres"].focus();
        return false;
    }
	test = getRadioGroupValue(objFrm.elements["ontvangen"]);
	if (test != "digitaal") {
    	test = trimString(objFrm.elements["adres"].value);
		if (test.length == 0) {
			alert("adres is verplicht");
			objFrm.elements["adres"].focus();
			return false;
		}
		test = trimString(objFrm.elements["postcode"].value);
		if (test.length == 0) {
			alert("postcode is verplicht");
			objFrm.elements["postcode"].focus();
			return false;
		}
		test = trimString(objFrm.elements["woonplaats"].value);
		if (test.length == 0) {
			alert("woonplaats is verplicht");
			objFrm.elements["woonplaats"].focus();
			return false;
		}
	}
    return true;
}
function getRadioGroupValue(radioObj) {
	if (!radioObj) return "";
	var radioLength = radioObj.length;
	if (radioLength == undefined) {
		if (radioObj.checked)
			return radioObj.value;
		else
			return "";
	}
	for (var i=0; i < radioLength; i++) {
		if (radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

