portal_url = 'http://www.platformseksueleintimidatie.nl'
if (document.getElementById || document.all) { // minimum dhtml support required
    document.write("<"+"script type='text/javascript' src='" + portal_url + "/x/x_core.js'><"+"/script>");
    document.write("<"+"script type='text/javascript' src='" + portal_url + "/x/x_event.js'><"+"/script>");
    document.write("<"+"script type='text/javascript' src='" + portal_url + "/x/x_dom.js'><"+"/script>");
    document.write("<"+"script type='text/javascript' src='" + portal_url + "/x/x_cook.js'><"+"/script>");
    document.write("<"+"link type='text/css' href='" + portal_url + "/local.css' rel='stylesheet' media='screen' />");
    window.onload = winOnLoad;
}
function winOnLoad()
{
    var ele = xGetElementById('portal-column-one');
    if (ele && xDef(ele.style, ele.offsetHeight)) { // another compatibility check
      adjustLayout();
      xAddEventListener(window, 'resize', winOnResize, false);
    }
    if(xGetElementById('pageLinks')) {
      initPageLinks();
    }
    if(xGetElementById('bookmarks')) {
      initBookmarks();
    }
    initPortlets();

}
function winOnResize()
{
    adjustLayout();
}

function stripLocation() {
  var loc = window.location.href;
  l = loc.split('#')[0]
  return l
}
/***********************************************************
 * saveBookmark
 * save cookie bookmark
 **********************************************************/
function saveBookmark() {
  var b = xGetCookie('NumOfBookmarks');
  if (b == null) {
    num = 0;
  } else {
    num = parseInt(b);
  }
  num += 1;
  var today = new Date();
  var expires = new Date();
  expires.setTime(today.getTime() + 1000*60*60*24*365);
  xSetCookie('NumOfBookmarks',num,expires);
  loc = stripLocation();
  xSetCookie('PSIBookmark' + (num - 1),loc,expires)
  title= xGetElementsByTagName('h1')[1].innerHTML;
  xSetCookie('PSIPageTitle' + (num - 1),title,expires)
  window.location = loc;
}

/***********************************************************
 * deleteBookmark
 * delete cookie bookmark
 **********************************************************/
function deleteBookmark() {
  var b = xGetCookie('NumOfBookmarks');
  if (b == null) {
    num = 0;
  } else {
    num = parseInt(b);
  }
  var i;
  var j = 0;
  var total = num;
  var today = new Date();
  var expire_now = new Date();
  expire_now.setTime(today.getTime());
  var expires = new Date();
  expires.setTime(today.getTime() + 1000*60*60*24*365);
  var loc;
  for(i=0;i<total;i++) {
    loc = xGetCookie('PSIBookmark' + i);
    title = xGetCookie('PSIPageTitle' + i);
    if(loc != stripLocation()) {
      xSetCookie('PSIBookmark' + j,loc,expires)
      xSetCookie('PSIPageTitle' + j,title,expires)
      j++;
    } else {
      // expire cookie
      xSetCookie('PSIBookmark' + i,loc,expire_now)
      xSetCookie('PSIPageTitle' + i,title,expire_now)
    }
  }
  num -= 1;
  xSetCookie('NumOfBookmarks',num,expires);
  loc = stripLocation();
  window.location = loc;
}

/***********************************************************
 * initBookmark
 * set up cookie bookmark and portlet
 **********************************************************/
function initBookmarks() {
  var box = xGetElementById('bookmarks');
  var b = xGetCookie('NumOfBookmarks');
  if (b == null) {
    num = 0;
  } else {
    num = parseInt(b);
  }
  favs = '';
  var dodel = 0;
  var i;
  for(i=0;i<num;i++) {
    loc = xGetCookie('PSIBookmark' + i);
    title = xGetCookie('PSIPageTitle' + i);
    favs += '<div><a href="' + loc + '">';
    favs += title;
    favs += '</a></div>';
    if (loc == window.location) {
      dodel = 1;
    }
  }
  if (dodel == 1) {
    favs += '<div style="text-align:right;">'
               + '<a href="javascript:deleteBookmark()" style="font-weight:bold">'
               + 'verwijder bookmark'
               + '</a></div>';
  } else {
    favs += '<div style="text-align:right;">'
                 + '<a href="javascript:saveBookmark()" style="font-weight:bold">'
                 + 'maak bookmark'
                 + '</a></div>';
  }
  if (favs != '') {
    str = '<h5>uw bookmarks</h5>';
    str += '<div class="portletBody">';
    str += '<div class="portletContent">';
    str += favs;
    str += '</div>';
    str += '</div>';
    box.innerHTML = str;
  }
}

/***********************************************************
 * initPageLinks
 * set anchor and insert menu to portlet
 **********************************************************/
function initPageLinks() {
  var box = xGetElementById('pageLinks');

  var content = xGetElementById('portal-column-content');
  aH = xGetElementsByTagName('h2',content);  // Headers
  links = '';
  if(aH.length > 1) { // 3 or more subheadings
    for (i = 0; i < aH.length; ++i) {
      h = aH[i];
      title = h.innerHTML;
      aname = 'Sect' + (i + 1);
      links += '<div>';
      links += '<a href="' + window.location 
             + '#' + aname 
             + '" title="' + title 
             + '">';
      links += title;
      links += '</a>';
      links += '</div>';
      // append the anchor
      anchor = document.createElement('a');
      anchor.setAttribute("name", aname);
      anchor.id = aname;
      anchor.className = 'page-anchor';
      anchor.innerHTML = '.';
      // append the to top
      if(i > 0) {
        link = document.createElement('a');
        link.setAttribute("href", window.location + '#documentContent');
        link.className = 'page-to-top';
        anchor.appendChild(link);
        span = document.createElement('span');
        span.innerHTML = 'top';
        link.appendChild(span);
      }
      h.parentNode.insertBefore(anchor,h);
    }
  }
  
  if(links != '') {
    str = '<h5>inhoudsopgave</h5>';
    str += '<div class="portletBody">';
    str += '<div class="portletContent">';
    str += links;
    str += '</div>';
    str += '</div>';
    box.innerHTML = str;
  }
}

/***********************************************************
 * initPortlets
 * set open close action on portlets
 **********************************************************/
function initPortlets() {

  // right col only
  rc = xGetElementById('portal-column-two');
  aH = xGetElementsByTagName('h5',rc);  // Headers
  aC = xGetElementsByClassName('portletBody',rc); // collapsable body
  
  for (i = 0; i < aH.length; ++i) {
    h = aH[i]; // sTag element (trigger)
    c = aC[i]; // collapsible element (target)
    if (h && c) {
      parid = h.parentNode.id;
      h.collapsibleEle = c;
      cook = xGetCookie('h_' + parid);
      h.collapsed = parseFloat(cook);
      h.onclick = fnOnClick;
      h.id = 'h_' + parid;
      h.onclick();
      //xResizeTo(h,160,17);
    }
  }
}

/***********************************************************
 * fnOnClick
 * action on portlet headers
 **********************************************************/
function fnOnClick() {
  var d, t;
  if (!(this.collapsed)) {
    d = 'block';
    t = 'Hide';
    c = 'open';
    cook = 0;
  }
  else {
    d = 'none';
    t = 'Show';
    c = 'closed';
    cook = 1;
  }
  //alert(this.id);
  xSetCookie(this.id,cook);
  this.className = c;
  this.collapsibleEle.style.display = d;
  this.setAttribute('title', 'Click to ' + t + ' Section');
  this.collapsed = !this.collapsed;
}

/***********************************************************
 * adjustLayout
 * set up layout
 **********************************************************/
function adjustLayout() {

  var c= xGetElementById('portal-column-content');
  aH = xGetElementsByTagName('h2',c);  // Headers
  // add space created by dyn added anchors
  space = aH.length * 14;

  // Get content heights
  var cHeight = xHeight('portal-column-content') + space;
  var lHeight = xHeight('portal-column-one');
  var rHeight = xHeight('portal-column-two') + 10;
  var clientHeight = xClientHeight();

  // Find the maximum height
  var maxHeight = Math.max((clientHeight - 85),Math.max(cHeight, Math.max(lHeight, rHeight)) + 80);

  //xHeight('portal-column-content',cHeight);
  // Move and Show the footer
  xTop('portal-footer',maxHeight);
  xShow('portal-footer');
  

  // check doc description
  dD = xGetElementsByClassName('documentDescription',c);
  // should be just one
  for (i=0;i<dD.length;i++) {
    if (dD[i].innerHTML == '') {
      dD[i].style.display = 'none';
    }
  }

}

