//
//Copyright (2003) Tobias Ouwejan, Wolters-Noordhoff B.V.
//oBrowser=new BrowserCheck();
// globals
var currentElement;
var activeElements = new Array();
// body scripts
//attachFunctionToElementEvent(window,'onmousedown',deselectElements);
window.document.onclick = deselectElements;

/**********************************************************************/
/* loadImageMark                                                      */
/*                                                                    */
/**********************************************************************/
function loadImageMark(){
  var markImageSplash = new oUrl('../_include/images/logo_cover.gif')
  var iframe = document.frames('main_iframe');
  var markImage = iframe.document.getElementById('mark_image');
  markImage.src = markImageSplash.href;
}

/**********************************************************************/
/* togglebyId                                                         */
/*                                                                    */
/**********************************************************************/
function togglebyId(id) {
  var oElem = document.getElementById(id);
  if (document.getElementById(id).style.display != "block") {
    oElem.style.display = "block";
	choosePosition(oElem);
//    ScrollIntoView(oElem,1);
	} else {
    oElem.style.display = "none";
  }
  activeElements[activeElements.length] = oElem;
  currentElement = oElem;
  //alert('togglebyId ' + currentElement);
  //window.event.cancelBubble = true;
}

// give element a negative marginTop when it falls of the page
function choosePosition(element)
{
  if(document.getElementById('GeneralDiv') != null)
  {
  var maindiv = document.getElementById('GeneralDiv').parentNode;
  // outOfsight = number of pixels below the bottom of maindiv
  var outOfsight = GetTop(element) + element.childNodes[0].offsetHeight - maindiv.offsetHeight;
  if (outOfsight > 0)
  {
    var marginTop = (0 - outOfsight) + "px";
    element.style.marginTop = marginTop;
  }
}
}

function InView(element,margin) {
  if(!margin) margin=0;
  var Top=GetTop(element), ScrollTop=GetScrollTop();
  return !(Top<ScrollTop+margin||
    Top>ScrollTop+GetWindowHeight()-element.offsetHeight-margin);
}
function ScrollIntoView(element,bAlignTop,margin) {
  if(!margin) margin=0;
  var posY=GetTop(element);
  if(bAlignTop) posY-=margin;
  else posY+=element.offsetHeight+margin-GetWindowHeight();
  window.scrollTo(0, posY/2);
}
function GetWindowHeight() {
  return window.innerHeight||
    document.documentElement&&document.documentElement.clientHeight||
    document.body.clientHeight||0;
}
function GetScrollTop() {
  return window.pageYOffset||
    document.documentElement&&document.documentElement.scrollTop||
    document.body.scrollTop||0;
}
function GetTop(element) {
  var pos=0;
  do pos+=element.offsetTop
  while(element=element.offsetParent);
  return pos;
}

/**********************************************************************/
/* deselectElements                                                   */
/*                                                                    */
/**********************************************************************/
function deselectElements(){
  //alert('deselectElements');
  for (var n=0;n<activeElements.length;n++){
    if (activeElements[n] != currentElement)
      activeElements[n].style.display = "none";
     //alert('?');
    //}
  }
  currentElement = null;
}

/**********************************************************************/
/* ignore                                                             */
/*                                                                    */
/**********************************************************************/
function ignore(){
  window.event.cancelBubble = true;
}

/**********************************************************************/
/* swapImage                                                          */
/*                                                                    */
/**********************************************************************/
function swapImage(imgId, href){
  var menu = document.getElementById(imgId);
  if (!menu)
    return false;
  menu.src = href;
  return true;
}

/**********************************************************************/
/* swapExample                                                        */
/*                                                                    */
/**********************************************************************/
function swapExample(oEl, exampleId){
  var example = document.getElementById(exampleId);
  if (example.style.display == 'block'){
    example.style.display = 'none';
    oEl.className = 'exampleTitle';
  }else{
    example.style.display = 'block';
    oEl.className = 'exampleTitleActive';
  }
}

/**********************************************************************/
/* attachFunctionToElementEvent                                                      */
/*   this function is ment to attach functions to events of elements  */
/*   this function will implement these calls in different ways       */
/*   for netscape and Internet explorer.                              */
/**********************************************************************/
function attachFunctionToElementEvent(oEl, ev, f){
//  oEl.addEventListener(ev, f, false);
//  alert("uitgevoerd");
  if (oEl.addEventListener){
    //alert(ev.slice(2, ev.length));
    // "on" wordt voor het event weggehaald, omdat dit niet wordt gebruikt bij browsers behalve bij IE.
    ev = ev.slice(2, ev.length);
    oEl.addEventListener(ev, f, true);
    return true;
  } else if (oEl.attachEvent) {
    var r = oEl.attachEvent(ev, f);
    return r;
  }
}

/**********************************************************************/
/* getNumberedList                                                    */
/*   this function returns a linear list with numbers                 */
/**********************************************************************/
function getNumberedList(listLength){
  var list = new Array();
  for(var n=0;n<listLength;n++)
    list[n] = n;
  return list;
}

/**********************************************************************/
/* getRandomNumberedList                                              */
/*   this function returns a list with random numbers                 */
/**********************************************************************/
function getRandomNumberedList(listLength, randomNumber){
  if(!randomNumber)
    var randomNumber = listLength;

  var randomList = new Array();
  var tmpList = new Array();
  for (var n=0;n<randomNumber;n++){tmpList[n]=n;}
  for (var n=0;n<listLength;n++){
    var r = (Math.round(Math.random() * (tmpList.length-1)));
    randomList[n] = tmpList[r];
    tmpList.splice(r,1);
  }
  return randomList;
}

/**********************************************************************/
/* launchGlossary                                                     */
/*   open glossary                                                    */
/*   this function will check if the glossary-window is already open. */
/*   If so, it will focus the gloss window                            */
/*   otherwise it will create a new one and jump to the glossId       */
/**********************************************************************/
function launchGlossary(glossId){
  var glossLocation = '';           //'../_Glossary/';
  var glossDoc = 'glossary.htm';
  var anchor = '#' + glossId;
  //alert(glossLocation + glossDoc + '?glossId='+ glossId + anchor);
  glossWin = window.open (glossLocation + glossDoc + '?glossId='+ glossId + anchor, 'glossWin', 'resizable=yes,location=0,directories=0,status=0,menubar=0,scrollbars=0,toolbar=0,width=485,height=395')
  glossWin.focus();
}

/****************************************************************************/
/* launchUrl                                                                */
/*   this function will open an url.                                        */
/*   the implementation depends on the browser(version)                     */
/*   the implementation may differ on media and players (cd-rom, LMS, etc.) */
/****************************************************************************/
function launchUrl(url, anchor){
  if (!url)
    return false;
  if (anchor && anchor != '')
    url += '#' + anchor;
  if (target){
  }
  else{
    var target = '_blank';
  }
  window.open(url, target);
  //document.location = url + '#' + anchor;
}

/**********************************************************************/
/* openRelatedTheory                                                  */
/**********************************************************************/
function openRelatedTheory(url, paragraphId){
  launchUrl(url, paragraphId);
}

/**********************************************************************/
/* launchAppendix                                                     */
/**********************************************************************/
function launchAppendix(href){
  launchUrl(href);
}

/******************************************************************************/
/*getParams                                                                   */
/* this function try's to return the value that go's with the param parameter */
/* otherwise it will returns the last appeared key-less value                 */
/******************************************************************************/
function getParams(url, param) {
  var paramWithoutName = '';
  var anchor;
  var loc;
  var querystr;
  loc = unescape(url).split("#");
  if (loc.length > 1)
    anchor = loc[1];
  querystr = loc[0].split("?");
  if (querystr.length < 1)
    return false;
  for (var i=1;i<querystr.length;i++) {
    aQuerypairs = querystr[i].split('&');
    for (var j=0;j<aQuerypairs.length;j++) {
      aParampair = aQuerypairs[j].split('=');
      if (aParampair.length <= 1)
        paramWithoutName = aParampair[0]; // can't find a key/value pair
      else
        if (aParampair[0] == param)
          return aParampair[1]; //found the right parameter
    }
  }
  return paramWithoutName;
}

/******************************************************************************/
/*  oUrl                                                                      */
/******************************************************************************/
function oUrl(url){
  this.href = url;
}

/*
  Function: getArgs
    this function returns an array containing all postdata of the current url

  Parameters:
  - strUrl

  Returns:
  - array
*/
function getArgs() {
  var args   = [];
  var strURL = (strURL) ? strURL : location.search;
  var query  = strURL.substring(1);
  var pairs  = query.split('&');
  for(var i = 0; i < pairs.length; i++) {
    var pos       = pairs[i].indexOf('=');
    if(pos == -1) continue;
    var argname   = pairs[i].substring(0, pos);
    var val       = pairs[i].substring(pos + 1);
    args[argname] = unescape(val);
  }
  return args;
}

/******************************************************************************/
/*  createMailto (this prevents SPAM mail)                                    */
/******************************************************************************/
function createMailto(pMailName,pMailDomain, pLink) {
	document.write("<a href='mailto:" + pMailName + '@' + pMailDomain + "'>" + pLink + "</a>");
}

/******************************************************************************/
/*  sortNumber.   Function to perform numbersorting on a array                */
/******************************************************************************/
function sortNumber(a, b){
    return a - b
}


function openImagePopup(location, options){
  var imagePopup = window.open(location, 'popup', options);
  imagePopup.focus();  
}

/******************************************************************************/
/*  wmpCreate. Create a windows media player object               */
/******************************************************************************/
function wmpCreate(url, divId) { 
    var str = ""; 
    if(!divId)
      var divId="";
    if (browser.ie) { 
         str += '<object id="' + divId + '_contentPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="320" height="240">'; 
    } else { 
         str += '<object id="' + divId + '_contentPlayer" type="application/x-ms-wmp" data="'+url+'" width="320" height="240">'; 
    } 
    str += '<param name="URL" value="'+url+'" />'; 
    str += '<param name="AutoStart" value="true" />'; 
    str += '<param name="Prebuffer" value="true" />'; 
    str += '<param name="ShowControls" value="true" />'; 
    str += '<param name="SendPlayStateChangeEvents" value="true" />';    
    str += '</object>'; 
            
    var d = document.getElementById(divId);
    d.innerHTML = str;   
} 

function createObjects(){
    var divs = document.getElementsByTagName('div');
    for(var i=0;i<divs.length;i++){
        if(divs[i].className=='wmvContainer'){
          var movie = divs[i].getAttribute('url');
          wmpCreate(movie, divs[i].id);
        }
    }          
}

function flashCreate(url, divId, width, height){
  if(!width || width==0 || width=='')
  {
    width = 400;
  }
  if(!height || height==0 || height=='')
  {
    height = 300;
  }
   var div = document.getElementById(divId);
   
   var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" viewastext="true" width="' + width + '" height="' + height + '">';
   str += '<param name="movie" value="'+url+'" />';
   str += '<param name="quality" value="high"/>';
   str += '<param name="bgcolor" value="#ffffff"/>';
   str += '<embed quality="high" bgcolor="#ffffff" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" width="' + width + '" height="' + height + '" src="'+url+'">';
   str += '</embed>';
   str += '</object>';
   
   div.innerHTML = str;
}

function flvCreate(url, divId, relativePath){
	var s1 = new SWFObject(relativePath + "_include/js/mediaplayer.swf","mediaplayer","320","260","7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("width","320");
	s1.addVariable("height","260");
	s1.addVariable("file",url);
	s1.write(divId);
}
function getInnerText(object)
{
  //--| IE and FF read the innerText differently
  //--| Using innerHTML can be dangerous

  var value = object.innerText;
  if(value + '' == 'undefined')
  {
    value = object.textContent;
  }
  return value;  
}

function setInnerText(object, value)
{
  if(object.innerText + '' == 'undefined')
  {
    object.textContent = value;
  }
  else
  {
    object.innerText = value;
  }
}
