/* copyright 2000-2005 Trezorix BV */

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 openWindow(_url, _name, _features) {
  top.window[_name] = window.open(_url, _name, _features);
  if (top.window[_name] != null) {
    top.window[_name].focus();
  }  
}

function argFromURL(url) {
  var args = String(url).split("#");
  if (args.length > 1) {
    return args[1];
  } 
  else {
    return ""; 
  }  
}

function changeImage(imgDocID,imgObjName) {
  document.images[imgDocID].src = eval( imgObjName + ".src")
}
	
function showContextPopUp(srcElement, chosenid, refid, refsite, thisalias, thisid) {
  var featuresString = "left=100,top=100,height=500,width=460,scrollbars=yes,resizable=yes";
  _url = srcElement.getAttribute("href");
  openWindow(_url, "contextsearch", featuresString);
}


function showPopUp(srcElement, windowName, features) {
  var featuresString;
  
  if (features != null) {
    featuresString = features;
  }
  else {
    featuresString = "left=100,top=100,height=477,width=607,scrollbars=yes,resizable=yes";
  }
  _url = srcElement.getAttribute("href");
  openWindow(_url, windowName, featuresString);
}

function showZoomImg(fullname) {                                                                               
  var featuresString = "left=100,top=100,height=500,width=500,scrollbars=yes,resizable=yes,viewbar=yes";
  var _url = site_root + "/asp/page.asp?alias=" + view_alias + "&page_alias=imageview&image=" + fullname;
  top.window["imageview"] = window.open(_url,"imageview",featuresString);
  top.window["imageview"].focus();
}

// begin trefwoord hi-light //
var lastHiLight = null;  

function hilightTerm(ref) {
  var termItem;
  var name;
  
  if (ref == "") return;
  
  if (typeof ref == "string") {
    name = ref;
  }
  else {
    name = argFromURL(ref.getAttribute("href"));
  }
  
  if (document.getElementById) {
    termItem = document.getElementById(name);
  }
  else if (document.anchors(name) != null) {
    termItem = document.anchors(name);
  } 
  else {
    //?
  }
  if (lastHiLight!=null) lastHiLight.className = "dfn";
  
  if (termItem != null) {
    termItem.className = "dfnHi";
    termItem.scrollIntoView();
    lastHiLight = termItem;
  }
  //document.URL = name;
}
// end trefwoord hi-light //

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('content').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'absolute';
				footerElement.style.top = (windowHeight - footerHeight) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}

/* tabs */
function swapTab(obj) {
  var tabItem = obj.parentNode;
  var tabList = tabItem.parentNode;
  var tabs = tabList.getElementsByTagName("li");
  var panelList = tabList.parentNode.nextSibling; 
  var panels = panelList.childNodes;// .getElementsByTagName("div"); geeft alle descendants!!!!
  for (var i = 0; i < tabs.length; i++) {
    if (tabs[i] == tabItem) {
      tabItem.className = "activetab";
      if (panels[i]) {
        panels[i].className = "activetabpanel";
      }  
    }
    else {
      tabs[i].className = "";
      if (panels[i]) {
        panels[i].className = "tabpanel";
      }  
    }  
  }
}

function focusAnchor() {
  this.blur();
}

function clickDfn() {
  showContextPopUp(this);
  return false;
}

function updateAnchors() {
	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++)
	{
		anchors[i].onfocus = focusAnchor;
	}
}


function updateDefinitions() {
	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++)
	{
		if (anchors[i].className == "dfn" || anchors[i].className == "lemma") {
		  anchors[i].onclick = clickDfn;
		}  
	}
}

function updateHilightedTerm() {
	if (document.location) hilightTerm(argFromURL(document.location));
}

var XMLHTTP;

function GetXMLHTTP() {
  var result = null;
  try {
    result = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e){
    try {
      result = new ActiveXObject("Microsoft.XMLHTTP") 
    }
    catch(sc) {
      result = null;
    }
  }
  if (!result && typeof XMLHttpRequest != "undefined") {
    result = new XMLHttpRequest();
  }
  return result;
}

function addEvent(obj, evType, fn) { 
  if (obj.addEventListener) { 
    obj.addEventListener(evType, fn, true); 
    return true; 
  }  
  else if (obj.attachEvent) { 
    var r = obj.attachEvent("on"+evType, fn); 
    return r; 
  } 
  else { 
    return false; 
  } 
}

addEvent(window, 'load', updateHilightedTerm);
addEvent(window, 'load', updateAnchors);
addEvent(window, 'load', updateDefinitions);