var windowWidth =-1;
var windowHeight = -1
function getWindowWidth()
{  	if (windowWidth <= 0)
	  getWindowSize(); 
	return windowWidth;
}	
function getWindowHeight()
{  	if (windowHeight <= 0)
	  getWindowSize(); 
	return windowHeight;
}	

function findPos(obj) 
{var curleft = curtop = 0;
	if (obj.offsetParent) 
	{	do 
		{	curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}



function getWindowSize() 
{	if( typeof( window.innerWidth ) == 'number' )	//Non-IE
	{	windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	} else 
		if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )    //IE 6+ in 'standards compliant mode'
		{	 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else 
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) //IE 4 compatible
			{	windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
 
}
function setContentHeight()
{ 	getWindowSize(); 
	var el = document.getElementById('content')
	if (el) 
	{ 	var pos = findPos(el);
		var len = (getWindowHeight()-(25+pos[1])) + 'px';

		if (getWindowHeight() > 600)
			el.style.height = len;
		else   
			el.style.height = 'auto';
	}	

   // else alert(len);
   // var el = document.getElementById('content')

}	
function WindowEvent(ev,fn)
{	if (window.addEventListener)
 		window.addEventListener(ev, fn, false); 
	else 
		if (window.attachEvent)
			window.attachEvent('on'+ev, fn);
		
}		
WindowEvent('load', setContentHeight);
WindowEvent('resize', setContentHeight);
WindowEvent('load', initKeepAlive);

function keepSessionAlive()
{    elImg = document.getElementById('keepSessionAliveImg');
     if (elImg) elImg.src = '/keepalivegif.php?' + escape(new Date());
}	 
function initKeepAlive()
{	if (document.getElementById('keepSessionAliveImg'))
		window.setInterval("keepSessionAlive()", 100000);
}
      
/*********************************Cookies ***************************************/
function createCookie(name,value,days) 
{	if (days) 
	{	var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{	var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}


/*********************************End Cookies ***************************************/

function verify_delete(deletemess) 
{	if ( deletemess === undefined || deletemess=='') 
		deletemess = "Weet u zeker dat u dit record wil verwijderen?";
	if  (confirm(deletemess))
	{ 	if (document.getElementById('_act'))
			document.getElementById('_act').value='del';
		return true;
	} else return false;	
}

var gRecord = {"_result":"fail"};
function loadJSON(load_url,dataRecord,func)
{
    var xmlhttp = new XMLHttpRequest();
	xmlhttp.setRequestHeader('X-REQUESTED-WITH', 'xmlhttprequest');
    xmlhttp.open("GET", load_url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {   dataRecord = eval( "(" + xmlhttp.responseText +")"); //un-safe !!
            func(dataRecord);
        }
    }
    xmlhttp.send(null);
}


var isIE = document.all ? true : false;

function HidePop()
{	var pop = document.getElementById('pop');
	if (pop) 
	{	pop.style.visibility='hidden';
		return false;	
	}	
}

function loadPop(url,titel)
{	var pop = document.getElementById('pop');
	if (pop)
	{	loadDiv(url,'popContent');
		pop.style.visibility = 'visible';
		document.getElementById('popTitle').innerHTML = titel;
		return false;
	}	
}

function verify_delete(deletemess) 
{	if ( deletemess === undefined || deletemess=='') 
		deletemess = "Weet u zeker dat u dit record wil verwijderen?";
	if  (confirm(deletemess))
	{ 	if (document.getElementById('_act'))
			document.getElementById('_act').value='del';
		return true;
	} else return false;	
}

var gRecord = {"_result":"fail"};
function loadJSON(load_url,dataRecord,func)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", load_url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {   dataRecord = eval( "(" + xmlhttp.responseText +")"); //un-safe !!
            func(dataRecord);
        }
    }
    xmlhttp.send(null);
}

function xhr_return(dat)
{  	if (dat.mess) 
		alert(dat.mess);
	else 
		alert('geen boodschap');
}

function xhr(url)
{  	loadJSON(url,gRecord,xhr_return);
	return false;
}

function inserthtml(html)
{
edit.focus();
if (isIE)
	{
	var range = document.selection.createRange();
	range.pasteHTML(html);
	}
else
	document.execCommand('inserthtml', false, html);
}

function loadHTML(load_url,htmlStr,func)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", load_url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {   htmlStr = xmlhttp.responseText;
            func(htmlStr);
        }
    }
    xmlhttp.send(null);
}

function init()
{
  /*if (isIE)
  {  for (i=0; i<document.all.length; i++)
            document.all(i).unselectable = "on";
    <!-- Prepare the editable regions                                      -->
    editDiv.unselectable = "off";
  }*/
  
  var edit = document.getElementById(id);
  edit.designMode = 'on';  
  edit.focus();
}
//-----------------------------------------------------------------------------------------------------------
function rte_cmd(id,x)
{var edit = document.getElementById(id);
	document.execCommand(x, false, null);
	edit.focus();
}
function rte_inserthtml(id,html)
{var edit = document.getElementById(id);
	edit.focus();
	if (isIE)
	{	var range = document.selection.createRange();
		range.pasteHTML(html);
	}
	else
		document.execCommand('inserthtml', false, html);
}
function rte_save(id)
{
	var edit = document.getElementById('rte_'+id);
	var msg  = document.getElementById(id);
	msg.value = edit.innerHTML;
}
//-----------------------------------------------------------------------------------------------------------
function rte_addlink(id)
{var edit = document.getElementById(id);
	link = prompt("Please insert URL, don't use \'http://\' ","");
	var name = link;
	if (link.indexOf(':') == -1)
	{
		if (link.indexOf('@') == -1) link = 'http://' + link;
		else link = 'mailto:' + link;
 	}
	rte_inserthtml(id,'<a href="' + link + '">' + name + '</a>');
}
//-----------------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------------
// Dit moet anders!!
var browser = navigator.userAgent;
var isIE = (browser.indexOf("MSIE") >= 0);
var isOpera = (browser.indexOf("Opera") >= 0);
var isFirefox = (browser.indexOf("Gecko") >= 0);
//-----------------------------------------------------------------------------------------------------------

var viewmode = 0;
var lbrReg = new RegExp('((&lt;br&gt;)|(&lt;/p&gt;))','gi');
function rte_toggleview(id)
{var edit = document.getElementById(id);
   if (isIE)
	{  if (viewmode == 0) 
      	edit.innerText = edit.innerHTML;
   	else
	   	edit.innerHTML = edit.innerText;
	} else
	{
	   if (viewmode == 0)
	   {  edit.textContent = edit.innerHTML;
	   	edit.innerHTML = edit.innerHTML.replace(lbrReg,'$1<BR>');
	   } else
	    	edit.innerHTML = edit.textContent;
	}
	edit.focus();
	viewmode = 1 - viewmode;
}

function eventPos(evt)
{	if (evt.pageX) return [evt.pageX,evt.pageY];
	else 
		if (evt.clientX)
		{   var x = evt.clientX + (document.documentElement.scrollLeft ?
					document.documentElement.scrollLeft : document.body.scrollLeft);
			var y  = evt.clientY + (document.documentElement.scrollTop ?
					document.documentElement.scrollTop : document.body.scrollTop);		
			return [x,y];			
		} else return [null,null];
}

function loadDiv(URL,divid)
{   var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function()
		{   if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{   htmlStr = xmlhttp.responseText;
				displayDiv(divid,htmlStr);
			}
		}	
	xmlhttp.open("GET", URL);
	xmlhttp.setRequestHeader('X-REQUESTED-WITH', 'xmlhttprequest');
	xmlhttp.send(null);
	return false;
}

function displayDiv(divid,content)
{	var el = document.getElementById(divid);
	if (el)
	{	el.innerHTML = content;
	    var x = el.getElementsByTagName("script");   
	    for(var i=0;i<x.length;i++)  
		{  
			eval(x[i].text);  
	   	}  
	}	
}



var dragObj = new Object();
dragObj.zIndex = 0;
/********************* Drag pop ****************************************/
function dragStart(event, id)
{

  var el;
  var x, y;

    dragObj.elNode = document.getElementById(id);
	pos = findPos(dragObj.elNode) 
	epos = eventPos(event);
    x = epos[0];
    y = epos[1];

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = pos[0];
  dragObj.elStartTop   = pos[1];

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  
}

function dragGo(event) 
{var x, y;
   x = event.clientX ;
   y = event.clientY ;

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
}

function dragStop(event)
{
 // Stop capturing mousemove and mouseup events.
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
	if (findPos(dragObj.elNode)[1] <-1) dragObj.elNode.style.top =0 +'px'; 
}
/********************* end Drag pop ****************************************/



