// referonline.js, part of Refer-Online - Copyright (C) 2005 Refer-Online
// code utilizes X library, a Cross-Browser.com Javascript Library Copyright (C) 2001,2002,2003,2004,2005 Michael Foster - Distributed under the terms of the GNU LGPL - OSI Certified
function rs_showBox(ID) {
  return rs_visibility(ID, 1);
}

function rs_hideBox(ID) {
  return rs_visibility(ID, 0);
}

function rs_visibility(ID, bShow) {
  if(!(e=xGetElementById(ID))) return null;
  if(e.style && xDef(e.style.display)) {
    if (xDef(bShow)) e.style.display = bShow ? 'block' : 'none';
    return e.style.visibility;
  }
  return null;
}

function rs_toggle(ID) {

  if(!(e=xGetElementById(ID))) return null;
  if (e.style.display == 'none') {
    e.style.display = 'block';
  }
  else if (e.style.display == 'block' || !(xDef(e.style.display))) {

    e.style.display = 'none';
  }
}

function rs_setClassName(ID, NAME) {
  if(!(e=xGetElementById(ID))) return null;
  if (xDef(NAME)) {
    e.className = NAME;
  }
}

function rs_addLoadEvent(eventListener) {
	var oldonload = window.onload;

	if (typeof window.onload != 'function') {
		window.onload = eventListener;
	}
	else {
		window.onload = function() {
      oldonload();
      eventListener();
		}
	}
}

// Frontpage Flag toggle buttons
rs_addLoadEvent(function() {
  if(!(fHide=xGetElementById('hide_flags'))) return null;
  if(!(fShow=xGetElementById('show_all'))) return null;

  fHide.onclick = function () {
    rs_showBox('members-with-photos');
    rs_hideBox('members-with-or-without-photos');
    fShow.style.display = 'block';
    fHide.style.display = 'none';
  }

  fShow.onclick = function () {
    rs_showBox('members-with-or-without-photos');
    rs_hideBox('members-with-photos');
    fHide.style.display = 'block';
    fShow.style.display = 'none';
  }
});

var popupW
var popupH
var xOffset  = 0
var yOffset  = 15
var follow   = 1
var maxWidth = 200
var px       = "px"
var follow   = 1
  var scrollX   = 0;
  var scrollY   = 0;
var x,y,winW,winH

rs_addLoadEvent(function() {
  x,y  = 0;
  winW = 800;
  winH = 600;
  tip  = null;

  if (follow)     {xAddEventListener(document, 'mousemove', rs_followTip, false);}
  if (xNN4||xKon) {setTimeout("window.onrezise = rebrowse", 2000);}
  if (xNN4)       {px = "";}
});

function rs_followTip(EVT) {
  rs_moveTip(EVT);
}

function rs_showTip(EVT, ID) {
  if(!(tip=xGetElementById(ID))) return null;

  winW      = xClientWidth();
  winH      = xClientHeight();
  scrollY   = xScrollTop();
  scrollX   = xScrollLeft();
  topW      = xOffsetLeft();
  topH      = xOffsetTop();

  rs_moveTip(EVT);
}

function rs_hideTip(ID) {
  xHide(ID);
  tip=null;
}

function rs_moveTip(EVT) {
  var e = EVT ? EVT : window.event;

  if (e) {
    x = e.pageX ? e.pageX : e.clientX ? e.clientX + scrollX : 0;
    y = e.pageY ? e.pageY : e.clientY ? e.clientY + scrollY : 0;
  }
  else {
    x = 0; y = 0;
  }

  if (popupW > maxWidth) {
    popupW = maxWidth;
    xWidth(tip, maxWidth);
  }

  var vleft = (((x + popupW + xOffset) > winW) ? x - popupW - xOffset : x + xOffset);
  xLeft(tip, vleft);

  if ((popupH + yOffset) > winH) {
    xTop(tip, yOffset);
  }
  else {
    var vtop = (((y + popupH + yOffset) > winH) ? winH - popupH - yOffset: y + yOffset);
    xTop(tip, vtop);
  }

  xShow(tip);
}

if (xOp7) {
  document.write('<link rel="stylesheet" type="text/css" href="http://localhost/refer-online/css/base/opera.css" />');
}

function showTab(id, c) {
  for (i=0;i<document.getElementsByTagName("div").length; i++) {
    if (document.getElementsByTagName("div").item(i).className == c){
      document.getElementsByTagName("div").item(i).style.display = "none";
    }
  }
  for (i=0;i<document.getElementsByTagName("li").length; i++) {
    if (document.getElementsByTagName("li").item(i).className == "tab-on") {
      document.getElementsByTagName("li").item(i).className = "tab";
    }
  }

  document.getElementById(id).style.display = "block";
  document.getElementById(id+"-tab").className = "tab-on";
}
