// functies voor preloading van images

function preloadImage(src){
	if (document.images){
		n = imageArray.length;		
		imageArray[n] = new Image();
		imageArray[n].src = src;
   }
}
	
function loadAll(){  
	if (document.images){
	imageArray = new Array();
		for(var n = 0; n < document.images.length; n++){
		    // als de naam van de image begint met tab dan preloaden			
			if (document.images[n].src.indexOf("_up.") != -1) 
				preloadImage(document.images[n].src.replace("_up.","_over."));
		}
	}
}

// functies voor swapping van images
function swapOver(theName){
	if (navigator.appVersion.indexOf("3")==0) return;
  if (document.images){
    if(document.layers) theImage = document.images[theName];
    else theImage = document.images[theName];
	if (theImage.src.indexOf("_up.")!=-1)
	  theImage.src = theImage.src.replace("_up.","_over.");
	  
  }
}

function swapOut(theName){
  if (navigator.appVersion.indexOf("3")==0) return;
  if (document.images){
    if(document.layers) theImage = document.images[theName];
    else theImage = document.images[theName];
	if (theImage.src.indexOf("_over.")!=-1)
		theImage.src = theImage.src.replace("_over.","_up.");	
  }
}	


function showMainMenuPopup(whatPopup,popupMaster){
	if (document.getElementById && document.getElementById(whatPopup)){
		document.getElementById(whatPopup).style.display="block";
		var divs = document.getElementsByTagName("DIV");
		for (var i=0;i<divs.length;i++) if (divs[i].className=='flashAsset') divs[i].style.visibility='hidden';
		if (!document.all) {
			document.getElementById(whatPopup).onmouseout=hideThisPopup;
			document.getElementById("mainMenu").onmouseout=hideAllPopups;
				
			}
		else {
			document.getElementById(whatPopup).popupMaster = popupMaster;
			
			}
		} 
}

// ie child test
function isChildOf(elem,parentId){
	if (document.getElementById && document.getElementById(parentId)){
		if (document.getElementById(parentId).contains(elem)) return true;
		else return false;
	} else return false;
}

//ie hide
function hideMainMenuPopup(whatPopup){
	whatPopup = document.getElementById(whatPopup);
	if (whatPopup &&event && event.toElement && !hasParent(event.toElement,whatPopup)&& !hasParent(event.toElement,whatPopup.popupMaster)){
		whatPopup.style.display="none";
	}
}

//mozilla childtest
function hasParent(elem,parentelem){
	while (elem && elem.parentNode){
		if (elem==parentelem) {return true;}
		else elem=elem.parentNode;
	}
	return false;
}

//mozilla hide
function hideThisPopup(e){
	if (e.currentTarget){
	 if (!hasParent(e.relatedTarget,e.currentTarget)){	 
		e.currentTarget.style.display="none";
		showFlashAssets();
		}
	}
}

//mozilla hide
function hideAllPopups(e){
	if (e.relatedTarget && e.relatedTarget.className!="mainMenuPopup"){
		document.getElementById("divZiekten").style.display="none";
		document.getElementById("divBelangrijk").style.display="none";
		showFlashAssets();
	}
}

function showFlashAssets(){
	var divs = document.getElementsByTagName("DIV");
	for (var i=0;i<divs.length;i++) if (divs[i].className=='flashAsset') divs[i].style.visibility='visible';
}

function hidePopups(){
	hideMainMenuPopup("divZiekten");
	hideMainMenuPopup("divBelangrijk");
	if (document.getElementById("divZiekten") && document.getElementById("divZiekten").style.display=="block") return;//klaar
	if (document.getElementById("divBelangrijk") && document.getElementById("divBelangrijk").style.display=="block") return;//klaar
	showFlashAssets();
}

function init(){
	if (document.forms && document.forms.Login && document.forms.Login.username) document.forms.Login.username.focus();
}

function hover(e){
	//ie hover
	if (event && event.toElement ){//&& !isChildOf(event.toElement,event.fromElement)
		if (event.toElement.tagName=="TD") event.toElement.style.backgroundColor="#ccdee1";
	}
}

function deHover(e){
	if (event && event.toElement && !hasParent(event.toElement,event.fromElement)){
		if (event.fromElement.tagName=="TD") event.fromElement.style.backgroundColor="#FFFFFF";
	}
	if (e && e.currentTarget){
	 if (!hasParent(e.relatedTarget,e.currentTarget)){	 
		e.currentTarget.style.style.backgroundColor="#FFFFFF";
		}
	}

}
