// update this when you make edits!
var version_scripts = 3

var navoldclassname = "";
var navoldcolor = "";
var isIexplore = true;
var isCritTextAdded = false;
var isCritSaved = false;

var servScript = null;
var servScriptFwd = "";
var servResponse = "";
var pX = 0;
var pY = 0;
var hoverUrl = "";
var hoverTimer = 0;
var hoverWidth = 400;
var ttHideTimer = 0;
var isWinIE = navigator.userAgent.indexOf("pera") < 0 && navigator.userAgent.indexOf("MSIE") >= 0 && navigator.platform == "Win32" && navigator.userAgent.indexOf("MSIE 7") < 0;

var isSpellChecking = false;

var quicktextElement = null;

var mousePosX = 0
var mousePosY = 0

function BookSetStatus(id, asin, status)
{
	window.frames["worker"].location.href = 'worker_library.asp?action=setstatus&id='+id+'&asin='+asin+'&status='+status;
}

function BookRemove(id)
{
	window.frames["worker"].location.href = 'worker_library.asp?action=removebook&id='+id;
}

function DefaultImg(what)
{
	if (what.src != 'images/def.png')
		what.src = 'images/def.png'
}

function UserListEntry(id, name, ishidden, ishelper)
{
	mr = ""
	if (ishelper > 0)
		mr = ' style="color:119533; font-weight:bold;" title="This member can help you if you\'re having problems"'
	else if (ishidden > 0)
		mr = ' style="color:gray;"'
	document.write('<a '+mr+'class=hoverlink OnMouseOver="HoverInfo(this, '+id+', 1);" OnMouseOut="StopInfo(this);" href="members.asp?lookup='+id+'">'+name+'</a><br>')
}

function OutDB(txt)
{
	//window.frames["worker"].document.write(txt + '<br>');
}

function DoOnUnload()
{	}

function ToggleHiddenNext(what)
{
	d = what.nextSibling;
	if (d.style.display == 'inline')
		d.style.display = 'none';
	else
		d.style.display = 'inline';
}

function correctPNG() 
   {
   

   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
if (isWinIE) window.attachEvent("onload", correctPNG);

function Working()
{
	var t = document.getElementById('g_tt');
	if (t != null) {
		t.innerHTML = '<center style="padding:5px;" class=LargeText>Working...</center>';
		t.style.left = "10px";
		t.style.top = "10px";
		t.style.display = "block";
		t.style.width = "100px";
	}
}

function ClearBuddy(what, id)
{
	what.parentNode.parentNode.style.display = "none";
	window.frames["worker"].location.href = 'worker_buddy.asp?action=dismiss&id='+id;
}
/*
	These functions handle various worker processes
*/

function HideGlobalTooltip()
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	t.style.display = "none";
	t.innerHTML = '';
}

function OverTT(isit)
{
	if (isit) {
		if (ttHideTimer > 0) {
			clearTimeout(ttHideTimer);
			ttHideTimer = 0;
//			window.frames["worker"].document.write('over the tooltip...<br>');
		}
	} else {
		OutDB('OverTT()');
		ttHideTimer = setTimeout('HideGlobalTooltip()', 1000);
//		window.frames["worker"].document.write('hiding the tooltip...<br>');
	}
}

function hoverUnreadForumMess(e, isit)
{
//	document.onmousemove = updRightTT;
	hoverWhat = e;
	var t = document.getElementById('g_tt');
	if (t == null) return;
	if (!isit) {
//		t.style.display = "none";
		clearTimeout(hoverTimer);
		hoverTimer = 0;
		if (ttHideTimer == 0) {
			OutDB('hoverUnreadForumMess()');
			ttHideTimer = setTimeout('HideGlobalTooltip()', 1000);
		}
//		window.frames["worker"].document.write('hiding in 1 sec...<br>');
	} else {
		if (e != null) {
			hoverUrl = 'worker_forum.asp?action=unread';
			hoverTimer = setTimeout("DoFetchForumMess()", 1000);
		}
	}
}

function DoFetchForumMess()
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	pollServer(hoverUrl, 'ForumMessResponse');
}

function ForumMessResponse()
{
	if (hoverTimer == 0)
		return;
	if (servResponse == '-1') {
		alert("Unable to get a sane response from server...");
		return;
	} else {
		var t = document.getElementById('g_tt');
		t.innerHTML = unescape(servResponse);
		t.style.display = "block";
		t.style.width = "400px";
		var w = document.body.clientWidth;
		var cw = t.clientWidth;
		cw = 400;
		x = w - cw - 20;
		y = 40;
		t.style.left = (x + 10) + "px";
		t.style.top = (y + 10) + "px";	
	}
}
	
function pollServer(query, fwdFunc)
{
	if (servScript) {
		return;
		document.getElementsByTagName('head')[0].removeChild(servScript);
		servScript = null;
	}
	servScript = document.createElement('script');
	servScriptFwd = fwdFunc;
	servScript.src = query;
	servScript.type = 'text/javascript';
	document.getElementsByTagName('head')[0].appendChild(servScript);
	return false;
}

function processServerResponse(data)
{
//	window.frames["worker"].document.write('Got Server response: '+data+'<br>');
	setTimeout('RemoveServScript()', 50);
	if (servScriptFwd != '') {
		servResponse = escape(data);
		setTimeout(servScriptFwd+'()', 50);
	}
	return;
}

function RemoveServScript()
{ 
	document.getElementsByTagName('head')[0].removeChild(servScript);
	servScript = null;
	return;
}

/*
	This function gets called on every mouse move to update position of nice tooltip

function windowSize(var x, var y) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}
*/
function updTT(e)
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	var x = 0; var y = 0;
	if (e != null && e != 1) {
		x = e.pageX;
		y = e.pageY;
		pX = x; pY = y;
	} else if (e == 1) {
		x = pX; y = pY;
	} else {
		x = (document.all) ? window.event.x + document.body.scrollLeft : pX;
		y = (document.all) ? window.event.y + document.body.scrollTop  : pY;
		pX = x; pY = y;
	}
	var w = document.body.clientWidth;
	if ((x + t.clientWidth + 20) > w)  {
		x = w - t.clientWidth - 20;
		pX = x;
	}
	t.style.left = (x + 10) + "px";
	t.style.top = (y + 10) + "px";	
//	windowSize(sx, sy);
}

function updRightTT(e)
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	var x = 0; var y = 0;
	if (e != null && e != 1) {
		x = e.pageX;
		y = e.pageY;
		pX = x; pY = y;
	} else if (e == 1) {
		x = pX; y = pY;
	} else {
		x = (document.all) ? window.event.x + document.body.scrollLeft : pX;
		y = (document.all) ? window.event.y + document.body.scrollTop  : pY;
		pX = x; pY = y;
	}
	var w = document.body.clientWidth;
	var cw = t.clientWidth;
	cw = 400
	x = w - cw - 20;
	pX = x;
	t.style.left = (x + 10) + "px";
	t.style.top = (y + 10) + "px";	
//	windowSize(sx, sy);
}

function GotoThread(forum, thread) 
{
	Goto('forums_viewthread_update.asp?action=viewforum&index='+forum+'&thread='+thread+'&offset=-1');
}

// mark a thread as 'read' and hide the entry in the forum popup
function ForumPopRead(what, id)
{
	window.frames["worker"].location.href = 'worker_forum.asp?action=markasread&id='+id;
	var e = what;
	while (e.tagName!="TR")
		{e=e.parentNode;}		
	e.style.display = "none";
}

// unsubscribe to a thread  and hide the entry in the forum popup
function ForumPopUnsubscribe(what, id)
{
	window.frames["worker"].location.href = 'worker_forum.asp?action=unsubscribe&id='+id;
	var e = what;
	while (e.tagName!="TR")
		{e=e.parentNode;}		
	e.style.display = "none";
}


function ToggleShowThread(action)
{
	document.themessage.action = action;
	var show = true;
	if (getMultipleCookie("flags", "threadwithreply") == "1") show = false;
	setMultipleCookie("flags", "threadwithreply", show ? "1" :  "");
	document.themessage.submit();
}
		
function AddQT(formName, id, n) 
{
	var v = null;
	if (currForm != null)
		v = currForm;
	else if (formName != '') {
		v = document.getElementById(formName);
	} else {
//		alert("no control specified.");
	}
	var txt = getCaretTextQT(v);
	if (txt != null) {
		//OpenWindow('Quicktext.asp?action=edit&id='+id+'&text='+escape(txt), 100, 2);
		window.frames["worker"].location.href="worker_addqt.asp?id="+id+"&text="+escape(txt)+"&area="+formName+"&num="+n;
	}
	return 0;
}
var oldQTBack = null;
function OverQTBlock(bl, over)
{
	if (over) {
		bl.style.border = "1px solid #9999BB";
		oldQTBack = bl.style.backgroundColor;
		bl.style.backgroundColor="#FFFFFF"
		bl.style.padding = "0px";
	} else {
		bl.style.border = "0px";
		bl.style.padding = "1px";
		bl.style.backgroundColor= oldQTBack;
	}
}

function ToggleQueueOpen(id, isFilter)
{
	var element = document.getElementById("qd"+id);
	var head = document.getElementById("head"+id);
	var isopen;
	if (element.style.display == 'none') {
		isopen = true;
		element.style.display = 'inline';
		head.style.filter = '';
		head.style.MozOpacity = 1;
	} else {
		isopen = false;
		element.style.display = 'none';
		head.style.filter = 'Alpha (Opacity=32)';
		head.style.MozOpacity = 0.4;
	}
	window.frames["worker"].location.href = 'worker_queue.asp?action=togglequeue&id='+id+'&open='+(isopen ? 1 : 0);
	return;
	var txt = 'closed';
	if (isopen)
		txt = '';
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	var cook = RemoveFromMultipleCookie(getMultipleCookie('flags', 'QueueHidden'), ''+id, !isopen);
	setMultipleCookie("flags", "QueueHidden", cook, now);
	
}

function FilterTable(name)
{
	var element = document.getElementById(name);
	var url = document.location.href;
	if (element != null) {
		var idx = url.indexOf(name);
		if (idx >= 0) {
			var query = window.location.search.substring(1);
			var elements = query.split('&');
			url = url.slice(0, url.indexOf('?')+1);
			for (var i = 0; i < elements.length; i++) {
				if (elements[i].indexOf(name) == 0) {
					elements[i] = name+'='+element.value
					if (element.value != '')
						url += elements[i] + "&";
				} else
					url += elements[i] + "&";
			}
			url = url.slice(0, url.length-1);
			document.location.href = url;
		} else {
			var letter = '&';
			if (url.indexOf('?') < 0)
				letter = '?';
			else if (url.indexOf('?') == url.length-1)
				letter = '';
			document.location.href = document.location.href+letter+name+'='+element.value;
		}
	}
}

function NavOver(element, on)
{
	var s = 'm_s';
	var ns = 'm_ns';
	if (isIexplore && 0) {
		s = 'm_s_e';
		ns = 'm_ns_e';
	}
	var m = element.getElementsByTagName('a');
	if (m == null || m[0] == null)
		return

	if (on) {
		navoldclassname = element.className;
		navoldcolor = m[0].style.color
		var name = navoldclassname;
		var idx = name.indexOf(ns);
		if (idx < 0)
			var idx = name.indexOf(s);
		if (idx >= 0) {
			name = name.slice(0, idx);
			name = name + s;
		} else
			name = s;
		element.className = name;
		m[0].style.color = '#990000';
	} else {
		element.className = navoldclassname;
		m[0].style.color = navoldcolor;
	}
}

function NavToggleChildren(img, id, bookmark)
{
	var element = document.getElementById(id)
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	if (element.style.display == "inline") {
		element.style.display = "none"
		img.src = "images/expand_plus.gif";
		if (bookmark)
			setMultipleCookie("flags", "closed_"+id, "1", now);
	} else {
		element.style.display = "inline"
		img.src = "images/contract_minus.gif";
		if (bookmark)
			setMultipleCookie("flags", "closed_"+id, "", now);
	}
}

function RemoveFromMultipleCookie(cookiestring, element, append, value)
{
	var exact = true;
	if (value != null)
		exact = false;
	if (cookiestring != null && cookiestring != '') {
		var myarr = cookiestring.split(',');
		for (var i = 0; i < myarr.length; i++) {
			// if we found the element we're looking for
			var found = false;
			if (exact) {
				found = (myarr[i] == element);
			} else {
				var n = myarr[i].indexOf(element);
				//alert(myarr[i]+" "+element+" "+i);
				found = (n >= 0);
			}
			if (found) {
				for (var j = i; j < myarr.length-1; j++) {
					myarr[j] = myarr[j+1];
					//alert(myarr[j]+" "+id);
				}
				myarr.length -= 1;
			}
		}
		if (append) {
			if (!exact)
				myarr[myarr.length] = ''+element+':'+value;
			else
				myarr[myarr.length] = ''+element;
		}
			
		return myarr.join(',');
		
	} else if (append) {
		if (!exact)
			return ''+element+':'+value;
		else
			return ''+element;
	} else
		return '';
}

function MOM(who, isiton)
{
	if (isiton) {
		who.style.border='1px solid #99CCFF'
		who.style.padding='2px';
		who.style.backgroundColor="#FFFFFF";
	} else {
		who.style.border='';
		who.style.padding='3px';
		who.style.backgroundColor="";
	}
}

var prevbrd;
var prevpadd;
var prevcol;
function MOLM(who, isiton)
{
	if (isiton) {
		prevbrd = who.style.border;
		prevpadd = who.style.padding;
		prevcol = who.style.backgroundColor;
		who.style.border='1px solid #99CCFF'
		who.style.padding='3px';
		who.style.backgroundColor="#FFFFFF";
	} else {
		who.style.border=prevbrd;
		who.style.padding=prevpadd;
		who.style.backgroundColor=prevcol;
	}
}

function Goto(url)
{
	document.location.href = url;
}

function GotoNew(url)
{
	window.open(url);
}	

var oldClass;
function HighlightTable(table, doit)
{
	if (doit) {
		oldClass = table.className;
		table.className = "hightbl"
	} else {
		table.className = oldClass;
		oldClass = null;
	}
}
function HighlightPremiumTable(table, doit)
{
	if (doit) {
		table.style.border='2px solid #FF0000'
		table.style.padding='4px';
		table.style.backgroundColor="#FFFFFF"
	} else {
		table.style.border='1px solid #5555FF'
		table.style.padding='5px';
		table.style.backgroundColor="#FFFFBB"
	}
}
function CCA(CB){
	if (CB.checked)
		hL(CB)
	else
		dL(CB)
}

function hL(E){
	while (E.tagName!="TR")
		{E=E.parentNode;}
	if (E.className.indexOf("hr") < 0)
		E.className = E.className+"hr";
}

function hL2(E)
{
	E.className = "sc hr";
}

function dL2(E)
{
	E.className = "sc";
}

function dL(E){
	while (E.tagName!="TR")
		{E=E.parentNode;}
	var cls = "" + E.className;
	cls = cls.slice(0, cls.length-2);
	if (E.className.indexOf("hr") > 0)
		E.className = cls;
}


function showtip(current,e,text){
	if (document.all||document.getElementById){
		thetitle=text.split('<br>')
		if (thetitle.length>1) {
			thetitles=''
			for (i=0;i<thetitle.length;i++)
				thetitles+=thetitle[i]
			current.title=thetitles
		} else
			current.title=text
	} else if (document.layers){
		document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
		document.tooltip.document.close()
		document.tooltip.left=e.pageX+5
		document.tooltip.top=e.pageY+5
		document.tooltip.visibility="show"
	}
}

function hidetip(){
	if (document.layers)
		document.tooltip.visibility="hidden"
}

function confirmSubmit(text) {
	var agree=confirm(text);
	if (agree)
		return true ;
	else
		return false ;
}
	
function setCookie(name, value, expires, path, domain, secure) {
	if (expires == undefined) {
		expires = new Date();
		expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);
		}
  var curCookie = name + "=" + escape(value) +
	  ((expires) ? "; expires=" + expires.toGMTString() : "") +
	  ((path) ? "; path=" + path : "") +
	  ((domain) ? "; domain=" + domain : "") +
	  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function setMultipleCookie(name, subname, value) 
{
	var expires = new Date();
	expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);
	var cook = getCookieRaw(name);
	if (cook == null) {
		cook = escape(subname) + "=" + escape(value) + "&";
	}
	var i = cook.indexOf(subname+"=");
	var l = cook.split("&");
	cook = ""
	var inCook = false;
	for (i = 0; i < l.length; i++) {
		if (l[i] != "") {
			if (l[i].indexOf(subname) == 0) {
				l[i] = escape(subname) + "=" + escape(value);
				inCook = true;
			}
			cook += l[i] + "&"
		}
	}
	if (!inCook) {
		cook += escape(subname) + "=" + escape(value);
	}
	cook = name + "=" + cook + '; expires=' + expires.toGMTString();
	document.cookie = cook;
}

function getCookie(name) {
	return unescape(getCookieRaw(name));
}

function getCookieRaw(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return dc.substring(begin + prefix.length, end);
}

function getMultipleCookie(name, subitem) 
{
	var cook = getCookie(name);
	var i = cook.indexOf(subitem);
	if (i < 0) {
		return '';
	}
	var v_start = i+subitem.length+1;
	var v_end = cook.indexOf('&', v_start);
	if (v_end < 0) v_end = cook.length
	var v = cook.substring(v_start, v_end);
	return v;
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
	document.cookie = name + "=" + 
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
	date.setTime(date.getTime() - skew);
}
// cookie stuff ends

function OpenWindow(url, w, h) {
	hwnd = window.open(url, 'wa', 'directories=no, location=no, toolbar=no, status=no, resizeable=no, scrollbars=no, height=' + h + ', width=' + w);
	hwnd.focus();
}

function OpenWindowScroll(url, w, h) {
	hwnd = window.open(url, 'wa', 'directories=no, location=no, toolbar=no, status=no, resizeable=no, scrollbars=yes, height=' + h + ', width=' + w);
	hwnd.focus();
}

function OpenWindowSize(url, w, h) {
	hwnd = window.open(url, 'wa', 'toolbar=no,status=no,scrollbars=no,resizable=1, height=' + h + ', width=' + w);
	hwnd.focus();
}

function ToggleExpand(elementID){
	var element = document.getElementById(elementID)
	if (element.style.display == "block")
		element.style.display = "none"
	else
		element.style.display = "block"
}

function ToggleColorSettings(isThin)
{
	elementID = 'dsett';
	var element = document.getElementById(elementID)
	if (element.style.display == "block")
		element.style.display = "none"
	else
		element.style.display = "block"
	l = 310;
	t = 38;
	if (isThin) {
		l = 52;
		t = 20;
	}
	
	element.style.left = l;
	element.style.top = t;
	
	element.innerHTML = GetColorSettingsContents()

}
function DOL() {
	if (document.themessage != null) {
		if (document.themessage.Receiver != null) {
			//document.themessage.Receiver.focus();
		} else if (document.themessage.thetitle != null) {
			//document.themessage.thetitle.focus();
		}
	}
}
function ChangeNavColor(tableCellRef, color) {
	var element = tableCellRef.getElementsByTagName('a');
	if (element[0] != null) {
		element[0].style.color = color;
	}
}

function NavGoTo(tableCellRef, url, color) {
	var element = tableCellRef.getElementsByTagName('a');
	if (element[0] != null) {
		element[0].style.color = color;
	}
	try {
		window.location.href = url;
	} catch(e) {
	
	}
}
function setActiveStyleSheet(title, reset) {
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie("text", title, now);
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) 
				a.disabled = false;
		}
	}
}

// text window functions
function SetSizeCookie(n, col, rows)
{
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	c = col+":"+rows
	setCookie(n, c, now);
}

function MakeBigger(name)
{
	var element = document.getElementById(name);
	var cols = element.cols;
	var rows = element.rows;
	if (cols < 128)
		element.cols = cols + 16;
	if (rows < 30)
		element.rows = rows + 5;
	SetSizeCookie('sz_t', element.cols, element.rows);
}

function MakeSmaller(name)
{
	var element = document.getElementById(name);
	var cols = element.cols;
	var rows = element.rows;
	if (cols >= 112)
		element.cols = cols - 16;
	if (rows >= 30)
		element.rows = rows - 5;
	SetSizeCookie('sz_t', element.cols, element.rows);
}

var lostForm = null;
function LostFocus(formName) {
	lostForm = formName
	//formName.rows = 6;
	var element = document.getElementById("toolbar");
	//element.style.display = "none";
}

function MoveToolbar(formName, smallrows, largerows) {
	/*if (smallrows == null) {
		smallrows = 6;
	}
	if (largerows == null) {
		largerows = 16;
	}
	if (lostForm != null)
		lostForm.rows = smallrows;
	formName.rows = largerows;
	*/
	var element = document.getElementById("toolbar");
	formName.insertAdjacentElement( "afterEnd" , element );
	element.style.display = "inline";
}

var cp = 0;
var currForm = null;
function storeCaret(formName) {
	currForm = formName;
	if (formName.createTextRange) {
		cp = document.selection.createRange().duplicate();
	} else
		formName.caretPos = 0;
}

function insertAtCaret(formName, text) {
	var v = null;
	if (currForm != null)
		v = currForm;
	else {
		v = document.getElementById(formName);
	}
	if (v == 0 || v.style.display == "none")
		return 0;
	if (v.createTextRange && cp) {
		cp.text = cp.text + text;
	} else if (!v.createTextRange) {
		v.value += text;
	}
	currForm = v;
	currForm.focus();
	return 0;
}

function insertQTAtCaret(form, num)
{
	var v = document.getElementById('qtopt');
	var txt = v.value;
	lst = txt.split('||');
	var t = lst[num];
	var d = "";
	for (i = 0; i < t.length; i++) {
		if (t.charAt(i) == "\\" && t.charAt(i+1) == "n")
			d += "\n";
		else if (t.charAt(i) == "\\" && t.charAt(i+1) == "'")
			d += "";
		else
			d += t.charAt(i)+'';
	}
//	var s = lst[num].replace(new RegExp("'", "g"), "ble");
//	alert(d);
	insertAtCaret(form, d);
}

function getCaretText(formName)
{
	if (formName.createTextRange && formName.caretPos) {
		var caretPos = formName.caretPos;
		return caretPos.text;
	}
	return '';
}

function ToggleAll() {
	var element = document.getElementById('allt');
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	if (element.style.display == "block") {
		element.style.display = "none"
		setMultipleCookie("flags", "textgraphicsall", "1", now);
	} else {
		element.style.display = "block"
		setMultipleCookie("flags", "textgraphicsall", "", now);
	}
}

/*           Queue stuff                */ 

function OpenThisLayer(name)
{
	var element = document.getElementById(name)
	element.style.display = "";
}

function CloseThisLayer(name)
{
	var element = document.getElementById(name)
	element.style.display = "none";
}

function ToggleStory()
{
	var num = 50
	for (i=1; i<num+1; i+=1) {
	  var name = "t"+i
	  var element = document.getElementById(name)
	  if (element == null)
	  	break;
	  if (element.style.display != "")
		  OpenThisLayer(name);
	  else
	      CloseThisLayer(name);
	}
}
var colchange = false
var col = 0
function ToggleStoryColor()
{
	col = col+1;
	if (col > 2)
		col = 0;
	var num = 50
	for (i=1; i<num+1; i+=1) {
	  var name = "t"+i
	  var element = document.getElementById(name)
	  if (element == null)
	  	break;
	  if (col == 0)
		  element.style.color = "#888888";
	  else if (col == 1)
	      element.style.color = "#009900";
	  else if (col == 2)
		  element.style.color = "#000099";
	}
}

var sz = 1
function ToggleStorySize()
{
	sz = sz+1;
	if (sz > 2)
		sz = 0;
	var num = 50
	for (i=1; i<num+1; i+=1) {
	  var name = "t"+i
	  var element = document.getElementById(name)
	  if (element == null)
	  	break;
	  if (sz == 0)
		  element.style.fontSize = "9px";
	  else if (sz == 1)
	      element.style.fontSize = "10px";
	  else if (sz == 2)
	      element.style.fontSize = "12px";
	}
}

// Forum_viewthread.asp stuff
	
function OpenThisLayer(name)
{
	var element = document.getElementById(name)
	element.style.display = "inline";
}

function CloseThisLayer(name)
{
	var element = document.getElementById(name)
	element.style.display = "none";
}

function CloseMessage(id) 
{
	var openthis1 = "message"+id
	CloseThisLayer(openthis1);
	var closethis = "message"+id+"_inv"
	OpenThisLayer(closethis);
}

function OpenMessage(id) 
{
	var openthis1 = "message"+id
	OpenThisLayer(openthis1);
	var closethis = "message"+id+"_inv"
	CloseThisLayer(closethis);
}

function ToggleMessage(id) {
	var openthis1 = "message"+id
	var elemento1 = document.getElementById(openthis1)
	if (elemento1.style.display == "inline") {
		CloseMessage(id)
	} else {
		OpenMessage(id)
	}
}
function OpenCloseThread(num)
{
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	var lokad = getMultipleCookie("flags", "forumClosed");
	for (i = 1; i < num+1; i += 1) {
		var testIfExists = document.getElementById("message"+i)
		if (testIfExists == null && i > 10) break;
		if (testIfExists != null) {
			//break;
			if (lokad == "1")
				OpenMessage(i);
			else
				CloseMessage(i);
		}
	}
	if (lokad == "1") {
		setMultipleCookie("flags", "forumClosed", "0", now);
		OpenThisLayer('loka1');
		OpenThisLayer('loka2');
		CloseThisLayer('opna1');
		CloseThisLayer('opna2');
	} else {
		setMultipleCookie("flags", "forumClosed", "1", now);
		CloseThisLayer('loka1');
		CloseThisLayer('loka2');
		OpenThisLayer('opna1');
		OpenThisLayer('opna2');
	}
}


// story bookmarks

var storyBook = 0;
var lastStoryBookmark = null;
var lastStoryBookmarkNum = '';
function SetStoryBookAll(storyid)
{
	what = document.getElementById('btop');
	/*
	if (what.className == "sbs") {
		ClearStoryBook(storyid);
		return;
	}
	what.className = "sbs";
	*/
	if (lastStoryBookmark != null)
		lastStoryBookmark.className = "sb";
	lastStoryBookmark = what;
	document.getElementById('booksel').style.display = "inline";
	var cook = RemoveFromMultipleCookie(getCookie('StoryBookmark'), ''+storyid, true, 'top');
	setCookie("StoryBookmark", cook);
}

function ssb(what, b, storyid, showbookmarks)
{
	if (b == 0)
		return;
	document.getElementById('booksel').style.display = "inline";
	var v = document.getElementById('bookselalt');
	if (v != null) {
		v.style.display = "inline";
		moveBookIcon();
	}
	if (b == storyBook) {
		window.location = "#"+showbookmarks;
	} else {
		storyBook = b;
		if (lastStoryBookmark != null) {
			lastStoryBookmark.className = "sb";
			lastStoryBookmark.innerHTML = lastStoryBookmarkNum;
		}
		lastStoryBookmark = what;
		what.className = "sbs";
		lastStoryBookmarkNum = what.innerHTML;
		what.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		var cook = RemoveFromMultipleCookie(getCookie('StoryBookmark'), ''+storyid, true, ''+b);
		setCookie("StoryBookmark", cook);
		//alert(cook);
	}
}

function GotoStoryBook()
{
	var b = storyBook;
	if (b > 1)
		b--;
	if (b > 0)
		window.location = "#"+b;
}

function ClearStoryBook(storyid)
{
	if (lastStoryBookmark != null) {
		lastStoryBookmark.className = "sb";
		lastStoryBookmark.innerHTML = lastStoryBookmarkNum;
	}
	storyBook = 0;
	document.getElementById('booksel').style.display = "none";
	var v = document.getElementById('bookselalt');
	if (v != null) v.style.display = "none";
	var now = new Date(); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	var cook = RemoveFromMultipleCookie(getCookie('StoryBookmark'), ''+storyid, false, '');
	setCookie("StoryBookmark", cook, now);
}

function ToggleStoryBook()
{
	var num = 200;
	disp = "inline";
	for (i=1; i<num+1; i+=1) {
		var name = "b"+i
		var element = document.getElementById(name)
		if (element == null)
			break;
		if (i == 1 && element.style.display != "none") {
			disp = "none";
		}
		element.style.display = disp;
	}
	setMultipleCookie("flags", "StoryNumbering", disp);
}

/* changes the table color */
function setBackground(elem, namelist, collist)
{
	var children = elem.childNodes;
	for (var i=0; i<children.length; i++) {
		if (children[i].className != '' && children[i].className != null) {
			var s = children[i].className.split(' ');
			for (j = 0; j < s.length; j++)
				for (k = 0; k < namelist.length; k++)
					if (namelist[k] == s[j]) {
						children[i].style.backgroundColor = collist[k];
						break;
					}
		}
		if (children[i].childNodes.length > 0)
			setBackground(children[i], namelist, collist);
	}
}

function setBorder(elem, namelist, collist)
{
	var children = elem.childNodes;
	for (var i=0; i<children.length; i++) {
		if (children[i].className != '' && children[i].className != null) {
			var s = children[i].className.split(' ');
			for (j = 0; j < s.length; j++)
				for (k = 0; k < namelist.length; k++)
					if (namelist[k] == s[j]) {
						children[i].style.borderColor = collist[k];
						break;
					}
		}
		if (children[i].childNodes.length > 0)
			setBorder(children[i], namelist, collist);
	}
}

function confirmDelete(isEng)
{
	if (isEng == 'True') {
		return confirmSubmit('Are you sure you want to delete this message?');
	} else {
		return confirmSubmit('Ertu viss um að þú viljir eyða út þessum skilaboðum?');
	}
}

function SelCol(n)
{
	var col = "FF0000";
	var m = document.getElementById("main");
	var namelist = new Array("hdr", "hdr_sel", "or", "er", "smallmenu", "largemenu");
	var collist = new Array("#"+list_hdr[n], "#"+list_hdr_sel[n], "#"+list_or[n], "#"+list_er[n], "#"+list_or[n], "#"+list_hdr[n]);
	setBackground(m, namelist, collist);
	namelist = new Array("colbdr", "colbdrbottom");
	collist = new Array("#"+list_hdr_sel[n], "#"+list_hdr_sel[n]);
	setBorder(m, namelist, collist);
	if (isIexplore)	
		setGradients(m, ""+list_hdr_sel[n], ""+list_or[n]); 
	setMultipleCookie("col", "tbl", ""+n);
}

function setGradients(m, col1, col2)
{
	var children = m.childNodes;
	for (var i=0; i<children.length; i++) {
		var c = children[i];
		if (c.className == 'smallmenu' || c.className == 'largemenu') {
			c.style.filter = 'progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=\'#FF'+col1+'\', EndColorStr=\'#FF'+col2+'\')';
		}
		setGradients (c, col1, col2);
	}
}

function setBodyCol(n)
{
	setMultipleCookie("col", "bck", ""+n);
	document.body.style.backgroundColor = list_bod[n];
	var fr = 'AAAADD';
	if (n == 0)
		fr = 'EEEEEE';
	var v = document.getElementById('framepic');
	if (v != null) {
		v.style.borderColor = fr;
	}
}

function DispFontSize(i)
{
	if (i == 1) {
		if (getCookie("text") == 'Small Text')
			setActiveStyleSheet('Bigger Text', false);
		else if (getCookie("text") == 'Bigger Text')
			setActiveStyleSheet('Biggest Text', false);
		else if (getCookie("text") == 'Smaller Text')
			setActiveStyleSheet('Small Text', false);
		else
			setActiveStyleSheet('Smaller Text', false);
	} else {
		if (getCookie("text") == 'Smaller Text')
			setActiveStyleSheet('Biggest Text', false);
		else if (getCookie("text") == 'Biggest Text')
			setActiveStyleSheet('Bigger Text', false);
		else if (getCookie("text") == 'Bigger Text')
			setActiveStyleSheet('Small Text', false);
		else
			setActiveStyleSheet('Smaller Text', false);
	}
}

function DispColFront(i)
{
	n = getMultipleCookie("col", "tbl");
	if (n == '') n = 0;
	n = Number(n)+i;
	if (n >= list_hdr.length)
		n = 0;
	else if (n < 0)
		n = list_hdr.length-1;
	SelCol(n);
}

function DispColBack(i)
{
	n = getMultipleCookie("col", "bck");
	n = Number(n)+i;
	if (n == '') n = 0;
	if (n >= list_bod.length)
		n = 0;
	else if (n < 0)
		n = list_bod.length-1;
	setBodyCol(n);
}

function SetBgCol(col)
{
	document.body.style.backgroundColor = col;
}

function SetFgCol(hdr, hdrsel, or, er)
{
	var m = document.getElementById("main");
	var namelist = new Array("hdr", "hdr_sel", "or", "er", "smallmenu", "largemenu");
	var collist = new Array("#"+hdr, "#"+hdrsel, "#"+or, "#"+er, "#"+or, "#"+hdr);
	setBackground(m, namelist, collist);
	namelist = new Array("colbdr");
	collist = new Array("#"+hdrsel);
	setBorder(m, namelist, collist);
	if (isIexplore)	
		setGradients(m, ""+hdrsel, ""+or); 
	//setMultipleCookie("col", "tbl", ""+n);
}

function CheckLength(fld, l)
{
	v = document.getElementById(fld);
	ml = v.value.length
	if (ml > l) {
		alert('Your message is too long ('+ml+' characters).\nThe maximum message length is '+l+' characters.');
		return false;
	}
	return true;
}

function ToggleReply()
{
	c = document.getElementById('reply');
	ToggleExpand('reply');
	window.location = "#nedst";
	setTimeout('DelayedSetFocus(\'message\')', 100);
}

function DelayedSetFocus(name)
{
	c = document.getElementById(name);
	c.focus();
}

// Toolbar buttons
function TBB(title, tip, page, img, disabled, selected, expanded, id)
{
	t = document.getElementById("toolbar");
	r = t.insertRow(-1);
	c_left = r.insertCell(0);
	c = r.insertCell(1);
	click = '';
	t = '<font color=gray>'+title+'</font>'
	tblstl = '';
	linkstl = '';
	cls = 'm_ns';
	if (!disabled) {
		p = page.replace(new RegExp("'", "g"), "\\\'");
		click = 'onclick="NavGoTo(this, \''+p+'\', \'\');" '
		t = '<a href="'+page+'">'+title+'</a>'
		tblstl = ' style="cursor:pointer"'
	} else
		tip = 'You must be logged in to access this function'
	if (selected) {
		t = '<a href="'+page+'" style="color:#990000;">'+title+'</a>'
		cls = 'm_s'
	}
	if (expanded > 0) {
		p = expanded != 2 ? "expand_plus" : "contract_minus"
		c_left.innerHTML = '<img src="images/'+p+'.gif" align=absmiddle OnClick="NavToggleChildren(this, \'chld_'+id+'\', false);" style="cursor: pointer;" width="9">\n';
	}
	ic = '';
	if (img != "")
		ic = '<img src="images/menu_'+img+'.png" align="absmiddle" height="16">'
	c.innerHTML = '\n<table'+tblstl+' cellpadding=0 cellspacing=0 width="100%"><tr title="'+tip+'"><td colspan=2 class='+cls+' onmouseover="NavOver(this, true);" onmouseout="NavOver(this, false);" '+click+'align="left"><span id=icon'+id+'>'+ic+'</span>&nbsp;'+t+'</td></tr></table>\n'
}


function TBSB(titles, tips, pages, id, open, selected)
{
	t = document.getElementById("toolbar");
	r = t.insertRow(-1);
	c_left = r.insertCell(0);
	c = r.insertCell(1);
	dis = open ? "inline" : "none";
	txt = '<div id="chld_'+id+'" style="display:'+dis+';">\n <table cellpadding="0" cellspacing="2" width="95%" style="margin-left:6px;">\n'
	for (i = 0; i < titles.length; i++) {
		cls = "m_ns"
		t = '<a href="'+pages[i]+'">'+titles[i]+'</a>';
		if (i == selected) {
			cls = "m_s"
			t = '<a href="'+pages[i]+'" style="color:#990000;">'+titles[i]+'</a>';
		}
		p = pages[i].replace(new RegExp("'", "g"), "\\\'");
		txt += '  <tr title="'+tips[i]+'"><td class="smalltext '+cls+'" onMouseOver="NavOver(this, true);" onMouseOut="NavOver(this, false);" onClick="NavGoTo(this, \''+p+'\', \'\');" style="cursor:pointer;">'+t+'</td></tr>\n'
	}
	txt += ' </table>\n</div>\n\n'
	c.innerHTML = txt
}

function TBL()
{
	t = document.getElementById("toolbar");
	r = t.insertRow(-1);
	c_left = r.insertCell(0);
	c = r.insertCell(1);
	c.innerHTML = "<hr size=0>"
}


function InsertQuickText(what, name)
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	t.innerHTML = "...";
	t.style.left = mousePosX - 180 + "px";
	t.style.top = mousePosY + 10 + "px";
	t.style.display = "block";
	t.style.width = "180px";
	quicktextElement = what;
	SetTooltipPosition(what);
	window.frames["worker"].location.href="worker_quicktext.asp?action=menu&id="+name;
}

function ProcessQuickTextMenu(arr, name)
{
	//quicktextElement.style.display = 'none';
	
	var t = document.getElementById('g_tt');
	t.style.display = "block";
	t.style.width = "180px";
	var cl = "or";
	txt = ""
	for (i = 0; i < arr.length; i++) {
		cl = "or";
		//if ((i % 2.0) > 0) cl = "or";
		if (arr[i].length >= 1) {
			tx = arr[i].replace(new RegExp("\n", "g"), "\\n")
			tx = tx.replace(new RegExp("\'", "g"), "\\'")
			txt = txt + '<tr class="sc '+cl+'" OnMouseover="hL2(this);" OnMouseOut="dL2(this);" title="'+arr[i]+'"><td onClick="PickQuickText(\''+name+'\', \''+tx+'\');"><nobr><span class=tinytext>' + arr[i].substr(0, 32) + '</span></nobr></td></tr>\n'
		}
	}
	if (arr.length == 0) {
		txt += '<tr class="sc er"><td class=tinytext>You have no QuickTexts</td></tr>';
	}
	txt += '<tr class="sc er"><td class=tinytext OnMouseover="hL2(this);" OnMouseOut="dL2(this);" onClick="GotoNew(\'mypage.asp?action=quicktext\');" title="Add and Edit your quicktext macros">Edit Quicktext</td></tr>';
	txt = '<table cellpadding=2 cellspacing=0 width="180" border=0 class=colbdr>\n' + txt + '</table>\n';
	t.innerHTML = txt;
	ttHideTimer = setTimeout('HideGlobalTooltip()', 5000);


	quicktextElement = null;
}

function GetCaretPosition(control) 
{
var CaretPos = 0;
// IE Support
if (document.selection) 
{
control.focus();
var Sel = document.selection.createRange ();
var Sel2 = Sel.duplicate();
Sel2.moveToElementText(control);
var CaretPos = -1;
while(Sel2.inRange(Sel))
{
Sel2.moveStart('character');
CaretPos++;
}
}

// Firefox support

else if (control.selectionStart || control.selectionStart == '0')
CaretPos = control.selectionStart;

return (CaretPos);

}




function SetCaretPosition(ctrl, pos){
	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}

function encloseSelection2(name, prefix, suffix) {

    textarea = document.getElementById(name);
    DoEncloseSelection2(textarea, prefix, suffix);
}

function DoEncloseSelection2(textarea, prefix, suffix) {
    textarea.focus();
    pos = GetCaretPosition(textarea);
    var start, end, sel, scrollPos, subst;
    if (typeof(document["selection"]) != "undefined") {
      sel = document.selection.createRange().text;
    } else if (typeof(textarea["setSelectionRange"]) != "undefined") {
      start = textarea.selectionStart;
      end = textarea.selectionEnd;
      scrollPos = textarea.scrollTop;
      sel = textarea.value.substring(start, end);
    }

    if (sel.match(/ $/)) { // exclude ending space char, if any
      sel = sel.substring(0, sel.length - 1);
      suffix = suffix + " ";
    }

    subst = prefix + sel + suffix;

    if (typeof(document["selection"]) != "undefined") {
      var range = document.selection.createRange().text = subst;
      if (sel.length == 0)
      	p = pos + 3;
      else
        p = pos + subst.length;
      SetCaretPosition(textarea, p);
    } else if (typeof(textarea["setSelectionRange"]) != "undefined") {
      textarea.value = textarea.value.substring(0, start) + subst +
                       textarea.value.substring(end);
	     
      if (sel) {
        textarea.setSelectionRange(start + subst.length, start + subst.length);
      } else {
        textarea.setSelectionRange(start + prefix.length, start + prefix.length);
      }
      textarea.scrollTop = scrollPos;
    }
  }
  
function PickQuickText(name, text)
{
	encloseSelection2(name, text, "");
}

function UpdateMousePos(e)
{
	if (e != null && e != 1) {
		x = e.pageX;
		y = e.pageY;
		mousePosX = x; mousePosY = y;
	} else if (e == 1) {
		x = mousePosX; y = pY;
	} else {
		x = (document.all) ? window.event.x + document.body.scrollLeft : pX;
		y = (document.all) ? window.event.y + document.body.scrollTop  : pY;
		mousePosX = x; mousePosY = y;
	}
//	var w = document.body.clientWidth;
//	if ((x + t.clientWidth + 20) > w)  {
//		x = w - t.clientWidth - 20;
//		mousePosX = x;
//	}
}


// frontpage boxes

function ToggleBlock(what, name)
{
	what = what.parentNode.parentNode.parentNode.parentNode
	t = document.getElementById('div_'+name);
	chevron = document.getElementById('chevron_'+name);
	//alert(t.tagName)
	var isOpen = null;
	if (t.style.display != 'none') {
		chevron.src = 'images/chevronDown.png';
		t.style.display = 'none';
		what.className = 'hdr colbdr';
		isOpen = 0
	} else {
		chevron.src = 'images/chevronUp.png';
		t.style.display = 'inline';
		what.className = 'hdr_sel colbdr';
		isOpen = 1
	}
	window.frames["worker"].location.href = 'worker_switchlayout.asp?action=frontpageopen&name='+name+'&open='+isOpen;
}

movingElement = null;
movingCol = 0;
movingBefore = '';
movingIsAfter = false;
movingCatID = null;

function GrabBox(e, what)
{
	w = what;
	while (w != null && w.className != 'clsPart') {
		w = w.parentNode;
	}
	if (w == null)
		return
	movingElement = w;
	w.style.border = '2px dashed #888888';
	//w.style.MozOpacity = 0.5;
	if (window.event) {
		window.event.cancelBubble = true;
	} else if (e.stopPropagation) {
		e.stopPropagation();
	}
	return false;
}

function OverBox(e, what, before)
{
	if (movingElement == null) return;
	e = what;
	while (e != null && e.className != 'clsPart') {
		e = e.parentNode;
	}
	bef = e;
	id = bef.id;
	if (!before) {
		bef = bef.nextSibling;
		//window.frames["worker"].document.write(bef.tagName+'<br>')
		movingIsAfter = false;
	} else {
		movingIsAfter = true;
	}
	col = what;
	while (col != null && col.className != 'fpcol') {
		col = col.parentNode;
	}
	//window.frames["worker"].document.write(bef);
	if (bef != null && id != movingElement.id) {
		movingBefore = id;
		if (col != null)
			movingCol = col.id.substring(4, 5);
	}

	e.parentNode.insertBefore(movingElement, bef);
}

function OverEmpty(e, what)
{
	if (movingElement == null) return;
	//window.frames["worker"].document.write('over empty<br>')
	for (i = 0; i < what.childNodes.length; i++) {
		c = what.childNodes[i];
		if (c.tagName != null && c.tagName.toLowerCase() == 'table') {
			return;
		}
	}

	movingIsAfter = true;
	movingBefore = '';
	movingCol = what.id.substring(4, 5);
	what.appendChild(movingElement, what.childNodes[0]);
}

function ReleaseBox(e, what)
{
	if (movingElement == null) return;
	name = movingElement.id;
	movingElement.style.border = '';
	//movingElement.style.MozOpacity = 1.0;
	var topTable = document.getElementById('topTable');
	for (i = 0; i < topTable.childNodes.length; i++) {
		td = topTable.childNodes[i];
	}
	if (movingCol > 0) {
		a = movingIsAfter ? 1 : 0
		window.frames["worker"].location.href = 'worker_switchlayout.asp?action=frontpagemove&name='+name+'&col='+movingCol+'&after='+movingBefore+'&isAfter='+a;
	}
	movingElement = null;
	movingBefore = '';
	movingCol = 0
}

function GrabBoxFunInfo(e, what, catID)
{
	w = what;
	while (w != null && w.className != 'clsPart') {
		w = w.parentNode;
	}
	if (w == null)
		return
	movingElement = w;
	movingCatID = catID;
	w.style.border = '2px dashed #888888';
	w.style.backgroundColor = '#EFFFE0';
	if (window.event) {
		window.event.cancelBubble = true;
	} else if (e.stopPropagation) {
		e.stopPropagation();
	}
	return false;
}

function OverBoxFunInfo(e, what, before, catID)
{
	if (movingElement == null) return;
	if (catID != movingCatID) return;
	e = what;
	while (e != null && e.className != 'clsPart') {
		e = e.parentNode;
	}
	bef = e;
	id = bef.id;
	if (!before) {
		bef = bef.nextSibling;
		//window.frames["worker"].document.write(bef.tagName+'<br>')
		movingIsAfter = false;
	} else {
		movingIsAfter = true;
	}
	col = what;
	while (col != null && col.className != 'fpcol') {
		col = col.parentNode;
	}
	//window.frames["worker"].document.write(bef);
	if (bef != null && id != movingElement.id) {
		movingBefore = id;
		if (col != null)
			movingCol = col.id.substring(4, 5);
	}

	e.parentNode.insertBefore(movingElement, bef);
}

function OnRelease(e)
{
	if (movingElement == null) return;
	if (movingCatID)
		ReleaseBoxFunInfo(e)
	else
		ReleaseBox(e)
}

function ReleaseBoxFunInfo(e)
{
	if (movingElement == null) return;
	name = movingElement.id;
	movingElement.style.border = '';
	movingElement.style.borderBottom = '1px solid #BBCCDD';
	w.style.backgroundColor = '';
	a = movingIsAfter ? 1 : 0
	window.frames["worker"].location.href = 'worker_funinfo.asp?action=move&name='+name+'&after='+movingBefore+'&isAfter='+a;
	movingElement = null;
	movingBefore = '';
	movingCol = 0
	movingCatID = null;
}

// end of frontpage boxes

function OnUpdateNewManuscriptPoint(which)
{
	if (which.name == "newunits") {
		document.addpoint.totalunits.value = Number(which.value) + Number(document.addpoint.fixedtotal.value);
	} else {
		document.addpoint.newunits.value = Number(which.value) - Number(document.addpoint.fixedtotal.value);
	}
}

function OnUpdateNewManuscriptPoint2(which, id)
{
	v = document.getElementById('addpoint_'+id);
	if (which.name == "newunits") {
		
		v.totalunits.value = Number(which.value) + Number(v.fixedtotal.value);
	} else {
		v.newunits.value = Number(which.value) - Number(v.fixedtotal.value);
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "Unknown";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "??";
		this.OS = this.searchString(this.dataOS) || "Unknwown";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function ob(what, isit)
{
	if (isit) {
		what.className = 'butt2_over';
	} else {
		what.className = 'butt2';
	}
}
function obsml(what, isit)
{
	if (isit) {
		what.className = 'butt2sml_over';
	} else {
		what.className = 'butt2sml';
	}
}
function obbig(what, isit)
{
	if (isit) {
		what.className = 'butt2big_over';
	} else {
		what.className = 'butt2big';
	}
}

function GetScrollX()
{
	db = document.body;
	return(window.pageXOffset || (db ? (db.scrollLeft || 0) : 0));
}

function GetScrollY()
{
	db = document.body;
	return(window.pageYOffset || (db ? (db.scrollTop || 0) : 0));
}

function GetClientW()
{
	var de = document.documentElement;
	return((de && de.clientWidth) ? de.clientWidth : (document.body.clientWidth || window.innerWidth || 0));
}

function GetClientH()
{
	var de = document.documentElement;
	return((de && de.clientHeight) ? de.clientHeight : (document.body.clientHeight || window.innerHeight || 0));
}

function SetTooltipPosition(e)
{
  hoverWhat = e;
  var x = e.offsetLeft;
  
  var y = e.offsetTop;
  var parent = e;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop;
  }

  scrollX = GetScrollX();
  clientW = GetClientW();

  
  var t = document.getElementById('g_tt');
  if (t == null) return;
  
  ttwidth = t.style.width;
  ttwidth = ttwidth.replace("px", "");
  ttwidth = Number(ttwidth);
  //window.frames["worker"].document.write(ttwidth+'<br>');
  maxPosX = GetClientW() - ttwidth - 1 + scrollX;
  
  x = Math.min(x, maxPosX-10);
  
  t.style.left = x;
  t.style.top = y + 12;
  t.style.display="none";
  clearTimeout(hoverTimer);
  hoverTimer = 0;

}

function HoverInfo(e, id, tp)
{
  clearTimeout(ttHideTimer);
  ttHideTimer = 0;
  SetTooltipPosition(e)

  if (e != null) {
    hoverUrl = 'worker_info.asp?action=getinfo&id='+id+'&type='+tp;
    hoverTimer = setTimeout("DoFetchInfo()", 500);
    hoverWidth = 400;
    if (tp == 3)
    	hoverWidth = 530;
  }
}

function StopInfo(e)
{
  clearTimeout(hoverTimer);
  hoverTimer = 0;
  ttHideTimer = setTimeout('HideGlobalTooltip()', 1000);
}

function DoFetchInfo()
{
  var t = document.getElementById('g_tt');
  if (t == null) return;
  t.className = "";
  pollServer(hoverUrl, 'FetchInfoResponse');
}

function FetchInfoResponse()
{
  if (hoverTimer == 0)
    return;
  if (servResponse == '-1') {
    alert("Unable to get a sane response from server...");
    return;
  } else {
    var t = document.getElementById('g_tt');
    t.style.display = "block";
    t.style.width = hoverWidth + "px";
    t.innerHTML = unescape(servResponse);
  }
}


function AddBookmarkRow(id, title, url)
{
	var tbl = document.getElementById('bookmarktbl');
	var tbody = tbl.getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR");
	var td = document.createElement("TD");
	td.width = '6';
	td.innerHTML = '<img src="images/arrowSmlRight.gif" border="0" align="absmiddle" width="6">'
	td.onclick = function() {SetBookmark(id)};
	td.className = "link"
	td.title = langStrings[0];
	row.appendChild(td);
	var tooltip = url;
	if (url == "") {
		url = 'javascript:SetBookmark('+id+');'
		tooltip = langStrings[0];
	} else {
		td.onclick = function() {Goto(url)};
	}
	
	var td = document.createElement("TD");
	td.innerHTML = '<div class=bmd style="position: relative; top=-1px; left=0px;"><a id="b_'+id+'" href="'+url+'" class=curs>'+title+'</a></div>'
	td.onmouseover = function() {NavOver(this, true);}
	td.onmouseout = function() {NavOver(this, false);}
	
	td.title = tooltip;
	td.className = "smalltext m_ns link";
	row.appendChild(td);

	tbody.appendChild(row);
}

function DoAds(which, link, text, url, border, bg)
{
	if (which == 'bottom') {
		google_ad_client = "pub-0596651943190775";
		google_ad_width = 728;
		google_ad_height = 90;
		google_ad_format = "728x90_as";
	} else if (which == 'side') {
		google_ad_client = "pub-0596651943190775";
		google_ad_width = 120;
		google_ad_height = 600;
		google_ad_format = "120x600_as";
	} else if (which == 'toolbar') {
		google_ad_client = "pub-0596651943190775";
		google_ad_width = 120;
		google_ad_height = 90;
		google_ad_format = "120x90_0ads_al_s";
	}

	google_color_border = border;
	google_color_bg = bg;
	google_color_link = link;
	google_color_text = text;
	google_color_url = url;
}

function DeleteFunInfo(entryid, what)
{
	if (!confirm('Are you sure you want to delete this entry?'))
		return

	window.frames['worker'].location.href = 'worker_funinfo.asp?action=deleteentry&entryid='+entryid;
}

function EditFunInfo(entryid, catid)
{
	window.frames['worker'].location.href = 'worker_funinfo.asp?action=editentryform&entryid='+entryid+'&catid='+catid;
}


function AddFunInfoEditForm(entryid, catid, isTitle, isTitleUrl, isAuthor, title, titleurl, maintxt, author, authorurl, privat, isDesc)
{
	txt = ''
	txt += '<form method=post action="worker_funinfo.asp?action=editentry" target=worker>'
	txt += '<input type=hidden name=entryid value='+entryid+'>'
	txt += '<input type=hidden name=catid value="'+catid+'">'
	txt += '<table cellspacing=0 cellpadding=3 class="colbdr or" width="100%">'
	hdr = 'Edit Entry'
	if (entryid == 0)
		hdr = 'Add New Entry'
	txt += '<tr><td class=hdr_sel colspan=2><b>'+hdr+'</b></td></tr>'
	if (isTitle) {
		txt += '<tr><td class=smalltext width=200>Title<br><input type=text class=input name=title value="'+title+'" size=50></td>'
		if (isTitleUrl) {
			txt += '<td class=smalltext>Title URL (optional)<br><input type=text class=input name=titleurl value="'+titleurl+'" size=70></td>'
		}

		txt += '</tr>'
	}

	if (isDesc)
		txt += '<tr><td colspan=2><textarea name=message id=txt_'+catid+' cols=12 rows=7 style="width:100%">'+maintxt+'</textarea></td></tr>'
	
	if (isAuthor) {
		txt += '<tr><td class=smalltext>Author (optional)<br><input type=text class=input name=author value="'+author+'" size=50></td>'
		txt += '<td class=smalltext>Author URL (optional)<br><input type=text class=input name=authorurl value="'+authorurl+'" size=70></td>'
		txt += '</tr>'

	}
	c = ''
	if (privat) c = ' Checked'
	txt += '<tr><td colspan=2 align=left><input class=check type=checkbox id="privat_'+entryid+'" name=privat value="1"'+c+'><label for="privat_'+entryid+'">This is a hidden entry</label></td>'
	txt += '<tr><td colspan=2 align=center><input name=submit type=submit value="Submit Changes" class=butt2 OnMouseOver="ob(this, true);" OnMouseOut="ob(this, false);"></td>'

	txt += '</table>'
	txt += '</form>'
	var v = document.getElementById('funinfoform_'+catid);
	v.innerHTML = txt;
	var p = GetElementAbsolutePos(v);
        var top = (document.documentElement.scrollTop ?
            document.documentElement.scrollTop :
            document.body.scrollTop);
            
        diff = (top + document.body.clientHeight - p)
	if (diff < 100)
		window.scrollTo(0, p - 200);
	setTimeout('AddFunInfoToolbar('+catid+')', 100);
}

function GetElementAbsolutePos(e)
{
	var theElement = e;
	var selectedPosX = 0;
	var selectedPosY = 0;
	while(theElement != null) {
		selectedPosX += theElement.offsetLeft;
		selectedPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
	return selectedPosY;

}

function AddFunInfoToolbar(name)
{
	textarea = document.getElementById('txt_'+name);	
	AddFormattingToolbar(textarea, 1);
}
//document.onmousemove = UpdateMousePos;

function DisableDefault(e)
{
	// FF
	if (e.preventDefault)
		e.preventDefault();
	// MSIE
	else {
		e.returnValue = false;
		// Fix som stuborn events, like F5 and ctrl-f
		e.keyCode = 0;
	}

	return;
}

function GoBackIfAppropriate()
{
	a = navigator.userAgent;
	a = a.toLowerCase();
	if (a.indexOf("pera") < 0 && a.indexOf("webkit") < 0)
		history.go(-1);
}
// end of scripts.js