/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.5.0 Beta 2
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2005 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

// define vbphrase if it doesn't already exist as an array
if (typeof vbphrase != 'object')
{
	var vbphrase = new Array();
}

// array of message editor objects
var vB_Editor = new Array();

// define a few variables that are required
var vbmenu_usepopups = false;
var ignorequotechars = 0;
var pagenavcounter = 0;

// array to store open attachment window references
var openmanage = new Array();

// lets define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac    = (userAgent.indexOf('mac') != -1);

// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

// let's find out what DOM functions we can use
var vbDOMtype = '';
if (document.getElementById)
{
	vbDOMtype = 'std';
}
else if (document.all)
{
	vbDOMtype = 'ie4';
}
else if (document.layers)
{
	vbDOMtype = 'ns4';
}

/**
* Workaround for heinous IE bug - add special vBlength property to all strings
*
* This method is applied to ALL string objects automatically
*
* @return	integer
*/
String.prototype.vBlength = function()
{
	return (is_ie && this.indexOf('\n') != -1) ? this.replace(/\r?\n/g, '_').length : this.length;
}

/**
* Legacy array items for IE < 5.5
*/
function array_pop(a)
{
	if (typeof a != 'object' || !a.length)
	{
		return null;
	}
	else
	{
		var response = a[a.length - 1];
		a.length--;
		return response;
	}
}

function array_push(a, value)
{
	a[a.length] = value;
	return a.length;
}

// #############################################################################
// function to emulate document.getElementById
function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

// #############################################################################
// function to emulate document.getElementsByTagName
function fetch_tags(parentobj, tag)
{
	if (typeof parentobj.getElementsByTagName != 'undefined')
	{
		return parentobj.getElementsByTagName(tag);
	}
	else if (parentobj.all && parentobj.all.tags)
	{
		return parentobj.all.tags(tag);
	}
	else
	{
		return null;
	}
}

// #############################################################################
// function to handle the different event models of different browsers
// and prevent event bubbling
function do_an_e(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

// #############################################################################
// another function to handle the different event models of different browsers
// and prevent event bubbling in a lesser way
function e_by_gum(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		if (eventobj.target.type == 'submit')
		{
			// naughty safari
			eventobj.target.form.submit();
		}
		eventobj.stopPropagation();
		return eventobj;
	}
}

// #############################################################################
// function to open a generic window
function openWindow(url, width, height)
{
	var dimensions = "";
	if (width)
	{
		dimensions += ",width=" + width;
	}
	if (height)
	{
		dimensions += ",height=" + height;
	}
	window.open(url, "vBPopup", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes" + dimensions);
	return false;
}

// #############################################################################
// function to open an IM Window
function imwindow(imtype, userid, width, height)
{
	return openWindow("sendmessage.php?" + SESSIONURL + "do=im&type=" + imtype + "&u=" + userid, width, height);
}

// #############################################################################
// function to send a MSN message
function SendMSNMessage(name)
{
	if (!is_ie)
	{
		alert(vbphrase["msn_functions_only_work_in_ie"]);
		return false;
	}
	else
	{
		MsgrObj.InstantMessage(name);
	}
}

// #############################################################################
// function to add a MSN Contact
function AddMSNContact(name)
{
	if (!is_ie)
	{
		alert(vbphrase["msn_functions_only_work_in_ie"]);
		return false;
	}
	else
	{
		MsgrObj.AddContact(0, name);
	}
}

// #############################################################################
// function to show list of posters in a thread
function who(threadid)
{
	return openWindow("misc.php?" + SESSIONURL + "do=whoposted&t=" + threadid, 230, 300);
}

// #############################################################################
// function to open the reputation window
function reputation(postid)
{
	window.open("reputation.php?" + SESSIONURL + "p=" + postid, "Reputation", "toolbar=no, scrollbars=yes, resizable=yes, width=400, height=241");
	return false;
}

// #############################################################################
function manageattachments(url, width, height, hash)
{
	if (typeof(openmanage[hash]) != 'undefined' && openmanage[hash].closed == false)
	{
		openmanage[hash].focus();
	}
	else
	{
		openmanage[hash] = window.open(url, "Attach" + hash, "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	}

	return false;
}

// #############################################################################
// function to do a single-line conditional
function iif(condition, trueval, falseval)
{
	return condition ? trueval : falseval;
}

function js_toggle_all(formobj, formtype, option, exclude, setto)
{
	for (var i =0; i < formobj.elements.length; i++)
	{
		var elm = formobj.elements[i];
		if (elm.type == formtype && PHP.in_array(elm.name, exclude, false) == -1)
		{
			switch (formtype)
			{
				case "radio":
					if (elm.value == option) // option == '' evaluates true when option = 0
					{
						elm.checked = setto;
					}
				break;
				case "select-one":
					elm.selectedIndex = setto;
				break;
				default:
					elm.checked = setto;
				break;
			}
		}
	}
}

function js_select_all(formobj)
{
	exclude = new Array();
	exclude[0] = "selectall";
	js_toggle_all(formobj, "select-one", '', exclude, formobj.selectall.selectedIndex);
}

function js_check_all(formobj)
{
	exclude = new Array();
	exclude[0] = "keepattachments";
	exclude[1] = "allbox";
	exclude[2] = "removeall";
	js_toggle_all(formobj, "checkbox", '', exclude, formobj.allbox.checked);
}

function js_check_all_option(formobj, option)
{
	exclude = new Array();
	exclude[0] = "useusergroup";
	js_toggle_all(formobj, "radio", option, exclude, true);
}

function checkall(formobj) // just an alias
{
	js_check_all(formobj);
}
function checkall_option(formobj, option) // just an alias
{
	js_check_all_option(formobj, option);
}

function validatemessage(messagetext, subjecttext, minchars)
{
	if (is_kon || is_saf || is_webtv)
	{
		// ignore less-than-capable browsers
		return true;
	}
	else if (subjecttext.length < 1)
	{
		// subject not specified
		alert(vbphrase['must_enter_subject']);
		return false;
	}
	else
	{
		var stripped = PHP.trim(stripcode(messagetext, false, ignorequotechars));

		if (stripped.length < minchars)
		{
			// minimum message length not met
			alert(construct_phrase(vbphrase['message_too_short'], minchars));
			return false;
		}
		else
		{
			// everything seems ok
			return true;
		}
	}
}

// #############################################################################
// function to trim quotes and vbcode tags
function stripcode(str, ishtml, stripquotes)
{
	if (!is_regexp)
	{
		return str;
	}

	if (stripquotes)
	{
		while ((startindex = PHP.stripos(str, '[quote')) !== false)
		{
			if ((stopindex = PHP.stripos(str, '[/quote]')) !== false)
			{
				fragment = str.substr(startindex, stopindex - startindex + 8);
				str = str.replace(fragment, '');
			}
			else
			{
				break;
			}
			str = PHP.trim(str);
		}
	}

	if (ishtml)
	{
		var html1 = new RegExp("<(\\w+)[^>]*>", "gi");
		var html2 = new RegExp("<\\/\\w+>", "gi");

		str = str.replace(html1, '');
		str = str.replace(html2, '');

		var html3 = new RegExp("(&nbsp;)", "gi");
		str = str.replace(html3, ' ');
	}
	else
	{
		var bbcode1 = new RegExp("\\[(\\w+)[^\\]]*\\]", "gi");
		var bbcode2 = new RegExp("\\[\\/(\\w+)\\]", "gi");

		str = str.replace(bbcode1, '');
		str = str.replace(bbcode2, '');
	}

	return str;
}

// #############################################################################
// emulation of the PHP version of vBulletin's construct_phrase() sprintf wrapper
function construct_phrase()
{
	if (!arguments || arguments.length < 1 || !is_regexp)
	{
		return false;
	}

	var args = arguments;
	var str = args[0];
	var re;

	for (var i = 1; i < args.length; i++)
	{
		re = new RegExp("%" + i + "\\$s", "gi");
		str = str.replace(re, args[i]);
	}
	return str;
}

// #############################################################################
// set control panel frameset title
function set_cp_title()
{
	if (typeof(parent.document) != "undefined" && typeof(parent.document) != "unknown" && typeof(parent.document.title) == "string")
	{
		if (document.title != '')
		{
			parent.document.title = document.title;
		}
		else
		{
			parent.document.title = "vBulletin";
		}
	}
}

// #############################################################################
// open control panel help window
function js_open_help(scriptname, actiontype, optionval)
{
	window.open("help.php?s=" + SESSIONHASH + "&do=answer&page=" + scriptname + "&pageaction=" + actiontype + "&option=" + optionval, "helpwindow", "toolbar=no,scrollbars=yes,resizable=yes,width=600,height=450");
}

// #############################################################################
function switch_id(selectobj, type)
{
	var id = selectobj.options[selectobj.selectedIndex].value;

	if (id == "")
	{
		return;
	}

	var url = new String(window.location);
	var fragment = new String("");

	// get rid of fragment
	url = url.split("#");

	// deal with the fragment first
	if (url[1])
	{
		fragment = "#" + url[1];
	}

	// deal with the main url
	url = url[0];

	// remove id=x& from main bit
	if (url.indexOf(type + "id=") != -1 && is_regexp)
	{
		re = new RegExp(type + "id=\\d+&?");
		url = url.replace(re, "");
	}

	// add the ? to the url if needed
	if (url.indexOf("?") == -1)
	{
		url += "?";
	}
	else
	{
		// make sure that we have a valid character to join our id bit
		lastchar = url.substr(url.length - 1);
		if (lastchar != "&" && lastchar != "?")
		{
			url += "&";
		}
	}
	window.location = url + type + "id=" + id + fragment;
}

// #############################################################################
// simple function to toggle the 'display' attribute of an object
function toggle_display(idname)
{
	obj = fetch_object(idname);
	if (obj)
	{
		if (obj.style.display == "none")
		{
			obj.style.display = "";
		}
		else
		{
			obj.style.display = "none";
		}
	}
	return false;
}

// #############################################################################
// ##################### vBulletin Cookie Functions ############################
// #############################################################################

// #############################################################################
// function to set a cookie
function set_cookie(name, value, expires)
{
	document.cookie = name + "=" + escape(value) + "; path=/" + (typeof expires != 'undefined' ? "; expires=" + expires.toGMTString() : '');
}

// #############################################################################
// function to retrieve a cookie
function fetch_cookie(name)
{
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (";", value_begin);
			if (value_end == -1)
			{
				value_end = cookie_length;
			}
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0)
		{
			break;
		}
	}
	return null;
}

// #############################################################################
// function to delete a cookie
function delete_cookie(name)
{
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// #############################################################################
// ################## vBulletin Collapse HTML Functions ########################
// #############################################################################

// #############################################################################
// function to toggle the collapse state of an object, and save to a cookie
function toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}

	obj = fetch_object("collapseobj_" + objid);
	img = fetch_object("collapseimg_" + objid);
	cel = fetch_object("collapsecel_" + objid);

	if (!obj)
	{
		// nothing to collapse!
		if (img)
		{
			// hide the clicky image if there is one
			img.style.display = "none";
		}
		return false;
	}

	if (obj.style.display == "none")
	{
		obj.style.display = "";
		save_collapsed(objid, false);
		if (img)
		{
			img_re = new RegExp("_collapsed\\.gif$");
			img.src = img.src.replace(img_re, '.gif');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
			cel.className = cel.className.replace(cel_re, '$1');
		}
	}
	else
	{
		obj.style.display = "none";
		save_collapsed(objid, true);
		if (img)
		{
			img_re = new RegExp("\\.gif$");
			img.src = img.src.replace(img_re, '_collapsed.gif');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)$");
			cel.className = cel.className.replace(cel_re, '$1_collapsed');
		}
	}
	return false;
}

// #############################################################################
// update vbulletin_collapse cookie with collapse preferences
function save_collapsed(objid, addcollapsed)
{
	var collapsed = fetch_cookie("vbulletin_collapse");
	var tmp = new Array();

	if (collapsed != null)
	{
		collapsed = collapsed.split("\n");

		for (var i in collapsed)
		{
			if (collapsed[i] != objid && collapsed[i] != "")
			{
				tmp[tmp.length] = collapsed[i];
			}
		}
	}

	if (addcollapsed)
	{
		tmp[tmp.length] = objid;
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	set_cookie("vbulletin_collapse", tmp.join("\n"), expires);
}

// #############################################################################
// this is deprecated, use vBmenu.register(controlid, noimage) instead
function vbmenu_register(controlid, noimage, datefield)
{
	if (typeof vBmenu == 'object')
	{
		vBmenu.register(controlid, noimage);
	}
}

// #############################################################################
// functions to handle active cells

// active cell mouse-over
function activecells_mouseover(e)
{
	this.className = this.swapclass;
	this.style.cursor = (is_ie) ? 'hand' : 'pointer';
	return true;
}

// active cell mouse-out
function activecells_mouseout(e)
{
	this.className = this.origclass;
	this.style.cursor = "default";
	return true;
}

// set an element and all its children to be 'unselectable'
function set_unselectable(obj)
{
	if (!is_ie4 && typeof obj.tagName != 'undefined')
	{
		if (obj.hasChildNodes())
		{
			for (var i = 0; i < obj.childNodes.length; i++)
			{
				set_unselectable(obj.childNodes[i]);
			}
		}
		obj.unselectable = 'on';
	}
}

// active cell click
function activecells_click(e)
{
	if (!is_regexp)
	{
		return;
	}
	var regex = new RegExp("/^([a-z]{1})([0-9]+)$/");
	this.className = this.origclass;
	var script = '';
	if (r = this.id.match(regex))
	{
		switch (r[1])
		{
			case "u": // user
				script = "member.php?" + SESSIONURL + "u=";
				break;

			case "f": // forum
				script = "forumdisplay.php?" + SESSIONURL + "f=";
				break;

			case "t": // thread
				script = "showthread.php?" + SESSIONURL + "t=";
				break;

			case "p": // post
				script = "showthread.php?" + SESSIONURL + "p=";
				break;

			case "m": // private message
				script = "private.php?" + SESSIONURL + "pmid=";
				break;

			default:
				return;
		}
		window.location = script + r[2];
	}
}

function global_menu_hide(e)
{
	if (e && e.button && e.button != 1 && e.type == 'click')
	{
		return true;
	}
	else
	{
		vBmenu.hide();
	}
}

// #############################################################################
// ############## Main vBulletin Javascript Initialization #####################
// #############################################################################

function vBulletin_init()
{
	if (is_webtv)
	{
		return true;
	}

	// set 'title' tags for image elements
	var imgs = fetch_tags(document, 'img');
	for (var i = 0; i < imgs.length; i++)
	{
		if (!imgs[i].title && imgs[i].alt != "")
		{
			imgs[i].title = imgs[i].alt;
		}
	}

	// do stuff with pagenav thingies
	var inputs = fetch_tags(document, 'input');
	for (var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].className == 'vbmenu_control')
		{
			inputs[i].onclick = function(e) { this.select(); };
			inputs[i].onkeypress = function(e) { e = e ? e : window.event; if (e.keyCode == 13) { window.location = window.location + '&page=' + this.value; return false; } };
		}
	}

	// finalize popup menus
	if (typeof vBmenu == 'object')
	{
		// close all menus on document click
		if (window.attachEvent && !is_saf)
		{
			document.attachEvent('onclick', global_menu_hide);
			window.attachEvent('onresize', global_menu_hide);
		}
		else if (document.addEventListener && !is_saf)
		{
			document.addEventListener('click', global_menu_hide, false);
			window.addEventListener('resize', global_menu_hide, false);
		}
		else
		{
			window.onclick = global_menu_hide;
			window.onresize = global_menu_hide;
		}

		// add popups to pagenav elements
		var pagenavs = fetch_tags(document, 'td');
		for (var n = 0; n < pagenavs.length; n++)
		{
			if (pagenavs[n].hasChildNodes() && pagenavs[n].firstChild.name && pagenavs[n].firstChild.name.indexOf('PageNav') != -1)
			{
				var addr = pagenavs[n].title;
				pagenavs[n].title = '';
				pagenavs[n].innerHTML = '';
				pagenavs[n].id = 'pagenav.' + n;
				var pn = vBmenu.register(pagenavs[n].id);
				if (is_saf)
				{
					pn.controlobj._onclick = pn.controlobj.onclick;
					pn.controlobj.onclick = function(e)
					{
						this._onclick(e);
						var inputs = fetch_tags(this.menu.menuobj, 'input');
						for (var i = 0; i < inputs.length; i++)
						{
							if (inputs[i].type == 'text')
							{
								inputs[i].focus();
								break;
							}
						}
					};
				}
			}
		}

		// process the pagenavs popup form
		if (typeof addr != 'undefined')
		{
			fetch_object('pagenav_form').gotopage   = function(e) { if ((pagenum = parseInt(fetch_object('pagenav_itxt').value, 10)) > 0) {	 window.location = addr + '&page=' + pagenum; } return false; };
			fetch_object('pagenav_ibtn').onclick    = function(e) { return this.form.gotopage(); };
			fetch_object('pagenav_itxt').onkeypress = function(e) { return ((e ? e : window.event).keyCode == 13 ? this.form.gotopage() : true); };
		}

		// activate the menu system
		vBmenu.activate(true);
	}

	return true;
}

// #############################################################################
// function to initialize active cells
function activecells_init()
{
	// hide this functionality from browsers that break it
	if (is_webtv || is_opera)
	{
		return;
	}

	// init active alt color classes
	tds = fetch_tags(document, 'td');
	for (var i = 0; i < tds.length; i++)
	{
		switch (tds[i].className)
		{
			case "alt1Active":
			case "alt2Active":
			{
				tds[i].origclass = tds[i].className;
				tds[i].swapclass = iif(tds[i].className == "alt1Active", "alt2Active", "alt1Active");
				tds[i].onmouseover = activecells_mouseover;
				tds[i].onmouseout = activecells_mouseout;
				tds[i].onclick = activecells_click;
			}
			break;
		}
	}
}

// #############################################################################
// vB_PHP_Emulator class
// #############################################################################

/**
* PHP Function Emulator Class
*/
function vB_PHP_Emulator()
{
}

// #############################################################################
// vB_PHP_Emulator Methods

/**
* Find a string within a string (case insensitive)
*
* @param	string	Haystack
* @param	string	Needle
* @param	integer	Offset
*
* @return	mixed	Not found: false / Found: integer position
*/
vB_PHP_Emulator.prototype.stripos = function(haystack, needle, offset)
{
	if (typeof offset == 'undefined')
	{
		offset = 0;
	}

	index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);

	return (index == -1 ? false : index);
}

/**
* Trims leading whitespace
*
* @param	string	String to trim
*
* @return	string
*/
vB_PHP_Emulator.prototype.ltrim = function(str)
{
	return str.replace(/^\s+/g, '');
}

/**
* Trims trailing whitespace
*
* @param	string	String to trim
*
* @return	string
*/
vB_PHP_Emulator.prototype.rtrim = function(str)
{
	return str.replace(/(\s+)$/g, '');
}

/**
* Trims leading and trailing whitespace
*
* @param	string	String to trim
*
* @return	string
*/
vB_PHP_Emulator.prototype.trim = function(str)
{
	return this.ltrim(this.rtrim(str));
}

/**
* Emulation of PHP's preg_quote()
*
* @param	string	String to process
*
* @return	string
*/
vB_PHP_Emulator.prototype.preg_quote = function(str)
{
	// replace + { } ( ) [ ] | / ? ^ $ \ . = ! < > : * with backslash+character
	return str.replace(/(\+|\{|\}|\(|\)|\[|\]|\||\/|\?|\^|\$|\\|\.|\=|\!|\<|\>|\:|\*)/g, "\\$1");
}

/**
* Emulates unhtmlspecialchars in vBulletin
*
* @param	string	String to process
*
* @return	string
*/
vB_PHP_Emulator.prototype.unhtmlspecialchars = function(str)
{
	f = new Array(/&lt;/g, /&gt;/g, /&quot;/g, /&amp;/g);
	r = new Array('<', '>', '"', '&');

	for (var i in f)
	{
		str = str.replace(f[i], r[i]);
	}

	return str;
}

/**
* Emulates PHP's htmlspecialchars()
*
* @param	string	String to process
*
* @return	string
*/
vB_PHP_Emulator.prototype.htmlspecialchars = function(str)
{
	//var f = new Array(/&(?!#[0-9]+;)/g, /</g, />/g, /"/g);
	var f = new Array(
		(is_mac && is_ie ? new RegExp('&', 'g') : new RegExp('&(?!#[0-9]+;)', 'g')),
		new RegExp('<', 'g'),
		new RegExp('>', 'g'),
		new RegExp('"', 'g')
	);
	var r = new Array(
		'&amp;',
		'&lt;',
		'&gt;',
		'&quot;'
	);

	for (var i = 0; i < f.length; i++)
	{
		str = str.replace(f[i], r[i]);
	}

	return str;
}

/**
* Searches an array for a value
*
* @param	string	Needle
* @param	array	Haystack
* @param	boolean	Case insensitive
*
* @return	integer	Not found: -1 / Found: integer index
*/
vB_PHP_Emulator.prototype.in_array = function(ineedle, haystack, caseinsensitive)
{
	var needle = new String(ineedle);

	if (caseinsensitive)
	{
		needle = needle.toLowerCase();
		for (var i in haystack)
		{
			if (haystack[i].toLowerCase() == needle)
			{
				return i;
			}
		}
	}
	else
	{
		for (var i in haystack)
		{
			if (haystack[i] == needle)
			{
				return i;
			}
		}
	}
	return -1;
}

/**
* Emulates PHP's strpad()
*
* @param	string	Text to pad
* @param	integer	Length to pad
* @param	string	String with which to pad
*
* @return	string
*/
vB_PHP_Emulator.prototype.str_pad = function(text, length, padstring)
{
	text = new String(text);
	padstring = new String(padstring);

	if (text.length < length)
	{
		padtext = new String(padstring);

		while (padtext.length < (length - text.length))
		{
			padtext += padstring;
		}

		text = padtext.substr(0, (length - text.length)) + text;
	}

	return text;
}

/**
* A sort of emulation of PHP's urlencode - not 100% the same, but accomplishes the same thing
*
* @param	string	String to encode
*
* @return	string
*/
vB_PHP_Emulator.prototype.urlencode = function(text)
{
	return escape(text).replace(/\+/g, "%2B");
}

/**
* Works a bit like ucfirst, but with some extra options
*
* @param	string	String with which to work
* @param	string	Cut off string before first occurence of this string
*
* @return	string
*/
vB_PHP_Emulator.prototype.ucfirst = function(str, cutoff)
{
	if (typeof cutoff != 'undefined')
	{
		var cutpos = str.indexOf(cutoff);
		if (cutpos > 0)
		{
			str = str.substr(0, cutpos);
		}
	}

	str = str.split(' ');
	for (var i = 0; i < str.length; i++)
	{
		str[i] = str[i].substr(0, 1).toUpperCase() + str[i].substr(1);
	}
	return str.join(' ');
}

// initialize the PHP emulator
var PHP = new vB_PHP_Emulator();

// #############################################################################
// vB_DblClick_Handler
// #############################################################################

var vB_DblClick_Timer = null;
var vB_DblClick_Obj = null;
var vB_DblClick_E = null;

/**
* Special Double-Click Handler
*/
function vB_DblClick_Handler(obj, callback)
{	
	if (typeof obj.onclick == 'function')
	{
		obj.singleclick = obj.onclick;
		obj.onclick = function(e)
		{			
			clearTimeout(vB_DblClick_Timer);
			vB_DblClick_Obj = this;
			vB_DblClick_E = e;
			vB_DblClick_Timer = setTimeout('vB_DblClick_Obj.singleclick(vB_DblClick_E)', 500);
			return false;
		};
	}
	else if (typeof obj.href != 'undefined')
	{
		obj.onclick = function(e)
		{
			clearTimeout(vB_DblClick_Timer);
			vB_DblClick_Timer = setTimeout("window.location = '" + this.href + "';", 500);
			return false;
		};
	}
	obj.dblclick_callback = callback;
	obj.ondblclick = function(e)
	{
		e = do_an_e(e);
		
		clearTimeout(vB_DblClick_Timer);
		this.dblclick_callback(e);
		
		return false;
	}
}

// #############################################################################
// vB_AJAX_Handler
// #############################################################################

/**
* XML Sender Class
*
* @param	boolean	Should connections be asyncronous?
*/
function vB_AJAX_Handler(async)
{
	/**
	* Should connections be asynchronous?
	*
	* @var	boolean
	*/
	this.async = async ? true : false;
}

// #############################################################################
// vB_AJAX_Handler methods

/**
* Initializes the XML handler
*
* @return	boolean	True if handler created OK
*/
vB_AJAX_Handler.prototype.init = function()
{
	try
	{
		this.handler = new XMLHttpRequest();
		return (this.handler.setRequestHeader ? true : false);
	}
	catch(e)
	{
		try
		{
			this.handler = new ActiveXObject('Microsoft.XMLHTTP');
			return true;
		}
		catch(e)
		{
			return false;
		}
	}
}

/**
* Detects if the browser is fully compatible
*
* @return	boolean
*/
vB_AJAX_Handler.prototype.is_compatible = function()
{
	if (is_ie && !is_ie4) { return true; }
	else if (XMLHttpRequest)
	{
		try { return XMLHttpRequest.prototype.setRequestHeader ? true : false; }
		catch(e)
		{
			try { var tester = new XMLHttpRequest(); return tester.setRequestHeader ? true : false; }
			catch(e) { return false; }
		}
	}
	else { return false; }
}

/**
* Checks if the system is ready
*
* @return	boolean	False if ready
*/
vB_AJAX_Handler.prototype.not_ready = function()
{
	return (this.handler.readyState && (this.handler.readyState < 4));
}

/**
* OnReadyStateChange event handler
*
* @param	function
*/
vB_AJAX_Handler.prototype.onreadystatechange = function(event)
{
	if (!this.handler)
	{
		this.init();
	}
	if (typeof event == 'function')
	{
		this.handler.onreadystatechange = event;
	}
	else
	{
		alert('XML Sender OnReadyState event is not a function');
	}
}

/**
* Sends data
*
* @param	string	Destination URL
* @param	string	Request Data
*
* @return	mixed	Return message
*/
vB_AJAX_Handler.prototype.send = function(desturl, datastream)
{
	if (!this.handler)
	{
		this.init();
	}
	if (!this.not_ready())
	{
		this.handler.open('POST', desturl, this.async);
		this.handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.handler.send(datastream);

		if (!this.async && this.handler.readyState == 4 && this.handler.status == 200)
		{
			return true;
		}
	}
	return false;
}

// we can check this variable to see if browser is AJAX compatible
var ajax_compatible = vB_AJAX_Handler.prototype.is_compatible();

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 18:23, Tue Jun 21st 2005
|| # CVS: $RCSfile: vbulletin_global.js,v $ - $Revision: 1.131 $
|| ####################################################################
\*======================================================================*/