// JavaScript Document
var newmenuid;
var menutime;
var droptime;
var openmenu=new Array();
var oldstyle="none";
var hoverelement;
var level1element;
var timedelement;
var menuitemsarray;
var menuarray;
var openItems=new Array();
var currentitem=false;
var slowhidetimer;


function OpenPOD2(code) {
	var newName = "mySite";
	var newFeatures = "height=550,width=750,innerHeight=550,innerWidth=750,screenX=10,left=10,screenY=10,top=10,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=1,toolbar=0";
	open("http://www.photonic.nl/?idh=" + code, newName, newFeatures); 
}

function clearothers(obj) {
		if (obj.id!="sisnummer") d('sisnummer').value='';
		if (obj.id!="reserveringsnummer") d('reserveringsnummer').value='';
		if (obj.id!="naam") d('naam').value='';
	}

function toggleName(str) {
	document.getElementById('student').style.display="none";
	document.getElementById('werknemer').style.display="none";
	document.getElementById('prom').style.display="none";
	if (str=="prom") {
		document.getElementById('geboortedatum').style.display="none";
	}
	else {
		document.getElementById('geboortedatum').style.display="block";
	
	}
	document.getElementById(str).style.display="block";
		
}
function toggleMore(str) {
	document.getElementById('ja').style.display=(str=="ja")?"block":"none";
		
}

function searchreservation() {
	document.getElementById('checkreservation').style.display="block";
	document.getElementById('sellcards').style.display="none";
}

function sellacard() {
	document.getElementById('checkreservation').style.display="none";
	document.getElementById('sellcards').style.display="block";
}

function updateList(forced) {
	// alert(currentitem);
	if((currentitem) && (menuid != currentitem)) document.location.href='index.php?menuid='+currentitem;
	str="&sis="+d('sisnummer').value+'&res='+d('reserveringsnummer').value+'&naam='+d('naam').value+'&forced='+forced;
	xmlhttp.open("GET", 'index.php?window=tulist&menuid='+menuid+'&'+Math.random()+str,true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				if (obj=d('lustrumcontent')) {
					obj.innerHTML=xmlhttp.responseText;
					
				}
		}
	}
	xmlhttp.send(null);
}

function updateSellList(page) {

	str="&sis="+d('sisnummer2').value+'&naam='+d('naam2').value+'&page='+page;
	xmlhttp.open("GET", 'index.php?window=tulist&new=true&menuid='+menuid+'&'+Math.random()+str,true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				if (obj=d('lustrumcontent')) {
					obj.innerHTML=xmlhttp.responseText;
					
				}
		}
	}
	xmlhttp.send(null);
}

function tuDetail(id) {
	str="&tuid="+id;
	xmlhttp.open("GET", 'index.php?window=tulist&menuid='+menuid+'&'+Math.random()+str,true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				if (obj=d('lustrumcontent')) {
					obj.innerHTML=xmlhttp.responseText;
					
				}
		}
	}
	xmlhttp.send(null);
}
function tuDetailNew(id,sis) {
	str="&tuid="+id+"&new=true";
	if (sis) str+="&sis="+sis;

	xmlhttp.open("GET", 'index.php?window=tulist&menuid='+menuid+'&'+Math.random()+str,true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				if (obj=d('lustrumcontent')) {
					obj.innerHTML=xmlhttp.responseText;
					
				}
		}
	}
	xmlhttp.send(null);
}

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


function jumpToEditMode() {
	document.location.href="index.php?login=start&menuid="+menuid;
}
var maybe=false;
var posID;
var pijlpos;

function getkey() {
	if (editmode) shortCuts();
	eventChooser = event.keyCode;
	if ((eventChooser==10 || eventChooser==20) && editmode=="") jumpToEditMode();
}

function openAgenda() {
	agendaWindow=window.open("?window=agenda&menuid="+menuid,"agendaWindow"," width=500px; height=350px; status=no, buttons=no, scrollbars=yes, resizable");
	agendaWindow.focus();
}

function tickInit() {
		document.onkeypress=getkey;
		menuarray=getMenuElements();
		menuitemsarray=getMenuItemElements();
		if (editmode!="menu") setCurrent();
		if (!editmode)getHash();
		if (!d('content_home'))giveMeContent(0);
		attachCurse();
		attachSprt();
		attachAgend();
                
                
// funcity hack
var funtivity_id = ((site_language=='nl')?5606:5620);

var obj = document.getElementById('menuitem_'+funtivity_id);
if (obj) {
var divjes = obj.getElementsByTagName('a');
if (divjes){
for(var k=0; k<divjes.length; k++){
divjes[k].setAttribute('mama',funtivity_id);
}
}
}

if (levels && document.getElementById('funcitycss') && editmode=='') {
	if (levels[1]==funtivity_id) {
		document.getElementById('funcitycss').href='site/css/funcity.css';
	}
	else {
		document.getElementById('funcitycss').href='site/css/lastchange.css';
	}
	
}
		
}

function trend_event() {
  var a = document.createElement('a');
  a.id='tend_event';
  a.href='index.php?menuid='+((site_language=='nl')?'5905':'5930');
  a.title='TREND event';
  a.innerHTML='TREND event';
  document.getElementById('srolldiv').appendChild(a);
  if (Math.random()>0.45) {
    $('#snc_foto').css('background-image','url(site/img/trend_event.jpg)');
    $('#content_home .content img.img').attr('url','index.php?menuid='+((site_language=='nl')?'5905':'5930')).attr('title','TREND Event - details');
  }
}
function attachCurse() {
	var obj;
	if (editmode=="start") {
		if (obj=d('editButtons')) {
			courseUnit=document.createElement('div');
			courseUnit.className="CJavascriptItem";
			courseUnit.unselectable="on";
			courseUnit.name="course";
			courseUnit.id="course";
			courseUnit.title="attach course";
			courseUnit.onclick=function() {
				courseWindow=window.open("?window=coursepicker&menuid="+menuid,"courseWindow"," width=490px; height=170px; status=no, buttons=no, scrollbars=yes, resizable");
				courseWindow.focus();	
			}
			courseUnit.onmouseover=function() {
				editOver(this);
			}
			courseUnit.onmouseout=function() {
				editOut(this);
			}
			courseUnit.style.backgroundImage="url(blueprint/img/i/course.gif)";
			obj.appendChild(courseUnit);
		}
	}
}

function attachSprt() {
	var obj;
	if (editmode=="start") {
		if (obj=d('editButtons')) {
			sportUnit=document.createElement('div');
			sportUnit.className="CJavascriptItem";
			sportUnit.unselectable="on";
			sportUnit.name="sport";
			sportUnit.id="sport";
			sportUnit.title="attach sport";
			sportUnit.onclick=function() {
				sportWindow=window.open("?window=sportpicker&menuid="+menuid,"sprortWindow"," width=490px; height=170px; status=no, buttons=no, scrollbars=yes, resizable");
				sportWindow.focus();	
			}
			sportUnit.onmouseover=function() {
				editOver(this);
			}
			sportUnit.onmouseout=function() {
				editOut(this);
			}
			sportUnit.style.backgroundImage="url(blueprint/img/i/sport.gif)";
			obj.appendChild(sportUnit);
		}
	}
}

function attachAgend() {
	var obj;
	if (editmode=="start") {
		if (obj=d('editButtons')) {
			agendUnit=document.createElement('div');
			agendUnit.className="CJavascriptItem";
			agendUnit.unselectable="on";
			agendUnit.name="agenda";
			agendUnit.id="agenda";
			agendUnit.title="attach calender";
			agendUnit.onclick=function() {
				agendWindow=window.open("?window=agenda&ac=pick&menuid="+menuid,"agendWindow"," width=490px; height=170px; status=no, buttons=no, scrollbars=yes, resizable");
				agendWindow.focus();	
			}
			agendUnit.onmouseover=function() {
				editOver(this);
			}
			agendUnit.onmouseout=function() {
				editOut(this);
			}
			agendUnit.style.backgroundImage="url(blueprint/img/i/agenda.gif)";
			obj.appendChild(agendUnit);
		}
	}
}


function giveSearch() {
	var obj, searchobj;
	if (obj=d('content_search')) {
		if (getX(obj)<0) {
			obj.style.left="230px";
			obj.style.top="100px";
			ajaxContent('search', '','');
		}
	}
}
function closeSearch() {
	var obj, searchobj;
	if (obj=d('content_search')) {
		obj.style.left="-4300px";
		obj.style.top="100px";
		ajaxContent('search', '','');
	}
}

function searchResults(str) {
/*	if (editmode && editmode!="offmode") {
		document.location.href="index.php?menuid="+menuid+"&searchq="+str;
	}
	else {
*/
	giveSearch();
	if (obj=d('content_search_content')) {
		obj.innerHTML=obj.getAttribute("busyStr");
	}
	xmlhttp.open("GET", 'index.php?window=content&searchq='+str+'&'+Math.random(),true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				if (obj=d('content_search_content')) {
					obj.innerHTML=xmlhttp.responseText;
				}
		}
	}
	xmlhttp.send(null);
/*	}*/
	
}

function setCurrent(){
	if (levels && currentitem!=levels[levels.length-1]){
		closeAll();
		currentitem=levels[levels.length-1];
		if(levels){
			count=levels.length;
			for (var i=1;i<count;i++){
				var itemcurrent=d('menuitem_'+levels[i]);
				placeMenu(itemcurrent);
				setOpenState(itemcurrent,true);
				if (itemcurrent.className && itemcurrent.className.match(/level1/))level1element=itemcurrent;
				if(itemcurrent.menuparent){
					setOpenState(itemcurrent.menuparent,true);
				}
			}
		}
	}
}

function destroyContent(objmenuid) {
	var obj;
	var itemunit;
	if (obj=d('srolldiv')) {
		if (itemunit=d('content_'+objmenuid)){
			obj.removeChild(itemunit);
		}
	}
}


function ajaxContent(newmenuid, editstring, editstate) {
	var obj;
	if (obj=d('srolldiv')) {
		if (itemunitx=d('content_'+newmenuid)){
			levels=eval(itemunitx.getAttribute("levels"));
			obj.appendChild(obj.removeChild(itemunitx));
			setCurrent();
			window.scroll(0,0);
			if (newmenuid=='search')if(d('searchq')){
				d('searchq').focus();
				d('searchq').select();
			}
		}else{
			document.body.className="loading";
			
			xmlhttp.open("GET", 'index.php?window=content&menuid='+newmenuid+'&'+Math.random(),true);
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					document.body.className="";
					ff=document.createElement('div');
					ff.id='content_'+newmenuid;
					ff.className='var_'+(Math.round(newmenuid%randomcolors)+1 + randextra);
					ff.innerHTML=xmlhttp.responseText;
					obj.appendChild(ff);
					ff2=ff.childNodes[0];
					if (!ff2) return;
					ff2.menuid=newmenuid;
					if (newmenuid>0){
						ff2.style.left=getX(ff2)+(((Math.random()*40))-((Math.random()*40)))+"px";
						ff2.style.top=getY(ff2)+(((Math.random()*40))-((Math.random()*40)))+"px";
						ff.levels=eval(ff2.getAttribute("levels"));
					 	levels=ff.levels;
					 	setCurrent();
						openItems.push(newmenuid);
						if (openItems.length>5){
							removeitemid=openItems.shift();
							if (itemunitx=d('content_'+removeitemid)){
								obj.removeChild(itemunitx);
							}
						}
						d('backframe').src="site/back.php?menuid="+newmenuid;
						window.scroll(0,0);
					}
				}
			}
			xmlhttp.send(null);
		}
	}
}

function ajaxNews(itemid) {
	var obj;
	if (obj=d('srolldiv')) {
		
			document.body.className="loading";
			
			xmlhttp.open("GET", 'index.php?window=content&agendaid=0&itemid='+itemid+'&'+Math.random(),true);
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					document.body.className="";
					ff=document.createElement('div');
					ff.id='content_news'+itemid;
					ff.className='var_'+(Math.round(itemid%4)+1 + randextra);
					ff.innerHTML=xmlhttp.responseText;
					obj.appendChild(ff);
					ff2=ff.childNodes[0];
					
					if (itemid>0){
try {
						ff2.style.left=getX(ff2)+(((Math.random()*40))-((Math.random()*40)))+"px";
						ff2.style.top=getY(ff2)+(((Math.random()*40))-((Math.random()*40)))+"px";
} catch(e){}
						window.scroll(0,0);

					}
				}
			}
			xmlhttp.send(null);

	}
}

function giveMeContent(menuid, editstring, editstate,sender) {
	if (menuid){
		if (editstate || !doajax || menuid=='2004') {
			document.location.href='index.php?menuid='+menuid+editstring;
		}
		else{
			newmenuid=menuid;
			 ajaxContent(menuid, editstring, editstate);
if (sender) {
if ((sender.getAttribute('mama')==5606)) {
document.getElementById('funcitycss').href='site/css/funcity.css';
}
else {
document.getElementById('funcitycss').href='';
}
}
		}
	}
}

function quickPlaceMenu(id){

	var itemQ=d("menuitem_"+id);
	hideOthers(itemQ);
	slowHide();
	placeMenu(itemQ);


}

function slowPlaceMenu(currentelement){
	hideOthers(currentelement);
	timedelement=currentelement;
	currentelement.onmouseout=function (){if (this.timer)clearTimeout(this.timer);}
	if (currentelement.timer)clearTimeout(currentelement.timer);
	currentelement.timer=setTimeout("slowHide();timedMenu();",200);
}

function slowPlaceItem(currentelement){
	hideOthers(currentelement);
	timedelement=currentelement;
	currentelement.onmouseout=function (){if (this.timer)clearTimeout(this.timer);}
	if (currentelement.timer)clearTimeout(currentelement.timer);
	currentelement.timer=setTimeout("slowHide();",200);
}


function timedMenu(){
	if (timedelement)placeMenu(timedelement);
	timedelement=null;
}

function getMenuElements(obj){
	if(!obj)obj=document.body;
	function sortmenuitem(obj1,obj2){
		return obj2.getAttribute("level")-obj1.getAttribute("level");
	}
	var elementlist=document.body.getElementsByTagName('DIV');
	classelementlist=new Array();
	for (var i=0;i<elementlist.length;i++){
		classelement=elementlist[i];
		if(classelement.className.match(/menulevel/))classelementlist.push(classelement);
	}
	classelementlist.sort(sortmenuitem);
	return classelementlist;
}

function getMenuItemElements(){
	var elementlist=document.body.getElementsByTagName('DIV');
	classelementlist=new Array();
	for (var i=0;i<elementlist.length;i++){
		classelement=elementlist[i];
		if(classelement.className.match(/menuitemlevel/))classelementlist.push(classelement);
	}
	return classelementlist;
}

function slowHide(){	
	if (menuarray)	{
		for (var i=0;i<menuarray.length;i++){
			closemenuobj(menuarray[i]);
		}
	}
}

function hideOthers(currentelement){
	if (currentelement){
			if(hoverelement && hoverelement.timer)clearTimeout(hoverelement.timer);
			hoverelement=currentelement;
			if (level1element && !level1element.onit)level1element.style.backgroundColor='transparent';
			if (currentelement.className && currentelement.className.match(/level1/))level1element=currentelement;
			currentelement.style.backgroundColor=currentColor;	
	 }
}

function placeMenu(currentelement){
	setOpenState(currentelement,true);

	if (currentelement)var openmenuid=currentelement.getAttribute('submenuid');
	if(d('menu_'+openmenuid)){
		d('menu_'+openmenuid).style.display='inline';
		d('menu_'+openmenuid).menuparent=currentelement;
		d('menu_'+openmenuid).onmouseover=function(){this.onit=true;this.menuparent.onit=true;}
		d('menu_'+openmenuid).onmouseout=function (){if (this.timer)clearTimeout(this.timer);this.onit=false;}
		currentelement.onmouseover=function(){this.onit=true;}
		currentelement.onmouseleave=function(){this.onit=false;}
		currentelement.onmouseout=function (){if (this.timer)clearTimeout(this.timer);this.onit=false;}
	}
}

function closemenuobj(obj){
	if (!obj.className.match(/level1/) && !obj.onit){
		obj.style.display='none';
		if (obj.menuparent){
			setOpenState(obj.menuparent,false);
		}
	}
}

function closemenu(id){
	if (d(id)){
		if (d(id).onit || (d(id).menuparent && d(id).menuparent.onit))d(id).menuparent.timer=setTimeout('closemenu("'+id+'")',1000);
		else d(id).style.display='none';	
	}
}

function closeAll(){
	for (var i=0;i<menuitemsarray.length;i++){
		ptelem=menuitemsarray[i];
		setOpenState(ptelem,false);
		ptelem.onit=false;
	}
	for (var i=0;i<menuarray.length;i++){
		ptelem=menuarray[i];
		ptelem.onit=false;
		closemenuobj(ptelem);
		if (level1element && !level1element.onit)level1element.style.backgroundColor='transparent';
	}
}

function getHash(){
	var hash=document.location.hash;
	if (hash.match(/#/))hash=hash.replace(/#m/,"");
	else hash=hash.replace(/m/,"");
	
	if (hash && hash!="#")giveMeContent(hash);
}

function setOpenState(obj,state){
	var oldstate=obj.openstate;
	obj.openstate=state;
	var menuitemtitle=d(obj.id+'_e');
	if (menuitemtitle){
		var ccolor=obj.className.match(/level1/)?currentColor:othercurrentColor;
		if (state && !oldstate)menuitemtitle.oldcolor=menuitemtitle.style.backgroundColor;
		menuitemtitle.style.backgroundColor=state?ccolor:menuitemtitle.getAttribute('oldcolor');
	}
}

function forceFocus(obj){
	//d('snc_menu_container').style.zIndex=9;
	//d('snc_menu_container').onmouseover=function(){this.style.zIndex=11;}
	if (!newmenuid)newmenuid=menuid;
	if(obj.menuid && newmenuid!=obj.menuid){
		newmenuid=obj.menuid;
  	if (!newmenuid)newmenuid=obj.getAttribute(menuid);
  	if (newmenuid)giveMeContent(newmenuid);
  }
}

function releaseFocus(obj){

	//d('snc_menu_container').style.zIndex=11;
}



function validateForm() //wordt gebruikt voor het ABN-AMRO verhaal
{
 var okSoFar=true
 with (document.phpformmailer)
 {
  var foundAt = email.value.indexOf("@",0)
  if (foundAt < 1 && okSoFar)
  {
    okSoFar = false
    alert ("Vul aub een geldig emailadres in.")
    email.focus()
  }
  var e1 = email.value
  var e2 = email2.value
  if (!(e1==e2) && okSoFar)
  {
    okSoFar = false
    alert ("De emailadressen komen niet overeen. Controleer de invoer.")
    email.focus()
  }
  if (phone.value=="" && okSoFar)
  {
    okSoFar=false
    alert("Vul aub een telefoonnummer in.")
    phone.focus()
  }

  if (okSoFar==true)  submit();
 }
}

function subPoll(id){
		
	var pollvote='novalue';
	var pollform=document.getElementById('poll_cont_'+id);
	var elementlist=pollform.getElementsByTagName('INPUT');
	for (var i=0;i<elementlist.length;i++){
		classelement=elementlist[i];
		if(classelement.checked)pollvote=classelement.value;
	}
	new CXmlHttp('get','index.php?window=linkpoll&pollid='+id+'&newvote='+pollvote,setResult);	
	function setResult(result){
		if(document.all)d('poll_'+id).outerHTML=result;
		else d('poll_'+id).innerHTML=result;
	}
}

function pollOver() {
	var obj;
	if (obj=d('poll_home_pollcontent')) {
		poll_conts=obj.getElementsByTagName('DIV');
		for (k=0; k<poll_conts.length; k++) {
			if (poll_conts[k].className.match(/poll_cont/) || poll_conts[k].className.match(/poll_bot/)) poll_conts[k].style.display='block';
			
		}
	}
}
function pollOut() {
	var obj;
	if (obj=d('poll_home_pollcontent')) {
		poll_conts=obj.getElementsByTagName('DIV');
		for (k=0; k<poll_conts.length; k++) {
			if (poll_conts[k].className.match(/poll_cont/) || poll_conts[k].className.match(/poll_bot/)) poll_conts[k].style.display='none';
		}
	}
}



