﻿function InitPage() {
    objMainMenu = new MainMenu();
}
/* MENU SECTION */
function MainMenu() {
	this.doMouseOver = mDoMouseOver;
	this.doMouseOut = mDoMouseOut;
	this.doSelect = mSelect;
	this.showDropDown = mShowDropDown;
	this.arrDropDowns = new Array();
	this.pathLength = 0;
	this.arrHover = new Array();
	this.clear = mClear;
	this.clearTimer = null;
	this.dropDownTimer = null;
	var arrMnuItems = document.getElementsByTagName("div");
	for (var i=0; i < arrMnuItems.length; i++) {
		if (arrMnuItems[i].className.indexOf("menuItem") > -1) {
			arrMnuItems[i].onmouseover = Function("objMainMenu.doMouseOver(this, true);");
			arrMnuItems[i].onmouseout = Function("objMainMenu.doMouseOut();");
			arrMnuItems[i].onclick = Function("objMainMenu.doSelect(this);");
		}
		else if (arrMnuItems[i].className == "dropDownMenuBottom") {
			arrMnuItems[i].onmouseover = Function("objMainMenu.doMouseOver(this, false);");
			arrMnuItems[i].onmouseout = Function("objMainMenu.doMouseOut();");
		}
	}		
	var arrImg = document.getElementsByTagName("img");
	for (var i=0; i < arrImg.length; i++) {
		if (arrImg[i].src.indexOf("menu-sep.gif") > -1) {
			arrImg[i].onmouseover = Function("objMainMenu.doMouseOver(this, false);");
			arrImg[i].onmouseout = Function("objMainMenu.doMouseOut();");
		}
	}		
	this.menuHeight = 21;
	this.menuWidth = 126;
	this.menuLeft = 0;
	if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
		//this.menuLeft = 0;
	}
}
function mSelect(objDiv) {
	var arrAnchors = objDiv.getElementsByTagName("A");
	if (arrAnchors.length > 0 && arrAnchors[0].onclick == null) {
		if (arrAnchors[0].target != null && arrAnchors[0].target == "_blank") {
			openPage(arrAnchors[0].href);
		}
		else {
			loadPage(arrAnchors[0].href);
		}
    }
	return false;
}
function loadPage(url) {
	document.location.href = url;
}
function openPage(url) {
	window.open(url);
}
function mDoMouseOver(objMenu, isMenu) {
	if (this.clearTimer != null) {
		window.clearTimeout(this.clearTimer);
		this.clearTimer = null;
	}
	if (this.dropDownTimer != null) {
	    window.clearTimeout(this.dropDownTimer);
		this.dropDownTimer = null;
	}
	if (isMenu) {
		var arrNewHover = new Array();
		for (var i=this.arrHover.length - 1; i >= 0; i--) {
			var objParentMenu = document.getElementById(this.arrHover[i]);
			if (objParentMenu) {
				if (isParent(objMenu.id, this.arrHover[i])) {
					if (objParentMenu.className.indexOf("Hover") == -1) {
						objParentMenu.className += "Hover";
					}
					arrNewHover[arrNewHover.length] = this.arrHover[i];
				}
				else {
					objParentMenu.className = objParentMenu.className.replace("Hover", "");
				}
			}
		}
		this.arrHover = arrNewHover;
		if (objMenu.className.indexOf("Hover") == -1) {
			objMenu.className += "Hover";
		}
		if (!inArray(this.arrHover, objMenu.id)) {
			this.arrHover[this.arrHover.length] = objMenu.id;
		}
		this.dropDownTimer = window.setTimeout("objMainMenu.showDropDown('" + objMenu.id + "')", 100);
	}
}
function inArray(arrTest, id) {
	for (var i=0; i < arrTest.length; i++) {
		if (arrTest[i] == id) {
			return true;
		}
	}
	return false;
}
function isParent(childId, parentId) {
	var objMenu = document.getElementById(childId);
	if (objMenu) {
		var objParent = objMenu.parentNode;
		if (objParent != null && objParent.className == "dropDownMenu") {
			if (objParent.id == "dropDown" + parentId) {
				return true;
			}
			else {
				return isParent(objParent.id.replace("dropDown", ""), parentId);
			}
		}
	}
	return false;
}
function mDoMouseOut() {
    if (this.dropDownTimer != null) {
	    window.clearTimeout(this.dropDownTimer);
		this.dropDownTimer = null;
	}
	if (this.clearTimer == null) {
		this.clearTimer = window.setTimeout("objMainMenu.clear()", 200);
	}
}
function mClear() {
	for (var i = this.pathLength -1; i >= 0; i--) {
		this.arrDropDowns[i].style.display = "none";
	}
	this.pathLength = 0;
	for (var i=this.arrHover.length - 1; i >= 0; i--) {
		var objParentMenu = document.getElementById(this.arrHover[i]);
		if (objParentMenu) {
			objParentMenu.className = objParentMenu.className.replace("Hover", "");
		}
	}
	this.arrHover = new Array();
}
function mShowDropDown(menuId) {
    var objMenu = document.getElementById(menuId);
	if (this.arrDropDowns.length > 0) {
		var objParent = objMenu.parentNode;
		var parentId = -1;
		if (objParent != null && objParent.className == "dropDownMenu") {
			parentId = objParent.id;
		}				
		for (var i = this.pathLength -1; i >= 0; i--) {
			if (this.arrDropDowns[i].id != parentId)
				this.arrDropDowns[i].style.display = "none";
			else
				break;
		}
	}
	var objDropDown = document.getElementById("dropDown" + objMenu.id);
	if (objDropDown) {
		var notRoot = objMenu.parentNode.className && objMenu.parentNode.className == "dropDownMenu";
		if (notRoot) {
			objDropDown.style.top = getAbsoluteTop(objMenu);
			objDropDown.style.left = getAbsoluteLeft(objMenu) + this.menuWidth;
		}
		else {
			objDropDown.style.top = getAbsoluteTop(objMenu) + this.menuHeight;
			objDropDown.style.left = getAbsoluteLeft(objMenu) + this.menuLeft; 
		}
		objDropDown.style.display = "block";
		this.arrDropDowns[this.pathLength] = objDropDown;
		this.pathLength++;
	}
}
function getAbsoluteTop(element){
	try{if(element.tagName.toUpperCase()!="BODY"){if(element.offsetParent!=null) 
	return element.offsetTop-element.scrollTop+getAbsoluteTop(element.offsetParent);
	else return element.offsetTop;} return 0;} catch(e){}
}
function getAbsoluteLeft(element){
	try{if(element.tagName.toUpperCase()!="BODY"){if(element.offsetParent!=null)
	return element.offsetLeft-element.scrollLeft+getAbsoluteLeft(element.offsetParent);
	else return element.offsetLeft;} return 0;} catch(e){}
}
function trimString(str) {
    return str.replace(/^\s+/g,'').replace(/\s+$/g,'');
}
function validateForm(objFrm) {
    var test = trimString(objFrm.elements["Email"].value);
    if (test.length == 0) {
        alert("E-mail is verplicht.");
        objFrm.elements["Email"].focus();
        return false;
    }
    test = trimString(objFrm.elements["Col1"].value);
    if (test.length == 0) {
        alert("Naam is verplicht.");
        objFrm.elements["Col1"].focus();
        return false;
    }
    test = trimString(objFrm.elements["Col2"].value);
    if (test.length == 0) {
        alert("Adres is verplicht.");
        objFrm.elements["Col2"].focus();
        return false;
    }
    test = trimString(objFrm.elements["Col3"].value);
    if (test.length == 0) {
        alert("Postcode is verplicht.");
        objFrm.elements["Col3"].focus();
        return false;
    }
    test = trimString(objFrm.elements["Col4"].value);
    if (test.length == 0) {
        alert("Plaats is verplicht.");
        objFrm.elements["Col4"].focus();
        return false;
    }
    return true;
}

