/*
Javascript for Runescape Clan Statistics
All code is custom, please give credit if you use any of this code.
Created by NESGamepro 2007-2009 - http://nescgi.com
*/

// dynamic menus
function sidebars(div,side) {
  if (arguments.length > 2) { var tmp=[]; for (var i = 1; i < arguments.length; i++) { tmp.push(arguments[i]); } side=tmp; }
  for (var i = 0; i < side.length; i++) {
    if (document.getElementById(side[i])) { document.getElementById(side[i]).style.display = 'none'; }
  }
  if (document.getElementById(div)) { document.getElementById(div).style.display = 'block'; }
}

function announces(div) {
  for (var i = 0; i < 5; i++) {
    if (document.getElementById('announce'+i)) { document.getElementById('announce'+i).style.display = 'none'; }
  }
  if (document.getElementById(div)) { document.getElementById(div).style.display = 'block'; }
}

function toggle() {
  for (var i = 0; i < arguments.length; i++) {
    if (document.getElementById(arguments[i])) {
      if (document.getElementById(arguments[i]).style.display == 'none') { document.getElementById(arguments[i]).style.display = 'block'; }
      else { document.getElementById(arguments[i]).style.display = 'none'; }
    }
  }
}


// popup windows
function AuxWin(u,n,h,w,o) {
  w=w+10; h=h+32; if (o != "") { o = o+','; }
  PWin = window.open(u, n, o+'resizable,width='+w+',height='+h);
  PWin.moveTo(((screen.width / 2) -  (w / 2)), ((screen.height / 2) - (h / 2)));
  PWin.focus();
}


// countdown
function cd() {
 if (sec == 0) {
   if (min > 0) { min-=1; sec=60; }
   else if (hr > 0) { hr-=1; min=59; sec=60; }
 }

 if (hr > 0 || min > 0 || sec > 0) {
   sec-=1;
   if (hr<=9){ face="0"+hr+":"; } else { face=hr+":"; }
   if (min<=9){ face=face+"0"+min+":"; } else { face=face+min+":"; }
   if (sec<=9){ face=face+"0"+sec; } else { face=face+sec; }
   if (document.getElementById('data_countdown_clock')) { document.getElementById('data_countdown_clock').innerHTML = face; }
   setTimeout("cd()",1000);
 }
}

// logout
function logout(sid) {
  if (confirm('Are you sure you want to log out of Clan Stats?')) { document.location = '/forums/ucp.php?mode=logout&sid='+sid; }
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08    http://xkr.us/code/javascript/XHConn/    **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn() {
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone) {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET") {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && !bComplete) { bComplete = true; fnDone(xmlhttp); }
      };
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
thetext = thetext.replace(/&/g, "&amp;")
thetext = thetext.replace(/"/g, "&quot;")
thetext = thetext.replace(/</g, "&lt;")
thetext = thetext.replace(/>/g, "&gt;")
thetext = thetext.replace(/\[br\]/gi, "<br>")
thetext = thetext.replace(/\[p\]/gi, "<p>")
thetext = thetext.replace(/\[b\]/gi, "<b>")
thetext = thetext.replace(/\[\/b\]/gi, "</b>")
thetext = thetext.replace(/\[i\]/gi, "<i>")
thetext = thetext.replace(/\[\/i\]/gi, "</i>")
thetext = thetext.replace(/\[u\]/gi, "<u>")
thetext = thetext.replace(/\[\/u\]/gi, "</u>")
tipobj.innerHTML='<span class="txtsm">'+thetext+'<\/span>'
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

pointerobjLT.style.visibility="hidden"
pointerobjRT.style.visibility="hidden"
pointerobjLB.style.visibility="hidden"
pointerobjRB.style.visibility="hidden"

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+offsetdivfrompointerX-5+"px"
pointL=curX-offsetfromcursorX-5
pointposH = 'R'
}
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointL=curX+offsetfromcursorX
pointposH = 'L'
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
pointT=curY-offsetfromcursorY-1 // remove pixel 1 for border width
pointposV = 'B'
if (pointposH=='R') { pointL = pointL-offsetfromcursorX+5; tipobj.style.left=curX-tipobj.offsetWidth+offsetdivfrompointerX-offsetfromcursorX+"px" }
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointT=curY+offsetfromcursorY
pointposV = 'T'
}

// make the tip and the proper pointer visible
tipobj.style.visibility="visible"
pointpos = pointposH + pointposV
if (pointpos == 'LT') { pointerobj = pointerobjLT; }
else if (pointpos == 'RT') { pointerobj = pointerobjRT; }
else if (pointpos == 'LB') { pointerobj = pointerobjLB; }
else if (pointpos == 'RB') { pointerobj = pointerobjRB; }
pointerobj.style.visibility="visible"
pointerobj.style.left=pointL+"px"
pointerobj.style.top=pointT+"px"
}
}

function hidetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobjLT.style.visibility="hidden"
pointerobjRT.style.visibility="hidden"
pointerobjLB.style.visibility="hidden"
pointerobjRB.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

