/* Combine all the .js files used in ubbthreads */
	
// --- File: autocomplete.js ---

/** 
 * Author and Version Information {{{
 * author: Antonio Ramirez http://webeaters.blogspot.com
 *
 * class: AutoComplete for Prototype 1.6.0
 *
 * version: 1.2.1 - 2007-11-11 
 * 		(based on AutoSuggest 2.1.3 - 2007-07-19)
 * version: 1.3.0 - 2008-01-03 by Andrew Nicols <andrew@nicols.co.uk>
 *  - Fixed incorrect title-casing - CSS is Case Sensitive!!!
 *  - Adjusted the way in which the Notifier images are loaded.
 *  - Changed json code to pass all json variables back instead of just id, value and name
 *  - Fixed 'GMAIL' code such that if valueSep is undefined, it is ignored
 *  - Changed the default for valueSep to null
 *  - Fixed the resetTimeout function
 *
 * REFERENCES AND THANKS 
 * this class is based on the work in AutoSuggest.js of
 * Timothy Groves - http://www.brandspankingnew.net
 * and adapted for use with prototype 1.6.0
 *
 * UPDATED by RŽéda HADJOUTI
 * GMAIL like AutoComplete (semicolon separator) Update
 *
 }}}*/

var AutoComplete = Class.create();

AutoComplete.prototype = { // {{{
  Version: '1.3.0',
  REQUIRED_PROTOTYPE: '1.6.0',

  initialize: function (id, param) { // {{{
  	// check whether we have the appropiate javascript libraries
  	this.PROTOTYPE_CHECK();
	
    // Get the field we're watching.
    // It needs to be a valid field so throw an error if it's not valid or can't be found.
    this.fld = $(id);
    if (!this.fld)
    {
      throw("AutoComplete requires a field id to initialize");
    }
	
    // Init variables
    this.sInp 	= ""; // input value 
    this.nInpC 	= 0;	// input value length
    this.aSug 	= []; // suggestions array 
    this.iHigh 	= 0;	// level of list selection 
	
  // Parameter Handling {{{
	// Set the use specified options
	this.options = param ? param : {};
	// These are the default settings {{{
  var k, def = {
    valueSep:null,
    minchars:1,
    meth:"get",
    varname:"input",
    className:"autocomplete",
    timeout:3000,
    delay:500,
    offsety:-5,
    shownoresults: true,
    noresults: "No results were found.",
    maxheight: 250,
    cache: true,
    maxentries: 25,
    onAjaxError:null,
    setWidth: false,
    minWidth: 100,
    maxWidth: 200,
    useNotifier: true
  };
  //}}}
  // Overlay any values which weren't user specified.
	for (k in def) 
	{
		if (typeof(this.options[k]) != typeof(def[k]))
			this.options[k] = def[k];
	}
  // End of Parameter Handling }}}

  // Not everyone wants to use the Notifier. Give them the option	
	if (this.options.useNotifier)
  {
    this.fld.addClassName('ac_field');
  }

	// set keyup handler for field
	// and prevent AutoComplete from client
	var p = this;
	
	// NOTE: not using addEventListener because UpArrow fired twice in Safari
	this.fld.onkeypress 	= function(ev){ return p.onKeyPress(ev); };
	this.fld.onkeyup      = function(ev){ return p.onKeyUp(ev); };
  // ARN-DEBUG Chances are we want to reset the timeout when they lose focus, at least that's what I prefer
	this.fld.onblur			  = function(ev){ p.resetTimeout(); return true; };	
  // ARN-DEBUG Not sure what this is about!
	this.fld.setAttribute("AutoComplete","off");

  }, //}}}

  convertVersionString: function (versionString){ // {{{
      var r = versionString.split('.');
      return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
  }, // }}}

  PROTOTYPE_CHECK: function() { // {{{
    if((typeof Prototype=='undefined') || 
       (typeof Element == 'undefined') || 
       (typeof Element.Methods=='undefined') ||
       (this.convertVersionString(Prototype.Version) < 
        this.convertVersionString(this.REQUIRED_PROTOTYPE)))
       throw("AutoComplete requires the Prototype JavaScript framework >= " +
        this.REQUIRED_PROTOTYPE);
  }, // }}}

  // set responses to keypress events in the field
  // this allows the user to use the arrow keys to scroll through the results
  // ESCAPE clears the list
  // RETURN sets the current highlighted value
  // UP/DOWN move around the list

  onKeyPress: function (e) { // {{{
  	if (!e) e = window.event;
  	var key	= e.keyCode || e.wich;
  	

    switch(key)
    {
      case Event.KEY_RETURN:
        this.setHighlightedValue();
        Event.stop(e);
        break;
      case Event.KEY_TAB:
        this.setHighlightedValue();
        //Event.stop(e);
        break;
      case Event.KEY_ESC:
        this.clearSuggestions();
        break;
    }
    return true;
  }, //}}}

  onKeyUp: function (e) { // {{{
  	if (!e) e = window.event;
  	
  	var key = e.keyCode || e.wich;
  	
  	if (key == Event.KEY_UP || key == Event.KEY_DOWN) 
  	{
  		this.changeHighlight(key);
  		Event.stop(e);
  	}
  	else this.getSuggestions(this.fld.value);
  	
	return true;
  }, //}}}

  getSuggestions: function(val) { // {{{
  	// input the same? do nothing
  	if(val==this.sInp) return false;
  	
  	// kill the old list
  	if($(this.acID)) $(this.acID).remove();
  	
  	this.sInp = val;
  	
  	// input length is less than the min required to trigger a request
  	// do nothing
  	if (val.length < this.options.minchars)
  	{
  		this.aSug 	= [];
  		this.nInpC	= val.length; 
  		return false;
  	}

  	// Here we will detect if there is a comma and the splitted value has a value to check
  	// comma stars a new search and val is converted to the new value after the comma
  	var ol	= this.nInpC; // old length
  	this.nInpC	= val.length ? val.length : 0;
  	
  	// if caching enabled, and we didn't receive the maxentries value
    // and user is typing (ie. length of input is increasing)
  	// filter results out of suggestions from last request
  	var l = this.aSug.length;
  	if( this.options.cache && ( this.nInpC > ol ) && l && ( l < this.options.maxentries ) )
  	{
  		var arr = new Array();
  		for (var i=0;i<l;i++) {
  			if (this.aSug[i].value.toLowerCase().indexOf(val.toLowerCase()) != -1)
        {
  				arr.push(this.aSug[i]);
        }
  		}
  		this.aSug = arr;
  		
  		// recreate the list
  		this.createList(this.aSug);
  	} else {
  		// do new request
  		var p = this;
  		//var input	= this.sInp; // send the converted new value (comma)
  		clearTimeout(this.ajID); // ajax id timer
  		this.ajID = setTimeout( function () {p.doAjaxRequest(p.sInp)}, this.options.delay);
  	}
    document.helper = this;	
  	return false;
  }, // }}}

  getLastInput : function(str) { // {{{
  	var ret = str;
  	if (undefined != this.options.valueSep) {
  		var idx = ret.lastIndexOf(this.options.valueSep);
      ret = idx == -1 ? ret : ret.substring(idx + 1, ret.length);
  	}
  	
  	return ret;
  }, // }}}

  doAjaxRequest: function (input) { // {{{
  	// we have to check here if there is a new splitted value (, or ;)
  	// always check against the last part of the comma and then check
  	// saved input is still the value of the field
  	if (input != this.fld.value) 
  		return false;
  	
  	// Gmail like : get only the last user's input
  	this.sInp = this.getLastInput(this.sInp);
 	
  	// create ajax request
  	// do we need to call a function to recreate the url?
  	if (typeof this.options.script == 'function')
  		var url = this.options.script(encodeURIComponent(this.sInp));
  	else
  		var url = this.options.script+this.options.varname+'='+encodeURIComponent(this.sInp);
  	
  	if(!url) return false;
  	
  	var p = this;
  	var m = this.options.meth;  // get or post?
    if( this.options.useNotifier )
    {
      this.fld.removeClassName('ac_field');
	    this.fld.addClassName('ac_field_busy');
    };
  	
  	var options = {
  		method: m,
  		onSuccess: function (req) { // {{{
        if( p.options.useNotifier )
        {
          p.fld.removeClassName('ac_field_busy');
          p.fld.addClassName('ac_field');
        };
        p.setSuggestions(req,input);
  		}, // }}}

  		onFailure: (typeof p.options.onAjaxError == 'function')? function (status) { // {{{
        if (p.options.useNotifier)
        {
          p.fld.removeClassName('ac_field_busy');
          p.fld.addClassName('ac_field');
        }
        p.options.onAjaxError(status)
      } : // }}}

      function (status) { // {{{
        if (p.options.useNotifier)
        {
          p.fld.removeClassName('ac_field_busy');
          p.fld.addClassName('ac_field');
        }
        alert("AJAX error: "+status); 
      } // }}}
    }
  	// make new ajax request
  	new Ajax.Request(url, options);
  }, // }}}

  setSuggestions: function (req, input) { // {{{
	  // if field input no longer matches what was passed to the request
	  // don't show the suggestions
	  // here we need to check against the splitted values if any (, or ;)
    if (input != this.fld.value)
      return false;
	
    this.aSug = [];
	
    if(this.options.json) 
    { // response in json format?
      var jsondata = eval('(' + req.responseText + ')');
      this.aSug = jsondata.results;
    } else {
      // response in xml format?
      var results = req.responseXML.getElementsByTagName('results')[0].childNodes;
    
      for(var i=0;i<results.length;i++)
      {
        if(results[i].hasChildNodes())
          this.aSug.push(  { 'id':results[i].getAttribute('id'), 'value':results[i].childNodes[0].nodeValue, 'info':results[i].getAttribute('info') }  );
      }
    }
    this.acID = 'ac_'+this.fld.id;
    this.createList(this.aSug);
  }, // }}}

  createDOMElement: function ( type, attr, cont, html ) { // {{{
    var ne = document.createElement( type );
	
    if (!ne)
      return 0;
      
    for (var a in attr)
      ne[a] = attr[a];
    
    var t = typeof(cont);
    
    if (t == "string" && !html)
      ne.appendChild( document.createTextNode(cont) );
    else if (t == "string" && html)
      ne.innerHTML = cont;
    else if (t == "object")
      ne.appendChild( cont );

    return ne;
  }, // }}}

  createList:	function(arr) { // {{{
    // get rid of the old list if any  
  	if($(this.acID)) $(this.acID).remove();
  	
  	// clear list removal timeout
  	this.killTimeout();
  	
  	// if no results, and showNoResults is false, do nothing
  	if (arr.length == 0 && !this.options.shownoresults) return false;
  	
  	// create holding div
  	var div	= this.createDOMElement('div', {id:this.acID, className:this.options.className});
  	
  	// create div header
  	var hcorner = this.createDOMElement('div', {className: 'ac_corner'});
  	var hbar	= this.createDOMElement('div', {className: 'ac_bar'});
  	var header	= this.createDOMElement('div', {className: 'ac_header'});
  	header.appendChild(hcorner);
  	header.appendChild(hbar);
  	div.appendChild(header);
  	
    // create and populate ul
    var ul	= this.createDOMElement('ul', {id:'ac_ul'});
    var p 	= this; // pointer that we will need later on
    // no results?
    if (arr.length == 0 && this.options.shownoresults)
    {
      var li = this.createDOMElement('li', {className: 'ac_warning'}, this.options.noresults );
      ul.appendChild(li);
    } else {
      // loop through arr of suggestions creating an LI element for each of them
      for (var i=0,l = arr.length; i<l; i++)
      {
        // format output with the input enclosed in a EM elementFromPoint
        // (as HTML not DOM)
        var val 	= arr[i].value;
        var st 		= val.toLowerCase().indexOf(this.sInp.toLowerCase()); // HERE WE CHECK AGAINST THE SPLITTED VALUE IF ANY***
        var output 	= val.substring(0,st) + '<em>' + val.substring(st,st+this.sInp.length) + '</em>' + val.substring(st+this.sInp.length);
			
        var span	= this.createDOMElement('span',{},output,true); // type of, properties, output, isHTML?
			
				// SD Mod - We'll carry along the info, but use it later and not in the pull-down
        if(0 /* arr[i].info != '' */) // do we need to add extra info?
        {
          var br	= this.createDOMElement('br',{});
          span.appendChild(br);
          
          var small = this.createDOMElement('small',{}, arr[i].info);
          span.appendChild(small);
        }
        var a 	= this.createDOMElement('a',{href:'#'});
        
        var tl	= this.createDOMElement('span',{className:'tl'},'&nbsp;',true);
        var tr	= this.createDOMElement('span',{className:'tr'},'&nbsp;',true);
        
        a.appendChild(tl);
        a.appendChild(tr);
        a.appendChild(span); // add the object span into the link
			
        a.name = i+1;
        
        a.onclick 		= function () { // {{{
          p.setHighlightedValue();
          return false; 
        }; // }}}
        a.onmouseover	= function () { // {{{
          p.setHighlight(this.name); 
        }; // }}} 
			
        var li = this.createDOMElement('li', {}, a); // add the link element to a li element
        
        // finally add the newly created li element to the ul element 
        ul.appendChild(li);
      }
    }
    
    div.appendChild(ul); // add the newly created list to the div element
    
    // create div footer
    var fcorner = this.createDOMElement('div', {className: 'ac_corner'});
  	var fbar	= this.createDOMElement('div', {className: 'ac_bar'});
  	var footer	= this.createDOMElement('div', {className: 'ac_footer'});
  	footer.appendChild(fcorner);
  	footer.appendChild(fbar);
  	div.appendChild(footer);
  	
  	// get position of target textfield
    // position holding div below it
    // set width of holding div to width of field 
    // if 
    
    var pos         = this.fld.cumulativeOffset();
    div.style.left 	= pos[0] + "px";
    div.style.top 	= pos[1] + this.fld.offsetHeight + "px";
    
    var w = 
    (
      this.options.setWidth && this.fld.offsetWidth < this.options.minWidth
    )
    ? this.options.minWidth : 
    (
      this.options.setWidth && this.fld.offsetWidth > this.options.maxWidth
    )
    ? this.options.maxWidth : 
    this.fld.offsetWidth;

    
    div.style.width 	= w + "px";
    
    // set mouseover functions for div
    // when mouse pointer leaves div, set a timeout to remove the list after an interval
    // when mouse enters div, kill the timeout so the list won't be removed
    //
    div.onmouseover 	= function(){ p.killTimeout() };
    div.onmouseout 		= function(){ p.resetTimeout() };
    
    // add DIV to document
    document.getElementsByTagName("body")[0].appendChild(div);
    
    // highlight first item
    this.iHigh = 1;
    this.setHighlight(1);
    
    // remove list after interval
    this.toID	= setTimeout(
      function () {
        p.clearSuggestions() 
      }, this.options.timeout
    );
	
  }, // }}}

  changeHighlight:	function(key) { // {{{
  	var list = $("ac_ul");
    if (!list)
      return false;
	
    var n;

    n = (key == Event.KEY_DOWN || key == Event.KEY_TAB)? this.iHigh + 1 : this.iHigh - 1; // false assumed to be Event.KEY_UP
    
    n = (n > list.childNodes.length)? list.childNodes.length : ((n < 1)? 1 : n);	
    
    this.setHighlight(n);
  }, // }}}

  setHighlight:		function(n) { // {{{
  	var list = $('ac_ul');
  	
  	if (!list) return false;
  	
  	if (this.iHigh > 0) this.clearHighlight();
  	
  	this.iHigh = Number(n);
  	
  	list.childNodes[this.iHigh-1].className = 'ac_highlight';
  	
  	this.killTimeout();
  }, // }}}

  clearHighlight:	function() { // {{{
  	var list = $('ac_ul');
  	
  	if(!list) return false;
  	
  	if(this.iHigh > 0)
  	{
  		list.childNodes[this.iHigh-1].className = '';
  		this.iHigh = 0;
  	}
  	
  }, // }}}

  setHighlightedValue:	function() { // {{{
  	if (this.iHigh)
  	{
  		// HERE WE NEED TO IMPLEMENT THE GMAIL LIKE SPLITTED VALUE
  		if (!this.aSug[this.iHigh - 1]) return;
  		
  		// Gmail like
      if (undefined != this.options.valueSep) {
        var str = this.getLastInput(this.fld.value);
        var idx = this.fld.value.lastIndexOf(str);
        str = this.aSug[ this.iHigh -1 ].value + this.options.valueSep;
        this.sInp = this.fld.value = idx == -1 ? str : this.fld.value.substring(0, idx) + str;
      } else {
        var str = this.getLastInput(this.fld.value);
        var idx = this.fld.value.lastIndexOf(str);
        str = this.aSug[ this.iHigh -1 ].value;
        this.sInp = this.fld.value = idx == -1 ? str : this.fld.value.substring(0, idx) + str;
      }
  		
  		// move cursor to end of input (safari)
  		this.fld.focus();
  		if(this.fld.selectionStart)
  			this.fld.setSelectionRange(this.sInp.length, this.sInp.length);
  			
  		this.clearSuggestions();
  		
  		// pass selected object to callback function, if exists
  		if (typeof this.options.callback == 'function')
  			this.options.callback(this.aSug[this.iHigh-1]); // the object has the properties we want, it will depend of
  	}
  }, // }}}

  killTimeout:	function() { // {{{
  	clearTimeout(this.toID);
  }, // }}}

  resetTimeout:	function() { // {{{
  	this.killTimeout();
  	var p = this;
  	this.toID = setTimeout(
      function () { 
        p.clearSuggestions();
      }, p.options.timeout
    );
    // ARN-DEBUG Added p.options.timeout back :|
  }, // }}}

  clearSuggestions:	function () { // {{{
	
    this.killTimeout();
    if ($(this.acID))
    {
      this.fadeOut(300,function () {
        $(this.acID).remove();
      } );
    }
  }, // }}}

  fadeOut:	function (milliseconds, callback) { // {{{
  	this._fadeFrom 	= 1;
  	this._fadeTo	= 0;
  	this._afterUpdateInternal = callback;
  	
  	this._fadeDuration	= milliseconds;
  	this._fadeInterval = 50;
  	this._fadeTime = 0;
  	var p = this;
  	this._fadeIntervalID = setInterval(
      function() {
        p._changeOpacity()
      }, this._fadeInterval
    );
  
  }, // }}}

  _changeOpacity: function() { // {{{
 
    if (!$(this.acID))
    {
  		this._fadeIntervalID=clearInterval(this._fadeIntervalID);
  		return;
  	} 
  	this._fadeTime += this._fadeInterval;
  	
  	var ieop = Math.round( (this._fadeFrom + ((this._fadeTo - this._fadeFrom) * (this._fadeTime/this._fadeDuration))) * 100)
  	var op = ieop / 100;
 
  	var el = $(this.acID);
  	if (el.filters) // internet explorer
  	{
      try {
        el.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;
      } catch (e) { 
        // If it is not set initially, the browser will throw an error.
        // This will set it if it is not set yet.
        el.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';
      }
    } else	{
      el.style.opacity = op;
    }
	
    if (this._fadeTime >= this._fadeDuration)
    {
      clearInterval( this._fadeIntervalID );
      if (typeof this._afterUpdateInternal == 'function')
        this._afterUpdateInternal();
    }

  } // }}}
 
} // }}}

// Specific ubbthreads functions
function showMemberLink(id, name) {
	var URI = 'Profile for: [<a href="' + baseurl + '/ubbthreads.php?ubb=showprofile&User=' + id + '">' + name + '</a>]';
	URI += '&nbsp; Poasts for: [<a href="' + baseurl + '/ubbthreads.php?ubb=userposts&archive=0&id=' + id + '">' + name + '</a>]';
//	URI += '&nbsp; Show user archive posts: [<a href="' + baseurl + '/ubbthreads.php?ubb=userposts&archive=1&id=' + id + '">' + name + '</a>]';
	
	$('json_info').innerHTML = URI;
	}

// --- File: boxover.js ---

/* --- BoxOver ---
/* --- v 2.1 17th June 2006
By Oliver Bryant with help of Matthew Tagg
http://boxover.swazz.org */

// Modified from original to fit in with ubbthreads 7.3 by SD

if (typeof document.attachEvent!='undefined') {
   window.attachEvent('onload',initBoxover);
   document.attachEvent('onmousemove',moveMouse);
   document.attachEvent('onclick',checkMove); }
else {
   window.addEventListener('load',initBoxover,false);
   document.addEventListener('mousemove',moveMouse,false);
   document.addEventListener('click',checkMove,false);
}

var oDv=document.createElement("div");
var dvHdr=document.createElement("div");
var dvBdy=document.createElement("div");
var windowlock,boxMove,fixposx,fixposy,lockX,lockY,fixx,fixy,ox,oy,boxLeft,boxRight,boxTop,boxBottom,evt,mouseX,mouseY,boxOpen,totalScrollTop,totalScrollLeft;
boxOpen=false;
ox=10;
oy=10;
lockX=0;
lockY=0;

function initBoxover() {
	oDv.appendChild(dvHdr);
	oDv.appendChild(dvBdy);
	oDv.style.position="absolute";
	oDv.style.visibility='hidden';
	document.body.appendChild(oDv);
}

function defHdrStyle() {
	dvHdr.innerHTML='<img  style="vertical-align:middle"  src="info.gif">&nbsp;&nbsp;'+dvHdr.innerHTML;
	dvHdr.style.fontWeight='bold';
	dvHdr.style.width='350px';
	dvHdr.style.fontFamily='arial';
	dvHdr.style.border='1px solid #A5CFE9';
	dvHdr.style.padding='3';
	dvHdr.style.fontSize='11';
	dvHdr.style.color='#4B7A98';
	dvHdr.style.background='#D5EBF9';
	dvHdr.style.filter='alpha(opacity=85)'; // IE
	dvHdr.style.opacity='0.85'; // FF
	dvHdr.style.display='none';
}

function defBdyStyle() {
	dvBdy.style.borderBottom='1px solid #A5CFE9';
	dvBdy.style.borderLeft='1px solid #A5CFE9';
	dvBdy.style.borderRight='1px solid #A5CFE9';
	dvBdy.style.width='350px';
	dvBdy.style.fontFamily='arial';
	dvBdy.style.fontSize='11';
	dvBdy.style.padding='3';
	dvBdy.style.color='#1B4966';
	dvBdy.style.background='#FFFFFF';
	dvBdy.style.filter='alpha(opacity=85)'; // IE
	dvBdy.style.opacity='0.85'; // FF
	dvBdy.style.display='none';
}

function checkElemBO(txt) {
if (!txt || typeof(txt) != 'string') return false;
if ((txt.indexOf('header')>-1)&&(txt.indexOf('body')>-1)&&(txt.indexOf('[')>-1)&&(txt.indexOf('[')>-1))
   return true;
else
   return false;
}

function scanBO(curNode) {
	  if (checkElemBO(curNode.title)) {
      curNode.boHDR=getParam('header',curNode.title);
      curNode.boBDY=getParam('body',curNode.title);
			curNode.boCSSBDY='popup_content';
			curNode.boCSSHDR='popup_content_header';
			curNode.IEbugfix=(getParam('hideselects',curNode.title)=='on')?true:false;
			curNode.fixX=parseInt(getParam('fixedrelx',curNode.title));
			curNode.fixY=parseInt(getParam('fixedrely',curNode.title));
			curNode.absX=parseInt(getParam('fixedabsx',curNode.title));
			curNode.absY=parseInt(getParam('fixedabsy',curNode.title));
			curNode.offY=10;
			curNode.offX=10;
			curNode.fade=false;
			curNode.fadespeed=0.05;
			curNode.delay=0;
			curNode.windowLock=false;
			curNode.title='';
			curNode.hasbox=1;
			} else {
	    curNode.hasbox=2;
	  	}
}

function getParam(param,list) {
	var reg = new RegExp('([^a-zA-Z]' + param + '|^' + param + ')\\s*=\\s*\\[\\s*(((\\[\\[)|(\\]\\])|([^\\]\\[]))*)\\s*\\]');
	var res = reg.exec(list);
	if(res)
		return res[2].replace(/&lbr;/g,'[').replace(/&rbr;/g,']');
	else
		return '';
}

function Left(elem){
	var x=0;
	if (elem.calcLeft)
		return elem.calcLeft;
	var oElem=elem;
	while(elem){
		 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderLeftWidth);
		 x+=elem.offsetLeft;
		 elem=elem.offsetParent;
	  }
	oElem.calcLeft=x;
	return x;
	}

function Top(elem){
	 var x=0;
	 if (elem.calcTop)
	 	return elem.calcTop;
	 var oElem=elem;
	 while(elem){
	 	 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderTopWidth);
		 x+=elem.offsetTop;
	         elem=elem.offsetParent;
 	 }
 	 oElem.calcTop=x;
 	 return x;

}

var ah,ab;
function applyStyles() {
	if(ab)
		oDv.removeChild(dvBdy);
	if (ah)
		oDv.removeChild(dvHdr);
	dvHdr=document.createElement("div");
	dvBdy=document.createElement("div");
	CBE.boCSSBDY?dvBdy.className=CBE.boCSSBDY:defBdyStyle();
	CBE.boCSSHDR?dvHdr.className=CBE.boCSSHDR:defHdrStyle();
	dvHdr.innerHTML=CBE.boHDR;
	dvBdy.innerHTML=CBE.boBDY;
	ah=false;
	ab=false;
	if (CBE.boHDR!='') {
		oDv.appendChild(dvHdr);
		ah=true;
	}
	if (CBE.boBDY!=''){
		oDv.appendChild(dvBdy);
		ab=true;
	}
}

var CSE,iterElem,LSE,CBE,LBE, totalScrollLeft, totalScrollTop, width, height ;
var ini=false;

// Customised function for inner window dimension
function SHW() {
   if (document.body && (document.body.clientWidth !=0)) {
      width=document.body.clientWidth;
      height=document.body.clientHeight;
   }
   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
      width=document.documentElement.clientWidth;
      height=document.documentElement.clientHeight;
   }
   return [width,height];
}


var ID=null;
function moveMouse(e) {
   //boxMove=true;
	e?evt=e:evt=event;

	CSE=evt.target?evt.target:evt.srcElement;

	if (!CSE.hasbox) {
	   // Note we need to scan up DOM here, some elements like TR don't get triggered as srcElement
	   iElem=CSE;
	   while ((iElem.parentNode) && (!iElem.hasbox)) {
	      scanBO(iElem);
	      iElem=iElem.parentNode;
	   }
	}

	if ((CSE!=LSE)&&(!isChild(CSE,dvHdr))&&(!isChild(CSE,dvBdy))){
	   if (!CSE.boxItem) {
			iterElem=CSE;
			while ((iterElem.hasbox==2)&&(iterElem.parentNode))
					iterElem=iterElem.parentNode;
			CSE.boxItem=iterElem;
			}
		iterElem=CSE.boxItem;
		if (CSE.boxItem&&(CSE.boxItem.hasbox==1))  {
			LBE=CBE;
			CBE=iterElem;
			if (CBE!=LBE) {
				applyStyles();
				if (!CBE.requireclick)
					if (CBE.fade) {
						if (ID!=null)
							clearTimeout(ID);
						ID=setTimeout("fadeIn("+CBE.fadespeed+")",CBE.delay);
					}
					else {
						if (ID!=null)
							clearTimeout(ID);
						COL=1;
						ID=setTimeout("oDv.style.visibility='visible';ID=null;",CBE.delay);
					}
				if (CBE.IEbugfix) {hideSelects();}
				fixposx=!isNaN(CBE.fixX)?Left(CBE)+CBE.fixX:CBE.absX;
				fixposy=!isNaN(CBE.fixY)?Top(CBE)+CBE.fixY:CBE.absY;
				lockX=0;
				lockY=0;
				boxMove=true;
				ox=CBE.offX?CBE.offX:10;
				oy=CBE.offY?CBE.offY:10;
			}
		}
		else if (!isChild(CSE,dvHdr) && !isChild(CSE,dvBdy) && (boxMove))	{
			// The conditional here fixes flickering between tables cells.
			if ((!isChild(CBE,CSE)) || (CSE.tagName!='TABLE')) {
   			CBE=null;
   			if (ID!=null)
  					clearTimeout(ID);
   			fadeOut();
   			showSelects();
			}
		}
		LSE=CSE;
	}
	else if (((isChild(CSE,dvHdr) || isChild(CSE,dvBdy))&&(boxMove))) {
		totalScrollLeft=0;
		totalScrollTop=0;

		iterElem=CSE;
		while(iterElem) {
			if(!isNaN(parseInt(iterElem.scrollTop)))
				totalScrollTop+=parseInt(iterElem.scrollTop);
			if(!isNaN(parseInt(iterElem.scrollLeft)))
				totalScrollLeft+=parseInt(iterElem.scrollLeft);
			iterElem=iterElem.parentNode;
		}
		if (CBE!=null) {
			boxLeft=Left(CBE)-totalScrollLeft;
			boxRight=parseInt(Left(CBE)+CBE.offsetWidth)-totalScrollLeft;
			boxTop=Top(CBE)-totalScrollTop;
			boxBottom=parseInt(Top(CBE)+CBE.offsetHeight)-totalScrollTop;
			doCheck();
		}
	}

	if (boxMove&&CBE) {
		// This added to alleviate bug in IE6 w.r.t DOCTYPE
		bodyScrollTop=document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
		bodyScrollLet=document.documentElement&&document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft;
		mouseX=evt.pageX?evt.pageX-bodyScrollLet:evt.clientX-document.body.clientLeft;
		mouseY=evt.pageY?evt.pageY-bodyScrollTop:evt.clientY-document.body.clientTop;
		if ((CBE)&&(CBE.windowLock)) {
			mouseY < -oy?lockY=-mouseY-oy:lockY=0;
			mouseX < -ox?lockX=-mouseX-ox:lockX=0;
			mouseY > (SHW()[1]-oDv.offsetHeight-oy)?lockY=-mouseY+SHW()[1]-oDv.offsetHeight-oy:lockY=lockY;
			mouseX > (SHW()[0]-dvBdy.offsetWidth-ox)?lockX=-mouseX-ox+SHW()[0]-dvBdy.offsetWidth:lockX=lockX;
		}
		oDv.style.left=((fixposx)||(fixposx==0))?fixposx:bodyScrollLet+mouseX+ox+lockX+"px";
		oDv.style.top=((fixposy)||(fixposy==0))?fixposy:bodyScrollTop+mouseY+oy+lockY+"px";

	}
}

function doCheck() {
	if (   (mouseX < boxLeft)    ||     (mouseX >boxRight)     || (mouseY < boxTop) || (mouseY > boxBottom)) {
		if (!CBE.requireclick)
			fadeOut();
		if (CBE.IEbugfix) {showSelects();}
		CBE=null;
	}
}

function pauseBox(e) {
   e?evt=e:evt=event;
	boxMove=false;
	evt.cancelBubble=true;
}

function showHideBox(e) {
	oDv.style.visibility=(oDv.style.visibility!='visible')?'visible':'hidden';
}

function hideBox(e) {
	oDv.style.visibility='hidden';
}

var COL=0;
var stopfade=false;
function fadeIn(fs) {
		ID=null;
		COL=0;
		oDv.style.visibility='visible';
		fadeIn2(fs);
}

function fadeIn2(fs) {
		COL=COL+fs;
		COL=(COL>1)?1:COL;
		oDv.style.filter='alpha(opacity='+parseInt(100*COL)+')';
		oDv.style.opacity=COL;
		if (COL<1)
		 setTimeout("fadeIn2("+fs+")",20);
}


function fadeOut() {
	oDv.style.visibility='hidden';

}

function isChild(s,d) {
	while(s) {
		if (s==d)
			return true;
		s=s.parentNode;
	}
	return false;
}

var cSrc;
function checkMove(e) {
	e?evt=e:evt=event;
	cSrc=evt.target?evt.target:evt.srcElement;
	if ((!boxMove)&&(!isChild(cSrc,oDv))) {
		fadeOut();
		if (CBE&&CBE.IEbugfix) {showSelects();}
		boxMove=true;
		CBE=null;
	}
}

function showSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
      elements[i].style.visibility='visible';
   }
}

function hideSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
   elements[i].style.visibility='hidden';
   }
}

// --- File: gallery.js ---

/* Script Version 7.5.4.2 */

function showFullSize(width,height,id) {
	window.open(script + "?ubb=showpic&id=" + id,'pic','scrollbars=yes,toolbar=yes,status=no,resizable=yes,width=' + width + ',height = ' + height); 
} // end showFullSize

function updateMedium(id) {
	if (is_pending) return;
	is_pending = 1;

	var url = script;
	var ajax = new ubbtAJAX(url,updateMediumPic,'xml');
	ajax.sendData("POST","ubb=getmediumpic&id=" + id);
}

function updateMediumPic(responseXML) {
	retval = responseXML;
	var imageNode = retval.getElementsByTagName("imgsrc")[0];
	if (imageNode.childNodes[0]) {
		var image = imageNode.childNodes[0].nodeValue;
	}
	var widthNode = retval.getElementsByTagName("width")[0];
	if (widthNode.childNodes[0]) {
		var w = widthNode.childNodes[0].nodeValue;
	}
	var heightNode = retval.getElementsByTagName("height")[0];
	if (heightNode.childNodes[0]) {
		var h = heightNode.childNodes[0].nodeValue;
	}
	var idNode = retval.getElementsByTagName("id")[0];
	if (idNode.childNodes[0]) {
		var id = idNode.childNodes[0].nodeValue;
	}
	var descNode = retval.getElementsByTagName("description")[0];
	if (descNode.childNodes[0]) {
		var desc = descNode.childNodes[0].nodeValue;
	}
	var thumbNode = retval.getElementsByTagName("thumb")[0];
	if (thumbNode.childNodes[0]) {
		var thumb = thumbNode.childNodes[0].nodeValue;
	}
	var mediumNode = retval.getElementsByTagName("medium")[0];
	if (mediumNode.childNodes[0]) {
		var medium = mediumNode.childNodes[0].nodeValue;
	}
	var fullNode = retval.getElementsByTagName("full")[0];
	if (fullNode.childNodes[0]) {
		var full = fullNode.childNodes[0].nodeValue;
	}
	var sizeNode = retval.getElementsByTagName("size")[0];
	if (sizeNode.childNodes[0]) {
		var size = sizeNode.childNodes[0].nodeValue;
	}

	obj = get_object('mediumpic');
	obj.src = image; 
	obj.onclick = function(){showFullSize( w,h,id );};
	obj = get_object('mediumpic_desc');
	if (desc != "" && desc != undefined) {
		obj.innerHTML = desc;
	}

	obj = get_object('thumb');
	obj.value = thumb;

	obj = get_object('medium');
	obj.value = medium;

	obj = get_object('full');
	obj.value = full;

	obj = get_object('dimensions');
	obj.innerHTML = w + "x" + h;

	obj = get_object('size');
	obj.innerHTML = size;

	is_pending = 0;
}

// --- File: image.js ---

/* Script Version 7.5.4.2 */

var image_pending = 0;

function newCaptcha(type) { 
	if (image_pending) return;
	image_pending = 1;
	get_object('ajax_wait').style.display = "";
    	var url = script + "?ubb=captcha&init=1&t=" + type;
    	var ajax = new ubbtAJAX(url, updateCaptcha); 
    	ajax.sendData("GET"); 
}

function updateCaptcha(responseXML) {
	id = responseXML;
	obj = get_object('captcha_image');
	obj.src = script + "?ubb=captcha&id=" + id;
	image_pending = 0;
	get_object('ajax_wait').style.display = "none";
}

// --- File: inline_moderation.js

/* Script Version 7.5.4.2 */

/**
 * Javascript functions for inline moderation
 */

function toggle_moderation(check, row_id, uncheck_all_box) {
	if (!check.checked) {
		var cells = get_object(row_id).getElementsByTagName('td');
		for (var i in cells) {
			if (cells[i].className != null) {
				cells[i].className = cells[i].className.replace(/ inline_selected/, '');
			}
		}
	} else {
		var cells = get_object(row_id).getElementsByTagName('td');
		for (var i in cells) {
			if (cells[i].className != null) {
				cells[i].className += ' inline_selected';
			}
		}
	}
}

function select_topics(option) {

	switch (option) {
		case "invert":
			for (var i=0; i < document.inline_moderation.elements.length; i++) {
				var e = document.inline_moderation.elements[i];
				if (e.type == "checkbox" && e.name.match("check-inline") != null) {
					e.checked = !e.checked;
					toggle_moderation(e, "postrow-inline-" + e.value, false);
				}
			}
			break;
		case "all":
			for (var i=0; i < document.inline_moderation.elements.length; i++) {
				var e = document.inline_moderation.elements[i];
				if (e.type == "checkbox" && e.name.match("check-inline") != null) {
					if (e.checked == true) next;
					e.checked = true;
					toggle_moderation(e, "postrow-inline-" + e.value, false);
				}
			}
			break;
		case "none":
			for (var i=0; i < document.inline_moderation.elements.length; i++) {
				var e = document.inline_moderation.elements[i];
				if (e.type == "checkbox" && e.name.match("check-inline") != null) {
					if (e.checked == false) next;
					e.checked = false;
					toggle_moderation(e, "postrow-inline-" + e.value, false);
				}
			}
			break;
		default:
			for (var i=0; i < document.inline_moderation.elements.length; i++) {
				var e = document.inline_moderation.elements[i];
				if (e.type == "checkbox" && e.name.match("check-inline") != null) {
					if (topics_for_moderation[e.value].match(option)) {
						e.checked = true;
						toggle_moderation(e, "postrow-inline-" + e.value, false);
					} else {
						e.checked = false;
						toggle_moderation(e, "postrow-inline-" + e.value, false);
					}
				}
			}
			break;
	}
}

function init_inline_moderation() {
	var inputs = document.getElementsByTagName('input');

	for (var i in inputs) {
		if (inputs[i].type == "checkbox" && inputs[i].name.match("check-inline") != null) {
			inputs[i].checked = false;
		} else if(inputs[i].name == 'check-all-inline') {
			inputs[i].checked = false;
			inputs[i].disabled = false;
		}
	}
}

// --- pt.js ---

/* Script Version 7.5.4.2 */
var count = 0;
var user_array = new Array(0);
var do_submit = 0;
var curr_username = '';

function addUser() {
	document.replier.ubb.value = "sendprivate";
	document.replier.submit();
} // end addUser

function checkArray(value) {

	var i;

	for (i=0; i < user_array.length; i++) {	
		if (user_array[i].toLowerCase() == value.toLowerCase()) {
			return true;
		}
	}

} // end checkArray

function checkTotal() {

	if (user_array.length >= pmLimit) {
		return true;
	}

} // end checkTotal

function checkUser(user) {
	curr_username = user;
	var url = script + "?ubb=checkrecipient&user=" + encodeURIComponent(user);
	var ajax = new ubbtAJAX(url, addRecipient,'xml');
	ajax.sendData("GET");
} // end function checkUser


function updateList(username) {
	dup = checkArray(username);
	if (dup) {
		return alert(dupUser);
	} // end if

	max = checkTotal();
	if (max) {
		return alert(tooMany);
	} // end if
	
	checkUser(username);
	
}

function addRecip(checkval) {
	username = document.replier.User.value;

	if (checkval == 'submit') do_submit = 1;	
	if (do_submit == 1 && !username) {
		document.replier.submit();
	}
	if (!username) return;
	dup = checkArray(username);
	if (dup) {
		return alert(dupUser);
	} // end if

	max = checkTotal();
	if (max) {
		return alert(tooMany);
	} // end if

	return checkUser(username);
	
}

function addRecipient(responseXML) {

	retval = responseXML;

	if (retval.getElementsByTagName("error")[0]) {
		var textNode = retval.getElementsByTagName("error")[0];
		if (textNode.childNodes[0]) {
			is_error = 1;
			var error = textNode.childNodes[0].nodeValue;
			return alert(error);
		}
	}
	var textNode = retval.getElementsByTagName("user")[0];
	if (textNode.childNodes[0]) {
		var username = textNode.childNodes[0].nodeValue;
	}
	username = curr_username;
	
	obj = get_object('recips');
	obj.innerHTML += username + "; "
	document.replier.User.value = "";
	
	obj2 = get_object('hidden_list');
	obj2.innerHTML += "<input type='hidden' name='recip[" + count + "]' value='" +username.replace(/'/g,"&#39;")+ "' />";
	
	user_array[count] = username;
	count = count + 1;

	if (do_submit == 1) {
		document.replier.submit();
	}
	return true;
	
} // end addRecipient

// --- File: quickquote.js ---

/* Script Version 7.5.4.2 */

var this_post = 0;
var is_quote = 0;
var is_pending = 0;

function switchAdvanced(type) {
	if (type == 'pt') {
		document.replier.ubb.value = "mess_handler";
	} else {
		document.replier.ubb.value = "newreply";
	}
	document.replier.submit();
} // end switchAdvanced

function quickReply(post_id,quote,pt) { 
	if (is_pending) return;
	is_pending = 1;
	this_post = post_id;
	is_quote = quote;
	if (quote) {
    		var url = script + "?ubb=quickquote&post=" + post_id + "&pt=" + pt;
    		var ajax = new ubbtAJAX(url, updateQuickReply); 
    		ajax.sendData("GET"); 
	} else {
		updateQuickReply();
	}
}

function updateQuickReply(responseXML) {	
		postBody = responseXML;
		obj = document.replier;
		obj.Parent.value = document.getElementById('number' + this_post).innerHTML;
		if (is_quote) {
			obj.Body.value += postBody;
		}
		insertAtCaret(obj.Body, ' ');
		obj.Body.focus();
		is_pending = 0;
}

function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPost) {
		var caretPos = textEl.caretPost;
		caretPost.text =
			caretPost.text.charAt(caretPost.text.length - 1) == ' ' ?
			text + ' ' : text;
	}
	else {
		textEl.value = textEl.value + text;
	}
	return true;
}

// --- File: shoutbox.js ---

/* Script Version 7.5.4.2 */

var firstshout = 0;
var lastshout = 0;
var shoutTimer;
var shoutBox = 1;
var is_pending = 0;
var shoutschecked = new Array();				// Pish Mod - Bash

function shoutit() {
	
	if (is_pending) return;
	is_pending = 1;
	
	obj = document.shoutbox;
	shouttext = obj.shoutbody.value;
	if (!shouttext) {
		is_pending = 0;
		return;
	}
	if (!s_priv) {
		alert(notLogged);
		return;
	}
	
	stopTimer();
	
	obj.shoutbody.value = "";
	
	shoutfield = get_object('shout_field');
	shoutfield.style.display = "none";

	sendingfield = get_object('sending_field');
	sendingfield.style.display = "";
	
	var url = script;
	var ajax = new ubbtAJAX(url, getShouts);
	ajax.sendData("POST","ubb=shoutit&shout=" + encodeURIComponent(shouttext));

}

// Pish Mod - Bash
if (!Array.prototype.indexOf)
{
	Array.prototype.indexOf = function(elt /*, from*/) {
    	var len = this.length;

    	var from = Number(arguments[1]) || 0;
    	from = (from < 0)
        	? Math.ceil(from)
         	: Math.floor(from);
    	if (from < 0) from += len;

    	for (; from < len; from++) {
    		if (from in this && this[from] === elt) return from;
    	}
    	return -1;
	};
}

function shoutcheck(id) {
	arraypos = shoutschecked.indexOf(id);
	if(arraypos > -1) {
		shoutschecked.splice(arraypos,1);
	} else {
		shoutschecked.push(id);
	}
}

function bashit () {

	if (!s_priv) {
		alert(notLogged);
		return;
	}

	if(!shoutschecked.length) {
		//alert('No shouts selected!');
		return;
	}

	if (is_pending) return;
	is_pending = 1;

	stopTimer();

	shoutschecked.sort();
	sids=shoutschecked.toString();

	shoutfield = get_object('shout_field');
	shoutfield.style.display = "none";

	bashingfield = get_object('bashing_field');
	bashingfield.style.display = "";

	var url = script;
	var ajax = new ubbtAJAX(url, getShouts);
	ajax.sendData("POST","ubb=bashit&shoutids=" + encodeURIComponent(sids));

}
	
function getShouts() {

	stopTimer();
	var url = script;
	var ajax = new ubbtAJAX(url, updateShout, 'xml'); 
	ajax.sendData("POST","ubb=getshouts&shout=" + lastshout); 
	is_pending = 0;
	
}

function updateShout(responseXML) {

	var shoutData = responseXML;
	if (shoutData == null) return;
	var lastShout = shoutData.getElementsByTagName("lastshout");
	if (lastShout.length == 0) return;
	var shoutNode = lastShout[0];
	if (!shoutNode) return;
	if (shoutNode.childNodes[0]) {
		var shoutTextNode = shoutNode.childNodes[0];
		var last_shoutid = shoutTextNode.nodeValue;
		if (last_shoutid > 0) {
			lastshout = last_shoutid;
		}
	}	
	var shoutNode = shoutData.getElementsByTagName("firstshout")[0];
	if (shoutNode.childNodes[0]) {
		var shoutTextNode = shoutNode.childNodes[0];
		var first_shoutid = shoutTextNode.nodeValue;
		if (!firstshout) {
			firstshout = first_shoutid;
		}
	}
	
	var shouts = shoutData.getElementsByTagName("shoutdata");
	
	if (shouts.length) {
	
		for (var i = 0 ; i < shouts.length ; i++) {
			var nameNode = shoutData.getElementsByTagName("shoutdata")[i];
			var nameTextNode = nameNode.childNodes[0];
			var name = nameTextNode.nodeValue;
			obj = get_object('shout_content');
			obj.innerHTML += name;
		}

		for (x = firstshout - 1; x <=last_shoutid; x++) {
			if (x < (last_shoutid - 30) ) { 
				obj = get_object("shout" + x);
				if (obj) {
					obj.innerHTML = '';
					obj.style.display = "none";
				}
			}
		}
	}

	shoutfield = get_object('shout_field');
	shoutfield.style.display = "";
	
	sendingfield = get_object('sending_field');
	sendingfield.style.display = "none";

	bashingfield = get_object('bashing_field');
	bashingfield.style.display = "none";
	
	startTimer();
	
	// IE has a problem with scrolling before the shoutbox
	// is filled in.  A 1 millisecond timer fixes this.  *shrug*
	if (shouts.length) {
		scrollTimer = setTimeout("scrollBottom()",1);
	}
	
}

function scrollBottom() {
		var objDiv = get_object("shout_box");
		
		if (objDiv.scrollHeight) {
			objDiv.scrollTop = objDiv.scrollHeight;
		} else if (objDiv.offsetHeight) {
			objDiv.scrollTop = objDiv.offsetHeight;
		}
		return false;
}

function startTimer(){
	shoutTimer = setTimeout("getShouts()",5000);
}

function stopTimer() {
	clearTimeout(shoutTimer);
}

function confirmDelete(id)	{
	
	input_box=confirm(confirmText + id + "?");
	
	if (input_box==true)	{
		obj = get_object("shout" + id);
		obj.innerHTML = '';
		obj.style.display = "none";
    		var url = script + "?ubb=shoutdelete&id=" + id;
    		var ajax = new ubbtAJAX(url); 
    		ajax.sendData("GET"); 
	}	
}

// --- File: standard_text_editor.js ---

/* Script Version 7.5.4.2 */

var listStart = false;

function changeTextArea(direction) {
	if (goal == null) goal = get_object('texteditor');
	var txtarea = goal;
	if (direction=='bigger') {
		txtarea.rows = txtarea.rows + 3;
	} else {
		if (txtarea.rows > 6) {
			txtarea.rows = txtarea.rows - 3;
		}
	}
}

function hide_menus() {
	if (menus == null) return false;
	for (var i in menus) {
		var ob = get_object(menus[i]);
		if (ob != null) ob.style.display = 'none';
	}
}

function showHTML(id,html) {
	if (menus == null) return false;

	for (var i in menus) {
		if (menus[i] != html) {
			var ob = get_object(menus[i]);
			if (ob != null) ob.style.display = 'none';
		}
	}

	obj = get_object(id);
	pos = get_offset(obj);
	leftpx = pos['left'];
	toppx = pos['top'] + obj.offsetHeight - 3;

	element = get_object(html);
	element.style.position = 'absolute';
	element.style.zIndex = 50;
	element.style.left = leftpx + 'px';
	element.style.top  = toppx + 'px';

	if (element.style.display == 'none') {
		element.style.display = '';
	} else {
		element.style.display = 'none';
	}
}

function showHideElement(element, showHide) {
	if (document.getElementById(element)) {
		element = document.getElementById(element);
	}

	if (showHide == "show") {
		element.style.display = "";
	} else if (showHide == "hide") {
		element.style.display = "none";
	}
}

function litSelection(e) {
	obj = get_object(e)
	if (obj)
		obj.className = "markup_panel_select_text";
	return;
}

function unlitSelection(e) {
	obj = get_object(e)
	if (obj)
		obj.className = "markup_panel_unselect_text";
	return;
}

function raiseButton(e) {
	obj = get_object(e)
	if (obj)
		obj.className = "markup_panel_hover_button";
	return;
}

function normalButton(e) {
	obj = get_object(e)
	if (obj)
		obj.className = "markup_panel_normal_button";
	return;
}

function lowerButton(e) {
	obj = get_object(e)
	if (obj)
		obj.className = "markup_panel_down_button";
	return;
}

function x() {
	return;
}

function storeCaret (textEl) {
	if (textEl.createTextRange)
		textEl.caretPos = document.selection.createRange().duplicate();
} // end fn

function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) { // IE
		var caretPos = textEl.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	} else if(textEl.selectionStart && textEl.setSelectionRange) { // Mozilla 1.3+
		var val = textEl.value;
		var cpos = textEl.selectionStart;
		var fpos = cpos + text.length +1;

		var before = val.substr(0,cpos);
		var after = val.substr(cpos, val.length);
		var aspace = after.charAt(0) == ' ' ? "" : " ";
		var bspace = before.charAt(before.length) == ' ' ? "" : " ";

		textEl.value = before + bspace + text + aspace + after;
		textEl.setSelectionRange(fpos,fpos); // set cursor pos to end of text
		textEl.focus();
	} else {
		textEl.value  = textEl.value + text; // for non MSIE browsers just append it
	}

	return true;
}// fn

function fontFamily(font) {
	hide_menus();
	formatText("[font:" + font + "]","[/font]");
}

function formatText(tagstart,tagend,type) {
	hide_menus();
	if (goal == null) goal = get_object('texteditor');
	el = goal;

	if (el.setSelectionRange) {
		el.value = el.value.substring(0,el.selectionStart) + tagstart + el.value.substring(el.selectionStart,el.selectionEnd) + tagend + el.value.substring(el.selectionEnd,el.value.length)
	} else {
		selectedText = document.selection.createRange().text;
		if (selectedText) {
			newText = tagstart + selectedText + tagend;
			document.selection.createRange().text = newText;
		} else {
			insertAtCaret(document.replier.Body, ' ' + tagstart + ' ' + tagend + ' ' );
		}
	}

	el.focus();

  	return;
}


function DoPrompt(action,hint_text,open_tag,close_tag) {
	if (goal == null) goal = get_object('texteditor');
	var textarea = goal;
	var currentMessage = textarea.value;

	switch (action) {
		case "url":
			var thisURL = prompt(urlText, "http://");
			if (thisURL == null){break;}

			var thisTitle = prompt(urlTitle, "");
			if (thisTitle == null){break;}

			insertAtCaret(textarea, ' ' + "[url=" + thisURL + "]" + thisTitle + "[/url]" + ' ');
			textarea.focus();
			break;
		case "email":
			var thisEmail = prompt(enterEmail, "");
			if (thisEmail == null){break;}

			insertAtCaret(textarea, ' ' + "[email]" + thisEmail + "[/email]" + ' ' );
			textarea.focus();
			break;
		case "listitem":
			var thisItem = prompt(enterItem, "");
			if (thisItem == null){break;}

			if (listStart == false) {
				insertAtCaret(textarea, ' ' + "\n[list]\n[*]" + thisItem);
				listStart = true;
				textarea.focus();
				return;
			}

			if (thisItem == "")	{
				listStart = false;
				insertAtCaret(textarea, ' ' + "\n[/list]");
			} else {
				insertAtCaret(textarea, ' ' + "[*]" + thisItem);
			}
			textarea.focus();
			break;
		case "image-left":
		case "image-non":
		case "image-right":
		case "image-center":
			var thisImage = prompt(enterImage, "http://");
			if (thisImage == null){break;}

			if (action == "image-left") {
				insertAtCaret(textarea, ' ' + "[img:left]" + thisImage + "[/img]" + ' ' );
			} else if (action == "image-right") {
				insertAtCaret(textarea, ' ' + "[img:right]" + thisImage + "[/img]" + ' ' );
			} else if (action == "image-center") {
				insertAtCaret(textarea, ' ' + "[img:center]" + thisImage + "[/img]" + ' ' );
			} else {
				insertAtCaret(textarea, ' ' + "[img]" + thisImage + "[/img]" + ' ' );
			}
			textarea.focus();
			break;
		case "bbcode":
			var thisBBCode = prompt(enterBBCode + '\n' + hint_text,"");
			if (thisBBCode == null){break;}

			insertAtCaret(textarea, ' ' + open_tag + thisBBCode + close_tag + ' ' );
			break;
	}

	hide_menus();
	return;
}

function InitColorPalette() {
	var ct = get_object('colors-table');
	if (ct == null) return;
	
	var cells = get_object("colors-table").getElementsByTagName( "td" );
	for( var i = 0; i < cells.length; i++ ) {
		var cell = cells[i];
		if( cell.id != "sample" ) {
			cell.onmouseover = function() {
				document.getElementById( "sample" ).style.color = this.bgColor.toUpperCase();
				document.getElementById( "sample" ).innerHTML = this.bgColor.toUpperCase();
			}
			cell.onmouseout = function() {
				document.getElementById( "sample" ).style.color = "#000";
				document.getElementById( "sample" ).innerHTML = noColor;
			}
			cell.onmousedown = function(e) {
				formatText('[color:' + this.bgColor.toUpperCase() + ']','[/color]');
			}
		}
	}
	hide_menus();
}

var filemanager = null;
function filemanager_popup(url) {
	filemanager = window.open(url);
}

var smileys = null;
function smiley_popup(url) {
	smileys = window.open(url);
}

// --- File: ubb_jslib.js ---

/* Script Version 7.5.4.2 */

// Current Menu
var currentMenu = null;
var currentMenuStatus = false;
var is_pending = 0;
var submit_clicked = 0;

function ubbtAJAX(url, callback, responseType) {

	var req = init();

	req.onreadystatechange = processRequest;

	if (!responseType) {
		responseType = "text";
	}

	var type = responseType;

 	function init() {
		if (window.XMLHttpRequest) {
			http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		return http_request;
	}

	function processRequest () {
		if (req.readyState != 4) { return; }
		if (req.readyState == 4) {
			if (callback) {
				if (type == "xml") {
					callback(req.responseXML);
				} else {
					callback(req.responseText);
				}
			}
			req.onreadystatechange = function() {};
			req.abort();
		}
	}

	this.sendData = function(meth,params) {

		if (meth == "GET") {
			req.open("GET", url, true);
			req.send(null);
		} else {
    			req.open('POST', url, true);
      			req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      			req.setRequestHeader("Content-length", params.length);
      			req.setRequestHeader("Connection", "close");
      			req.send(params);
    		}
	}
}

function markRead(forum,replacer) {

	var url = script + "?ubb=markread&forum=" + forum;
	var ajax = new ubbtAJAX(url);
	ajax.sendData("GET");

	image = get_object('icon-' + forum);
	image.src = baseurl + "/images/" + imagedir + "/" + replacer;

	obj = get_object('threads-' + forum);
	obj.innerHTML = '';

	obj = get_object('posts-' + forum);
	obj.innerHTML = '';

}

// SD:Mod
//
// Given an elements id, grab the contents and copy to the clipboard.
//
// Note: it tries the IE way 1st, then uses flash for all others.
function copyToClipboard(id) {
	var txtSrc = get_object(id).innerHTML;

	// Gotta strip all the tag crapola first
	var re = /<\S[^><]*>/g;
	txtSrc = txtSrc.replace(re,'');
	txtSrc = txtSrc.replace(/&nbsp;/g,' ');
	txtSrc = txtSrc.replace(/&gt;/g,'>');
	txtSrc = txtSrc.replace(/&lt;/g,'<');

  if (window.clipboardData) {
    window.clipboardData.setData("Text",txtSrc);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="'+baseurl+'/libs/geshi/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(txtSrc)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

function doPreview() {
	if (is_pending) return;
	is_pending = 1;

	obj = document.replier;

	body = get_object('texteditor').value;
	convert = '';
	if (obj.convert) {
		convert = obj.convert.value;
	}

	gallery = 0;
	if (obj.gallery) {
		gallery = obj.gallery.value;
	}

	obj = get_object('preview_text');
	obj.innerHTML = loadingpreview;
	area = get_object('preview_area');
	area.style.display = "";

	var url = script;
	var ajax = new ubbtAJAX(url, updatePreview);
	ajax.sendData("POST","ubb=previewpost&convert=" + convert + "&gallery=" + gallery + "&Body=" + encodeURIComponent(body));
}

function updatePreview(responseXML) {
	postBody = responseXML;
	obj = get_object('preview_text');
	obj.innerHTML = postBody;
	is_pending = 0;
}


// Get and retrieve an object
function get_object(obj) {
	if (document.getElementById) {
		return document.getElementById(obj);
	} else if (document.all) {
		return document.all[obj];
	} else if (document.layers) {
		return document.layers[obj];
	} else {
		return null;
	}
}

// Get the position of the current object
function get_offset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;

	while ((obj = obj.offsetParent) != null)
	{
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	top_offset += 2;
	return { 'left' : left_offset, 'top' : top_offset };
}


// Show/Hide a block of content and set a cookie
function showHideBlock(e) {

	element = get_object(e);
	image = get_object('toggle_' + e);

	currentCookie = "";
	currentCookie = getCookie('ubbt_collapsed');

	if (element.style.display == "none") {
		element.style.display = "";
		re = new RegExp(e, "ig");
		newCookie = currentCookie.replace(re, "");
		image.src = baseurl + "/images/" + imagedir + "/toggle_closed.gif";
	} else {
		element.style.display = "none";
		image.src = baseurl + "/images/" + imagedir + "/toggle_open.gif";
		newCookie = currentCookie + "|" + e + "|";
	}

	setCookie('ubbt_collapsed',newCookie);

} // end showHideBlock

// Show/Hide any block of text
function showHide(obj,delay) {

	obj = get_object(obj);
	if (obj.style.display == "none") {
		obj.style.display = '';
	} else {
		obj.style.display = "none";
	} // end if
	return true;

} // end showHide


// Show/Hide a popup menu
function showHideMenu(obj,e) {
	obj = get_object(obj);

	pos = get_offset(obj);
	leftpx = pos['left'];
	toppx = pos['top'] + obj.offsetHeight;

	element = get_object(e);

	// Close the last active menu
	if (currentMenu != null && typeof currentMenu == "object" && currentMenu != element) {
		currentMenu.style.display = "none";
	}


	if (element.style.display == "none") {
		// SD:Mod - Register it here and alleviate all that crap in the .tpls
		registerPopup(e);
		
		element.style.visibility = "hidden";
		element.style.display = "";
		currentMenu = element;
		currentMenuStatus = true;

		element.style.position = 'absolute';
		element.style.zIndex = 50;

		// Compensate for menus that are far to the right
		if ((leftpx + element.offsetWidth >= document.body.clientWidth) && (leftpx + obj.offsetWidth - element.offsetWidth) > 0) {
			element.style.left = (leftpx + obj.offsetWidth - element.offsetWidth) + 'px';
			element.style.top  = toppx + 'px';
		} else {
			element.style.left = leftpx + 'px';
			element.style.top  = toppx + 'px';
		}
		element.style.visibility = "visible";

	} else {
		element.style.display = "none";
		currentMenu = null;
		currentMenuStatus = false;
	}

}

// Clears the last active menu
function clearMenus(e) {

	if (!e) e = window.event
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3)
		targ = targ.parentNode;

	if (targ.className.indexOf("noclose") != -1 || (targ.parentNode != null && targ.parentNode.className != null && (targ.parentNode.className.indexOf("noclose") != -1 || (targ.parentNode.parentNode != null && targ.parentNode.parentNode.className != null && targ.parentNode.parentNode.className.indexOf("noclose") != -1)))) {
		return;
	}

	if (currentMenuStatus == true) {
		currentMenuStatus = false;
		return true;
	} // end if
	if (currentMenu != null && typeof currentMenu == "object") {
		currentMenu.style.display = "none";
	} // end if
} // end clearMenus


// Register a popup menu
function registerPopup(e) {
	element = get_object(e);

	if (element == null) return;

	element.style.display = "none";

	if (element.getElementsByTagName)
		var x = element.getElementsByTagName('TD');

	for (var i=0; i < x.length; i++) {
		if (x[i].className.indexOf("noclose") == -1) {
			x[i].onclick = click;
			x[i].id = e;
		}
		if (x[i].className == "popup_menu_header") continue;
		x[i].onmouseover = over;
		x[i].onmouseout = out;
	}
}

function over() {
	this.className = this.className.replace(/popup_menu_content/, "popup_menu_highlight");

}
function out() {
	this.className = this.className.replace(/popup_menu_highlight/, "popup_menu_content");
}
function click() {
	obj = get_object(this.id);
	obj.style.display="none";
}

function getCookie( name ) {

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


function setCookie(id,value) {

	var today = new Date();
	today.setTime( today.getTime() );
	expires = 1000 * 365 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = id + "=" +escape( value ) + ";expires=" + expires_date.toGMTString()  + ";path=/";

}

function toggleIgnore(e) {

	element = get_object(e);
	image = get_object('body' + e);

	if (element.style.display == "none") {
		element.style.display = "";
	} else {
		element.style.display = "none";
	}

} // end toggleIgnore

function submitPost() {
	if (submit_clicked == "1") {
		return alert(submitClicked);
	}
	submit_clicked = 1;
	document.replier.submit();
}

function clearSubmit() {
	submit_clicked = 0;
}

function toggle_spoiler(self, lang_hide_spoiler, lang_show_spoiler) {
	var spoiler_box = self.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0];

	if (spoiler_box.style.display == 'none') {
		spoiler_box.style.display = "";
		self.value = lang_hide_spoiler;
	} else {
		spoiler_box.style.display = "none";
		self.value = lang_show_spoiler;
	}
}

function goto_page(url,id) {
	var page = get_object(id).value;
	var loc = window.location.href;

	window.location.href = baseurl + "/ubbthreads.php?ubb=" + url + page;

	// OK
}

function changePrefs(what,value) {
	window.location.href = baseurl + "/ubbthreads.php?ubb=changeprefs&what=" + what + "&value=" + value + "&curl=" + document.location.href;
} // end changePrefs

// Centers the supplied window in the available realestate provided by the windows' dimensions
//
// Note: need to figure out why the height misreports :(
function showChromeless(url, name, w, h, scroll) {
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  // Optional scroll
  sc = (scroll == 1) ? 'yes' : 'no';

  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=' + sc + ', resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
  }

var grippy_list = new Array();
var additional_onloads = new Array();

function toggle_expandy_region (tarjay) {
	var anode = document.getElementById("plusmin-" + tarjay);
	var tnode = document.getElementById("expandy-" + tarjay);
	if(tnode.style.display != "") {
		// it's not visible, make it visible
		tnode.style.display = "";
		anode.appendChild(document.createTextNode("-"));
		anode.removeChild(anode.firstChild);
	} else {
		// make it invisible
		tnode.style.display = "none";
		anode.appendChild(document.createTextNode("+"));
		anode.removeChild(anode.firstChild);
	} // end if
} // end toggle_expandy_region

function hide_expandy_onload (tarjay, ignore) {
	var anode = document.getElementById("plusmin-" + tarjay);
	var tnode = document.getElementById("expandy-" + tarjay);
	if(ignore != 1) {
		tnode.style.display = "none";
		if(anode) {
			anode.appendChild(document.createTextNode("+"));
			anode.removeChild(anode.firstChild);
		} // end if
	} // end if
} // end hide_expandy_onload

