	// Comment page up/down functions
	var cmtUp = new Array();
	var cmtDown = new Array();	
	var cmtLastComment  = 0;
	var commentsBodyHTML = new Array();
	var expandedRoots = new Array();
	var tryPopupAgain;
	var tryPopupRoot;
	var tryPopupEvent;
	var tryPopupX;
	var tryPopupY;
	var removeTimerID;
	var popupTimerID;
	var popupDisabled = false;
	var currentComment;
	
	var popupX;
	var popupY;
	var popupW;
	var popupH;
	var mouseOverType;

	var ncDTLock = false;



	function doMM( e )
	{
		obj = window.event ? window.event.srcElement : e.target;

		oldType = mouseOverType;
	
/*		if( (obj.nodeType == 3) || ( ( obj.tagName != 'A' ) && ( obj.tagName != 'BODY' ) && ( obj.tagName != 'SPAN' ) && ( obj.tagName != 'I' )) )
		{
			obj = obj.parentNode;
		}

		if( obj.getAttribute )
		{
			mouseOverType = obj.getAttribute( "LINKTYPE" );
		} */
		
		newType = 'NONE';
		while( obj.parentNode )
		{
			if( obj.getAttribute && obj.getAttribute( "LINKTYPE" ) )
			{
				newType = obj.getAttribute( "LINKTYPE" );
				break;
			}
			else
			{
				obj = obj.parentNode;
			}
		}
		mouseOverType = newType;
		
		// Remove popup if outside the hover area.
		if( mouseOverType != oldType )
		{
			if( mouseOverType == "cmtlink" )
			{
				doRemovePopup();
			}	
		}
	}
	
	/*
	 * Various DThread functions
	 */
	function dLinkClick( event, id, root )
	{
		dComment( id, root );		
		return false;
	}

	function dLinkMouseOver( event, id, root )
	{
		if( msgPopup )
		{
			doMsgPopup( event, id, root );
		}
		
		return false;
	}
	
	function dLinkMouseOut( id, root )
	{
		doRemovePopup();
	}	
	
	function getScroll() 
	{
		if (document.all && typeof document.body.scrollTop != "undefined") 
		{	// IE model
			var ieBox = document.compatMode != "CSS1Compat";
			var cont = ieBox ? document.body : document.documentElement;
			return {x : cont.scrollLeft, y : cont.scrollTop};
		}
		else 
		{
			return {x : window.pageXOffset, y : window.pageYOffset};
		}
	}

	function RemovePopup()
	{
		tryPopupAgain = false;
		obj = document.getElementById( "tooltipspan" );
		if( obj )
		{
			obj.style.display = "none";
		}
	}
	
	function CancelRemovePopup()
	{
		if( removeTimerID )
		{
			clearTimeout( removeTimerID );
			removeTimerID = false;
		}
		
		if( popupTimerID )
		{
			clearTimeout( popupTimerID );
			popupTimerID = false;		
		}
	}
	
	function doRemovePopup()
	{
		tryPopupAgain = false;
		removeTimerID = setTimeout( "RemovePopup( )", 700 );
	}
	
	function doMsgPopup( e, id, root )
	{
//		document.all.dbgid.innerHTML = mouseOverType + "!";
	
		if( !popupDisabled && ( currentComment != id ) )
		{
			if( !tryPopupAgain )
			{
				// Skip load if we're reloading
				tryPopupX = e.clientX;
				tryPopupY = e.clientY;
			}
			
			CancelRemovePopup();
			
			delay = 900;
			if( commentsBodyHTML[ id ] ) delay = 300;
			
			popupTimerID = setTimeout( "MsgPopup( " + id + "," + root + ")", delay );
		}
	}
	
	function MsgPopup( id, root )
	{
		if( mouseOverType != "cmtprev" ) return;

		if( msgPopup && !typing )
		{
			clientX = tryPopupX;
			clientY = tryPopupY;				
		
			if( !commentsBodyHTML[ id ] )
			{
				tryPopupAgain = id;
				tryPopupRoot  = root;
				loadDSupport( id, root );
				return;
			}
				
			obj = document.getElementById( "tooltipspan" );
	
			var scroll = getScroll();

			// position tooltip
			var dw = document.width ? document.width : document.documentElement.offsetWidth - 25;
			if (obj.offsetWidth >= dw)
			{
				obj.style.width = dw - 10 + "px";
			}
			else
			{
				obj.style.width = "";
			}

			if (clientX > dw - obj.offsetWidth)
			{
				obj.style.left = dw - obj.offsetWidth + scroll.x + "px";
			}
			else
			{
				obj.style.left = clientX + 24 + scroll.x + "px";			
			}
			
			obj.style.top = ( clientY + scroll.y ) + 'px';
			
//			obj.style.backgroundColor = "#404040";
			obj.style.position = 'absolute';
			obj.style.display = 'block';

			obj.innerHTML =  "<A HREF='#' onclick='RemovePopup(); return false;'>&#215;</A> &nbsp; <A HREF='#' onclick='RemovePopup(); Reply( " + id + ", relComments[ " + id + " ] ); return false;'>reply</A><BR><img src='/i/blank.gif' width=1 height=10 border=0><BR>" + commentsBodyHTML[ id ];
		}
	}
	
	function doLink( linkObj, url )
	{
		if( linkInNewWindow )
		{
			if( checkIt( "opera" ) )
			{
				window.open( url );
				return false;
			}
			else
			{
				linkObj.target = "_blank";
				return true;			
			}
		} else
        {
            linkObj.target = "_parent";
        }

		return true;
	}
	
	function cmtAddComment( id )
	{
		cmtDown[ cmtLastComment ] = id;
		cmtUp[ id ] = cmtLastComment;

		cmtLastComment = id;
	}
	
	function doCmtUp( id )
	{
		if( cmtUp[ id ] )
		{
			location.replace( "ja.zz?id=" + cmtUp[ id ] );
		}
		return false;
	}

	function doCmtDown( id )
	{
		if( cmtDown[ id ] )
		{
			location.replace( "ja.zz?id=" + cmtDown[ id ] );
		}
		return false;
	}
	

	function checkIt(string)
	{
		var detect = navigator.userAgent.toLowerCase();
		place = detect.indexOf(string) + 1;
	        thestring = string;
	        return place;
	}
	
	function loadDSupport( commentID, showInID ) 
	{
		popupDisabled = true;
	    if(document.getElementById) 
		{
			window.frames[ 'bufferFrame' ].window.location.replace( "ja.zz?dsup=" + commentID + "&openedfor=" + showInID );
		}
	}

	function putDBody( commentID, htmlID ) 
	{
	    if(document.getElementById) 
		{ 
			obj = window.frames['bufferFrame'].document.getElementById( htmlID );
			if( obj )
			{
				commentHtml = obj.innerHTML;
				commentsHTML[ commentID ] = commentHtml;
			}
			else
			{
				alert( "Error - " + htmlID + " not found." );
				return;
			}

			if( document.getElementById( "loaded"+commentID ) )
			{
				document.getElementById( "loaded"+commentID ).innerHTML = "*";
			}
	 	}
	}

	function putDBodyTxt( commentID, htmlID ) 
	{
	    if(document.getElementById) 
		{ 
			obj = window.frames['bufferFrame'].document.getElementById( htmlID );
			if( obj )
			{
				commentHtml = obj.innerHTML;
				commentsBodyHTML[ commentID ] = commentHtml;
			}
	 	}
	}
	
	function putDRel( commentID, relID )
	{
		if( relComments )
		{
			relComments[ commentID ] = relID;
		}
	}

	function putDPrev( commentID, htmlID, rootID ) 
	{	
	    if(document.getElementById) 
		{ 
			commentHtml = window.frames['bufferFrame'].document.getElementById( htmlID ).innerHTML;
			previewHTML = previewHTML + commentHtml;
	 	}

		prevComments[ commentID ] = lastComment;
		if( lastComment != 0 )
		{
			nextComments[ lastComment ] = commentID;
		}
		lastComment = commentID;

		commentThreads[ commentID ] = rootID;

		if( rootID != lastTimerID )
		{
			setTimeout( "expireDSupport( " + rootID + ")", 29000 );
			lastTimerID = rootID;
		}
	}

	function expireDSupport( threadID )
	{
		if( !disableTRL )
		{
			var c = 0;
			for( var i in commentThreads )
			{
				if( commentThreads[ i ] == threadID )
				{
					commentsHTML[ i ] = false;
					c++;
				}
			}

			lastTimerID = 0;
		}
	}

	var oldHLVal = "";

	function dComment( commentID, showInID )
	{
		if( !expandedRoots[ showInID ] )
		{
			commentsHTML[ commentID ] = false;
		}
	
		if( !commentsHTML[ commentID ] )
		{
			tryAgain		= true;
			gshowCommentID	= commentID;
			gshowInID		= showInID;
			loadDSupport( commentID, showInID );
		}
		else
		{
			tryAgain = false;

			document.getElementById( "threadblock"+showInID ).innerHTML = commentsHTML[ commentID ];

			if( commentID != oldHL )
			{
				if( oldHL )
				{
					if( document.all )
					{
						document.getElementById( "prevline"+oldHL ).style.background = '';
					}
					else
					{
						document.getElementById( "prevline"+oldHL ).style.background = 'inherit';
					}
				}

				document.getElementById( "prevline"+commentID ).style.background = "#99a2c6";
				oldHL = commentID;
				currentComment = commentID;
			}

			if( document.all )
			{
				threadObj = document.getElementById( "threadblock"+showInID );
				if( document.body.scrollTop > getTopOffset( threadObj ) )
				{
					threadObj.scrollIntoView();
				}
			}
		}
		
		// auto reply dthread
		if( autoReply && document.forms[ "postform" ] && commentID && relComments && relComments[ commentID ] )
		{
			document.forms[ "postform" ].parent.value     = commentID;
			document.forms[ "postform" ].relparent.value  = relComments[ commentID ];
		}

		RemovePopup();
        parent.jazz_resize();
	}

	function getTopOffset( o )
	{
		return ( o.parentElement ? o.offsetTop + getTopOffset( o.parentElement ) : 0 );
	}

	function dStartPage()
	{
		lastComment = 0;
		previewHTML = "";
	}

	function dFinishPage()
	{
		if( tryAgain )
		{
			tryAgain = false;
			fullThreads[ gshowInID ] = previewHTML;

			obj = document.getElementById( "prevblock" + gshowInID );
			obj.innerHTML = previewHTML;
			expandedRoots[ gshowInID ] = 1;

			dComment( gshowCommentID, gshowInID );
		}
		
		if( tryPopupAgain )
		{
			MsgPopup( tryPopupAgain, tryPopupRoot );
			tryPopupAgain = false;
		}

		popupDisabled = false;
	}

	function getCookie(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 unescape(dc.substring(begin + prefix.length, end));
	}

	function setHiddenCookie()
	{
		var v = generateHiddenString();
	
		expires = new Date();
		expires.setTime (expires.getTime() + (1000 * 60 * 60 * 24 * 356) );
		document.cookie = "hide=" + v +"; expires=" + expires.toGMTString() +  "; path=/"; 
	}
	
	function getHiddenCookie()
	{
		hiddenN = new Array();
		var toHide = getCookie( "hide" );

		if( toHide )
		{
			hiddenN = toHide.split(",");
		
			for (var loop=0; loop < hiddenN.length; loop++)
			{
				hiddenA[ hiddenN[ loop ] ] = true;
			}
		}
	}
	
	function isHidden( c )
	{
		return hiddenA[ c ];
	}
	
	function removeHidden( c )
	{
		hiddenA[ c ] = false;
		setHiddenCookie();
	}
	
	function addHidden( c )
	{
		hiddenA[ c ] = true;
		setHiddenCookie();
	}
	
	function hideBlock( c )
	{
		var obj = document.getElementById('prevblock'+c);
		obj.style.display = "none";
		addHidden( c );

		document.getElementById( "threadblock"+c ).style.overflow = "hidden";
		document.getElementById( "threadblock"+c ).style.overflowY = "hidden";
		document.getElementById( "threadblock"+c ).style.height = 45;
		
		document.getElementById( "collapsei"+c ).innerHTML = "[<A href='#' onclick='toggleBlock( " + c + " ); return false;'>Collapsed</A>]";
		document.getElementById( "collapse"+c ).style.display = "block";
		document.getElementById( "collapse"+c ).style.borderTop = "2px dashed white";
	}

	function showBlock( c )
	{
		removeHidden( c );

		if( checkIt( "msie" ) )
		{
			var obj = document.getElementById('prevblock'+c);
			obj.style.display = "block";

			document.getElementById( "collapse"+c ).style.display = "none";
	
			document.getElementById( "threadblock"+c ).style.overflowY = "visible";
			document.getElementById( "threadblock"+c ).style.overflow = "visible";
			document.getElementById( "threadblock"+c ).style.height = '';
		}

		if( !checkIt( "msie" ) )
		{
			location.reload();
		}
	}

	function toggleBlock( c ) 
	{
		if( isHidden( c ) )
		{
			showBlock( c );
		}
		else
		{
			hideBlock( c );
		}
	}

	function generateHiddenString()
	{
		var rv = "";
		var sep = "";
		
		for( var i in hiddenA )
		{
			if( eval(i) > 0 )
			{
				if( hiddenA[ i ] == true )
				{
					rv = "" + rv + sep + i;
					sep = ",";
				}
			}
		}
		
		if( rv.length > 1024 )
		{
			rv = rv.substr( rv.length - 1024, 1024 );
		}
		
		return rv;
	}

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
}


function GetJazzOption( v )
{
	var cvi = getCookie( "jazzoptions" );
	var pairs;

	if( cvi )
	{
		pairs = cvi.split("&");

		for (var i=0;i<pairs.length;i++)
		{
			var pos = pairs[i].indexOf('=');
			if (pos >= 0)
			{
				var argname = pairs[i].substring(0,pos);
				var value = pairs[i].substring(pos+1);

				if( argname == v )
				{
					return value;
				}
			}
		}
	}

	return "";
}

function ReloadMode( mode )
{
	location.replace( "ja.zz?comments=" + QueryString("comments") + "&page=" + QueryString( "page" ) + "&mode=" + mode );
}

// MSGCENTER popup
function popup(author) { }



function genpopup( url ) { 

        // Center the window on the screen
        // In NS it'll appear in the centre of the screen (if maxed)
        // In IE it'll appear in the centre of the screen (maxed or not)
        if (document.all) {
                // Get the height and width of the screen, IE style
                var xwid = screen.width;
                var yhei = screen.height;
        } else {
                if (document.layers) {
                        // Get the width and height of the window, NS style
                        var xwid = window.outerWidth;
                        var yhei = window.outerHeight;
                } else {
                        // And if we can't get anything from NS, just default to this
                        var xwid = 640;
                        var yhei = 520;
                }
        }

        // Work out our offsets, half the screen - half the width of the window we're popping
        // We - a little more for the y so that it sits better on the screen
        var xoffset = (xwid / 2) - 310;
        var yoffset = (yhei / 2) - 160;

        g=open( url , "tableOfContents", "width=620,height=480,scrollbars=yes,resizable=yes,screenX="+xoffset+",screenY="+yoffset+",top="+yoffset+",left="+xoffset);
        g.focus();
}

function Nuke( id, group )
{
	url = '/jazz/nuke_post.x?id=' + id + "&comments=" + group;

	g=open( url , url, "width=400,height=260,scrollbars=no,resizable=yes");
	g.focus();
}

	function Moderate( newsarticle, pagenr, id )
	{
		var id = document.GetElementById( "modsel" + id );
		var flag = id.options[ id.selectedIndex ].value;
		alert( flag );
//		window.frames[ 'modFrame' ].window.location.replace( "/jazz/moderate.x?comments=" + newsarticle + "&page=" + pagenr + "&id=" + id + "&flag= " + flag );
	}

	var lastTimerID;
	var autoReply;
	var linkInNewWindow = ( GetJazzOption( "linw" ) == 1 );
	var debugMode = ( GetJazzOption( "debug" ) == 1 );
	var msgPopup = ( GetJazzOption( "mpop" ) == 1 );
	var noClickDT = ( GetJazzOption( "ncd" ) == 1 );

	// REDIR if not @ techreport.com
    /*
	if( location.host != "techreport.com" )
	{
		location.replace( "http://techreport.com" + location.pathname + location.search );
	}*/

function postOk( url )
{
        location.replace( url );
}
