﻿/// <reference path="prototype.js" />
Event.observe(window, "load", InitializePage);
Event.observe(window, "resize", SetScreenElements);

var pw;
var ph;
var availwidth;
var rightwidth;
var rightheight;
var oldarea = null;
var areaouter = null;

function OnShowTopic(event)
{
  CollapseSearchBar();
  var rightpanel = $("rightpanel");
  var topicframe = $("TopicFrame");
  var backtoresults = $("PanelNavigateToResults");
  var seealso = $("PanelSeeAlsoList");
  
  if (rightpanel) {
    rightpanel.style.left = "76px";
  }

  if (topicframe) {
    topicframe.style.left = "77px";
    topicframe.style.width = rightwidth + "px";
    topicframe.style.height = (rightheight - 2) + "px";
  }
  if (backtoresults) {
    backtoresults.style.left = (availwidth - 544) + "px";
    backtoresults.style.width = "260px";
  }
  if (seealso) {
    seealso.style.left = (availwidth - 280) + "px";
    seealso.style.height = (rightheight) + "px";
    seealso.style.width = "260px";  
  }
}

function OnShowTopicList(event)
{ 
  ExpandSearchBar();
  var rightpanel = $("rightpanel");
  if (rightpanel) {
    rightpanel.style.left = "340px";
  }
  if (event.memo.OrderBy == "workfield") {   
    var panelresultslist = $("PanelResultsList");
    if (panelresultslist) {
      Element.hide(panelresultslist);
      areaouter = $("wfareaouter_" + event.memo.SelectedWorkField);
      area = $("wfarea_" + event.memo.SelectedWorkField);
      if ((areaouter) && (area)) {
        if (oldarea) {
          Element.hide(oldarea);
          oldarea.setAttribute("status", "collapsed");           
        }
        area.innerHTML = panelresultslist.innerHTML;
        areaouter.style.height = (ph - 488) + "px";
        if (event.memo.PagerRequest == false) {
          Effect.SlideDown(areaouter, { duration: 0.8, transition: Effect.Transitions.spring });
        } else {
        Element.show(areaouter);
        }    
        areaouter.setAttribute("status", "expanded");     
        oldarea = areaouter;
      }     
    }     
  }
}
 
function InitializePage()
{
  topiclistview = true;  
  Event.observe(document, "client:submit", UnHookHintFields);
  Event.observe(document, "client:showtopic", OnShowTopic);
  Event.observe(document, "client:showtopiclist", OnShowTopicList);
  HookHintFields();
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(HookHintFields);
  SetScreenElements();  
  Element.show("header_left");
  Element.show("header_right");
}

function HookHintFields()
{
  var field = $("TextBoxFullText");
  if (field) {  
    new InputHint.Add(field, "zoeken in tekst");
  }

  field = $("TextBoxNumber");
  if (field) {
    new InputHint.Add(field, "zoeken op nummer");
  }
}

function UnHookHintFields()
{  
  var field = $("TextBoxFullText");
  if ((field) && (field.SetHint)) {    
    field.SetHint("");
  }

  field = $("TextBoxNumber");
  if ((field) && (field.SetHint)) {
    field.SetHint("");
  }
}

function SetScreenElements()
{
  var header_left = $("header_left");
  var header_right = $("header_right");
  var rightpanel = $("rightpanel");
  var panelresultsheader = $("PanelResultsHeader");
  var panelresults = $("PanelResults");
  var footer = $("footer");
  var topicframe = $("TopicFrame");
  var backtoresults = $("PanelNavigateToResults");
  var topictbarea = $("TopicToolBarArea");
  var seealso = $("PanelSeeAlsoList");
  var infobar = $("infobar");
  var modalmask = $("modaldialogmask");
  var infoarea = $("infoarea");
  var infoframe = $("infoframe");
  
  pw = parseInt(document.body.clientWidth);
  ph = parseInt(document.body.clientHeight);
  availwidth = pw - 16;
  
  if ((header_left) && (header_right)) {
    if (availwidth > 1200) {
      header_left.style.width = "1200px";
      header_right.style.width = (pw - 1188) + "px";
      Element.show(header_right);
    } else {
      header_left.style.width = availwidth + "px";
      Element.hide(header_right);
    }
  }

  rightwidth = (availwidth - 361);
  if (rightwidth < 100) {
    rightwidth = 100;
  }
  rightheight = (ph - 174);
  if (rightheight < 100) {
    rightheight = 100;
  }
  
  if (rightpanel) {
    rightpanel.style.width = rightwidth + "px";
    rightpanel.style.height = rightheight + "px";
  }  
  if (panelresultsheader) {
    panelresultsheader.style.width = (rightwidth - 20) + "px";
  }
  if (panelresults) {
    panelresults.style.width = (rightwidth - 20) + "px";
  }  
  if (footer) {
    footer.style.width = (availwidth - 20) + "px";
    footer.style.top = (ph - 20) + "px";
  }
 
  if (topicframe) {
    topicframe.style.width = rightwidth + "px";
    topicframe.style.height = rightheight + "px";
  }
  if (backtoresults) {
    backtoresults.style.left = (availwidth - 544) + "px";
    backtoresults.style.width = "260px";
  }
  if (seealso) {
    seealso.style.left = (availwidth - 280) + "px";
    seealso.style.height = seealso.style.height = rightheight + "px";
    seealso.style.width = "260px";
  }
  if (areaouter) {
    areaouter.style.height = (ph - 488) + "px";
  }
  if (infobar) {
    infobar.style.width = (availwidth - 20) + "px";
  }
  if (modalmask) {
    modalmask.style.width = pw + "px";
    modalmask.style.height = ph + "px";
  }
    popupwidth = pw - 200;
    popupheight = ph - 200; 
  if (infoarea) {     
    infoarea.style.width = popupwidth + "px";
    infoarea.style.height = popupheight + "px";
    infoarea.style.left = ((pw - popupwidth) / 2) + "px";
    infoarea.style.top = ((ph - popupheight) / 2) + "px";
  } 
  if (infoframe) {
    infoframe.style.height = (popupheight - 33) + "px";
    infoframe.style.width = (popupwidth - 2) + "px";
  }
}

function HoverInfoLink(obj) {
  if (obj) {
    obj.className = obj.className + "_hover";
  }
}

function DeHoverInfoLink(obj) {
  if (obj) {
    obj.className = obj.className.substring(0,obj.className.indexOf("_hover"));   
  }
}

function ClickInfoLink(obj) {
  var srootobj = $("SiteRoot");
  if (srootobj) {
    Event.observe($("infoframe"), "load", InfoAreaLoaded);
    var page = srootobj.value + "contents/info/" + obj.id + ".html"; 
    frames["infoframe"].location.href = page;
  }
}

function InfoAreaLoaded() {
  var infoarea = parent.$("infoarea");
  var caption = parent.$("infoarea_captiontext");
  if ((infoarea) && (caption)) {
    if (infoarea.getAttribute("status") != "show") {
      caption.innerHTML = frames["infoframe"].document.title;
      parent.ShowInfoArea();
    }
  }
}

function HideInfoArea() {
  Event.stopObserving(parent.frames["infoframe"], "load", InfoAreaLoaded);
  var modalmask = $("modaldialogmask");
  var infoarea = $("infoarea");
  if ((modalmask) && (infoarea)) {
    Effect.Fade(infoarea, {duration: 0.3});
    Effect.Fade(modalmask, {duration: 0.3, from:0.7, to:0.0});
    infoarea.setAttribute("status", "hide");
  }
}

function ShowInfoArea() {
  var modalmask = $("modaldialogmask");
  var infoarea = $("infoarea");
  if ((modalmask) && (infoarea)) {
    Effect.Appear(modalmask, {duration:0.3, from: 0.0, to:0.7})
    Effect.Appear(infoarea, {duration: 0.3});
    infoarea.setAttribute("status", "show");
  }
}

function OpenTopic(fileId)
{
  if ((fileId != null) && (typeof fileId == "string")) {
    var field = $("HiddenOpenTopicCommand");
    if (field) {
      field.value = fileId;
      __doPostBack('HiddenOpenTopicCommand', '');      
    }
  }
}

function PrintTopic() {
  window.frames["TopicFrame"].focus();
  window.frames["TopicFrame"].print();
}
