// CasusConsult javascript-functions
pauze = 0;
// variabelen 
countGroep = 0;
countProb = 0;
countMeth = 0;
hasChanged=false;
isSubmitting=false;
chngdfrm = "";
actieveVenster="formHoofdreactie";
var venster1="";
var venster2="formHoofdreactieOpen";
frms = document.forms;

// form-change-check functies
function saveAll(loading){
  hasChanged=false; // when page is reloaded
  for (j=0;j<frms.length;j++){
    var changedList = "";
    var elems = frms[j].elements;
    for (i=0;i<elems.length;i++){
      var elem = elems[i];
      if (elem.type  && (elem.type == 'text' || elem.type == 'textarea' || elem.type == 'password')) {
        if (loading) { // only onLoad
          elem.onchange=findchange;
          elem.onblur=findchange;
        }
        if (elem.value!=elem.defaultValue) {
          hasChanged=true;
          changedList += ','+elem.name;
        }
      }
	  if (elem.type  && (elem.type == 'radio' || elem.type == 'checkbox')) {
        if (loading) { // only onLoad
          elem.onchange=function(){if (this.checked!=this.defaultChecked) hasChanged=true}
          elem.onblur=function(){if (this.checked!=this.defaultChecked) hasChanged=true}
        }
        if (elem.checked!=elem.defaultChecked) {
          hasChanged=true;
          changedList += ','+elem.name;
        }
      }
	  if (elem.type  && elem.type == 'select') {
        if (loading) { // only onLoad
          elem.onchange=function(){
		  	if (this.checked!=this.defaultChecked) hasChanged=true}
          elem.onblur=function(){if (this.checked!=this.defaultChecked) hasChanged=true}
        }
        if (elem.checked!=elem.defaultChecked) {
          hasChanged=true;
          changedList += ','+elem.name;
        }
      }
    }
    if (changedList.length>0) {
		//frms[j].change.value=changedList.substring(1);
		chngdfrm = frms[j];
		blabla = j;
	}
  }

}

function findchange(){
  if (this.value!=this.defaultValue) hasChanged=true;
}

function subIt(theForm) {
  isSubmitting=true;
  saveAll();
}

// sectie showen/hiden
function doSection(secNum){
	if (document.getElementById(secNum)) {
		if (document.getElementById(secNum).style.display=='none'){
			//alert(actieveVenster);
			if (actieveVenster!='' && document.getElementById(actieveVenster)) document.getElementById(actieveVenster).style.display='none';
			document.getElementById(secNum).style.display="block";
			if (document.getElementById('opslaanicoon')) document.getElementById('opslaanicoon').style.display="block";
			//setCookie(secNum,'1');
			actieveVenster = secNum;
		} else {
			document.getElementById(secNum).style.display="none";
			if (document.getElementById('opslaanicoon')) document.getElementById('opslaanicoon').style.display="none";
			//setCookie(secNum,'0');
			if (actieveVenster!='' && document.getElementById(actieveVenster)) document.getElementById(actieveVenster).style.display='none';
			actieveVenster = '';
		}
	}
}
function doVensters(secNum1,secNum2){
	//console.log(actieveVenster);
	if (actieveVenster && actieveVenster!='') $('#' + actieveVenster).hide();
	if (document.getElementById(secNum1)) {
		if (venster1 && venster1!='' && venster1!=secNum1) $('#' + venster1).hide();
		if (document.getElementById(secNum1).style.display=='none'){
			$('#' + secNum1).show();
			$('#' + secNum1 + ' textarea').focus();
			$('#popslaanicoon').show();
			venster1 = secNum1;
		} else {
			$('#' + secNum1).hide();
			$('#popslaanicoon').hide();
			venster1 = '';
		}
	}
	if (document.getElementById(secNum2)) {
		if (venster2 && venster2!='' && venster2!=secNum2) $('#' + venster2).show();
		if (document.getElementById(secNum2).style.display=='none'){
			$('#' + secNum2).show();
			venster2 = '';
		} else {
			$('#' + secNum2).hide();
			venster2 = secNum2;
		}
		//if (venster2!=secNum2) document.getElementById(venster2).style.display='block';
	}
}
function showSection(secNum,type){
	if (document.getElementById(secNum)) {
		if (document.getElementById(secNum).style.display=='none'){
			document.getElementById(secNum).style.display=type;
		} else {
			document.getElementById(secNum).style.display="none";
		}
	}
}

// kennisgroepen showen/hiden
function doKG(soort,number) {
	pause(pauze);
	if (number) {
		var cijfer = number;
	} else {
		var cijfer = getCookie(soort);
	}
	//alert(cijfer);
	if (countGroep==1 && cijfer==0 && soort=='groep') cijfer = 1; 
	if (countProb==1 && cijfer==0 && soort=='prob') cijfer = 1; 
	if (countMeth==1 && cijfer==0 && soort=='meth') cijfer = 1; 
	if (document.getElementById(soort)) {
		var lCat = $('#' + soort);
		//alert ('#' + soort + 'rest');
		var glCat = $('#' + soort + 'rest');
		if (cijfer==0 || (lCat.is(":hidden") && glCat.is(":hidden"))) {
			//alert(lCat);
			lCat.show();
			glCat.hide();
			setCookie(soort,'1');
		} else
		if (cijfer==1 || (lCat.is(":visible") && glCat.is(":hidden"))) {
			lCat.show();
			glCat.show();
			setCookie(soort,'2');
		} else
		if (cijfer==2 || (lCat.is(":visible") && glCat.is(":visible") ) ) {
			lCat.hide();
			glCat.hide();
			setCookie(soort,'0');
		}
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}

// grootte divs aanpassen voor frontpage
function resizeFront() {
	
}

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
	if(re.test(els[i].className))a.push(els[i]);
	return a;
}

// setContent already run
setContentRun = true;

function setContentNew() {
	if (setContentRun) {
		setContentRun = false;
		var windowHeight = getWindowHeight();
		var contentWidth = getWindowWidth();
		//if (contentWidth >1224) contentWidth = 1224;
		if (contentWidth <780) contentWidth = 780;
		var contentElement = document.getElementById('container');
		contentElement.style.height = (windowHeight-10) + 'px';
		contentElement.style.width = (contentWidth-10) + 'px';
		var headerHeight = $('#header')[0].offsetHeight;
		//alert(document.getElementById('header').offsetHeight);
		var contentHeight = windowHeight -10 - headerHeight;	
		var leftWidth = 0;
		var rightWidth = 0;
		 $("body").css('overflow','hidden');
		  $("html").css('overflow','hidden');
		if (document.getElementById('left')) {
			var foldleft = $('#fold_left').height();
			document.getElementById('left').style.height = contentHeight - foldleft - 20 + 'px';
			leftWidth = document.getElementById('left').offsetWidth;
			$('#fold_left a').width(leftWidth);
		}
		if (document.getElementById('right')) {
			var foldright = $('#fold_right').height();
			document.getElementById('right').style.height = contentHeight - foldright - 20 + 'px';
			rightWidth = document.getElementById('right').offsetWidth;
		}
		if ($('#center')) {
			$('#center').height(contentHeight);
			$('#center').width(contentWidth-leftWidth-rightWidth-30);
			$('#center').css('marginLeft', (leftWidth+10) + 'px');
			$('#center').css('marginRight', (rightWidth+10) + 'px');
		}
		if (document.getElementById('objcontent')) {
			var objHead = $('#objhead')[0].offsetHeight;
			//alert(objHead);
			//document.getElementById('objcontent').style.top = objHead + 'px';
			$('#objcontent,.tabcontent').height(contentHeight - objHead - 10);
			if (document.getElementById('meta_content') || document.getElementById('inh_content'))
				$('#objcontent').css('overflow','hidden').css('overflow-y','hidden');
			$('#avchat_frame').height($('#objcontent').height() - 20);
			//$('#objcontent *').css('position', 'relative');
			//document.getElementById('objhead').style.height = objHead + 'px';
		}
		if (document.getElementById('pobjcontent')) {
			var pobjHead = document.getElementById('pobjhead').offsetHeight;
			//var totalWidth = (contentWidth-10-175-175);
			//var objWidth = round(totalWidth/2);
			//var pobjWidth = totalWidth - objWidth;
			//alert(objWidth);
			//document.getElementById('pobjcontent').style.top = pobjHead + 'px';
			document.getElementById('pobjcontent').style.height = (contentHeight-pobjHead-10) + 'px';
			//document.getElementById('pobjhead').style.height = pobjHead + 'px';
			var centerWidth = document.getElementById('center').offsetWidth;
			var objWidth = Math.round(centerWidth/2) - 10;			
			/*document.getElementById('objcontent').style.width = objWidth + 'px';
			document.getElementById('objhead').style.width = objWidth + 'px';
			document.getElementById('pobjcontent').style.width = objWidth + 'px';
			document.getElementById('pobjhead').style.width = objWidth + 'px';*/
			$('#object').width(objWidth);
			$('#discus').width(objWidth);
		} else if (document.getElementById('objcontent')) {
		    document.getElementById('objcontent').style.width = document.getElementById('center').offsetWidth;
			document.getElementById('objhead').style.width = 'auto';
			$('#table_catdetail').width($('#objcontent').width() - 30);
			$('.tabcontent').width($('#objcontent').width());
		}

		if (document.getElementById('cathome')) {
			elm = getElementsByClassName('object_wrapper');
			for (var i=0; i < elm.length; i++) {
				elm[i].style.width = ((document.getElementById('center').offsetWidth/2)-30) + 'px';
			}
			//document.getElementById('cathome').style.width((document.getElementById('center').offsetWidth/2)-20)
		}
		if (document.getElementById('front_center')) {
			document.getElementById('front_center').style.height = contentHeight + 'px';
			//document.getElementById('front_center').style.top = headerHeight + 'px';
			}
		if (document.getElementById('infocontent')) {
			document.getElementById('infocontent').style.height = (contentHeight-120) + 'px';
			//document.getElementById('front_center').style.top = headerHeight + 'px';
		}

		if (document.getElementById('homemenu')) {
			document.getElementById('homewerkw').style.width = (contentWidth-253-253-10)/2 + 'px';
			document.getElementById('homevoorw').style.width = (contentWidth-253-253-10)/2 + 'px';
			}
		if (document.getElementById('kdcontent')) {
			kdHeadHeight = document.getElementById('kdhead').offsetHeight;
			//alert(kdHeadHeight);
			kdContentHeight = contentHeight-kdHeadHeight-60;
			//document.getElementById('kdcontent').style.top = kdHeadHeight + 'px';
			document.getElementById('kdcontent').style.height = kdContentHeight + 'px';
		}
		if (document.getElementById('lpcontent')) {
			kdHeadHeight = document.getElementById('lphead').offsetHeight;
			kdContentHeight = contentHeight-kdHeadHeight-60;
			document.getElementById('lpcontent').style.height = kdContentHeight + 'px';
		}
		if (document.getElementById('kdcasuscontent')) {
			kdTitleHeight = document.getElementById('kdtitle').offsetHeight;
			kdSearchResultHeight = 0;
			if (document.getElementById('kdsearchresult'))
				kdSearchResultHeight = document.getElementById('kdsearchresult').offsetHeight;
			kdCasusTitleHeight = document.getElementById('kdcasustitle').offsetHeight;
			kdColumnContentHeight = contentHeight-kdTitleHeight-kdSearchResultHeight-kdCasusTitleHeight-60;
			
			//alert(kdColumnContentHeight);
			document.getElementById('kdcasuscontent').style.height = kdColumnContentHeight + 'px';
			document.getElementById('kdprofielcontent').style.height = kdColumnContentHeight + 'px';
			document.getElementById('kddoccontent').style.height = kdColumnContentHeight + 'px';
		}
		
		if (document.getElementById('mcetextar')) {
			document.getElementById('mcetextar').style.height = (contentHeight-objHead-100) + 'px';
			document.getElementById('mcetextar').style.width = (contentWidth-leftWidth-rightWidth-70) + 'px';
			document.getElementById('inhoudM').style.width = (contentWidth-leftWidth-rightWidth-70) + 'px';
		}
		
		displayContainer();
		if ($(".kdblock")) {
			kdColumnContentHeight = contentHeight - $("#kdtitle").height() - $("#kdsearchresult").height() - 2*($(".kdblock .title").height()) - 40;
			//alert($("#kdtitle").height());
			kdBlockHeight = (kdColumnContentHeight)/2;
			//alert(kdBlockHeight);
			$(".kdblock .content").height(kdBlockHeight);
			$(".kdblockspacer").height(kdBlockHeight + $(".kdblock .title").height());
		}
        if ($("#MyTextarea___Frame").height() > 0) {
            
            $("#MyTextarea___Frame").height($("#objcontent").height()-20);
            $("#objcontent").css("overflow","hidden");
            $("#objcontent").css("overflow-y","hidden");
        }
        //$('#pobjcontent').scrollTo(300);
        //deleteCookie('pobjcontent_scroll');
        //console.log('test');
		//$('#table_catdetail').show('slow');
		//alert(contentHeight-headerHeight-objHead);
	}
}

function setContentFront() {
			$("#container").css('width',function(){
		      var w = getWindowWidth();
		      if (w>1200)
		          return '1200px';
		      else
		          return w + 'px';
		          
		  });
		 $("#front-center").css('height','100%');
		  //$(".kdblock .content").css('height','250px');
		  displayContainer ();
		  $("#container").css('overflow','visible');
		  $('#kdback').width($("#container").width() - $('#lpback').width() - 85);
		  if (getIEVersion()==6) $('#kdcontent').width($('#kdback').width()-44);
}
function setContentOld() {
	if (setContentRun) {
		setContentRun = true;
		var windowHeight = getWindowHeight();
		var contentWidth = getWindowWidth();
		if (contentWidth >1224) contentWidth = 1224;
		if (contentWidth <780) contentWidth = 780;
		var contentElement = document.getElementById('container');
		contentElement.style.height = (windowHeight-10) + 'px';
		contentElement.style.width = (contentWidth-10) + 'px';
		var headerHeight = document.getElementById('header').offsetHeight;
		var contentHeight = windowHeight -10 - headerHeight;	
		var leftWidth = 0;
		var rightWidth = 0;
		 $("body").css('overflow','hidden');
		  $("html").css('overflow','hidden');
		if (document.getElementById('left')) {
			document.getElementById('left').style.height = contentHeight + 'px';
			leftWidth = document.getElementById('left').offsetWidth;
		}
		if (document.getElementById('right')) {
			document.getElementById('right').style.height = contentHeight + 'px';
			rightWidth = document.getElementById('right').offsetWidth;
		}
		if (document.getElementById('center')) {
			document.getElementById('center').style.height = contentHeight + 'px';
			document.getElementById('center').style.width = (contentWidth-leftWidth-rightWidth-30) + 'px';
			document.getElementById('center').style.marginLeft = (leftWidth+10) + 'px';
			document.getElementById('center').style.marginRight = (rightWidth+10) + 'px';
		}
		if (document.getElementById('objcontent')) {
			var objHead = document.getElementById('objhead').offsetHeight;
			//alert(objHead);
			//document.getElementById('objcontent').style.top = objHead + 'px';
			document.getElementById('objcontent').style.height = (contentHeight - objHead - 10) + 'px';
			//document.getElementById('objhead').style.height = objHead + 'px';
		}
		if (document.getElementById('pobjcontent')) {
			var pobjHead = document.getElementById('pobjhead').offsetHeight;
			//var totalWidth = (contentWidth-10-175-175);
			//var objWidth = round(totalWidth/2);
			//var pobjWidth = totalWidth - objWidth;
			//alert(objWidth);
			//document.getElementById('pobjcontent').style.top = pobjHead + 'px';
			document.getElementById('pobjcontent').style.height = (contentHeight-pobjHead-10) + 'px';
			//document.getElementById('pobjhead').style.height = pobjHead + 'px';
			var centerWidth = document.getElementById('center').offsetWidth;
			var objWidth = Math.round(centerWidth/2) - 10;			
			document.getElementById('objcontent').style.width = objWidth + 'px';
			document.getElementById('objhead').style.width = objWidth + 'px';
			document.getElementById('pobjcontent').style.width = objWidth + 'px';
			document.getElementById('pobjhead').style.width = objWidth + 'px';
		} else if (document.getElementById('objcontent')) {
		    document.getElementById('objcontent').style.width = 'auto';
			document.getElementById('objhead').style.width = 'auto';
		}
		if (document.getElementById('cathome')) {
			elm = getElementsByClassName('object_wrapper');
			for (var i=0; i < elm.length; i++) {
				elm[i].style.width = ((document.getElementById('center').offsetWidth/2)-30) + 'px';
			}
			//document.getElementById('cathome').style.width((document.getElementById('center').offsetWidth/2)-20)
		}
		if (document.getElementById('front_center')) {
			document.getElementById('front_center').style.height = contentHeight + 'px';
			//document.getElementById('front_center').style.top = headerHeight + 'px';
			}
		if (document.getElementById('infocontent')) {
			document.getElementById('infocontent').style.height = (contentHeight-120) + 'px';
			//document.getElementById('front_center').style.top = headerHeight + 'px';
		}

		if (document.getElementById('homemenu')) {
			document.getElementById('homewerkw').style.width = (contentWidth-253-253-10)/2 + 'px';
			document.getElementById('homevoorw').style.width = (contentWidth-253-253-10)/2 + 'px';
			}
		if (document.getElementById('kdcontent')) {
			kdHeadHeight = document.getElementById('kdhead').offsetHeight;
			//alert(kdHeadHeight);
			kdContentHeight = contentHeight-kdHeadHeight-60;
			//document.getElementById('kdcontent').style.top = kdHeadHeight + 'px';
			document.getElementById('kdcontent').style.height = kdContentHeight + 'px';
		}
		if (document.getElementById('lpcontent')) {
			kdHeadHeight = document.getElementById('lphead').offsetHeight;
			kdContentHeight = contentHeight-kdHeadHeight-60;
			document.getElementById('lpcontent').style.height = kdContentHeight + 'px';
		}
		if (document.getElementById('kdcasuscontent')) {
			kdTitleHeight = document.getElementById('kdtitle').offsetHeight;
			kdSearchResultHeight = 0;
			if (document.getElementById('kdsearchresult'))
				kdSearchResultHeight = document.getElementById('kdsearchresult').offsetHeight;
			kdCasusTitleHeight = document.getElementById('kdcasustitle').offsetHeight;
			kdColumnContentHeight = contentHeight-kdTitleHeight-kdSearchResultHeight-kdCasusTitleHeight-60;
			
			//alert(kdColumnContentHeight);
			document.getElementById('kdcasuscontent').style.height = kdColumnContentHeight + 'px';
			document.getElementById('kdprofielcontent').style.height = kdColumnContentHeight + 'px';
			document.getElementById('kddoccontent').style.height = kdColumnContentHeight + 'px';
		}
		
		if (document.getElementById('mcetextar')) {
			document.getElementById('mcetextar').style.height = (contentHeight-objHead-100) + 'px';
			document.getElementById('mcetextar').style.width = (contentWidth-leftWidth-rightWidth-70) + 'px';
			document.getElementById('inhoudM').style.width = (contentWidth-leftWidth-rightWidth-70) + 'px';
		}
		displayContainer();
		if ($(".kdblock")) {
			kdColumnContentHeight = contentHeight - $("#kdtitle").height() - $("#kdsearchresult").height() - 2*($(".kdblock .title").height()) - 40;
			//alert($("#kdtitle").height());
			kdBlockHeight = (kdColumnContentHeight)/2;
			//alert(kdBlockHeight);
			$(".kdblock .content").height(kdBlockHeight);
			$(".kdblockspacer").height(kdBlockHeight + $(".kdblock .title").height());
		}
        if ($("#MyTextarea___Frame").height() > 0) {
            
            $("#MyTextarea___Frame").height($("#objcontent").height()-20);
            $("#objcontent").css("overflow","hidden");
            $("#objcontent").css("overflow-y","hidden");
        }
		//alert(contentHeight-headerHeight-objHead);
	}
}

// hoogte divs aanpassen
function setContent() {
		/*
		var objHead = 100;
		if (getQueryVariable("type")=='user') {var objHead = 50};
		if (getQueryVariable("type")=='profiel') {var objHead = 50};
		if (getQueryVariable("type")=='vraag') {var objHead = 70};
		if (getQueryVariable("type")=='dossier') {
			if (getQueryVariable("passive") || getQueryVariable("discus")) {var objHead = 110;} 
			else {var objHead = 110;};
			}
		if (getQueryVariable("type")=='cat') {var objHead = 55};
		if (getQueryVariable("action")=='add') {var objHead = 50};
		if (getQueryVariable("action")=='displayAddUser') {var objHead = 50};
		if (getQueryVariable("action")=='admin') {var objHead = 0};
		if (getQueryVariable("action")=='home') {var objHead = 53};
		if (getQueryVariable("action")=='search') {var objHead = 110};
		//if (getQueryVariable("action")=='login') {var objHead = 50};
		var pobjHead = 100;
		if (getQueryVariable("ptype")=='user') {var pobjHead = 0};
		if (getQueryVariable("ptype")=='profiel') {var pobjHead = 50};
		if (getQueryVariable("ptype")=='vraag') {var pobjHead = 50};
		if (getQueryVariable("ptype")=='dossier') {var pobjHead = 110;};
		if (getQueryVariable("discus")) {var pobjHead = 50;};
		if (getQueryVariable("nlink")) {var pobjHead = 50;};
		if (getQueryVariable("ndisc")) {var pobjHead = 50;};
		if (getQueryVariable("page")) {var objHead = 80;};
		//if (getQueryVariable("ndisc")) {var pobjHead = 0;};
		*/
		var objHead = document.getElementById('objhead').offsetHeight;
				//var headerHeight = document.getElementById('header').offsetHeight;
		var windowHeight = getWindowHeight();
		var contentWidth = getWindowWidth();
		var contentHeight = windowHeight;
		var leftWidth = 0;
		var rightWidth = 0;
		var contentElement = document.getElementById('container');
		contentElement.style.position = 'absolute';
		contentElement.style.height = (contentHeight) + 'px';
		if (document.getElementById('hometext')) {
			contentElement.style.width = (contentWidth-10) + 'px';
		} else {
			contentElement.style.width = (contentWidth) + 'px';
		}
		if (document.getElementById('left')) {
			document.getElementById('left').style.height = (contentHeight-80) + 'px';
			leftWidth = document.getElementById('left').offsetWidth;
		}
		if (document.getElementById('right')) {
			document.getElementById('right').style.height = (contentHeight-80) + 'px';
			rightWidth = document.getElementById('right').offsetWidth;
		}
		if (document.getElementById('center')) {
			document.getElementById('center').style.height = (contentHeight-80) + 'px';
			//alert(document.getElementById('center').offsetWidth);
			//document.getElementById('center').style.width = (contentWidth-rightWidth-leftWidth-30) + 'px';
			//alert(document.getElementById('center').offsetWidth);
		}

		if (document.getElementById('object')) {
			document.getElementById('object').style.height = (contentHeight-80) + 'px';
			var halfWidth = Math.round((contentWidth-rightWidth-leftWidth-30)/2);
			//document.getElementById('object').style.width = halfWidth + 'px';
			//alert(Math.round((contentWidth-rightWidth-leftWidth-60)/2));
			document.getElementById('discus').style.height = (contentHeight-80) + 'px';
			//document.getElementById('discus').style.width = halfWidth + 'px';
		} else {
			document.getElementById('object_only').style.height = (contentHeight-80) + 'px';
			//document.getElementById('object_only').style.width = (contentWidth-rightWidth-leftWidth-30) + 'px';
			//document.getElementById('object_only').style.height = (contentHeight-80) + 'px';
		}
		//var objHead = document.getElementById('objhead').offsetHeight;
		//var pobjHead = document.getElementById('pobjhead').offsetHeight;
		if (document.getElementById('pobjcontent')) {
			var pobjHead = document.getElementById('pobjhead').offsetHeight;
			document.getElementById('pobjcontent').style.top = pobjHead + 'px';
			document.getElementById('pobjcontent').style.height = (contentHeight-82-pobjHead) + 'px';
			document.getElementById('pobjhead').style.height = pobjHead + 'px';
			//document.getElementById('pobjcontent').style.width = (halfWidth-4) + 'px';
			//document.getElementById('pobjhead').style.width = (halfWidth-4) + 'px';

		}
		if (document.getElementById('objcontent')) {
			document.getElementById('objcontent').style.top = objHead + 'px';
			document.getElementById('objcontent').style.height = (contentHeight-82-objHead) + 'px';
			document.getElementById('objhead').style.height = objHead + 'px';
			//document.getElementById('objcontent').style.width = document.getElementById('pobjcontent').style.width;
			//document.getElementById('objhead').style.width = document.getElementById('pobjhead').style.width;
		}

		/*
		if (document.getElementById('hometext')) {
			obj = document.getElementById('homefoto');
			foto = document.getElementById('homefoto');
			text = document.getElementById('hometext');
			menu = document.getElementById('homemenu');
			text.style.height = (obj.offsetHeight-foto.offsetHeight-10) + 'px';
			visie = document.getElementById('homevisie');
			werkw = document.getElementById('homewerkw');
			over = document.getElementById('homeover');
			news = document.getElementById('homenews');
			act = document.getElementById('homeact');
			high = document.getElementById('homehigh');
			newscontent = document.getElementById('homenewscontent');
			actcontent = document.getElementById('homeactcontent');
			highcontent = document.getElementById('homehighcontent');
			newstitle = document.getElementById('homekdline');
			acttitle = document.getElementById('homeacttitle');
			hightitle = document.getElementById('homehightitle');
			cWidth = contentWidth - 40;
			mWidth = contentWidth - 50;
			//news.style.width = Math.round(cWidth/3) + 'px';
			//high.style.width = news.style.width;
			//act.style.width = news.style.width;
			news.style.height = text.style.height;
			high.style.height = text.style.height;
			act.style.height = text.style.height;
			newscontent.style.height = (text.offsetHeight-visie.offsetHeight-newstitle.offsetHeight) + 'px';
			actcontent.style.height = (text.offsetHeight-visie.offsetHeight-newstitle.offsetHeight) + 'px';
			highcontent.style.height = newscontent.style.height;
		} 
		*/
		if (document.getElementById('mcetextar')) document.getElementById('mcetextar').style.height = (contentHeight-105-objHead) + 'px';
}
function setSplitPanes() {
		document.getElementById('pobjcontent').style.width = document.getElementById('discus').offsetWidth + 'px';
		document.getElementById('pobjhead').style.width = document.getElementById('discus').offsetWidth + 'px';
		document.getElementById('objcontent').style.width = document.getElementById('object').offsetWidth + 'px';
		document.getElementById('objhead').style.width = document.getElementById('object').offsetWidth + 'px';
}

function displayContainer () {
    var elem = document.getElementById('container');
        elem.style.left = '0px';
		elem.style.overflow = 'hidden';
}
function resizeTextar() {
	var windowHeight = getWindowHeight();
	if (document.getElementById('mcetextar')) document.getElementById('mcetextar').style.height = (windowHeight-205) + 'px';
}

//linkerkolom in/uitklappen
function colWidth(secNum){
     if (document.getElementById(secNum)) {
       if (document.getElementById(secNum).style.width=="21px"){
    	   document.getElementById(secNum).style.width="175px";
    	   document.getElementById(secNum).style.overflow="auto";
		   $('#center').css('margin' + secNum, '176px');
    	   document.getElementById('arrows_' + secNum + '_in').style.display="none";
    	   document.getElementById('arrows_' + secNum + '_out').style.display="block";
		   $('#arrows_' + secNum + '_out').width(165);
		   $('#fold_' + secNum).width(165);
    	   $('#pane_' + secNum).show();
    		setCookie(secNum,'1');
       } else {
    	   document.getElementById(secNum).style.width="21px";
    	   document.getElementById(secNum).style.overflow="hidden";
    	   $('#center').css('margin' + secNum, '30px');
    	   document.getElementById('arrows_' + secNum + '_out').style.display="none";
    	   document.getElementById('arrows_' + secNum + '_in').style.display="block";
		   $('#arrows_' + secNum + '_in').width(11);
		   $('#fold_' + secNum).width(11);
    	   $('#pane_' + secNum).hide();
    		setCookie(secNum,'0');
    	}
       setContentRun = true; 
    	setContentNew();
		$("#center").trigger("resize");
     }
}

function looseSideColumns() {
   document.getElementById('center').style.marginLeft="5px";
   document.getElementById('center').style.marginRight="5px";
   document.getElementById('center').style.width = "auto";
   document.getElementById('object_only').style.width = "99%"; 
   document.getElementById('left').style.display="none";
   document.getElementById('right').style.display="none";
   //document.getElementById('lside').style.display="none";
   //document.getElementById('rside').style.display="none"; 
}
function catEmpty() {
	document.getElementById('exp_content').style.display="none";
	document.getElementById('sub_content').style.display="none";
	document.getElementById('edit_content').style.display="none";
	document.getElementById('exp_tab').style.color="black";
	document.getElementById('sub_tab').style.color="black";
	document.getElementById('edit_tab').style.color="black";
}
function catTab(content,tab){
	catEmpty();
	document.getElementById(content).style.display="block";
	document.getElementById(tab).style.color="#FF860D";
}
// tabs
function objectTabChange(id,p) {
	$('.tab' + p + 'content').hide();
	$('.tab' + p + 'tabs>li').removeClass('active');
	$('#' + id + p + 'tab').addClass('active');
	$('#' + id + '_content' + p).show();
}
// general tab function  
function tabClick(tab,id,container) {
	$(tab).parents('ul').find('li').removeClass('active');
	$('#' + container + '>div').hide();
	$(tab).parent().addClass('active');
	$('#' + id).show();
}
function tabEdit(id,p){
	if (document.getElementById('inh_content' + p)) document.getElementById('inh_content' + p).style.display="none";
	if (document.getElementById('disc_content' + p)) document.getElementById('disc_content' + p).style.display="none";
	if (document.getElementById('meta_content' + p)) document.getElementById('meta_content' + p).style.display="none";
	if (document.getElementById('auto_content' + p)) document.getElementById('auto_content' + p).style.display="none";
	if (document.getElementById('inh_tab' + p)) document.getElementById('inh_tab' + p).className="jhf";
	if (document.getElementById('disc_tab' + p)) document.getElementById('disc_tab' + p).className="jhf";
	if (document.getElementById('meta_tab' + p)) document.getElementById('meta_tab' + p).className="fgj";
	if (document.getElementById('auto_tab' + p)) document.getElementById('auto_tab' + p).className="fgf";
	if (document.getElementById(id+'_content' + p)) document.getElementById(id+'_content' + p).style.display="block";
	if (document.getElementById(id+'_tab' + p)) document.getElementById(id+'_tab' + p).className="active";
}
function tabDosCas(id){
	if (document.getElementById('inh_content')) document.getElementById('inh_content').style.display="none";
	if (document.getElementById('link_content')) document.getElementById('link_content').style.display="none";
	if (document.getElementById('last_content')) document.getElementById('last_content').style.display="none";
	if (document.getElementById('inh_tab')) document.getElementById('inh_tab').style.color="black";
	if (document.getElementById('link_tab')) document.getElementById('link_tab').style.color="black";
	if (document.getElementById('last_tab')) document.getElementById('last_tab').style.color="black";
	if (document.getElementById(id+'_content')) document.getElementById(id+'_content').style.display="block";
	if (document.getElementById(id+'_tab')) document.getElementById(id+'_tab').style.color="#FF860D";
}

function tabAct(id){
	if (document.getElementById('alg_content')) document.getElementById('alg_content').style.display="none";
	if (document.getElementById('aanm_content')) document.getElementById('aanm_content').style.display="none";
	if (document.getElementById('int_content')) document.getElementById('int_content').style.display="none";
	if (document.getElementById('hv_content')) document.getElementById('hv_content').style.display="none";
	if (document.getElementById('afs_content')) document.getElementById('afs_content').style.display="none";
	if (document.getElementById('cont_content')) document.getElementById('cont_content').style.display="none";
	if (document.getElementById('bijl_content')) document.getElementById('bijl_content').style.display="none";
	if (document.getElementById('alg_tab')) document.getElementById('alg_tab').style.color="black";
	if (document.getElementById('aanm_tab')) document.getElementById('aanm_tab').style.color="black";
	if (document.getElementById('int_tab')) document.getElementById('int_tab').style.color="black";
	if (document.getElementById('hv_tab')) document.getElementById('hv_tab').style.color="black";
	if (document.getElementById('afs_tab')) document.getElementById('afs_tab').style.color="black";
	if (document.getElementById('cont_tab')) document.getElementById('cont_tab').style.color="black";
	if (document.getElementById('bijl_tab')) document.getElementById('bijl_tab').style.color="black";
	if (document.getElementById(id+'_content')) document.getElementById(id+'_content').style.display="block";
	if (document.getElementById(id+'_tab')) document.getElementById(id+'_tab').style.color="#FF860D";
	setCookie('dostab',id);
}
function tabActp(id){
	if (document.getElementById('alg_contentp')) document.getElementById('alg_contentp').style.display="none";
	if (document.getElementById('aanm_contentp')) document.getElementById('aanm_contentp').style.display="none";
	if (document.getElementById('int_contentp')) document.getElementById('int_contentp').style.display="none";
	if (document.getElementById('hv_contentp')) document.getElementById('hv_contentp').style.display="none";
	if (document.getElementById('afs_contentp')) document.getElementById('afs_contentp').style.display="none";
	if (document.getElementById('cont_contentp')) document.getElementById('cont_contentp').style.display="none";
	if (document.getElementById('bijl_contentp')) document.getElementById('bijl_contentp').style.display="none";
	if (document.getElementById('alg_tabp')) document.getElementById('alg_tabp').style.color="black";
	if (document.getElementById('aanm_tabp')) document.getElementById('aanm_tabp').style.color="black";
	if (document.getElementById('int_tabp')) document.getElementById('int_tabp').style.color="black";
	if (document.getElementById('hv_tabp')) document.getElementById('hv_tabp').style.color="black";
	if (document.getElementById('afs_tabp')) document.getElementById('afs_tabp').style.color="black";
	if (document.getElementById('cont_tabp')) document.getElementById('cont_tabp').style.color="black";
	if (document.getElementById('bijl_tabp')) document.getElementById('bijl_tabp').style.color="black";
	if (document.getElementById(id+'_contentp')) document.getElementById(id+'_contentp').style.display="block";
	if (document.getElementById(id+'_tabp')) document.getElementById(id+'_tabp').style.color="#FF860D";
	setCookie('pdostab',id);
}

function toggleElements(id,all_ids,prefix) {
	ids = all_ids.split(',');
	for(i=0;i<ids.length;i++) {
		$('#' + prefix + ids[i]).hide();
	}
	$('#' + prefix + id).show();
}
function toggleSugg(id){
	$('#sugg>.sugg').hide();
	$('#suggpage_all>a').css('color','black');
	$('#sugg'+id).show();
	$('#suggpage'+id).css('color','#FF860D');
}

function tabMail(id){
	pause(pauze);
	document.getElementById('smail_content').style.display="none";
	document.getElementById('rmail_content').style.display="none";
	document.getElementById('newmail_content').style.display="none";
	document.getElementById('viewmail_content').style.display="none";
	document.getElementById('smail_tab').className="";
	document.getElementById('rmail_tab').className="";
	document.getElementById('newmail_tab').className="";
	document.getElementById(id+'_content').style.display="block";
	document.getElementById(id+'_tab').className="active";
	setCookie('mailtab',id);
}

function advSearch() {
	if (document.getElementById('advSearch').style.display=="none") {	
		document.getElementById('objcontent').style.top = ((document.getElementById('objcontent').style.top.substring(0,document.getElementById('objcontent').style.top.length-2)*1)+50) + 'px';
		document.getElementById('objcontent').style.height = ((document.getElementById('objcontent').style.height.substring(0,document.getElementById('objcontent').style.height.length-2)*1)-50) + 'px';
		document.getElementById('objhead').style.height = ((document.getElementById('objhead').style.height.substring(0,document.getElementById('objhead').style.height.length-2)*1)+50) + 'px';
		document.getElementById('advSearch').style.display="block";
	}
}
function focusField(form,field) {
	//if (document.forms[form].elements[field] && document.forms[form].elements[field].style.display!="none") document.forms[form].elements[field].focus();
}

// auto-resize formfields
var agt=navigator.userAgent.toLowerCase();

function sz(t) {
	a = t.value.split('\n');
	t.cols=30;
	b=1;
	for (x=0;x < a.length; x++) {
	 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
	 }
	b+= a.length;
	if (b > t.rows && agt.indexOf('opera') == -1) t.rows = b;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function getPos(e){
	var left=0;var top=0; while (e.offsetParent){ left+=e.offsetLeft-e.scrollLeft;top+=e.offsetTop-e.scrollTop;e=e.offsetParent;}left+=e.offsetLeft-e.scrollLeft;top+=e.offsetTop-e.scrollTop;
	return {x:left, y:top};
}
function getPos2(e){
	var left=0;var top=0; 
	while (e.offsetParent){ 
	top+=e.offsetTop;
	e=e.offsetParent;
	}
	top+=e.offsetTop;
	return {y:top};
}
function scrollId (id) {
//pos = getPos2(document.getElementById(id));
//setCookie('kg_scroll',pos.y);
}

function submitReactie () {
	if (getCookie('reactieForm')) {
		var rid = getCookie('reactieForm');
		subIt(rid);
				$('#modalTest').jqmShow();
		//document.forms[rid].elements["Submit"].value = "Submit";
		document.forms[rid].submit();
	}
	//alert("bla");
}
function submitForm (rid) {
        
		subIt(rid);

		document.forms[rid].submit();
		//$('#' + p + 'opslaanicoon').replaceWith($('.waitcircle').clone());
}

function SetDivPosition(id){
	var intY = document.getElementById(id).scrollTop;
	setCookie(id+'_scroll',intY);
}

// scroll-position
function giMe() {
	if (document.getElementById('left') && getCookie('left_scroll')) {
		document.getElementById('left').scrollTop = getCookie('left_scroll');
	}
	if (document.getElementById('lpcontent') && getCookie('lpcontent_scroll')) {
		document.getElementById('lpcontent').scrollTop = getCookie('lpcontent_scroll');
	}
	if (document.getElementById('pobjcontent') && getCookie('pobjcontent_scroll')) {
		document.getElementById('pobjcontent').scrollTop = getCookie('pobjcontent_scroll');
	}
	//alert('offsetHeight: '+elem.scrollHeight+' | scrollTop: '+elem.scrollTop);
}
function resetScroll() {
	setCookie('pobjcontent_scroll','0')
}
function noenter() {
  return !(window.event && window.event.keyCode == 13);
 }
bla = '';
function showID(id) {
	if (bla!='') clearTimeout(bla);
	if (document.getElementById(id).style.display!="block") document.getElementById(id).style.display="block";
}
function hideID(id) {
	if (bla!='') clearTimeout(bla);
	bla = setTimeout("hideIDnow('" + id + "');",1000);
}
function hideIDnow(id) {
	document.getElementById(id).style.display="none";
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function getPos2 (obj) {
var pos = {x: obj.offsetLeft||0, y: obj.offsetTop||0};
while(obj = obj.offsetParent) {
pos.x += obj.offsetLeft||0;
pos.y += obj.offsetTop||0;
}
return pos.y;
}
function timeoutPosY(obj) {
	try {
		//obj = "'" + obj + "'";
		//alert(obj);
		setTimeout(function() {findPosY(obj)},50);
	}
	catch(err) { alert(err)}
}
function findPosY(obj)
  {
    var curtop = 0;
	obj = document.getElementById(obj);
    if(obj && obj.offsetParent)
	{
		//alert("bla");
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
	}
    else if(obj && obj.y) 
	{
        curtop += obj.y;
	}
	//alert(curtop);
	if (document.getElementById('left')) document.getElementById('left').scrollTop = curtop-200;
    return curtop;
  }

function showDiv(id) {
	if (document.getElementById(id)) document.getElementById(id).style.display="block";
}
function hideDiv(id) {
	if (document.getElementById(id)) document.getElementById(id).style.display="none";
}
function hideMelding() {
	document.getElementById('melding').innerHTML="<div align=\"center\" style=\"margin:1px;padding:5px;\"><br /></div>";
}
function expand(id,id2) {
	if (document.getElementById(id).style.display=='none'){
		document.getElementById(id).style.display="block";
		document.getElementById(id2).src="images/collapse.jpg";
	} else {
		document.getElementById(id).style.display="none";
		document.getElementById(id2).src="images/expand.jpg";
	}
}
function pause(numberMillis) {
        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true) {
            now = new Date();
            if (now.getTime() > exitTime)
                return;
        }
    }

function clearPWfield(id) {
	document.getElementById("tft_swapper").innerHTML="<input type=\"password\" name=\"password\" id=\"tft_pass_box\" style=\"display:inline;margin:0;padding:0;height:15px;\" onkeyup=\"if (window.event.keyCode==13) document.formlogin.submit();\" />" ;
	document.getElementById("tft_pass_box").focus();
	document.getElementById("tft_pass_box").focus();
}

function closePassive() {
    $('#discus').remove();
    $('#center').append($('#object').html());
    $('#object').remove();
    setContentNew();
    return false;
}

function ajaxCC(id,url) {
	$('body').css('cursor', 'wait');
	$(id).load(url, function() {
		sortables_init();
		setContentNew();
		$('body').css('cursor', 'default');
	});	
}

function getIEVersion() {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) ) 
	 return ieversion=new Number(RegExp.$1);
	else
	 return false;
}

function getHash() {
	  var hash = window.location.hash;
	  return hash.substring(1); // remove #
	}

$.fn.focusNextInputField = function() {
return this.each(function() {
var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
var index = fields.index( this );
if ( index > -1 && ( index + 1 ) < fields.length ) {
fields.eq( index + 1 ).focus();
}
return false;
});
};

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}
function msgClicked(id) {
	$.get('ajax/checkMsg.php?id=' + id);
}
//onload jquery
$(document).ready(function(){
	$('input:submit').css('border','none');
	
   var hash = getHash();
   if (hash){
	   if (hash == 'member') {
		   $('#catmember').show();
		   $('#cathome').hide();
	   }
	   var page = hash.split("=");
		if (page[0] == 'page') {		
			ajaxCC('#cathome','ajax/catDetail.php?action=view&type=cat&id=' + querySt('id') + '&page=' + page[1]);
			$('.tabh ul li').removeClass('active');
			$('#kg_page_' + page[1]).parent().addClass('active');
		}
	   //$('#rid' + hash).focus();
	   //console.log('#rid' + hash); 
   }

   $('textarea.textar').autoResize();
   $('textarea.textar').focus(function(){
	   $(this).autoResize();
   });
   //checkMsg 
   $(document).everyTime(10000, function(i) {
	   $.getJSON("ajax/checkMsg.php", function(data){
		   if (data) {
			   $('#msg_bar').html('&nbsp;');
			   for(i=0;i<data.length;i++)
				   $('#msg_bar').append(data[i].content);
			   document.title = $('#msg_bar a').html();
			   $('#msg_bar').cyclicFade({repeat: 4,
				   						params: [{fadeout:2000, stayout:300, opout:0, fadein:2000, stayin:300, opin:1.0}
			                              ]});
		   } else {
			   $('#msg_bar').html('&nbsp;');
			   $('#msg_bar').cyclicFade({repeat: 0});
		   }
	   });
	 }, 0);
   //open subcats on mouseover
   $('.cchild,.cparent').hoverIntent({    
	     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 100, // number = milliseconds for onMouseOver polling interval    
	     over: function(){
				   $(this).children('div:hidden').show().addClass('mouseover-cat');
			   }, // function = onMouseOver callback (REQUIRED)    
	     timeout: 300, // number = milliseconds delay before onMouseOut    
	     out: function(){
				   $(this).children('div.mouseover-cat').hide();
			   } // function = onMouseOut callback (REQUIRED)    
	});
   // load users when changing cat in object
   $('#cat_select').change(function(){
	   var value = $('#owner_select option:selected').val();
	   $('#owner_select').load('/ajax/selectCatUsers.php?id=' + $(this).val() + '',function(){
		   $("#owner_select option:[value='" + value + "']").attr("selected","selected");
	   });	   
   });
   //open tab link
   $('#open_tab').click(function(){
	   $($(this).attr('rel') + '>a').click();
	   return false;
   }); 
});


