﻿function treeView_OnNodeSelect(sender, eventArgs)
{  
  if ((eventArgs) && (eventArgs.get_node())) {
    var contentframe = frames["iframe_content"];
    if (contentframe) {    
      // Determine current document from statelist
      var currentdocument = null;
      var statelist = KMStateList.getStateList();
      if (statelist) {
        var currentdocumentid = statelist.values().valueOf(BBOnlineSession.CURRENTDOCUMENTID);
        if (currentdocumentid) {
          currentdocument = new BBOnlineDocument(currentdocumentid,
            statelist.values().valueOf(BBOnlineSession.CURRENTDOCUMENTTITLE),
            statelist.values().valueOf(BBOnlineSession.CURRENTDOCUMENTORIGIN));
        }
        
        var documentupdating = statelist.values().valueOf("documentupdating");
        if ((documentupdating) && (documentupdating == "true")) {
          return false;
        }
      }    
               
      if ((!currentdocument) || (!currentdocument.sameDocument(eventArgs.get_node().get_id())))  {    
        newdocument = new BBOnlineDocument(eventArgs.get_node().get_id(), 
          eventArgs.get_node().get_text(), BBOnlineOrigins.TOC);
        if (updateDocument) {
          updateDocument(newdocument, contentframe, BBOnlineOrigins.TOC);          
        }        
      } if ((currentdocument) && (currentdocument.getAssigned())) {
        // document already loaded, just scroll into view. Determine locator.    
        newdocument = new BBOnlineDocument(eventArgs.get_node().get_id());
        if (newdocument.locator != "") {
          locatorobj = contentframe.document.getElementById(newdocument.locator); 
          if (locatorobj) {
            locatorobj.scrollIntoView(true);
          }                       
        }
      } 
    }
  }  
}

// Central method called after loading and resizing page.
function resizePage()
{
  var innerrect = KMMeasurement.getInnerRect(self);

  // set menu toolbar width
  /*
  var menuarea = document.getElementById("bbmenuarea");
  if (menuarea) {
    var menuwidth = innerrect.width - BBOnlineSiteMeasurements.MENUTOPRIGHTCORRECTION;
    if (menuwidth > BBOnlineSiteMeasurements.MENUMAXWIDTH) {
      menuwidth = BBOnlineSiteMeasurements.MENUMAXWIDTH;      
    } else if (menuwidth < 0) {
      menuwidth = 0;
    } else {       
      menuwidth -= KMMeasurement.getLeft(menuarea);
    }
        
    KMMeasurement.setWidth(menuarea, menuwidth);
  }
  
  */
  
  // set button gffuncties
  /*
  var togglebutton = document.getElementById("togglegf_button");
  if (togglebutton) {
    var wval = innerrect.width - BBOnlineSiteMeasurements.MENUTOPRIGHTCORRECTION - 124;
    if (wval > BBOnlineSiteMeasurements.MENUMAXWIDTH - 124) {
      wval = BBOnlineSiteMeasurements.MENUMAXWIDTH - 124;
    }
    if (wval < 0) {
      wval = 0;
    }
    
    var wvalhot = wval; // vague correction factor
    if (wvalhot < 0) {
      wvalhot = 0;
    }
    
    KMMeasurement.setLeft(togglebutton, wval);    
    togglebutton.setAttribute("anchorleft", KMMeasurement.getSizeExpression(wval));
    togglebutton.setAttribute("anchorlefthot", KMMeasurement.getSizeExpression(wvalhot));
  }  
  */
  
  // resize overlays
  resizeDocumentOverlay();
  resizeIndexOverlay();
  resizeNoticeOverlay();
  resizePdfPrintOverlay();
}

// Called when pane for tree is resized
function resizeTree(DomElement, NewPaneHeight, NewPaneWidth)
{ 
  if (TreeView_content.Visible)
  TreeView_content.render();
}

// Menu support methods
function overMenuItem(obj) {
  if (obj.getAttribute("selected") != "true") {
    obj.className = "bbmenuitem_mainmenuhover";
  }
}

function outMenuItem(obj) {
  if (obj.getAttribute("selected") != "true") {
    obj.className = "bbmenuitem_mainmenu";
  }
}

function overMainMenuItem(obj) {
  if (obj.getAttribute("selected") != "true") {
    obj.className = "bbmenuitem_mainmenuhover";
  }
}

function outMainMenuItem(obj) {
  if (obj.getAttribute("selected") != "true") {
    obj.className = "bbmenuitem_mainmenu";
  }
}

function overTopMenuItem(obj) {
  if (obj.getAttribute("selected") != "true") {
    obj.className = "bbmenuitem_topmenuhover";
  }
}

function outTopMenuItem(obj) {
  if (obj.getAttribute("selected") != "true") {
    obj.className = "bbmenuitem_topmenu";
  }
}

function menuSelect(id) {
  var elem = document.getElementById(id);
  if (elem) {
    clickMenuItem(elem);
  }
}

function initializeInitialFilters() {
  if ((self.initialfilter) && (initialfilter.length > 0)) {
    // Uncheck all
    var col = document.getElementsByTagName("INPUT");
    for (var i=0;i<col.length;i++) {
      if (col[i].getAttribute("classtype") == "gf") {
        col[i].checked = false;
      } 
    }      
  
    // Check selected
    var filter;
    var checkbox;
    for (index = 0; index < initialfilter.length; index++) {
      filter = initialfilter[index];
      checkbox = document.getElementById(filter);
      if (checkbox != null) {
        checkbox.checked = true;
      }
    }
  }
}

function initializeInitialDocument() {  
  if ((self.initialdocid) && (initialdocid !== "")) {    
    updateDocument(initialdocid, null, BBOnlineOrigins.UNKNOWN, false);
  }
}

function resetMenuItems() {
  var menuarea = document.getElementById("bbmenuarea");
  if (menuarea) {
    var tdcol = menuarea.getElementsByTagName("TD");
    for (var index=0; index < tdcol.length; index++) {
      tdcol[index].className = "bbmenuitem_mainmenu";
      tdcol[index].setAttribute("selected", "false");
    }  
  }
}

function clickMenuItem(obj) {     
  var menuid = obj.id;

  if ((menuid == "contact") || (menuid == "disclaimer") || 
      (menuid == "about") || (menuid == "help")) {
    menuid = "notice";
  }   
  
  if (menuid == "navindex") {
    hideNotice(); 
    hidePdfPrint();   
    toggleIndex();
  } else if (menuid == "notice") {
    hideIndex();   
    hidePdfPrint(); 
    toggleNotice(obj.id);
  } else if (menuid == "print") {
    hideIndex();    
    hideNotice();
    doPrint();
  } else { // navsearch
    resetMenuItems();

    obj.className = "bbmenuitem_mainmenuselected";
    obj.setAttribute("selected", "true");
    
    // hide overlays
    hideIndex();    
    hideNotice();

    var navsearch_panel = document.getElementById("span_navsearch");
    if (menuid == "navsearch") {
      // display navsearch panel      
      if (navsearch_panel) {
        if (navsearch_panel.style.display == "none") {
          // hide navtoc
          TreeView_content.Visible = false;
          TreeView_content.render();
          navsearch_panel.style.display = "inline";
        }
      }
    }
    else if (menuid == "navtoc") {
      // hide navsearch panel
      if (navsearch_panel) {
        if (navsearch_panel.style.display == "inline") {        
          // display navtoc          
          navsearch_panel.style.display = "none";
          TreeView_content.Visible = true;                   
          TreeView_content.render();
          
          // sync navtoc
          var statelist = KMStateList.getStateList();
          if (statelist) {
            synchronizeToc(statelist.values().valueOf(BBOnlineSession.CURRENTDOCUMENTID));        
          }                
        }
      }
    }
  }
}

//  NEN AV support methods
var nenavinitialized = false;
var nenavshowing = false;
var nenavactiveid = "";

function initializeNenAv()
{
  if (nenavinitialized == true) {
    return true;
  } else {      
    var objbody = document.getElementsByTagName("body").item(0);
	  if (objbody) {
	    // Dynamically construct iframe for nen av
	    var nenaviframe = document.createElement("iframe");
	    nenaviframe.setAttribute("id", "nenaviframe");  
	    nenaviframe.setAttribute("name", "nenaviframe");  
	    nenaviframe.setAttribute("frameborder", "0");  
	    nenaviframe.setAttribute("border", "0");  
	    
	    // do not set display to none because of Safari bug
	    // objindexiframe.style.display = "none";
	    // instead set dimensions to zero
	    nenaviframe.style.width = "0px";
	    nenaviframe.style.height = "0px";
	    
	    // setAttribute does not work for IE for properties that impact display layout
	    nenaviframe.frameBorder = "0";	  
	    nenaviframe.border = "0";	  
	    objbody.appendChild(nenaviframe);   
	    Position.absolutize(nenaviframe);
	    
	    nenavinitialized = true;
	    return true;  
	  }
	}
}

function showNenAv(id)
{
  if (initializeNenAv()) {      
    if ((id) && (nenavactiveid) && (nenavactiveid == id)) {
      nenavactiveid = "";
      hideNenAv();
      return false;
    }
    
    nenavactiveid = id;
    resizeNenAv(true);
            
    var _nenaviframe = frames["nenaviframe"];
    if (_nenaviframe) {
      var innercontent = _nenaviframe.document.getElementById("innercontent");
      if (innercontent) {
        innercontent.innerHTML = "<span class='progresstext'>Inlezen...</span>";
      }
      
      _nenaviframe.location.href = "nenavlinkman.aspx?nenavid=" + id;	
	}

     var nenaviframe = $("nenaviframe");
     if (nenaviframe) {
      nenaviframe.style.display = "";  
    }	
  }
}

function hideNenAv()
{
  var nenaviframe = $("nenaviframe");
  if (nenaviframe) {
    nenaviframe.style.display = "none";  
  }
}

// Dynamically position iframe for nenav. Only works in case theiy are 
// visible or when force = true (for internal use).
function resizeNenAv(force)
{
  if ((nenavshowing) || (force)) {      
    var nenaviframe = $("nenaviframe");
    contentobject = $("iframe_content");
    
    if ((nenaviframe) && (contentobject) && (Splitter_main)) {             
      var contentrect = KMMeasurement.getRect(contentobject);
      var nenavrect = KMMeasurement.cloneRect(contentrect);
            
      nenavrect.width = (contentrect.width * 0.8);    
      nenavrect.height = (contentrect.height * 0.9);
      
      var margin = (contentrect.height - nenavrect.height) / 2;
      nenavrect.left = ((contentrect.left + contentrect.width) - nenavrect.width) / 2;
      nenavrect.top = contentrect.top + margin;
      
      KMMeasurement.setRect(nenaviframe, nenavrect);
    }
  }
}

function resizeNenAvContent()
{
  var innerrect = KMMeasurement.getInnerRect(self);
  var innerlayer = KMMeasurement.getInnerRect(self);
  var nenavcontent = document.getElementById("content");
  if (nenavcontent) {
    innerrect.left = BBOnlineSiteMeasurements.NENAVCONTENTLEFT;
    innerrect.top = BBOnlineSiteMeasurements.NENAVCONTENTTOP;
    innerrect.width -= BBOnlineSiteMeasurements.NENAVCONTENTWIDTHMARGIN;
    innerrect.height -= BBOnlineSiteMeasurements.NENAVCONTENTHEIGHTMARGIN;
    KMMeasurement.setRect(nenavcontent, innerrect);
  }
  
  var nslayer = document.getElementById("noselectlayer");
  if (nslayer) {
    innerlayer.left = BBOnlineSiteMeasurements.NENAVCONTENTLEFT;
    innerlayer.top = BBOnlineSiteMeasurements.NENAVCONTENTTOP;
    innerlayer.width -= BBOnlineSiteMeasurements.NENAVCONTENTWIDTHMARGIN + 20;
    innerlayer.height -= BBOnlineSiteMeasurements.NENAVCONTENTHEIGHTMARGIN;
    KMMeasurement.setRect(nslayer, innerlayer);  
  }
}

//  Grenswaarden support methods
var gwinitialized = false;
var gwshowing = false;
var gwactiveid = "";

function initializeGW()
{
  if (gwinitialized == true) {
    return true;
  } else {      
    var objbody = document.getElementsByTagName("body").item(0);
	  if (objbody) {
	    // Dynamically construct iframe for grenswaarden
	    var gwiframe = document.createElement("iframe");
	    gwiframe.setAttribute("id", "gwiframe");  
	    gwiframe.setAttribute("name", "gwiframe");  
	    gwiframe.setAttribute("frameborder", "0");  
	    gwiframe.setAttribute("border", "0");  
	    
	    // do not set display to none because of Safari bug
	    // objindexiframe.style.display = "none";
	    // instead set dimensions to zero
	    gwiframe.style.width = "0px";
	    gwiframe.style.height = "0px";
	    
	    // setAttribute does not work for IE for properties that impact display layout
	    gwiframe.frameBorder = "0";	  
	    gwiframe.border = "0";	  
	    objbody.appendChild(gwiframe);   
	    Position.absolutize(gwiframe);
	    
	    gwinitialized = true;
	    return true;  
	  }
	}
}

function showGW(artid)
{
  if (initializeGW()) {      
    if ((artid) && (gwactiveid) && (gwactiveid == artid)) {
      gwactiveid = "";
      hideGW();
      return false;
    }
    
    gwactiveid = artid;
    resizeGW(true);
            
    var _gwiframe = frames["gwiframe"];
    if (_gwiframe) {
      var innercontent = _gwiframe.document.getElementById("innercontent");
      if (innercontent) {
        innercontent.innerHTML = "<span class='progresstext'>Inlezen...</span>";
      }
      
      _gwiframe.location.href = "content.aspx?bbartid=" + artid;
    }
    
    if (!gwshowing) {
      gwshowing = true;               
      
      new Effect.Appear("gwiframe", { 
        duration: 0.2, 
        from: 0.0, 
        to: 0.99 });
    }          
  }
}

function hideGW()
{
  var gwiframe = $("gwiframe");
  if ((gwshowing) && (gwiframe)) {
    gwshowing = false;
    gwactiveid = "";
    
    new Effect.Fade(gwiframe, { 
      duration: 0.2, 
      from: 0.99, 
      to: 0 });    
  }
}

// Dynamically position iframe for grenswaarden. Only works in case theiy are 
// visible or when force = true (for internal use).
function resizeGW(force)
{
  if ((gwshowing) || (force)) {      
    var gwiframe = $("gwiframe");
    contentobject = $("iframe_content");
    
    if ((gwiframe) && (contentobject) && (Splitter_main)) {             
      var contentrect = KMMeasurement.getRect(contentobject);
      var gwrect = KMMeasurement.cloneRect(contentrect);
            
      gwrect.width = (contentrect.width * 0.4);    
      gwrect.height = (contentrect.height * 0.9);
      
      var margin = (contentrect.height - gwrect.height) / 2;
      gwrect.left = (contentrect.left + contentrect.width) - gwrect.width - margin;
      gwrect.top = contentrect.top + margin;
      
      KMMeasurement.setRect(gwiframe, gwrect);
    }
  }
}

// Filter support methods
function overLabel(obj) {
  obj.className = "filterlabel_hover";
}

function outLabel(obj) {
  obj.className = "filterlabel";
}

function clickFilter(obj) {
  if (typeof obj != 'undefined') {
    // log filteridValue
    if (obj.getAttribute("classtype") == "nbbb") {
      obj.setAttribute("filtertype","bouw")
    }
    else if (obj.getAttribute("classtype") == "gf") {
      obj.setAttribute("filtertype","gebruiksfunctie")
    }
    else {
      obj.setAttribute("filtertype","onbekend")
    }
    logBBOnlineBBFilter('logajax.aspx', obj);
  }

  var contentframe = frames["iframe_content"];
  if (contentframe) {
   if (contentframe.initBBFilter) {
     contentframe.initBBFilter();
   }
  }

  var gwframe = frames["gwiframe"];
  if (gwframe) {
   if (gwframe.doGfFilter) {
     gwframe.doGfFilter();
   }
  } 
}

function overGfButton(obj) {
  var gfbtnobj = $("togglegf_button");
  if (gfbtnobj) { 
    var counter = 0;
    var col = document.getElementsByTagName("INPUT");
    for (var i=0;i<col.length;i++) {
      if (col[i].getAttribute("classtype") == "gf") {
        if (col[i].checked == true) {
          counter += 1;
        }  
      }
    }    
    if (counter > 5) {
      gfbtnobj.className = "togglegf_button_off";
      gfbtnobj.setAttribute("status","off"); 
    } else {
      gfbtnobj.className = "togglegf_button_on";
      gfbtnobj.setAttribute("status","on"); 
    }      
    gfbtnobj.style.left = gfbtnobj.getAttribute("anchorlefthot"); 
    gfbtnobj.style.width = "114px"; 
  } 
}

function outGfButton(obj) {  
  var gfbtnobj = $("togglegf_button");
  if (gfbtnobj) {
    gfbtnobj.style.left = gfbtnobj.getAttribute("anchorlefthot");
    gfbtnobj.style.width = "114px";
  }
}

function clickGfButton(obj) {
  var status = "on";
  if (obj.getAttribute("status")) {
    status = obj.getAttribute("status");
  } 
  
  if (status == "on") {  
    ch = true;
    obj.className = "togglegf_button_off";
    obj.setAttribute("status","off");          
  } else { 
    ch = false; 
    obj.className = "togglegf_button_on";
    obj.setAttribute("status","on");       
  }   

  if (typeof obj != 'undefined') {
    obj.setAttribute("filtertype","allegebruiksfuncties")
    logBBOnlineBBFilter('logajax.aspx', obj);
  }
  
  var col = document.getElementsByTagName("INPUT");
  for (var i=0;i<col.length;i++) {
    if (col[i].getAttribute("classtype") == "gf") {
      col[i].checked = ch;
    } 
  }  
  
  clickFilter();  
}

var bwwindow = null;

// Connect to BrisWarenhuis. Variable bwurl should have been set in upcontent.xml.
function connectBW(id, releaseid, key) {
  if ((id) && (bwurl)) {
    var url = bwurl + "/bw.dll?action=login&externalaction=linkmanager&id=" + id;
    if ((releaseid == null) || (releaseid == "")){
      releaseid = bwreleaseid;
    }
    
    if ((releaseid) && (releaseid != "")) {
      url += "&release=" + releaseid;
    } 
    
    if ((key) && (key != "")) {
      url += "&key=" + key;
    }

    if ((bwwindow) && (!bwwindow.closed) && (bwwindow.location)) {
	    bwwindow.location = url;
    } else {
	    bwwindow = window.open(url, "bwwindow");
	    if (!bwwindow.opener) {
	      bwwindow.opener = self;
  	  }
    }

    if ((window.focus) && (bwwindow)) {
	    bwwindow.focus();
    }    
  }
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
