function openWindow(url,width,height,options,name) {
                width = width ? width : 800;
                height = height ? height : 600;
                options = options ? options : 'resizable=yes';
                name = name ? name : 'openWindow';
                window.open(
                    url,
                    name,
                    'screenX='+(screen.width-width)/2+',screenY='+(screen.height-height)/2+',width='+width+',height='+height+','+options
                )
            }
function foto(DOEL)
{
	window.open(DOEL,'mywindow','width=600,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function detailtrain(doela)
{
	window.open(doela,'mywindow','width=350,height=420,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function ganaar(doelb)
{
	// window.alert(doelb);
	this.location.href = doelb;
	// var win = window.open(doelb, 'this','');
	return 0;
}

function popUp(URL) {
window.open(URL,'mywindow','width=260,height=65,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
// day = new Date();
// id = day.getTime();
// eval("page" + id + " = window.open(URL, '" + id + "',
// 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=50');");
}

function herlaad() {
document.reload();
}

 function loadstreek(form) { 
	var index=form.hellingstreek.selectedIndex;
	if (form.hellingstreek.options[index].value != "0") 
	{
		location=form.hellingstreek.options[index].value;
	}
}
 function loadprovincie(form) { 
	var index=form.hellingprov.selectedIndex;
	if (form.hellingprov.options[index].value != "0") 
	{
		location=form.hellingprov.options[index].value;
	}
}
 function prut(form) { 
	var index=form.Landnaam.selectedIndex;
	if (form.Landnaam.options[index].value != "0") 
	{
		location=form.Landnaam.options[index].value;
	}
}

 function setstreek(form) { 
	var index=form.h_streekc.selectedIndex;
	if (form.h_streekc.options[index].value != "0") 
	{
		form.h_streek.value = form.h_streekc.value;
	}
}

 function setprovincie(form) { 
	var index=form.h_provinciec.selectedIndex;
	if (form.h_provinciec.options[index].value != "0") 
	{
		form.h_provincie.value = form.h_provinciec.value;
	}
}
 function gotourl(urle) { 
	var urle;
	window.location.href = urle;
}
  function resize_image(fig)
  {

      if ( fig.width > 500 )
      {
        fig.width = 400;
      }
  }
  
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return null
}

function checkCookie(param)
{
paramcookie =getCookie(param)
if (paramcookie!=null)
  {
	alert('Waarde uit cookie '+param+' = '+paramcookie+'!');
  }
else 
  {
	alert('geen cookie');
  }
}
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate)
}

function Delete_Cookie(name,path,domain) {
   if (Get_Cookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// Set_Cookie("monthdisplayadmin",false, cookie_expire_date,"","");
// Set_Cookie("monthdisplaydetail",false, cookie_expire_date,"","");
// Toggls to keep track of when to display and not display
// a element

changeDisplay.display = [ ];

function setDisplay(theWhat,theDisplay){
var b = document.getElementsByTagName("SPAN");
for(var i = 0; i < b.length; i++)
{
 var tabelid = b[i].getAttribute("id");
 if (tabelid == null)
 {
	var tabelid = "bla";
}
	if(tabelid.indexOf(theWhat)>=0)
	{
		b[i].style.display = theDisplay;
	}

}	
	
}

function changeDisplay(theWhat) {
	var theDisplay;
if (changeDisplay.display[theWhat] == 1)
{
	theDisplay = "none";
	changeDisplay.display[theWhat] = 0;
	setCookie(theWhat,0,"1");
}
else
{
	theDisplay = "";
	changeDisplay.display[theWhat] = 1;
	setCookie(theWhat,1,"1");
}
setDisplay(theWhat, theDisplay);
} 

function initW() {
	 if (document.getElementById) {
	 cnt = document.getElementById("wdata");
	 } 
	 else if (document.all) {
	 cnt = document.all["wdata"]; 
	 } 
	cnt.style.display = "block";
	
 } 
 function unsetW()
 {
	 if (document.getElementById) {
	 cnt = document.getElementById("wdata");
	 } 
	 else if (document.all) {
	 cnt = document.all["wdata"]; 
	 } 

    cnt.style.display = "none";
 }

function initWedstrijd(new_agenda_item,start_date)
{
	
	var selectval  = document.voeg_training_in.training.value;
	if (selectval == "6")
	{
		initW();
		setWedstrijden(new_agenda_item,start_date)
	}
	else
	{
		unsetW();
	}
}


// -->

// everything about the tagboard
// --------------------------------------
var requestTagboardUrl = baseUrl+'/getTagBoard.php';
var tagboardContainer = 'div_TagBoard';
function applicationinit(){
	   if(tagboardgroup >0){
		   tagboard = tagboardgroup;
		   requestTagboardUrl = baseUrl+'/getTagBoardGroup.php';
		   tagboardContainer = 'div_TagBoardGroup';
	   }	
   startTagBoard(0);
   
   if($('div_km') != undefined){
	   if(Math.floor(Math.random()*11) == 9){
	   	getKm(); // reduce load
	   }
	     if(modus_IE6 == 1){
		   startclock(); // start showing km animation.
	   	}
   	}


}
			var lastMessage = 0;

			var mTimer;
			var tagboardRefresh = 31000;
			var finalTimeout = 60000;
			var timeout = finalTimeout;
			
			// Function for initializating the page.
			function startTagBoard(start){
				if(start != 1){ // not in init
					// Start Recieving Messages.
					getTagBoardText();
				}
				else{
					lastMessage++;
					mTimer = setTimeout('getTagBoardText();',tagboardRefresh);
				}
				// Set the focus to the Message Box.
				if($('txt_message') && !$('txt_message').style.display == 'none'){
					$('txt_message').focus();
				}
			}		
		
			// Gets the current messages from the server
			function getTagBoardText() {
				if(timeout > 0){ // extra controle om geen oneindige lange
									// reeks requests te hebben als iemand zijn
									// browser laat openstaan.
					timeout = timeout - tagboardRefresh;
					new Ajax.Request (
						requestTagboardUrl,
						{
						method: "GET",
						parameters: {TagBoard: tagboard , last: lastMessage},
						onSuccess: handleReceiveTagBoard
						}
					);						
				}
			}
			
			function getOldTagboardText(){
					var element =$(tagboardContainer);
					var spinnerDiv = document.createElement('div');
					spinnerDiv.innerHTML = "<center><img src=\""+staticUrl+"/images/spinner.gif\"/></center>";
					element.appendChild(spinnerDiv);
					var oldestMessage = firstLastTagboardMessage();
					
					new Ajax.Request (
						requestTagboardUrl,
						{
						method: "GET",
						parameters: {TagBoard: tagboard , oldest: oldestMessage},
						onSuccess: handleReceiveOldTagBoard
						}
					);	
					Element.remove(spinnerDiv);
				}

			
			function tagboardmessagereply (messageid) {
			        $('txt_message').value = '@'+$(''+messageid).down('.user').down('a').readAttribute('username')+' ';
			        $('txt_message').focus();
			}
								
			function tagboardmessagedelete (messageid) {
			        new Ajax.Request (
			        		requestTagboardUrl,
			            {
			                method: "POST",
			                parameters: {method: 'deletemessage', messageID: messageid,TagBoard: tagboard},
			                onSuccess: function(transport) {
			                if (transport.responseText.match(true))
			                    $(''+messageid).fade({ duration: 0.2 });
			                }
			            }
			        );
			        $(''+messageid).fade({ duration: 0.2 });
			}
		
			// Add a message to the TagBoard server.
			function sendTagBoardText(type) {
			var messagetext = $('txt_message').value;
				if(messagetext == '') {
					alert("Gelieve een bericht te typen "+ messagetext);
					return;
				}
				else{
					new Ajax.Request (
							requestTagboardUrl,
						{
						method: "POST",
						parameters: {TagBoard: tagboard, last: lastMessage, message: messagetext, type: type },
						onSuccess: handleSendTagBoard
						}
					);					
				}
			
			}

			// Deletes the text of the users tagboard
			function deleteTagBoardText() {
				new Ajax.Request (
						requestTagboardUrl,
				{
				method: "POST",
				parameters: {TagBoard: tagboard,todelete: 'true'},
				onSuccess: handleDeleteTagBoard
				}
				);						
			}			
			function handleDeleteTagBoard(){
			// reset timeout timer
			timeout = finalTimeout;
				$(tagboardContainer).innerHTML ='';
			}
			// When our message has been sent, update our page.
			function handleSendTagBoard() {
				// clear text box
				$('txt_message').value = '';
				// reset timeout timer
				timeout = finalTimeout;
				// Clear out the existing timer so we don't have
				// multiple timer instances running.
				clearInterval(mTimer);
				getTagBoardText();
			}
			// Function for handling the return of TagBoard text
			function handleReceiveTagBoard(transport) {
					var TagBoard_div = $(tagboardContainer);
					var textToAdd = " " + transport.responseText;
					if (textToAdd.length > 2)
					{
						TagBoard_div.innerHTML = textToAdd + TagBoard_div.innerHTML;
						if(lastMessage > 0)
							new Effect.Highlight(tagboardContainer, {startcolor:'#fa8500'});
					}
					handleReceiveTagboardCommon();
				}	
			
			function handleReceiveOldTagBoard(transport){
					var TagBoard_div = $(tagboardContainer);
					var textToAdd = " " + transport.responseText;
					if (textToAdd.length > 2)
					{
						TagBoard_div.innerHTML =  TagBoard_div.innerHTML + textToAdd;
						if(lastMessage > 0)
							new Effect.Highlight(tagboardContainer, {startcolor:'#fa8500'});
					}
					handleReceiveTagboardCommon();
	
			}
			
			function handleReceiveTagboardCommon(){
				lastMessage = $(tagboardContainer).down().id.sub('m','');

				//	lastMessage++;
					 unmonitorTagboard();
					monitorTagboard();
					mTimer = setTimeout('getTagBoardText()',tagboardRefresh);
				
			}
			// This functions handles when the user presses enter. Instead of
			// submitting the form, we
			// send a new message to the server and return false.
			function blockSubmit() {
				sendTagBoardText();
				return false;
			}
            function unmonitorTagboard(){
                $(tagboardContainer).select('.tmember','.towner').each(function(tagboardmessagemember){
                        $(tagboardmessagemember).stopObserving();
                    });
                $(tagboardContainer).select('.tagboardaction').each(function(tagboardaction){
                        $(tagboardaction).remove();
                    });
            }
            
            function monitorTagboard(){
                $(tagboardContainer).select('.tmember').each(function(tagboardmessagemember){
                    var newelement = new Element("div", {id:'r' + $(tagboardmessagemember).id, 'class':'tagboardaction'});
                    var newlinkelement = new Element('a', { 'class': 'tagboardreply', onclick: 'tagboardmessagereply(\''+$(tagboardmessagemember).id+'\')', title:'Antwoord op dit bericht' }).update("&nbsp;");
                    $(tagboardmessagemember).appendChild(newelement).update(newlinkelement).setStyle({position: 'absolute', right: '10px', top: '5px', display: 'none',width:'20px',height:'15px'});
    				
                  
                    $(tagboardmessagemember).observe('mouseout', function(event){
                     if (checkMouseLeave(this, event)) {
                     $(newelement.id).hide();
						}
                    });
                    $(tagboardmessagemember).observe('mouseover', function(event){
                     $(newelement.id).show();
                    });
                    // IE 6 & 7 bugfix
                    newlinkelement.parentNode.innerHTML = newlinkelement.parentNode.innerHTML;
                    
                    });
                    
                    
                    
                $(tagboardContainer).select('.towner').each(function(tagboardmessagemember){
                var newelement = new Element("div", {id:'d' + $(tagboardmessagemember).id,  'class':'tagboardaction'});
                var newlinkelement = new Element('a', { 'class': 'tagboarddelete', onclick: 'tagboardmessagedelete(\''+$(tagboardmessagemember).id+'\')', title:'Verwijder dit bericht' }).update("&nbsp;");
                    $(tagboardmessagemember).appendChild(newelement).update(newlinkelement).setStyle({position: 'absolute', right: '10px', top: '25px', display: 'none',height:'15px',width:'20px'});
    
                    $(tagboardmessagemember).observe('mouseout', function(event){
                     if (checkMouseLeave(this, event)) {
                     $(newelement.id).hide();
						}
                    });
                    $(tagboardmessagemember).observe('mouseover', function(event){
                     $(newelement.id).show();
                    });
                    });           
            }
            /**
             * 
             * @return id of first message
             */
            function firstLastTagboardMessage(){
            	var oldestMessage = lastMessage;
                $(tagboardContainer).select('.tagboardmessagewrap').each(function(tagboardmessage){
                		var idTagboardMessage =  tagboardmessage.id.sub('m','');
                		if(idTagboardMessage < oldestMessage){
                			oldestMessage = idTagboardMessage;
                		}
                    });     
                return oldestMessage;
            	
            }
			         
            
            
            
            

// Things for total km standing
// ------------------------------
		// var kmRefresh = 60000
		var kmRefresh = 20;
		/**
		 * @DEPRECATED
		 */
		function verifyKm(start){
				if(start == 1){ // not in init
					getKm();
				}
				// alert('verify');
				setTimeout("verifyKm(1)",kmRefresh);
			}

		// get bigtotal km for all users
		function getKm() {
				new Ajax.Request (
				'getKm.php',
				{
				method: "GET",
				parameters: {counting : parseInt(countingTotalKm)},
				onSuccess: handleReceiveKm
				}
				);						
			}
			function handleReceiveKm(transport) {
					var km_div = $('div_km');
					var xmldoc = transport.responseXML;
					var message_nodes = xmldoc.getElementsByTagName("km"); 
					var n_messages = message_nodes.length;
					var n_messages = message_nodes.length				
					var km_node = message_nodes[0].getElementsByTagName("totalkm");
					var counting_node = message_nodes[0].getElementsByTagName("countingkm");

					bigTotalKm = parseInt(km_node[0].firstChild.nodeValue);
					countingTotalKm = parseInt(counting_node[0].firstChild.nodeValue);
					kmDifference = bigTotalKm - countingTotalKm;
					if(kmDifference == 0)
						kmDifference = 1;
					timerRefresh = Math.floor(kmRefresh / kmDifference);
					timerRefresh = timerRefresh * 2;
					if(timerRefresh < timerRefreshMin)
						timerRefresh = timerRefreshMin;
					if(timerRefresh > timerRefreshMax)
						timerRefresh = timerRefreshMax;

			}	
			
var timerID = null;
var timerRunning = false;
var timerRefresh = 1000;	// normal refresh rate : 1sec
var timerRefreshMin =  50;	// fastest refresh rate
var timerRefreshMax =  2000; // slowest refresh rate : 2sec
function showtime() {
	countingTotalKm = countingTotalKm + 1;
	var strcountingTotalKm = new String(countingTotalKm);
	strcountingTotalKm = addseps(strcountingTotalKm);
	if ($('div_km') != undefined){
		$('div_km').innerHTML = strcountingTotalKm  + ' km';
		timerID = setTimeout("showtime()",timerRefresh);
		if (countingTotalKm > bigTotalKm - 1){
			stopclock();
		}
		else
			timerRunning = true;
	}

}


function stopclock () {
if(timerRunning)
	clearTimeout(timerID);
timerRunning = false;
}

function startclock () {
// Make sure the clock is stopped
stopclock();
if (countingTotalKm < bigTotalKm){
	showtime();
	}
}
function addseps(x) {
// make x a new variable
var x=x;
// make x a string
x+="";
// or x=String(x);
// iLen is the number of digits before any decimal point
// for 45.123, iLen is 2
// iLen is the length of the number, if no decimals
iLen=x.length;
pos=x.indexOf(".");
if (pos>-1) // there are decimals
{
iLen=pos;
}
// add the decimal point
temp="";
// add the decimal part to begin
// with 45.123, we add the .123
temp=x.substring(iLen,x.length);
// iLen-1 is the rightmost non-decimal digit (5 in 98745.123)
for (var i=iLen-1;i>=0;i--)
// we add a separator when the expression (iLen-i-1)%3==0 is true...
// except when i is (iLen-1), or the first digit
// eg (98745.12). i is iLen-1, and the digit pos is next the decimal,
// it is 5. From here, we decrement i...iLen-2, iLen-3, iLen-4 ... when i is a
// multiple of
// 3, (i=iLen-iLen+4-1). This point is just before the number 7
if ((iLen-i-1)%3==0&&i!=iLen-1)
temp=x.charAt(i)+" "+temp;
else
temp=x.charAt(i)+temp;
return temp;
}// end of addseps(x)

/**
 * Logevents
 */
function numberLogevents(element){
lis = Element.childElements(element);
var titles = 0;
for(i = 0; i < lis.length ; i++){
if(Element.hasClassName(lis[i], 'dayname'))
 titles = titles + 1;
}

aantal = lis.length - 1;
// alert('titles :'+titles+ ' - '+aantal);
finalaantal = aantal - titles;
return finalaantal;
}

var myli;
function add(member,type){
var element =$('logList');
myli = document.createElement('li');
myli.innerHTML = "<center><img src=\""+staticUrl+"/images/spinner.gif\"/></center>";
element.appendChild(myli);

aantal = numberLogevents(element);
// alert(aantal);
getLogEvents(aantal,member,type);
}
function getLogEvents(offset,user,type){
  new Ajax.Request (
   'getLogevents.php',
   {
   method: "GET",
   parameters: {Offset: offset, Member: user, Type : type },
   onSuccess: handleReceiveLogEvents
   }
  );  
}
function handleReceiveLogEvents(transport){
var texttoadd = " " + transport.responseText;
if(texttoadd.length < 2)
{
	Element.remove($('logeventmore')); // de meerknop verwijderen
}

Element.remove(myli);
$('logList').innerHTML = $('logList').innerHTML + texttoadd ;

}
/*
 * function register(){ Event.observe('logeventsmeer', 'click', getmeer); }
 */
function getMore(member,type){
add(member,type);
}


function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}
 
function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}
 
function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}