//(c) 2001-2004 Creagraphy (E.F. de Moor) and WhizzWeb (A.J. van Delden)

// Global variables:
// mouseX  : current X position of mouse
// mouseY  : current Y position of mouse
// keyCode : Last pressed or released key
// popupId : Id of current popup window, 0 of none active
// popupGraceTimeout: Timeout value of current popup
// popupStartTimer : Handle of start timer of popup
// popupGraceTimer  : Handle of grace timer of popup
var popupId = 0;
var popupGraceTimeout = 0;
var popupStartTimer = 0;
var popupGraceTimer = 0;
var popupVisible = 0;
var PageInfo = '';

// EMO 2005-1-11: Remove check, as to.js is needed at topframe level. See if it gives problems to include it multiple times.
// Sensibility check: have we been included before?
//if(typeof(onload_functions) != "undefined")
//  alert("LETOP!!! to.js wordt meerdere keren geladen\n"+
//        "Dit kan ook middels to.inc of cms_add_to_header zijn!");

var onload_functions = new Array();
function add_onload(f) {
  onload_functions[onload_functions.length] = f;
}
var loaded = 0;
// Outdated function, keep for compatibility
function cms_onload() {
  cms_do_onload();
}
function cms_do_onload() {
  var i;
  loaded = 1;
  if(typeof(cms_sel) != 'undefined') {
    for (var i=0;i<onload_functions.length;i++) {
      onload_functions[i](cms_sel);
    }
  }
  if (window.name=='content' && typeof(cms_sel)!='undefined') {
    // Note: PageInfo is a global variable, added by $content->addto_header
    top.PageInfo = PageInfo;
    call_in_all_frames('set_page_info', cms_sel, PageInfo);
  }
}

var onunload_functions = new Array();
function add_onunload(f) {
  onunload_functions[onunload_functions.length] = f;
}
function cms_onunload() {
  cms_do_onunload();
}
function cms_do_onunload() {
  var i;
  if(typeof(cms_sel) != 'undefined') {
    for (var i=0;i<onunload_functions.length;i++) {
      onunload_functions[i](cms_sel);
    }
  }
}

var onbeforeunload_functions = new Array();
function add_onbeforeunload(f) {
  onbeforeunload_functions[onbeforeunload_functions.length] = f;
}
function cms_onbeforeunload() {
  cms_do_onbeforeunload();
}
function cms_do_onbeforeunload() {
  var i;
  var returnVal = '';
  var Val;
  if(typeof(cms_sel) != 'undefined') {
    for (var i=0;i<onbeforeunload_functions.length;i++) {
      Val = onbeforeunload_functions[i](cms_sel);
      if(Val)
        returnVal += Val;
    }
    if(returnVal)
      return(returnVal);
  }
}

var onresize_functions = new Array();
function add_onresize(f) {
  onresize_functions[onresize_functions.length] = f;
}
function cms_do_onresize() {
  var i;
  for (var i=0;i<onresize_functions.length;i++) {
    onresize_functions[i]();
  }
}

var onmousemove_functions = new Array();
function add_onmousemove(f) {
  onmousemove_functions[onmousemove_functions.length] = f;
}
function cms_do_onmousemove(x,y) {
  var i;
  for (var i=0;i<onmousemove_functions.length;i++) {
    onmousemove_functions[i](x,y);
  }
}

var onkeydown_functions = new Array();
function add_onkeydown(f) {
  onkeydown_functions[onkeydown_functions.length] = f;
}
function cms_do_onkeydown(key) {
  var i;
  for (var i=0;i<onkeydown_functions.length;i++) {
    onkeydown_functions[i](key);
  }
}

var onkeyup_functions = new Array();
function add_onkeyup(f) {
  onkeyup_functions[onkeyup_functions.length] = f;
}
function cms_do_onkeyup(key) {
  var i;
  for (var i=0;i<onkeyup_functions.length;i++) {
    onkeyup_functions[i](key);
  }
}

function stop_loading() {
  if(window.stop)                 // Mozilla Method
    window.stop()
  else if (navigator.userAgent.toLowerCase().indexOf("safari")!=-1) // Safari method
    window.location.href = '';
  else if (document.execCommand)  // IE method. May crash 5.x browsers????
    document.execCommand('Stop');
}

function break_out_of_frames() {
  if (parent.frames.length > 0) {
    try {
      top_host = top.location.host;
    } catch(err) {
      top_host = "error";   // Security error. This means we are in an outer frameset.
    }
    if(top_host != window.location.host) { // Reference from external host
      stop_loading();
      top.location.href = location.href;
    }
  }
}

function call_in_all_frames(func_name, parm1, parm2) {
  if(top)
    call_in_child_frames(top,func_name,parm1,parm2);
}

// Hide all select boxes.
// Optionally a list of selectbox id's can be given. Those stay visible.
function hideSelectBoxes() {
  var i, j;
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(navigator.userAgent) != null) {
      var rv = parseFloat( RegExp.$1 );
      if(rv < 7)  { // All internet explorers before 7 have this bug
        var content = document.getElementById("content");
        if(content) {
          var doc = content.contentDocument;
          if(doc==null)
            doc = content.Document;
        }
        else
          doc = document;
        if(doc && doc.getElementsByTagName) {
          var selects = doc.getElementsByTagName('select');
          for (i=0; i<selects.length; i++) {
            var doHide = true;
            for (j=0; j<hideSelectBoxes.arguments.length; j++) {
              if(selects[i].id == arguments[j])
                doHide = false;
            }
            if(doHide)
              selects[i].style.visibility = "hidden";
          }
        }
      }
    }
  }
}
function showSelectBoxes() {
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(navigator.userAgent) != null) {
      var rv = parseFloat( RegExp.$1 );
      if(rv < 7)  { // All internet explorers before 7 have this bug
        var content = document.getElementById("content");
        if(content) {
          var doc = content.contentDocument;
          if(doc==null)
            doc = content.Document;
        }
        else
          doc = document;
        if(doc && doc.getElementsByTagName) {
          var selects = doc.getElementsByTagName('select');
          for (i=0; i<selects.length; i++) {
            selects[i].style.visibility = "visible";
          }
        }
      }
    }
  }
}

function call_in_child_frames(the_frame,func_name,parm1,parm2) {
  if(the_frame) {
    // First check the function in this frame.
    var func = eval('the_frame.'+func_name);
    if(typeof(func) == "function")
      func(parm1,parm2);
    // Then visit all child frames.
    if(the_frame.frames) {
      for(var i=0; i<the_frame.frames.length; i++) {
        if (the_frame.frames[i] && the_frame.frames[i].loaded) {
          var func = eval('the_frame.frames[i].'+func_name);
          if(typeof(func) == "function")
            func(parm1,parm2);
        }
        if(the_frame.frames[i].frames)
          call_in_child_frames(the_frame.frames[i],func_name,parm1,parm2);
      }
    }
  }
}


function change_over() {
  var i;
  for (i=0; i<change_over.arguments.length; i++) {
    if ((ImageObject=FindObject(change_over.arguments[i]))!=null) {
      src = ImageObject.src;
      if (src.search(/_over.gif/) < 0) {
        src = src.replace(/.gif/g, "_over.gif");
        ImageObject.src = src;
      }
    }
  }
}

function change_out() {
  var i;
  for (i=0; i<change_out.arguments.length; i++) {
    if ((ImageObject=FindObject(change_out.arguments[i]))!=null) {
      src = ImageObject.src;
      if (src.search(/_over.gif/) >= 0) {
        src = src.replace(/_over.gif/g, ".gif");
        ImageObject.src = src;
      }
    }
  }
}

function preload_image() {
  if(document.images) {
    var i;
    for (i=0; i<preload_image.arguments.length; i++) {
      img = new Image();
      img.src = preload_image.arguments[i];
    }
  }
}

function preload_button() {
  if(document.images) {
    var i;
    for (i=0; i<preload_button.arguments.length; i++) {
      src = preload_button.arguments[i];
      src1 = src.replace(/.gif/g, "_over.gif");
      img = new Image();
      img.src = src1;
    }
  }
}

function calc_x(x_pos, x_align, rel_x, width) {
  var start_x;
  switch(x_align) {
    case 'r': // Right alignment
      start_x = get_client_width() - width + x_pos;
      break;
    case 'c': // Centre alignment
      start_x = get_client_width() - width + x_pos;
      start_x = start_x/2;
      break;
    case 'l': // Left alignment
      start_x = x_pos;
      break;
    case 'i': // Relative to given item pos
      start_x = rel_x + x_pos;
      break;
    case 'p': // Relative to mousepos
      start_x = mouseX + x_pos;
      break;
    default:
      start_x = 0;
      alert('invalid x-alignment specifiction: ' + x_align);
      break;
  }
  if(start_x > get_client_width() - width)    // Make sure it doesn't fall off the frame!
    start_x = get_client_width() - width;
  if(start_x < 1)
    start_x = 1;
  return(start_x);
}

function calc_y(y_pos, y_align, rel_y, height) {
  var start_y;
  switch(y_align) {
    case 'b': // Bottom alignment
      start_y = get_client_height() - height + y_pos;
      break;
    case 'm': // Middle alignment
      start_y = get_client_height() - height - y_pos;
      start_y = start_y/2;
      break;
    case 't': // Top alignment
      start_y = y_pos;
      break;
    case 'i': // Relative to given item pos
      start_y = rel_y + y_pos;
      if(start_y > get_client_height() - height)
        start_y = get_client_height() - height;
      break;
    case 'p': // Relative to mousepos (pointer)
      start_y = mouseY + y_pos;
      if(start_y > get_client_height() - height)
        start_y = get_client_height() - height;
      break;
    default:
      start_y = 0;
      alert('invalid y-alignment specifiction: '+y_align);
      break;
  }
//  if(start_y > get_client_height() - height)    // Make sure it doesn't fall off the frame!
//    start_y = get_client_height() - height;
//  if(start_y < 1)
//    start_y = 1;
  return(start_y);
}

// set_item(id, visible, align_x, align_y, x, y, scroll_fix)
function set_item() {
  // Set the defaults
  var visible = 1;
  var align_x = '';
  var align_y = '';
  var x = 0;
  var y = 0;
  var scroll_fix= 0;
  // Get the given parameters
  var argv = set_item.arguments;
  var id = argv[0];
  if(argv.length>1) visible = argv[1];
  if(argv.length>2) align_x = argv[2];
  if(argv.length>3) align_y = argv[3];
  if(argv.length>4) x = argv[4];
  if(argv.length>5) y = argv[5];
  if(argv.length>6) scroll_fix = argv[6];
  // set the position
  if(align_x != '') {
    var width=get_width(id);
    var cur_x = calc_x(x, align_x, 0, width);
    if(!scroll_fix || scroll_fix != "0")
      cur_x += get_scroll_x();
    set_x(id,cur_x);
  }
  if(align_y != '') {
    var height=get_height(id);
    var cur_y = calc_y(y, align_y, 0, height);
    if(!scroll_fix || scroll_fix != "0")
      cur_y += get_scroll_y();
    set_y(id,cur_y);
  }
  set_visible(id, visible);
  if(id==popupId) {
    popupVisible = visible;
    if(!visible)
      popupId = 0;
  }
}

function keep_popup() {
  if(popupVisible)
    window.clearTimeout(popupGraceTimer);
}

function hide_popup() {
  if(popupId) {
    window.clearTimeout(popupGraceTimer);
    var todo="set_item('"+popupId+"',0)";
    if(popupGraceTimeout)
      popupGraceTimer = window.setTimeout(todo, popupGraceTimeout);
    else
      eval(todo);
  }
}

// popup(id, visible, start_to, hide_to, grace_to, align_x, align_y, x, y, scroll_fix)
function popup() {
  // Set the defaults
  var visible = 1;
  var start_to = 500;
  var hide_to = 0;
  var grace_to = 500;
  var align_x = 'c';
  var align_y = 'm';
  var x = 0;
  var y = 0;
  var scroll_fix= 0;
  // Get the given parameters
  var argv = popup.arguments;
  var id = argv[0];
  if(argv.length>1) visible = argv[1];
  if(argv.length>2) start_to = argv[2];
  if(argv.length>3) hide_to = argv[3];
  if(argv.length>4) grace_to = argv[4];
  if(argv.length>5) align_x = argv[5];
  if(argv.length>6) align_y = argv[6];
  if(argv.length>7) x = argv[7];
  if(argv.length>8) y = argv[8];
  if(argv.length>9) scroll_fix = argv[9];
  // Create a function call
  var todo="set_item('"+id+"',"+visible+",'"+align_x+"','"+align_y+"',"+x+","+y+","+scroll_fix+");";
  if(visible) {
    set_onmouseover(id,keep_popup);
    set_onmouseout(id,hide_popup);
    if(popupId && popupVisible) {
      window.clearTimeout(popupGraceTimer);
//      set_visible(popupId,0);
//      PopupVisible=0;
    }
    popupId = id;
    popupGraceTimeout = grace_to;
    if(start_to)
      popupStartTimer = window.setTimeout(todo, start_to);
    else
      eval(todo);
    if(hide_to) {
      var todo="set_item('"+id+"',0)";
      popupGraceTimer = window.setTimeout(todo, hide_to + start_to);
    }
  }
  else {
    if(popupVisible) {
      var todo="set_item('"+id+"',0)";
      window.clearTimeout(popupGraceTimer);
      if(grace_to)
        popupGraceTimer = window.setTimeout(todo, grace_to);
      else
        eval(todo);
    }
    else
      window.clearTimeout(popupStartTimer);       // Prevent from displaying if not visible yet.
  }
}

// show a note
// show_note(text, start_to, hide_to, grace_to, align_x, align_y, x, y, width, height)
function show_note() {
  // Set the defaults
  var text = '';
  var start_to = 500;
  var hide_to = 0;
  var grace_to = 500;
  var align_x = 'p';
  var align_y = 'p';
  var x = -160;
  var y = -30;
  var width = 150;
  var height = 20;
  // Get the given parameters
  var argv = show_note.arguments;
  if(argv.length>0) text = argv[0];
  if(argv.length>1) start_to = argv[1];
  if(argv.length>2) hide_to = argv[2];
  if(argv.length>3) grace_to = argv[3];
  if(argv.length>4) align_x = argv[4];
  if(argv.length>5) align_y = argv[5];
  if(argv.length>6) x = argv[6];
  if(argv.length>7) y = argv[7];
  if(argv.length>8) width = argv[8];
  if(argv.length>9) height = argv[9];
  if(text != '')
  {
    poptext =  '';
//    poptext += '<table border=1 class=NoteStyle style="border-style:solid" cellspacing=0 cellpadding=3 height="100%" width="100%">';
//    poptext += '<table class=NoteStyle cellspacing=0 cellpadding=3 height="100%" width="100%">';
//    poptext += '<tr><td>';
    poptext += '<div class=NoteStyle>';
    poptext += text;
    poptext += '</div>';
//    poptext += '</td></tr>';
//    poptext += '</table>';
    set_text('note',poptext);
    set_width('note',width);
    set_height('note',height);
    popup('note',1, start_to, hide_to, grace_to, align_x, align_y, x, y);
  }
  else {
    popup('note',0);
  }
}

// OpenSatellite(Url,width,height,scrollbars,status,WindowName)
var SatelliteNames = new Array();
var SatelliteRefs  = new Array();

function OpenSatellite() {
  var argv = OpenSatellite.arguments;
  if(argv.length>0) SatUrl = argv[0]; else SatUrl='';
  if(argv.length>1) SatWidth = argv[1]; else SatWidth=400;
  if(argv.length>2) SatHeight = argv[2]; else SatHeight=400;
  if(argv.length>3) SatScrollbars = argv[3]; else SatScrollbars='no';
  if(argv.length>4) SatStatus = argv[4]; else SatStatus='no';
  if(argv.length>5) WindowName = argv[5]; // Optional WindowName to allow multiple satellites to be open...
  else WindowName = "DefaultSatellite";   // Default handle-/windowname...
  if(argv.length>6) WindowParms = argv[6]; // Optional additional window.open parameters...
  else WindowParms = "menubar=no";

  // Try to find already existing handle for this window...
  delete SatelliteWin;
  WindowExist = false;
  for (var FoundWin=0; FoundWin<SatelliteNames.length; FoundWin++) {
    if (SatelliteNames[FoundWin]==WindowName) {
      SatelliteWin = SatelliteRefs[FoundWin];
      WindowExist = true;
      break;
    }
  }

  if (typeof(SatelliteWin)=="undefined" || SatelliteWin.closed) {
    if (navigator.appName == 'Microsoft Internet Explorer') {
      SatWidth += 20;
      SatHeight += 20;
    }
    var SatLeft = (screen.width-SatWidth)/2;
    var SatTop = (screen.height-SatHeight)/2;
    var SatResizable = SatScrollbars;
    if(SatResizable == 'auto') SatResizable='yes';
    SatelliteWin = window.open(SatUrl,WindowName,"status="+SatStatus+",resizable="+SatResizable+",scrollbars="+SatScrollbars+","+WindowParms+",width="+SatWidth+",height="+SatHeight+",screenX="+SatLeft+",screenY="+SatTop+",left="+SatLeft+",top="+SatTop);
    if (SatelliteWin && SatelliteWin.opener==null) SatelliteWin.opener = self;

    // Store handle. Refresh reference if window was already opened this session (but closed)...
    if (WindowExist) {
      SatelliteRefs[FoundWin] = SatelliteWin;  // Refresh handle...
    } else {
      NextWin = SatelliteNames.length;
      SatelliteNames[NextWin] = WindowName;
      SatelliteRefs[NextWin]  = SatelliteWin; // New store...
    }
  } else {
    //cur_loc = SatelliteWin.location.pathname+SatelliteWin.location.search;
    //if (cur_loc!=SatUrl) SatelliteWin.location.href=SatUrl; // Refresh...
    SatelliteWin.location.href=SatUrl; // Refresh...
    SatelliteWin.focus();
  }
}

var popupw_wait_count;
var popupw_text;
function OpenPopupWindow(Text,width,height,scrollbars) {
  popupw_wait_count = 100;
  OpenSatellite('p-popup/',width,height,scrollbars);
  popupw_text = Text;
  UpdatePopupWindow();
}
function UpdatePopupWindow(Text) {
  if(!SatelliteWin.write_alert) { // Wait for the window to become active
    if(popupw_wait_count-- <= 0)
      alert('Kon het debug window niet openen');
    else
      setTimeout('UpdatePopupWindow()',100);
    return;
  }
  SatelliteWin.write_alert(popupw_text);
}

function safe() {
  var argv = safe.arguments;
  if(argv.length>0) name =    argv[0]; else name='';
  if(argv.length>1) domain =  argv[1]; else domain='';
  if(argv.length>2) subject = argv[2]; else subject='';
  if(argv.length>3) body =    argv[3]; else body='';
  loc = 'mailto:'+name+'@'+domain;
  if(subject != '' || body != '')
    loc += '?';
  if(subject != '')
    loc += subject;
  if(subject != '' && body != '')
    loc += '&';
  if(body != '')
    loc += body;
  window.location.href = loc;
}

//////////////////- Low level browser compatibility functions -//////////////////////

var mouseX;
var mouseY;
var keyCode;

// Capture mouse movements
window.onresize        = cms_do_onresize;
window.onload          = cms_do_onload;
window.onunload        = cms_do_onunload;
window.onbeforeunload  = cms_do_onbeforeunload;
if(document.all) {
  document.onmousemove = MouseMove;
  document.onkeydown   = KeyDown;
  document.onkeyup     = KeyUp;
}
else if(document.layers) {
  window.captureEvents(Event.MOUSEMOVE | Event.KEYDOWN | Event.KEYUP);
  window.onMouseMove = MouseMove;
  window.onKeyDown   = KeyDown;
  window.onKeyUp     = KeyUp;
}
else if(document.getElementById) {
  document.captureEvents(Event.MOUSEMOVE | Event.MOUSEOVER | Event.MOUSEOUT | Event.KEYDOWN | Event.KEYUP);
  document.onmousemove = MouseMove;
  document.onkeydown   = KeyDown;
  document.onkeyup     = KeyUp;
}

function MouseMove(e) {
  if(document.all) {
    mouseX = event.x;
    mouseY = event.y;
  }
  else if(document.layers) {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  else if(document.getElementById) {
    mouseX = e.pageX-get_scroll_x();
    mouseY = e.pageY-get_scroll_y();
  }
  cms_do_onmousemove(mouseX,mouseY);
}

function KeyDown(e) {
  if(document.all)
    keyCode = event.keyCode;
  else if(document.layers)
    keyCode = e.which;
  else if(document.getElementById)
    keyCode = e.which;
  cms_do_onkeydown(keyCode);
}

function KeyUp(e) {
  if(document.all)
    keyCode = event.keyCode;
  else if(document.layers)
    keyCode = e.which;
  else if(document.getElementById)
    keyCode = e.which;
  cms_do_onkeyup(keyCode);
}

function get_mouse_x() {
  return(mouseX);
}

function get_mouse_y() {
  return(mouseY);
}

function get_last_key() {
  return(keyCode);
}

function get_scroll_x() {
  if(document.layers || document.getElementById)
    scroll_x = window.pageXOffset;
  if(document.all && document.body)
    scroll_x = document.body.scrollLeft;

  if (!isNaN(scroll_x))
    return(scroll_x);
  else
    return(0);
}

function get_scroll_y() {
  if(document.layers || document.getElementById)
    scroll_y = window.pageYOffset;
  if(document.all && document.body)
    scroll_y = document.body.scrollTop;

  if (!isNaN(scroll_y))
    return(scroll_y);
  else
    return(0);
}

function get_client_width(){
  if(window.innerWidth)
    return(window.innerWidth);
  if(document.body && document.body.clientWidth)
    return(document.body.clientWidth);
  if(document.body && document.body.scrollWidth)
    return(document.body.scrollWidth);
  return(0);
}

function get_client_height(){
  if(window.innerHeight) {
    if(document.layers)
      return(window.innerHeight+3); // NS4
    else
      return(window.innerHeight);
  }
  if(document.documentElement && document.documentElement.clientHeight)
    return (document.documentElement.clientHeight); // IE6
  if(document.body.clientHeight)
    return(document.body.clientHeight);  // IE5+
  if(document.body.scrollHeight)
    return(document.body.scrollHeight);  // IE5 Mac
}

// Return a stylesheet rule with the mentioned name
function get_rule(name) {
  // W3C
  if(document.getElementById && document.styleSheets && document.styleSheets[0].cssRules) {
    for ( sheet = 0; sheet < document.styleSheets.length; sheet++ )
      for(rule=0; rule<document.styleSheets[sheet].cssRules.length; rule++)
        if(document.styleSheets[sheet].cssRules[rule].selectorText == name)
          return(document.styleSheets[sheet].cssRules[rule]);
  }
  // IE 
  else if(document.all && document.styleSheets) {
    for ( sheet = 0; sheet < document.styleSheets.length; sheet++ )
      for(rule=0; rule<document.styleSheets(sheet).rules.length; rule++)
        if(document.styleSheets(sheet).rules(rule).selectorText == name)
          return(document.styleSheets(sheet).rules(rule));
  }
  return(0);
}

function get_style_class(s) {
  var theclass = null;
  if(document.layers)
    theclass = eval('document.classes.' + s + '.all');
  else{
    myclass = get_rule('.' + s);
    if(!myclass)
      myclass = get_rule(s);
    if(!myclass)
      myclass = get_rule('*.' + s);
    if(myclass)
      return(myclass.style);
  }
  return(theclass);
}

function get_x(i) {
  if (document.getElementById && document.getElementById(i))
    return(document.getElementById(i).style.left);
  if (document.all && document.all[i]) {
    if(document.all[i].pixelLeft) return(document.all[i].pixelLeft);
    return(document.all[i].style.pixelLeft);
  }
  if (document.layers && document.layers[i])
    return(document.layers[i].left);
}

function get_y(i) {
  if (document.getElementById && document.getElementById(i))
    return(document.getElementById(i).style.top);
  if (document.all && document.all[i]) {
    if(document.all[i].pixelTop) return(document.all[i].pixelTop);
    return(document.all[i].style.pixelTop);
  }
  if (document.layers && document.layers[i])
    return(document.layers[i].top);
 }

function get_z(i) {
  if (document.getElementById && document.getElementById(i))
    return(document.getElementById(i).style.zIndex);
  if (document.all && document.all[i]) {
    if(document.all[i].zIndex) return(document.all[i].zIndex);
    return(document.all[i].style.zIndex);
  }
  if (document.layers && document.layers[i])
    return(document.layers[i].zIndex);
}

function get_width(i) {
  if(document.getElementById && document.getElementById(i))
    return(document.getElementById(i).offsetWidth);
  if (document.all && document.all[i]) {
    if(document.all[i].pixelWidth) return(document.all[i].pixelWidth);
    if(document.all[i].style.pixelWidth) return(document.all[i].style.pixelWidth);
  }
  if(document.layers)
    return(document.layers[i].clip.width);
}

function get_height(i) {
  if(document.getElementById && document.getElementById(i))
    return(document.getElementById(i).offsetHeight);
  if (document.all && document.all[i]) {
    if(document.all[i].pixelHeight) return(document.all[i].pixelHeight);
    if(document.all[i].style.pixelHeight) return(document.all[i].style.pixelHeight);
  }
  if(document.layers)
    return(document.layers[i].clip.height);
}

// get the source of an image
function get_img_src(i,src) {
  if ((ImageObject=FindObject(i))!=null) {
    return(ImageObject.src);
  }
  return('');
}

function get_style_property(i, p) {
  var obj = FindObject(i);
  return (get_obj_style_property(obj,p));
}

function get_obj_style_property(e,p) {
  if (e.currentStyle)
    return eval('e.currentStyle.' + p);
  else if (window.getComputedStyle)
    return window.getComputedStyle(e,null).getPropertyValue(p);
  return null;
}

// Get the display mode. Valid values: "none" (hidden) "block" and "inline"
// Return null if error occurs
function get_disp(i,mode) {
    if (document.getElementById && document.getElementById(i))
        return(document.getElementById(i).style.display);
    if (document.layers && document.layers[i])
        return(document.layers[i].display);
    if (document.all && document.all[i])
        return(document.all[i].style.display);
    return(null);
}

function set_position_abs(i,a) {
  if (document.getElementById)
    document.getElementById(i).style.position = a? "absolute" : "relative";
  if (document.all && document.all[i])
    document.all[i].style.position = a? "absolute" : "relative";
  if (document.layers && document.layers[i])
    document.layers[i].position = a? "absolute" : "relative";
}

function set_visible(i,v) {
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).style.visibility = v? "visible" : "hidden";
  if (document.all && document.all[i])
    document.all[i].style.visibility = v? "visible" : "hidden";
  if (document.layers && document.layers[i])
    document.layers[i].visibility = v? "show" : "hide";
}

function set_opacity(i,o) {
  if(document.getElementById) {
    if(o == 0 || o == 100)
      o = "";
    if(document.getElementById(i).style.MozOpacity != o+"%")
      document.getElementById(i).style.MozOpacity=o+"%";
    if(document.getElementById(i).style.opacity != o+"%")
      document.getElementById(i).style.opacity=o+"%";
  }
  if(document.all) {
    id = document.all[i];
    if(id.filters) {
      if (id.style.filter.indexOf("alpha")==-1)
        id.style.filter+=" alpha(opacity="+o+")";
      else
        if (id.filters.length&&id.filters.alpha)
          with(id.filters.alpha) {
            if(o == 0 || o == 100)
              enabled=false;
            else {
              opacity=o;
              enabled=true
            }
          }
    }
  }
}

function set_x(i,x) {
  if (!i || isNaN(x)) return;
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).style.left=x + "px";
  else if (document.all && document.all[i])
    document.all[i].style.pixelLeft=x;
  else if (document.layers && document.layers[i])
    document.layers[i].left=x;
}

function set_y(i,y) {
  if (!i || isNaN(y)) return;
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).style.top=y + "px";
  else if (document.all && document.all[i])
    document.all[i].style.pixelTop=y;
  else if (document.layers && document.layers[i])
    document.layers[i].top=y;
 }

function set_z(i,z) {
  if (!i || isNaN(z)) return;
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).style.zIndex = z;
  else if (document.all && document.all[i])
    document.all[i].style.zIndex=z;
  else if (document.layers && document.layers[i])
    document.layers[i].zIndex=z;
}

function set_width(i,w) {
  if (!i || isNaN(w)) return;
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).style.width=w + "px";
  else if (document.all && document.all[i])
    document.all[i].style.pixelWidth=w;
  else if (document.layers && document.layers[i])
    document.layers[i].width=w;
}

function set_height(i,h) {
  // Some validation
  if (h<0 || !i || isNaN(h)) return;
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).style.height=h + "px";
  else if (document.all && document.all[i])
    document.all[i].style.pixelHeight=h;
  else if (document.layers && document.layers[i])
    document.layers[i].height=h;
}

function set_text(i,text) {
  if(document.getElementById && document.getElementById(i))
    document.getElementById(i).innerHTML = text;
  if(document.all) {
    text += "\n";
    eval(i+".innerHTML = text;");
  }
  if(document.layers && document.layers[i]) {
    document.layers[i].document.write(text);
    document.layers[i].document.close();
  }
}

// Set the display mode. Valid values: "none" (hidden) "block" and "inline"
function set_disp(i,mode) {
    if (document.getElementById && document.getElementById(i))
        document.getElementById(i).style.display = mode;
    if (document.layers && document.layers[i])
        document.layers[i].display = mode;
    if (document.all && document.all[i] && document.all[i].style)
        document.all[i].style.display = mode;
}

// Change the source of an image
function set_img_src(i,src) {
  if ((ImageObject=FindObject(i))!=null) {
    ImageObject.src = src;
  }
}

// Set the indicated id to the indicated class
function set_class(i,class_name) {
  obj = FindObject(i);
  if (document.getElementById && obj)
    obj.className = class_name;
  else if (document.all && obj)
    obj.className = class_name;
  else if(document.layers && obj) {
    cur_class = eval('document.classes.' + class_name + '.all');
    color = cur_class.backgroundColor;
    if(color)
      obj.bgColor=color;
    image = cur_class.backgroundImage;
    // Strip the url( part, allowed in css but not in javascript.
    if(image)
      image=image.replace(/url\(/gi,"");
    if(image)
      image=image.replace(/\)/gi,"");
    if(image) {
      obj.background.src=image;
    }
  }
}

function set_onmouseover(i,func) {
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).onmouseover=func;
  else if (document.all && document.all[i])
    document.all[i].onmouseover=func;
  else if (document.layers && document.layers[i])
    document.layers[i].onmouseover=func;
}

function set_onmouseout(i,func) {
  if (document.getElementById && document.getElementById(i))
    document.getElementById(i).onmouseout=func;
  else if (document.all && document.all[i])
    document.all[i].onmouseout=func;
  else if (document.layers && document.layers[i])
    document.layers[i].onmouseout=func;
}

// Fit the entire window around the content (useful for satellites)
function fit_window() {
  var width=0;
  height=0;
  if(document.body && document.body.offsetHeight)
    height = document.body.offsetHeight;
  if(document.body && document.body.scrollHeight && document.body.scrollHeight > height)
    height = document.body.scrollHeight;
  if(document.body && document.body.offsetWidth)
    width = document.body.offsetWidth;
  if(document.body && document.body.scrollWidth && document.body.scrollWidth > width)
    width = document.body.scrollWidth;
  if(width && height) {
    width += 10;    // Some room
    height += 10;   // Some room
    // First try, but resizeTo may set the outer width.
    if(width>screen.width-20) width=screen.width-50;
    if(height>screen.height-20) height=screen.height-50;
    if(window && window.resizeTo)
      window.resizeTo(width, height);
    // Check if the window has the required size (innerwidth)
    var diff_w = width - get_client_width();
    var diff_h = height  - get_client_height();
    // If not: retry!
    if(diff_w > 0 | diff_h > 0) {
      width += diff_w;
      height += diff_h;
      if(width>screen.width-20) width=screen.width-50;
      if(height>screen.height-20) height=screen.height-50;
      if(window && window.resizeTo)
        window.resizeTo(width, height);
    }
  }
}

// Size an iframe to the window.
// Mode : 0=new source load in iframe, 1=resize of window 3=onload of window
function size_iframe(id, extra, mode) {
  var iframeClass = get_style_class(id+'_frame');
  if(document.getElementById && iframeClass) {
    var left = iframeClass.left;
    var right = iframeClass.right;
    var top = iframeClass.top;
    var bottom = iframeClass.bottom;
    var width = iframeClass.width;
    var height = iframeClass.height;
    var the_iframe = document.getElementById(id);

    if(width=='') {
      if(left!='' && right!='') {
        var screenwidth = get_client_width();
        var new_width = parseInt(screenwidth)-parseInt(left)-parseInt(right);
        // EMO 2007-11-10 : bug seems vanished, outcommented code below
        // if(document.all) // IE has in strict mode a bug, where it renders 20 pixels (a scrollbar) too small
        //   new_width += 20;
        set_width(id,new_width);
      }
    }
    if(height=='') {
      if(top!='' && bottom!='') {
        // It seems that the iframe must be fit within the outer window
        var screenheight = get_client_height();
        set_height(id,parseInt(screenheight)-parseInt(top)-parseInt(bottom));
      }
      else {
        // It seems that the iframe must be fit around the inner document
        if(the_iframe) {
          if(the_iframe.Document && the_iframe.Document.body && the_iframe.Document.body.scrollHeight)
            var height = the_iframe.Document.body.scrollHeight;
          else if(the_iframe.contentDocument && the_iframe.contentDocument.body && the_iframe.contentDocument.body.scrollHeight)
            var height = the_iframe.contentDocument.body.scrollHeight;
          else if(the_iframe.Document && the_iframe.Document.body && the_iframe.Document.body.offsetHeight)
            var height = the_iframe.Document.body.offsetHeight;
          else if(the_iframe.contentDocument && the_iframe.contentDocument.body && the_iframe.contentDocument.body.offsetHeight)
            var height = the_iframe.contentDocument.body.offsetHeight;
          if(mode > 0 || !extra)
            extra=0;
          set_height(id,height+extra);
          // Make sure the iframe is shown at the top
          if(mode!=1 && window.scrollTo)
            window.scrollTo(0,0);
        }
      }
    }
  }
}

var saved_divs = new Array();
/* Copy the contents of a (hidden) iframe to a div. Parameters:
*
* iframe_id (string) : The id of the source iframe
* div_id (string)    : The id of the destination div
* mode               : 0=No resize processing, 1=recalc height, add scrollbars if necessary, 2=don't recalc height, add scrollbars if necessary
* rescope_links      : if true: Make links absolute and target them to the iframe by default (as the code is effected in another frame)
*
*/
function copy_iframe(iframe_id, div_id, mode, rescope_links) {
  var the_iframe = document.getElementById(iframe_id);
  var the_div = document.getElementById(div_id);
  if(the_iframe && the_div) {
    if(mode && the_div.scrollHeight) {
      // Make sure we have a valid height! (if mode = 1!)
      if (mode == 1)
        the_div.style.height = the_div.scrollHeight+'px';
      // make it scrolling
      the_div.style.overflow = 'auto';
    }
    // W3C compatible method
    if(the_iframe.contentDocument && the_iframe.contentDocument) {
      innerDocument= the_iframe.contentDocument.body;
    }
    // IE compatible method
    else if (window.frames[iframe_id] && window.frames[iframe_id].document && window.frames[iframe_id].document.body) {
      innerDocument= window.frames[iframe_id].document.body;
    }
    if(rescope_links)
      rescope_content_links(innerDocument, iframe_id);
    if(innerDocument && innerDocument.innerHTML)
      the_div.innerHTML = innerDocument.innerHTML;
    else // Called the first time, save the div content
      saved_divs[div_id] = the_div.innerHTML;
    // Give IE7 a kick, or how else to apply transparency to new elements?
    if(window.IE7 && window.IE7.refresh_pngs) window.IE7.refresh_pngs(the_div);
  }
}

function rescope_content_links(innerDocument, iframe_id) {
  links = innerDocument.getElementsByTagName('a');
  for(i=0; i<links.length; i++) {
    link = links[i];
    if(link.target == '')
      link.target = iframe_id;
    link.href = link.href.toString(); // Make the links absolute, as they may end up in another frame!
  }
}

function restore_div(div_id) {
  if(saved_divs && saved_divs[div_id]) {
    var the_div = document.getElementById(div_id);
    if(the_div)
      the_div.innerHTML = saved_divs[div_id];
  }
}

function FindObject(n,d) { // Based on MM_findObj v4.0
  var p,i,x;
  if(document.getElementById && document.getElementById(n))
    return document.getElementById(n);
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=FindObject(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n);
  return x;
}

var loadedFiles = new Array();
function load_script(scriptname) {
  var i;
  var urlpath = '/p-httpd/_cms/js/';
  for (i=0; i<loadedFiles.length; i++) {
    if (loadedFiles[i] == scriptname)
      return;
  }
  document.write('<sc'+'ript type="text/javascript" src="' + urlpath + scriptname + '"></script>');
  loadedFiles[loadedFiles.length] = scriptname;
}

function get_navloc_str(args) {
  // Returns formatted string to show where a user has navigated, may be used as a clickable navigation path or 'breadcrumbs'...
  //
  // Optional input vars: sel, item_seperator, item_prefix, item_postfix
  // Define the seperator in the system table as 'navpath_separator', default = ' | '
  var prefix  = arguments[0]; // Optional prefix before every item in the chain...
  var postfix = arguments[1]; // Optional postfix after every item in the chain...

  if (!prefix)  prefix='';
  if (!postfix) postfix='';
  return (prefix+top.navpath+postfix);
}

// JavaScript function to return current time for 'now'-buttons in forms with datetime-fields...
function get_now_datetime() {
  var currentTime = new Date();
  var Month    = currentTime.getMonth() + 1;
  var DateTime = currentTime.getDate()+"-"+Month+"-"+currentTime.getFullYear()+" "+currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds();
  return(DateTime);
}

// ------------------------ From here on: V2.3 menu support ----------------------------- //

// Functions for adding information to site.php
function add_to_site_header(framename, query, maint) {
  if(menu_supported()) {
    add_onload(function() {size_iframe(framename,16,2);set_visible(framename,1);document.getElementById(framename).src=query;});
    add_onresize(function() {size_iframe(framename,16,1);});
    document.writeln('<style type=\"text/css\">.menu {display:none;}</style>');
  }
}

// Functions for adding information to site.php
function add_to_site_body(framename, maint) {
  if (menu_supported()) {
    if (maint)
      document.writeln('<iframe id="'+framename+'" name="'+framename+'" class="'+framename+'_frame" frameborder="0" allowtransparency="true" onload="size_iframe(\''+framename+'\',16,0);" src="/p-transparent/beheer">');
    else
      document.writeln('<iframe id="'+framename+'" name="'+framename+'" class="'+framename+'_frame" frameborder="0" allowtransparency="true" onload="size_iframe(\''+framename+'\',16,0);" src="/p-transparent/">');
  }
}

// Test if the browser is supported.
function menu_supported() {
  supported = 0;
  if(document.getElementById) {
    supported = 1;
    var tempStr = navigator.userAgent.toLowerCase();
    // IE on Mac is not supported
    if ((tempStr.indexOf("msi")!=-1) && (tempStr.indexOf("mac")!=-1))
      supported = 0;
    // Small screens not supported (??)
    // if(screen.width && screen.width < 800)
    //   supported = 0;
  }
  top.browser_supported = supported;
  return(supported);
}

// ------------------------ From here on: Tabs support ----------------------------- //

// Public functions

function add_tabset(tabset_id, callback) {
  if(cur_tabset_idx >= 0)
    myparent_idx = cur_tabset_idx;
  else
    myparent_idx = -1;
  cur_tabset_idx = tabsets.length;
  tabsets[cur_tabset_idx] = new tabset(cur_tabset_idx,tabset_id, callback, myparent_idx);
}

function end_tabset() {
  if(cur_tabset_idx >= 0)
    cur_tabset_idx = tabsets[cur_tabset_idx].parent_idx;
  else
    cur_tabset_idx = -1;
}

function add_tab(sheet_id, tab_text, tab_icon,tab_class, selected) {
  if(cur_tabset_idx >= 0)
    tabsets[cur_tabset_idx].add_tab(sheet_id, tab_text, tab_icon,tab_class, selected); 
}

function add_disabled_tab(sheet_id, tab_text, tab_icon,tab_class) {
  if(cur_tabset_idx >= 0)
    tabsets[cur_tabset_idx].add_disabled_tab(sheet_id, tab_text, tab_icon,tab_class); 
}

function create_tabs(cur_sel) {
  cur_idxs = cur_sel.split(',');
  for(var i=0; i<tabsets.length; i++) {
    if(cur_idxs.length >= i) {
      cur_idx = cur_idxs[i];
      tabsets[i].create_tabs(cur_idx);
    }
    else
      tabsets[i].create_tabs(0);
  }
}

function activate_parent_tab(object) {
  var search = object;
  while(search) {
    if(search.style && search.style.display && search.style.display=='none')
      select_tabs_by_sheet_obj(search);
    search=search.parentNode
  }
}

function select_tabs_by_sheet_obj(object) {
  for(var i=0; i<tabsets.length; i++)
    tabsets[i].select_tab_by_sheet_obj(object);
}

// Private functions

var cur_tabset_idx=-1;
var tabsets = new Array();

function tabset(idx, tabset_id, callback, parent_idx) {
  this.idx         = idx;           // index in total table of tabs
  this.tabset_id   = tabset_id;     // The id of this tabset
  this.callback    = callback;      // Callback function for on_tab_load and on_tab_unload events.
  this.parent_idx  = parent_idx;    // The parent of this tabset.
  this.cur_tab_idx = -1;            // Index of the currently created tab within this tabset
  this.sel_tab_idx = -1;            // Index of the currently created tab within this tabset
  this.pre_select_found = 0;        // Flag indicates if there is a pre selection
  return(this)
}

tabset.prototype.add_tab = function (sheet_id, tab_text, tab_icon, tab_class, selected) {
  if(typeof(this.tabs) == 'undefined')
    this.tabs = new Array();
  this.cur_tab_idx++;
  this.tabs[this.cur_tab_idx] = new tab(this, "tab_"+this.idx+'_'+this.cur_tab_idx, sheet_id, tab_text, tab_icon, tab_class, selected);
  if(selected)
    this.pre_select_found = 1;
};

tabset.prototype.add_disabled_tab = function (sheet_id, tab_text, tab_icon, tab_class) {
  if(typeof(this.tabs) == 'undefined')
    this.tabs = new Array();
  this.cur_tab_idx++;
  this.tabs[this.cur_tab_idx] = new tab(this, "tab_"+this.idx+'_'+this.cur_tab_idx, 0, tab_text, tab_icon, tab_class, 0);
  this.tabs[this.cur_tab_idx].disable();
};

tabset.prototype.create_tabs = function (cur_idx) {
  var text = '';
  var j;
  var selected_idx;
  var first_idx=-1;
  if(typeof(this.tabs) != 'undefined') {
    for(j=0; j<this.tabs.length; j++) {
      text += '<a';
      if(!this.tabs[j].tab_disabled)
        text += ' href="javascript:tabsets['+this.idx+'].select_tab('+j+');"';
      text += ' class="'+this.tabs[j].get_class()+'"';
      text += ' id="'+this.tabs[j].get_id()+'"';
      text += ' onFocus="this.blur()"';
      text += ' ><span class="tab_start"><span class="tab_end">';
      text += this.tabs[j].get_tab_html();
      text += '</span></span></a>';
      if(this.pre_select_found && this.tabs[j].tab_selected)
        selected_idx = j;
      if(first_idx < 0 && !this.tabs[j].tab_disabled)
        first_idx = j;
    }
    set_text(this.tabset_id,text);
    // EMO 20091019: Test for tab_disabled added: prevent disabled tabs from coming selected!
    if(cur_idx && !this.tabs[cur_idx].tab_disabled)
      this.init_tab(cur_idx);
    else if(this.pre_select_found && !this.tabs[selected_idx].tab_disabled)
      this.init_tab(selected_idx);
    else
      this.init_tab(first_idx);
  }
}

tabset.prototype.init_tab = function (sel_idx) {
  this.sel_tab_idx = sel_idx;
  this.store_selected_tabs();
  for(var j=0; j<this.tabs.length; j++) {
    if(sel_idx!=j)
      this.tabs[j].init_deselect();
  }
  for(var j=0; j<this.tabs.length; j++) {
    if(sel_idx==j)
      this.tabs[j].init_select();
  }
}

tabset.prototype.select_tab = function (idx) {
  this.sel_tab_idx = idx;
  this.store_selected_tabs();
  for(var j=0; j<this.tabs.length; j++) {
    if(idx!=j)
      this.tabs[j].deselect();
  }
  for(var j=0; j<this.tabs.length; j++) {
    if(idx==j)
      this.tabs[j].select();
  }
}

tabset.prototype.select_tab_by_sheet_obj = function (object) {
  for(var j=0; j<this.tabs.length; j++) {
    if(document.getElementById(this.tabs[j].sheet_id) == object) {
      // tab matched!
      var idx = j;
    }
  }
  this.sel_tab_idx = idx;
  this.store_selected_tabs();
  for(var j=0; j<this.tabs.length; j++) {
    if(idx!=j)
      this.tabs[j].deselect();
  }
  for(var j=0; j<this.tabs.length; j++) {
    if(idx==j)
      this.tabs[j].select();
  }
}

tabset.prototype.store_selected_tabs = function () {
  var i;
  var idx = '';
  if(document.theForm && document.theForm._current_tab) {
    for(i=0; i<tabsets.length; i++) {
      if(i>0)
        idx += ',';
      idx += tabsets[i].sel_tab_idx;
    }
    document.theForm._current_tab.value = idx;
  }
}

function tab(parent, tab_id, sheet_id, tab_text, tab_icon, tab_class, selected) {
  this.parent             = parent;        // Parent tabset!
  this.tab_id             = tab_id;        // object id of this tab
  this.sheet_id           = sheet_id;      // object id of the tab sheet (active div when this tab is selected)
  this.tab_text           = tab_text;
  this.tab_icon           = tab_icon;
  this.tab_class          = tab_class;
  this.tab_class_sel      = tab_class + "_sel";
  this.tab_class_disabled = tab_class + "_disabled";
  this.tab_selected       = selected;
  this.tab_disabled       = 0;
  return(this);
}

tab.prototype.get_id= function () {
  return(this.tab_id);
}

tab.prototype.get_class = function () {
  if(this.tab_disabled)
    return(this.tab_class_disabled);
  else
    return(this.tab_class);
}

tab.prototype.get_tab_html = function () {
  var text = '';
  if(this.tab_icon != '')
    text += '<img style="border:0px;" src="'+this.tab_icon+'" alt="icon" />';
  text += this.tab_text;
  return(text);
}

tab.prototype.disable= function () {
  this.tab_disabled = 1;
}

tab.prototype.enable= function () {
  this.tab_disabled = 0;
}

tab.prototype.init_select = function () {
  if(!this.tab_disabled) {
    set_disp(this.sheet_id,"block");
    set_class(this.tab_id,this.tab_class_sel);
    this.tab_selected = 1;
  }
}

tab.prototype.init_deselect = function () {
  if(!this.tab_disabled) {
    set_disp(this.sheet_id,"none");
    set_class(this.tab_id,this.tab_class);
    this.tab_selected = 0;
  }
}

tab.prototype.select = function () {
  if(!this.tab_disabled) {
    set_disp(this.sheet_id,"block");
    set_class(this.tab_id,this.tab_class_sel);
    if(!this.tab_selected) { // Call callback function if available
      if(this.parent.callback) {
        var cmd = 'if( typeof(' + this.parent.callback + ') == \'function\') ' + this.parent.callback + '(1, this.tab_text, this.tab_id, this.sheet_id);';
        eval(cmd);
      }
    }
    this.tab_selected = 1;
  }
}

tab.prototype.deselect = function () {
  if(!this.tab_disabled) {
    set_disp(this.sheet_id,"none");
    set_class(this.tab_id,this.tab_class);
    if(this.tab_selected) { // Call callback function if available
      if(this.parent.callback) {
        var cmd = 'if( typeof(' + this.parent.callback + ') == \'function\') ' + this.parent.callback + '(0, this.tab_text, this.tab_id, this.sheet_id);';
        eval(cmd);
      }
    }
    this.tab_selected = 0;
  }
}

// Cookie support
function setCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function eraseCookie(name) {
  createCookie(name,"",-1);
}

