/******************************************************************************
  Crossday Discuz! Board - Common Modules for Discuz!
  Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
*******************************************************************************/

var sPop = null;
var postSubmited = false;

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

function ctlent(event) {
	if(postSubmited == false && (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83) && $('postsubmit')) {
		if(in_array($('postsubmit').name, ['topicsubmit', 'replysubmit', 'editsubmit']) && !validate($('postform'))) {
			return;
		}
		postSubmited = true;
		$('postsubmit').disabled = true;
		$('postform').submit();
	}
}

function storeCaret(textEl){
	if(textEl.createTextRange){
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}

function checkall(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.elements[checkall].checked;
		}
	}
}

function arraypop(a) {
	if(typeof a != 'object' || !a.length) {
		return null;
	} else {
		var response = a[a.length - 1];
		a.length--;
		return response;
	}
}

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


function findtags(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 copycode(obj) {
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

function toggle_collapse(objname, unfolded) {
	if(typeof unfolded == 'undefined') {
		var unfolded = 1;
	}
	var obj = $(objname);
	var oldstatus = obj.style.display;
	var collapsed = getcookie('discuz_collapse');
	var cookie_start = collapsed ? collapsed.indexOf(objname) : -1;
	var cookie_end = cookie_start + objname.length + 1;

	obj.style.display = oldstatus == 'none' ? '' : 'none';
	collapsed = cookie_start != -1 && ((unfolded && oldstatus == 'none') || (!unfolded && oldstatus == '')) ?
			collapsed.substring(0, cookie_start) + collapsed.substring(cookie_end, collapsed.length) : (
			cookie_start == -1 && ((unfolded && oldstatus == '') || (!unfolded && oldstatus == 'none')) ?
			collapsed + objname + ' ' : collapsed);

	expires = new Date();
	expires.setTime(expires.getTime() + (collapsed ? 86400 * 30 : -(86400 * 30 * 1000)));
	document.cookie = 'discuz_collapse=' + escape(collapsed) + '; expires=' + expires.toGMTString() + '; path=/';

	var img = $(objname + '_img');
	var img_regexp = new RegExp((oldstatus == 'none' ? '_yes' : '_no') + '\\.gif$');
	var img_re = oldstatus == 'none' ? '_no.gif' : '_yes.gif'
	if(img) {
		img.src = img.src.replace(img_regexp, img_re);
	}
}

function imgzoom(o) {
	if(event.ctrlKey) {
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0) {
			o.style.zoom = zoom + '%';
		}
		return false;
	} else {
		return true;
	}
}

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function AddText(txt) {
	obj = $('postform').message;
	selection = document.selection;
	checkFocus();
	if(typeof(obj.selectionStart) != 'undefined') {
		var opn = obj.selectionStart + 0;
		obj.value = obj.value.substr(0, obj.selectionStart) + txt + obj.value.substr(obj.selectionEnd);
	} else if(selection && selection.createRange) {
		var sel = selection.createRange();
		sel.text = txt;
		sel.moveStart('character', -mb_strlen(txt));
	} else {
		obj.value += txt;
	}
}

function insertAtCaret (textEl,	text){
	if(textEl.createTextRange && textEl.caretPos){
		var caretPos = textEl.caretPos;
		caretPos.text += caretPos.text.charAt(caretPos.text.length - 2)	== ' ' ? text +	' '	: text;
	} else if(textEl) {
		textEl.value +=	text;
	} else {
		textEl.value = text;
	}
}

function checkFocus() {
	var obj = typeof wysiwyg == 'undefined' || !wysiwyg ? $('postform').message : editwin;
	if(!obj.hasfocus) {
		obj.focus();
	}
}

function closesmiliewindow(e) {
	if(typeof smiliewindow != 'undefined' && !smiliewindow.closed) {
		smiliewindow.close();
	}
}

function opensmiliewindow(width, height, editorid) {
	smiliewindow = window.open('post.php?action=smilies' + (editorid ? '&editorid=' + editorid : ''), 'Popup', 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes');
	window.onunload = closesmiliewindow;
}

function mb_strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function insertSmiley(smilieid) {
	checkFocus();
	var src = $('smilie_' + smilieid).src;
	var code = $('smilie_' + smilieid).pop ? $('smilie_' + smilieid).pop : $('smilie_' + smilieid).alt;
	if(typeof wysiwyg != 'undefined' && wysiwyg && allowsmilies && (!$('smileyoff') || $('smileyoff').checked == false)) {
		if(is_moz) {
			applyFormat('InsertImage', false, src);
			var smilies = findtags(editdoc.body, 'img');
			for(var i = 0; i < smilies.length; i++) {
				if(smilies[i].src == src && smilies[i].getAttribute('smilieid') < 1) {
					smilies[i].setAttribute('smilieid', smilieid);
					smilies[i].setAttribute('border', "0");
				}
			}
		} else {
			insertText('<img src="' + src + '" border="0" smilieid="' + smilieid + '" alt="" /> ', false);
		}
	} else {
		code += ' ';
		AddText(code);
	}
}

function announcement() {
	$('announcement').innerHTML = '<marquee style="filter:progid:DXImageTransform.Microsoft.Alpha(startX=0, startY=0, finishX=10, finishY=100,style=1,opacity=0,finishOpacity=100); margin: 0px 8px" direction="left" scrollamount="2" scrolldelay="1" onMouseOver="this.stop();" onMouseOut="this.start();">' +
		$('announcement').innerHTML + '</marquee>';
	$('announcement').style.display = 'block';
}

function $(id) {
	return document.getElementById(id);
}

function in_array(needle, haystack) {
	if(typeof needle == 'string') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}

document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText { font-family: Tahoma, Verdana; background-color: #FFFFCC; border: 1px #000000 solid; color: black; font-size: 12px; padding-right: 4px; padding-left: 4px; line-height: 18px; padding-top: 2px; padding-bottom: 2px; visibility: hidden; filter: Alpha(Opacity=80)}");

document.write("</style>");
document.write("<div id='popLayer' style='position:absolute;z-index:1000' class='cPopText'></div>");

function showPopupText(event) {
	if(event.srcElement) o = event.srcElement; else o = event.target;
	if(!o) {
		return;
	}
	MouseX = event.clientX;
	MouseY = event.clientY;
	if(o.alt != null && o.alt != '') {
		o.pop = o.alt;
		o.alt = '';
	}
	if(o.title != null && o.title != '') {
		o.pop = o.title;
		o.title = '';
	}
	if(o.pop != sPop) {
		sPop = o.pop;
		if(sPop == null || sPop == '') {
			$('popLayer').style.visibility = "hidden";
		} else {
			popStyle = o.dyclass != null ? o.dyclass : 'cPopText';
			$('popLayer').style.visibility = "visible";
			showIt();
		}
	}
}

function showIt() {
	$('popLayer').className = popStyle;
	$('popLayer').innerHTML = sPop.replace(/<(.*)>/g,"&lt;$1&gt;").replace(/\n/g,"<br>");
	var popWidth = $('popLayer').clientWidth;
	var popHeight = $('popLayer').clientHeight;
	var popLeftAdjust = MouseX + 12 + popWidth > document.body.clientWidth ? -popWidth - 24 : 0;
	var popTopAdjust = MouseY + 12 + popHeight > document.body.clientHeight ? -popHeight - 24 : 0;
	$('popLayer').style.left = (MouseX + 12 + document.body.scrollLeft + popLeftAdjust) + 'px';
	$('popLayer').style.top = (MouseY + 12 + document.body.scrollTop + popTopAdjust) + 'px';
}

function signature(obj) {
	if(obj.style.maxHeightIE != '') {
		var height = (obj.scrollHeight > parseInt(obj.style.maxHeightIE)) ? obj.style.maxHeightIE : obj.scrollHeight;
		obj.style.maxHeightIE = '';
		return height;
	}
}

if(!document.onmouseover) {
	document.onmouseover = function(e) {
		var event = e ? e : window.event;
		showPopupText(event);
	};
}

var languagemenustatus = false;

function languageRollover () {
	var languageArrow = document.getElementById('languagearrow');
	var languageTxt= document.getElementById('languagetxt');
	if( !languagemenustatus ) {
		if( languageArrow.className == 'languagearrowdefault' ) {
			languageArrow.className = 'languagearrowrollover';
			languageTxt.className = 'languagetxtrollover';
		} else {
			languageArrow.className = 'languagearrowdefault';
			languageTxt.className = 'languagetxtdefault';
		}
	}
	return true;
}

function toggleLanguageMenu() {
	var languageMenu = document.getElementById('languagemenu');
	var languageArrow = document.getElementById('languagearrow');
	var languageTxt= document.getElementById('languagetxt');
	if( languageMenu.style.display == 'none' ) {
		languageMenu.style.display = 'block';
		languageArrow.className = 'languagearrowonclick';
		languageTxt.className = 'languagetxtonclick';
		languagemenustatus = true;		
	} else {
		languageMenu.style.display = 'none';
		languageArrow.className = 'languagearrowrollover';
		languageTxt.className = 'languagetxtrollover';
		languagemenustatus = false;
	}
	return true;
}

function barRollover (id) {
	var elementId = document.getElementById(id);
	if( id == 'tabhelp' ) {
		if( elementId.className == 'tabhelpdefault' ) {
			elementId.className = 'tabhelprollover';
		} else {
			elementId.className = 'tabhelpdefault';
		}
	} else {
		if( elementId.className == 'tabdefault' ) {
			elementId.className = 'tabrollover';
		} else {
			elementId.className = 'tabdefault';
		}
	}
	return true;
}

var searchmenustatus = false;
function searchRollover (id) {
	var elementId = document.getElementById(id);
	if( !searchmenustatus ) {
		if( elementId.className == id+'default' ) {
			elementId.className = id+'rollover';
		} else {
			elementId.className = id+'default';
		}
	}
	return true;
}
function toggleSearchMenu() {
	var searchMenu = document.getElementById('searchmenu');
	var searchArrow = document.getElementById('searcharrow');
	var searchTxt= document.getElementById('searchtxt');
	if( searchMenu.style.display == 'none' ) {
		searchMenu.style.display = 'block';
		searchArrow.className = 'searcharrowonclick';
		searchTxt.className = 'searchtxtonclick';
		searchmenustatus = true;
	} else {
		searchMenu.style.display = 'none';
		searchArrow.className = 'searcharrowrollover';
		searchTxt.className = 'searchtxtdefault';
		searchmenustatus = false;
	}
	return true;
}
function selectSearchMenu( id ) {
	var itemSearch = document.getElementById('itemsearchdefault');
	var itemUsers = document.getElementById('itemsearchusers');
	var itemBlog = document.getElementById('itemsearchblog');
	var itemForum = document.getElementById('itemsearchforum');
	var selectUsers = document.getElementById('selectsearchusers');
	var selectBlog = document.getElementById('selectsearchblog');
	var selectForum = document.getElementById('selectsearchforum');
	var formUsers = document.getElementById('usersearch');
	var formBlog = document.getElementById('messagesearch');
	var formForum = document.getElementById('forumsearch');
	var searchMenu = document.getElementById('searchmenu');
	var searchArrow = document.getElementById('searcharrow');
	var searchTxt= document.getElementById('searchtxt');
	if( id == 'users' ) {
		itemUsers.style.display = 'block';
		itemSearch.style.display = itemBlog.style.display = itemForum.style.display = 'none';
		selectUsers.style.fontWeight = 'bold';
		selectBlog.style.fontWeight = selectForum.style.fontWeight = 'normal';
		formUsers.value = 1;
		formBlog.value = formForum.value = 0;
	} else if( id == 'blog' ) {
		itemBlog.style.display = 'block';
		itemSearch.style.display = itemUsers.style.display = itemForum.style.display = 'none';
		selectBlog.style.fontWeight = 'bold';
		selectUsers.style.fontWeight = selectForum.style.fontWeight = 'normal';
		formBlog.value = 1;
		formUsers.value = formForum.value = 0;
	} else {
		itemForum.style.display = 'block';
		itemSearch.style.display = itemUsers.style.display = itemBlog.style.display = 'none';
		selectForum.style.fontWeight = 'bold';
		selectUsers.style.fontWeight = selectBlog.style.fontWeight = 'normal';
		formForum.value = 1;
		formUsers.value = formBlog.value = 0;
	}
	searchMenu.style.display = 'none';
	searchArrow.className = 'searcharrowdefault';
	searchTxt.className = 'searchtxtdefault';
	searchmenustatus = false;
	return true;
}

var menuslidetimer = null;

function Popup_Handler() {
	this.open_steps = 2;
	this.open_fade = false;
	this.active = false;
	this.menus = new Array();
	this.activemenu = null;
	this.hidden_selects = new Array();

	this.activate = function(active) {
		this.active = active;
	}

	this.register = function(clickactive, controlkey, noimage) {
		this.menus[controlkey] = new Popup_Menu(clickactive, controlkey, noimage);
		return this.menus[controlkey];
	}

	this.hide = function() {
		if(this.activemenu != null) this.menus[this.activemenu].hide();
	}
}

function Popup_Events() {
	this.controlobj_show = function(e) {
		doane(e);
		clearTimeout(this.slidetimer);
		if(popupmenu.activemenu == null || popupmenu.menus[popupmenu.activemenu].controlkey != this.id)	{popupmenu.menus[this.id].show(this, false, popupmenu.menus[this.id].clickactive);}
	}

	this.controlobj_onclick = function(e) {
		doane(e);
		if(popupmenu.activemenu == null || popupmenu.menus[popupmenu.activemenu].controlkey != this.id)	{popupmenu.menus[this.id].show(this, false, popupmenu.menus[this.id].clickactive);}
		else {popupmenu.menus[this.id].hide();}
	}

	this.controlobj_onmouseover = function(e) {
		doane(e);
		popupmenu.menus[this.id].hover(this);
	}

	this.menuoption_onclick_function = function(e) {
		this.ofunc(e);
		popupmenu.menus[this.controlkey].hide();
	}

	this.menuoption_onclick_link = function(e) {
		popupmenu.menus[this.controlkey].choose(e, this);
	}

	this.menuoption_onmouseover = function(e) {
		this.className = 'popupmenu_highlight';
	}

	this.menuoption_onmouseout = function(e) {
		this.className = 'popupmenu_option';
	}
}

popupmenu = new Popup_Handler();
popupevents = new Popup_Events();

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

function Popup_Menu(clickactive, controlkey, noimage) {
	this.controlkey = controlkey;
	this.clickactive = clickactive;
	this.menuname = this.controlkey.split('.')[0] + '_menu';
	if($(this.menuname)) {this.init_menu(clickactive);}
	this.slide_open = (is_opera ? false : true);
	this.open_steps = popupmenu.open_steps;

	this.init_control = function(noimage) {
		this.controlobj = $(this.controlkey);
		this.controlobj.state = false;
		if(this.controlobj.firstChild && (this.controlobj.firstChild.tagName == 'TEXTAREA' || this.controlobj.firstChild.tagName == 'INPUT')) {
		} else {
			if(!this.clickactive && !noimage && !(is_mac && is_ie)) {
				var img = document.createElement('img');
				img.src = 'images/common/jsmenu.gif';
				img.border = 0;
				img.title = '';
				img.alt = '';
				this.controlobj.appendChild(img);
			}
			this.controlobj.unselectable = true;
			if(!noimage) {
				this.controlobj.style.cursor = is_ie ? 'hand' : 'pointer';
			}
			if(clickactive) {
				this.controlobj.onclick = popupevents.controlobj_onclick;
				this.controlobj.onmouseover = popupevents.controlobj_onmouseover;
			} else {
				this.controlobj.onmouseover = popupevents.controlobj_show;
			}
		}
	}

	this.init_control( noimage);

	this.init_menu = function() {
		this.menuobj = $(this.menuname);
		if(this.menuobj && !this.menuobj.initialized) {
			this.menuobj.initialized = true;
			this.menuobj.onclick = ebygum;
			this.menuobj.style.position = 'absolute';
			if(!this.clickactive) {
				this.menuobj.onmouseover = function() {
					clearTimeout(menuslidetimer);
				}
				this.menuobj.onmouseout = function() {
					menuslidetimer = setTimeout("menuhide()",500);
				}
			}
			this.menuobj.style.zIndex = 50;
			if(is_ie && !is_mac) {
				this.menuobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#CCCCCC,strength=2)";
			}
			this.init_menu_contents();
		}
	}

	this.init_menu_contents = function() {
		var tds = findtags(this.menuobj, 'td');
		for(var i = 0; i < tds.length; i++) {
			if(tds[i].className == 'popupmenu_option' || tds[i].className == 'editor_colornormal') {
				if(is_ie && !is_mac) {
					tds[i].style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=85,finishOpacity=100,style=0)";
				}
				tds[i].style.opacity = 0.85;
				if(tds[i].title && tds[i].title == 'nohighlight') {
					tds[i].title = '';
				} else {
					tds[i].controlkey = this.controlkey;
					if(tds[i].className != 'editor_colornormal') {
						tds[i].onmouseover = popupevents.menuoption_onmouseover;
						tds[i].onmouseout = popupevents.menuoption_onmouseout;
					}
					if(typeof tds[i].onclick == 'function') {
						tds[i].ofunc = tds[i].onclick;
						tds[i].onclick = popupevents.menuoption_onclick_function;
					} else {
						tds[i].onclick = popupevents.menuoption_onclick_link;
					}
					if(!is_saf && !is_kon)	{
						try {
							links = findtags(tds[i], 'a');
							for(var j = 0; j < links.length; j++) {
								if(typeof links[j].onclick  == 'undefined') links[j].onclick = ebygum;
							}
						}
						catch(e) {}
					}
				}
			}
		}
	}

	this.show = function(obj, instant) {
		if(!popupmenu.active){return false;}
		else if(!this.menuobj)	{this.init_menu();}
		if(!this.menuobj) {return false;}
		if(popupmenu.activemenu != null) {popupmenu.menus[popupmenu.activemenu].hide();}
		popupmenu.activemenu = this.controlkey;
		this.menuobj.style.display = '';
		if(popupmenu.slide_open) {this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';}
		this.pos = this.fetch_offset(obj);
		this.leftpx = this.pos['left'];
		this.toppx = this.pos['top'] + obj.offsetHeight;
		if((this.leftpx + this.menuobj.offsetWidth) >= document.body.clientWidth && (this.leftpx + obj.offsetWidth - this.menuobj.offsetWidth) > 0) {
			this.leftpx = this.leftpx + obj.offsetWidth - this.menuobj.offsetWidth;
			this.direction = 'right';
		} else {this.direction = 'left';}
		this.menuobj.style.left = this.leftpx + 'px';
		this.menuobj.style.top  = this.toppx + 'px';
		if(!instant && this.slide_open) {
			this.intervalX = Math.ceil(this.menuobj.offsetWidth / this.open_steps);
			this.intervalY = Math.ceil(this.menuobj.offsetHeight / this.open_steps);
			this.slide((this.direction == 'left' ? 0 : this.menuobj.offsetWidth), 0, 0);
		} else if(this.menuobj.style.clip && popupmenu.slide_open) {
			this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';
		}
		this.handle_overlaps(true);
		if(this.menuobj.scrollHeight > 400) {
			this.menuobj.style.height = '400px';
			if(is_ie || is_opera) {
				this.menuobj.style.width = this.menuobj.scrollWidth + 18;
			}
			if(is_opera) {
				this.menuobj.style.overflow = 'scroll';
			} else {
				this.menuobj.style.overflowY = 'scroll';
			}
		}
	}

	this.hide = function(e) {
		if(e && e.button && e.button != 1) {return true;}
		this.stop_slide();
		this.menuobj.style.display = 'none';
		this.handle_overlaps(false);
		popupmenu.activemenu = null;
	}

	this.slidehide = function() {
		popupmenu.menus[popupmenu.activemenu].hide()
	}

	this.hover = function(obj, clickactive) {
		if(popupmenu.activemenu != null) {
			if(popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {this.show(obj, true, clickactive);}
		}
	}

	this.choose = function(e, obj) {
		var links = findtags(obj, 'a');
		if(links[0]) {
			if(is_ie) {
				links[0].click();
				window.event.cancelBubble = true;
			} else {
				if(e.shiftKey) {
					window.open(links[0].href);
					e.stopPropagation();
					e.preventDefault();
				} else {
					window.location = links[0].href;
					e.stopPropagation();
					e.preventDefault();
				}
			}
			this.hide();
		}
	}

	this.slide = function(clipX, clipY, opacity) {
		if(this.direction == 'left' && (clipX < this.menuobj.offsetWidth || clipY < this.menuobj.offsetHeight)) {
			if(popupmenu.open_fade && is_ie) {
				opacity += 10;
				this.menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
			}
			clipX += this.intervalX;
			clipY += this.intervalY;
			this.menuobj.style.clip = "rect(auto, " + clipX + "px, " + clipY + "px, auto)";
			this.slidetimer = setTimeout("popupmenu.menus[popupmenu.activemenu].slide(" + clipX + ", " + clipY + ", " + opacity + ");", 0);
		} else if(this.direction == 'right' && (clipX > 0 || clipY < this.menuobj.offsetHeight)) {
			if(popupmenu.open_fade && is_ie) {
				opacity += 10;
				menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
			}
			clipX -= this.intervalX;
			clipY += this.intervalY;
			this.menuobj.style.clip = "rect(auto, " + this.menuobj.offsetWidth + "px, " + clipY + "px, " + clipX + "px)";
			this.slidetimer = setTimeout("popupmenu.menus[popupmenu.activemenu].slide(" + clipX + ", " + clipY + ", " + opacity + ");", 0);
		} else {this.stop_slide();}
	}

	this.stop_slide = function() {
		clearTimeout(this.slidetimer);
		this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';
		if(popupmenu.open_fade && is_ie) {this.menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = 100;}
	}

	this.fetch_offset = function(obj) {
		var left_offset = obj.offsetLeft;
		var top_offset = obj.offsetTop;
		while ((obj = obj.offsetParent) != null) {
			left_offset += obj.offsetLeft;
			top_offset += obj.offsetTop;
		}
		return { 'left' : left_offset, 'top' : top_offset };
	}

	this.overlaps = function(obj, m) {
		var s = new Array();
		var pos = this.fetch_offset(obj);
		s['L'] = pos['left'];
		s['T'] = pos['top'];
		s['R'] = s['L'] + obj.offsetWidth;
		s['B'] = s['T'] + obj.offsetHeight;
		if(s['L'] > m['R'] || s['R'] < m['L'] || s['T'] > m['B'] || s['B'] < m['T']) {return false;}
		return true;
	}

	this.handle_overlaps = function(dohide) {
		if(is_ie) {
			var selects = findtags(document, 'select');
			if(dohide) {
				var menuarea = new Array(); menuarea = {
					'L' : this.leftpx,
					'R' : this.leftpx + this.menuobj.offsetWidth,
					'T' : this.toppx,
					'B' : this.toppx + this.menuobj.offsetHeight
				};
				for(var i = 0; i < selects.length; i++) {
					if(this.overlaps(selects[i], menuarea)) {
						var hide = true;
						var s = selects[i];
						while (s = s.parentNode) {
							if(s.className == 'popupmenu_popup') {
								hide = false;
								break;
							}
						}
						if(hide) {
							selects[i].style.visibility = 'hidden';
							arraypush(popupmenu.hidden_selects, i);
						}
					}
				}
			} else {
				while (true) {
					var i = arraypop(popupmenu.hidden_selects);
					if(typeof i == 'undefined' || i == null) break;
					else selects[i].style.visibility = 'visible';
				}
			}
		}
	}
}

function doane(eventobj) {
	if(!eventobj || is_ie)	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	} else {
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

function ebygum(eventobj) {
	if(!eventobj || is_ie) {
		window.event.cancelBubble = true;
		return window.event;
	} else {
		if(eventobj.target.type == 'submit')  eventobj.target.form.submit();
		eventobj.stopPropagation();
		return eventobj;
	}
}

function menuregister(clickactive, controlid, noimage, datefield) {
	if(typeof popupmenu == 'object') {
		popupmenu.register(clickactive, controlid, noimage);
	}
}

function menuhide() {
	if(popupmenu.activemenu != null) {
		popupmenu.menus[popupmenu.activemenu].slidehide();
	}
}

if(typeof popupmenu == 'object') {
	if(window.attachEvent && !is_saf) {
		document.attachEvent('onclick', popupmenu_hide);
		window.attachEvent('onresize', popupmenu_hide);
	} else if(document.addEventListener && !is_saf) {
		document.addEventListener('click', popupmenu_hide, false);
		window.addEventListener('resize', popupmenu_hide, false);
	} else {
		window.onclick = popupmenu_hide;
		window.onresize = popupmenu_hide;
	}
	popupmenu.activate(true);
}

// STEPHEN: START OF CHANGES
// Add in DHTML/JS-based rollover menus
function showSubMenu() {
	var objThis = this;

	for(var i = 0; i  < objThis.childNodes.length; i++) {
		if(objThis.childNodes.item(i).nodeName == "UL") {
			objThis.childNodes.item(i).style.display = "block";	
		}
	}
}

function hideSubMenu()
{						
	var objThis = this;

	for(var i = 0; i  < objThis.childNodes.length; i++) {
		if(objThis.childNodes.item(i).nodeName == "UL") {
			objThis.childNodes.item(i).style.display = "none";
			return;
		}
	}
}

function registerMenu( elementName ) {
	var elementObj = document.getElementById(elementName);
	var objLICollection = elementObj.getElementsByTagName("LI");
	for(var i = 0; i < objLICollection.length; i++) {
		var objLI = objLICollection[i];
		for(var j = 0; j  < objLI.childNodes.length; j++) {
			if(objLI.childNodes.item(j).nodeName == "UL") {
				objLI.onmouseover=showSubMenu;
				objLI.onmouseout=hideSubMenu;
		
				for(var j = 0; j  < objLI.childNodes.length; j++) {
					if(objLI.childNodes.item(j).nodeName == "A") {
						objLI.childNodes.item(j).className = "hassubmenu";
					}
				}
			}
		}
	}
}
// STEPHEN: END OF CHANGES