/*****************************************************
 *	iCOACHING SCRIPTS
 *****************************************************/
 
var OBJECT_HEIGHT_REFERENCE = "bgFlower";

var arrSubmenuus = new Array();
var arrHeightScalers = new Array(new Array("wrapper",0));
 
function init(){

	resizeContent();
	
	window.onresize = function(){
		self.resizeContent();
	}	
	
	//*** add main mouse-overs:
	
	if(typeof(MAINS) != "undefined"){
		
		var intMCount = MAINS.length;
		for(var m=0; m<intMCount; m++){

			var objMain = document.getElementById("btnMain"+ (m+1));	
			var objMainImage = document.getElementById("btnMainImage"+ (m+1));			

			//*** add submenu if any
			if(MAINS[m][1].length > 0){		

				objMain.setInterval = function(a, b, c, arrArgs){
					var ID, func = function(){
						a[b].apply(a, arrArgs);						
					}
					ID = setInterval(func, c, arrArgs);
					return ID;
				};
				
				//*** function to keep main buttons highlighted when submenu is shown
				objMain.mouseOuter = function(){					
					//*** only mouseout when submenu not visible or hiding
					var objSub = SUBMENUUS.getSubmenu(this.strSubmenuId);
					if((!objSub.blnShowing) && (!objSub.blnActive)){
					
						//*** change class and image
						this.className = "btnMain btnMain"+ (this.intM+1);
						this.objImg.src = "img/btnMainImage"+ (this.intM+1) +".gif";						
						
						clearTimeout(this.intTO);
					}
				}
			
				arrSubmenuus[arrSubmenuus.length] = new Submenu(MAINS[m][0], "btnMain"+ (m+1), MAINS[m][1], ACTIVE_FOLDER);
				arrSubmenuus[arrSubmenuus.length-1].create("topSubMenu", "left="+ parseInt(findPosX(objMainImage)) +",width="+ parseInt(objMainImage.width));
				arrSubmenuus[arrSubmenuus.length-1].setPausehiding(420);
			}
			
			if(MAINS[m][0] != ACTIVE_MAIN){				
				
				objMain.intM = m;				
				objMain.style.cursor = "pointer";
				objMain.objImg = document.getElementById("btnMainImage"+ (m+1));
				
				if(MAINS[m][1].length > 0){
					objMain.strSubmenuId = "btnMain"+ (m+1);
					objMain.intTO = "";
				}else{
					objMain.strSubmenuId = "";
				}
						
				objMain.onmouseover = function(e){
					
					//*** change class and image
					this.className = "btnMain btnMain"+ (this.intM+1) +"on";
					this.objImg.src = "img/btnMainImage"+ (this.intM+1) +"on.gif";
					
					//*** show submenu if any
					if(this.strSubmenuId != ""){
						SUBMENUUS.showSubmenu(this.strSubmenuId);
					}
				};
				
				objMain.onmouseout = function(e){					
					
					if(this.strSubmenuId != ""){						
					
						//*** hide submenu
						SUBMENUUS.hideSubmenu(this.strSubmenuId);
					
						//*** change class and image only when submenu is really hiding or invisible
						if(!isNaN(this.intTO)){clearInterval(this.intTO);}
						this.intTO = this.setInterval(this, "mouseOuter", 300, new Array());						
						
					}else{
						//*** change class and image
						this.className = "btnMain btnMain"+ (this.intM+1);
						this.objImg.src = "img/btnMainImage"+ (this.intM+1) +".gif";					
					}
				};				
				
			}else{
				if(MAINS[m][1].length > 0){
					objMain.strSubmenuId = "btnMain"+ (m+1);
					objMain.style.cursor = "pointer";
					
					objMain.onmouseover = function(e){

						//*** show submenu if any
						if(this.strSubmenuId != ""){
							SUBMENUUS.showSubmenu(this.strSubmenuId);
						}
					};

					objMain.onmouseout = function(e){

						//*** show submenu if any
						if(this.strSubmenuId != ""){
							SUBMENUUS.hideSubmenu(this.strSubmenuId);
						}					
					};					
				}			
			}
			
			if(MAINS[m][2]){
				
				objMain.intId = MAINS[m][0];
			
				//*** make div clickable
				objMain.onclick = function(e){
					document.location.href = "index.php?fId="+ this.intId;
				}
			}
		}		
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function isBrowserSupported(){
	return(typeof(document.getElementById) != "undefined");
}


function popupper(strURL, strName, intWidth, intHeight, strScroll){
	window.open(strURL, strName,'height='+intHeight+',width='+intWidth+',toolbar=no,scrollbars='+ strScroll +',menubar=no,resizable=yes');

}

function popupFotoGroot(eId){

	var intW = document.getElementById("foto_"+ eId).width;
	var intH = document.getElementById("foto_"+ eId).height;
	var strURL = "foto.php?eId="+ eId;

	if(intW > intH){
		popupper(strURL, "Foto", 756, 300, "yes");
	}else{
		popupper(strURL, "Foto", 656, 400, "yes");
	}
}

function tryResizeFotoPopup(strId){

	var intMaxH = 700;

	var intW = document.getElementById(strId).width+40;
	var intH = document.getElementById(strId).height+60;
	if(intH > intMaxH){
		window.resizeTo(intW, intMaxH);
	}else{
		window.resizeTo(intW, intH);
	}
}

function checkContactForm(){


	var arrCheck = new Array(new Array("naam","Naam"),new Array("email","E-mail-adres"));

	var objForm = document.forms["contact"];
	var cango = 1;

	var a=0;
	do{
		if(objForm[arrCheck[a][0]].value == ""){
			cango = 0;
			alert("Vergeet niet uw '"+ arrCheck[a][1] +"'.");
		}else{
			if(arrCheck[a][0] == "email"){
				if(!echeck(objForm[arrCheck[a][0]].value)){
					cango = 0;
					alert("Vul een geldig e-mailadres in!");
				}
			}
		}
		a++;
	}while(cango && a<arrCheck.length);

	if(cango){
		objForm.action = "index.php";
		objForm.submit();
	}
}

function echeck(str) {
	var objReg = /[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	var matched = str.match(objReg);
	
	if(matched){		
		if(matched.length == 1){
			return true;
		}
		
	}
	return false;
/*	
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }

	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true
*/
}

/*****************************************************
 *	SCALING
 *****************************************************/
 
 function resizeContent(){
 	
	if(document.getElementById){
		var i=0;
		var th = document.getElementById(OBJECT_HEIGHT_REFERENCE).clientHeight;
		var sh = document.body.clientHeight;
		if(sh > th){
			th = sh;
		}	
		if(th >= 0){
			while(i<arrHeightScalers.length){
				document.getElementById(arrHeightScalers[i][0]).style.height = th + arrHeightScalers[i][1] +"px";
				i++;
			}	
		}	
	}
 	
 } 
