var vbphrase = {
	"css_value_invalid" : "Ошибка: %1$s недопустимое значение для записи CSS.",
	"color_picker_not_ready" : "Менеджер цветов загружается, подождите..."
};

// set the active element for the color picker
var activeElementId = 0;

// set color picker to use continuous tones initially
var colorPickerType = 0;

// don't allow the picker to be opened until it's ready
var pickerReady = false;

// lookup table for colors
var colors = new Array("00", "33", "66", "99", "CC", "FF");

// special colors
var specialColors = new Array('#000000', '#333333', '#666666', '#999999', '#CCCCCC', '#FFFFFF', '#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF');

// #############################################################################
// initialize all color swatches on css edit page
function init_color_preview()
{
	if (typeof(numColors) != "undefined")
	{		
		for (var i = 0; i < numColors; i++)
		{
			preview_color(i);
		}
		
		if (colorPickerType != 0)
		{
			init_color_picker(colorPickerType);
		}
		
		pickerReady = true;
	}
}

// #############################################################################
// update the color preview swatch for the current input field
function preview_color(elm)
{
	var colorElement = fetch_object("color_" + elm);
	var previewElement = fetch_object("preview_" + elm);
	var cssRegExp = new RegExp(/url\(('|"|)((http:\/\/|\/)?)(.*)\1\)/i);
	
	if (is_transparent(colorElement.value))
	{
		previewElement.style.background = "none";
		previewElement.style.borderStyle = "dashed";
		previewElement.title = window.status = "";
	}
	else
	{
		var cssValue = colorElement.value;
		var matches;
		if (matches = colorElement.value.match(cssRegExp))
		{			
			if (matches[3] == "")
			{
				cssValue = colorElement.value.replace((matches[3] + matches[4]), (bburl + matches[3] + matches[4]));
			}
		}
		
		// try/catch requires a version 5 browser
		try
		{
			previewElement.style.background = cssValue;
			previewElement.style.borderStyle = "inset";
			previewElement.title = window.status = "";
		}
		catch(csserror)
		{
			previewElement.style.background = "url('../cpstyles/" + cpstylefolder + "/cp_help.gif') no-repeat center";
			previewElement.style.borderStyle = "dashed";
			//previewElement.title = window.status = "Error: '" + cssValue + "' is not a valid value for a CSS entry.";
			previewElement.title = window.status = construct_phrase(vbphrase["css_value_invalid"], cssValue);
		}
	}
}

// #############################################################################
// set the color of one swatch on the color picker
function set_swatch_color(x, y, color)
{
	fetch_object("sw" + x + "-" + y).style.backgroundColor = color;
}

// #############################################################################
// initialize the color picker
function init_color_picker(setPickerType)
{
	colorPickerType = setPickerType;
	fetch_object("colorPickerType").value = setPickerType;

	var y, x, i, j;

	// set up the first three columns if they are not used
	if (setPickerType < 2)
	{
		for (y = 0; y < 12; y++)
		{
			set_swatch_color(0, y, '#000000');
			set_swatch_color(1, y, specialColors[y]);
			set_swatch_color(2, y, '#000000');
		}
	}

	switch(setPickerType)
	{
		// --------------------------------------------------
		// continuous tones
		case 0:
		{
			green = new Array(5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5);
			blue = new Array(0, 0, 0, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0);
			
			for (y = 0; y < 12; y++)
			{
				for (x = 3; x < 21; x++)
				{
					r = Math.floor((20 - x) / 6) * 2 + Math.floor(y / 6);
					g = green[y];
					b = blue[x];
					
					set_swatch_color(x, y, "#" + colors[r] + colors[g] + colors[b]);
				}
			}
		}
		break;
		
		// --------------------------------------------------
		// color cubes
		case 1:
		{
			green = new Array(0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5);
			blue = new Array(0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5);
			
			for (y = 0; y < 12; y++)
			{
				for (x = 3; x < 21; x++)
				{
					r = Math.floor((x - 3) / 6) + Math.floor(y / 6) * 3;
					g = green[x];
					b = blue[y];
					
					set_swatch_color(x, y, "#" + colors[r] + colors[g] + colors[b]);
				}
			}
		}
		break;
		
		// --------------------------------------------------
		// greyscales
		case 2:
		{
			i = 255;
			j = -1;
			
			for (y = 0; y < 12; y++)
			{
				for (x = 0; x < 21; x++)
				{
					set_swatch_color(x, y, "rgb(" + i + "," + i + "," + i + ")");
					i--;
					if (i == 4)
					{
						i = 0;
					}
				}
			}
		}
		break;
		
		// --------------------------------------------------
		// reds / greens / blues / yellows / magentas / cyans
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		{
			i = 255;
			j = 255;
			
			for(y = 0; y < 12; y++)
			{
				for (x = 0; x < 21; x++)
				{
					acolor = Math.round(j);
					bcolor = Math.round(i);
					
					if (acolor < 0)
					{
						acolor = 0;
					}
					
					switch(setPickerType)
					{
						// reds
						case 3: r = acolor; g = bcolor; b = bcolor; break;
						// greens
						case 4: r = bcolor; g = acolor; b = bcolor; break;
						// blues
						case 5: r = bcolor; g = bcolor; b = acolor; break;
						// yellows
						case 6: r = acolor; g = acolor; b = bcolor; break;
						// magentas
						case 7: r = acolor; g = bcolor; b = acolor; break;
						// cyans
						case 8: r = bcolor; g = acolor; b = acolor; break;
					}
					
					set_swatch_color(x, y, "rgb(" + r + "," + g + "," + b + ")");
					
					if (i > 1)
					{
						i -= 2.03174;
					}
					else
					{
						i = 0;
						if (j > 1.03)
						{
							j -= 2.03174;
						}
					}
				}
			}
		}
		break;
		
		// --------------------------------------------------
		// default
		default: return false;
	}
	
	pickerReady = true;
	return true;
}

// #############################################################################
// switches picker type from continuous tone to color cubes and vice versa
function switch_color_picker(direction)
{
	if (direction > 0)
	{
		if (colorPickerType < 8)
		{
			colorPickerType++;
		}
		else
		{
			colorPickerType = 0;
		}
	}
	else
	{
		if (colorPickerType > 0)
		{
			colorPickerType--;
		}
		else
		{
			colorPickerType = 8;
		}
	}

	init_color_picker(colorPickerType);
}

// #############################################################################
// open the color picker popup
function open_color_picker(clickedElementId, e)
{
	if (is_saf)
	{
		return;
	}

	if (!pickerReady)
	{
		alert(vbphrase["color_picker_not_ready"]);
		return;
	}
	
	pickerElement = fetch_object("colorPicker");
	
	if (activeElementId == clickedElementId && pickerElement.style.display != "none")
	{
		pickerElement.style.display = "none";
	}
	else
	{		
		activeElementId = clickedElementId;
		colorElement = fetch_object("color_" + clickedElementId);
		previewElement = fetch_object("preview_" + clickedElementId);
		
		// initialize the preview swatches on the color picker
		fetch_object("oldColor").style.background = previewElement.style.background;
		fetch_object("newColor").style.background = previewElement.style.background;
		fetch_object("txtColor").value = colorElement.value;

		// workaround for internet explorer (no one else supports window.event)
		if (!e)
		{
			e = window.event;
		}

		// get the colorPicker's position
		if(typeof(e.pageX) == "number")
		{
			xpos = e.pageX;
			ypos = e.pageY;
		}
		else if (typeof(e.clientX) == "number")
		{
			xpos = e.clientX + document.documentElement.scrollLeft;
			ypos = e.clientY + document.documentElement.scrollTop;
		}
		
		// offset a little
		xpos += 10;
		ypos += 5;
		
		// reposition colorPicker if result of click + box width is off the page
		if ((xpos + colorPickerWidth) >= document.body.clientWidth)
		{
			xpos = document.body.clientWidth - colorPickerWidth - 5;
		}
		
		// set the colorPicker's position
		pickerElement.style.left = xpos + "px";
		pickerElement.style.top = ypos + "px";
		
		// show the colorPicker
		pickerElement.style.display = "";
	}
}

// #############################################################################
// closes the popup color picker
function close_color_picker()
{
	activeElementId = 0;
	fetch_object("colorPicker").style.display = "none";
}

function swatch_over(e)
{
	col_over(this);
}
function swatch_click(e)
{
	col_click(this);
}

// #############################################################################
// triggered by onmouseover for the color picker swatches
function col_over(element)
{
	color = fetch_hex_color(element.style.backgroundColor);
	fetch_object("newColor").style.background = color;
	fetch_object("txtColor").value = color;
}

// #############################################################################
// triggered by onclick for the color picker swatches
function col_click(element)
{
	if (element == "none")
	{
		color = "";
	}
	else
	{
		color = fetch_hex_color(element.style.backgroundColor);
	}
	
	fetch_object("color_" + activeElementId).value = color;
	preview_color(activeElementId);	
	close_color_picker();
}

// #############################################################################
// return a #012345 color value from the browser-returned color
function fetch_hex_color(color)
{
	if (color.substr(0, 1) == "r")
	{
		colorMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/i);
		for (var i = 1; i < 4; i++)
		{
			colorMatch[i] = parseInt(colorMatch[i]).toString(16);
			if (colorMatch[i].length < 2)
			{
				colorMatch[i] = "0" + colorMatch[i];
			}
		}
		color = "#" + (colorMatch[1] + colorMatch[2] + colorMatch[3]).toUpperCase();
	}
	
	return color.toUpperCase();
}

// ##############################################################################
// is the value blank/none/transparent ?
function is_transparent(value)
{
	if (value == "" || value == "none" || value == "transparent")
	{
		return true;
	}
	else
	{
		return false;
	}
}


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

// #############################################################################
// 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));

// 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";
}

// make an array to store cached locations of objects called by fetch_object
var vBobjects = new Array();

// #############################################################################
// function to emulate document.getElementById
function fetch_object(idname, forcefetch)
{
	if (forcefetch || typeof(vBobjects[idname]) == "undefined")
	{
		switch (vbDOMtype)
		{
			case "std":
			{
				vBobjects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4":
			{
				vBobjects[idname] = document.all[idname];
			}
			break;

			case "ns4":
			{
				vBobjects[idname] = document.layers[idname];
			}
			break;
		}
	}
	return vBobjects[idname];
}

// #############################################################################
// 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;
	}
}

// #############################################################################
// 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 + "&userid=" + userid, width, height);
}

// #############################################################################
// function to show list of posters in a thread
function who(threadid)
{
	return openWindow("misc.php?" + SESSIONURL + "do=whoposted&threadid=" + 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)
{
	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 to search an array for a value
function in_array(ineedle, haystack, caseinsensitive)
{
	var needle = new String(ineedle);

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

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 && 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 to check message length before form submission
function validatemessage(messageText, subjectText, minLength, maxLength, ishtml, tForm)
{
	// bypass Safari and Konqueror browsers with Javascript problems
	if (is_kon || is_saf || is_webtv)
	{
		return true;
	}

	// attempt to get a code-stripped version of the text
	var strippedMessage = stripcode(messageText, ishtml, ignorequotechars);

	// check for completed subject
	if (subjectText.length < 1)
	{
		alert(vbphrase["must_enter_subject"]);
		return false;
	}
	// check for minimum message length
	else if (strippedMessage.length < minLength)
	{
		alert(construct_phrase(vbphrase["message_too_short"], minLength));
		return false;
	}
	// everything seems okay
	else
	{
		return true;
	}
}

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

	if (stripquotes)
	{
		var quote1 = new RegExp("(\\[QUOTE\\])(.*)(\\[\\/QUOTE\\])", "gi");
		var quote2 = new RegExp("(\\[QUOTE=(&quot;|\"|\\'|)(.*)\\1\\])(.*)(\\[\\/QUOTE\\])", "gi");

		while(str.match(quote1))
		{
			str = str.replace(quote1, '');
		}

		while(str.match(quote2))
		{
			str = str.replace(quote2, '');
		}
	}

	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;");
		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_styleid(selectobj)
{
	var styleid = selectobj.options[selectobj.selectedIndex].value;

	if (styleid == "")
	{
		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 styleid=x& from main bit
	if (url.indexOf("styleid=") != -1 && is_regexp)
	{
		re = new RegExp("styleid=\\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 styleid bit
		lastchar = url.substr(url.length - 1);
		if (lastchar != "&" && lastchar != "?")
		{
			url += "&";
		}
	}
	window.location = url + "styleid=" + styleid + 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)
{
	if (!expires)
	{
		expires = new Date();
	}
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

// #############################################################################
// 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)
{
	var expireNow = new Date();
	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 (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);
}

// #############################################################################
// function to register a menu for later initialization
function vbmenu_register(controlid, nowrite, datefield)
{
	if (vbmenu_usepopups)
	{
		vbmenu_doregister(controlid, nowrite, datefield);
	}
}

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

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

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

// active cell click
function activecells_click(e)
{
	this.className = this.origclass;
	var script = '';
	if (r = this.id.match(/^([a-z]{1})([0-9]+)$/))
	{
		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];
	}
}

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

function vBulletin_init()
{
	if (is_webtv)
	{
		return true;
	}
	var imgs = null;
	switch (vbDOMtype)
	{
		case "std": imgs = document.getElementsByTagName("img"); break;
		case "ie4": imgs = document.all.tags("img");             break;
		default:    imgs = false;                                break;
	}
	if (imgs)
	{
		// set 'title' tags for image elements
		for (var i = 0; i < imgs.length; i++)
		{
			if (!imgs[i].title && imgs[i].alt != "")
			{
				imgs[i].title = imgs[i].alt;
			}
		}
	}

	// init registered menus
	if (vbmenu_usepopups && vbmenu_registered.length > 0)
	{
		for (i in vbmenu_registered)
		{
			vbmenu_init(vbmenu_registered[i]);
		}

		// close all menus on mouse click
		document.onclick = vbmenu_close;
	}
	
	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 = document.getElementsByTagName("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;
		}
	}
}