// All script (C)1998-2009 Digital Photography Review, dpreview.com
// No code may be used elsewhere without permission
//

var i_forum,i_message,i_this_visit,i_last_visit,i_server_time,i_server_time_diff,i_threadmode,i_ignorecheckboxes;
var forummessages,i_messagecnt=0,i_thismessagepos=0,i_nextnewmessage=0;
var forumnewindicate='<span class="newindicate">&nbsp;NEW</span>',forumnew2indicate='<span class="new2indicate">&nbsp;NEW</span>';
var forumhotindicate='<span class="hotindicate">&nbsp;HOT</span>';
var imgdims=new Array();
var bookmarkdisabled=false;
var ignoredisabled=false;
var splitforumsignore=true;

var months=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var subicons_desc=new Array('Single message','Single message, inactive','Single message, locked','Single message, archived and locked','Single message, pinned','Thread','Thread, inactive','Thread, locked',' Thread, archived and locked','Thread, pinned');
var lastsubject,alttitle;
var maxmessagelength=6000;
var islive=false;

var cforumthreadrowtrim=68;
var cforumrowtrim=55;
var edittimerend=0;
var editreturnurl='';

if(document.URL.split('/')[2]=='rock') {
	var server_forum='', server_read='', server_thread='', cookie_domain='';
	var imgserver='';
} else {
	var server_forum='http://www.dpreview.com', server_read='http://forums.dpreview.com', server_thread='http://forums.dpreview.com', cookie_domain='dpreview.com';
	var imgserver='http://a.img-dpreview.com';
}

function safeNumber(n,def) {
	if(n*1==n) return n; else return def;
}

function dprfindObj(n) {
	var x;

	d=document;
	if(!(x=d[n])&&d.all) x=d.all[n];
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

function textareamax(s,maxchars) {
	if (s.value.length > maxchars)
		s.value = s.value.substring(0,maxchars);
}

function jumptoanchor(ahref) {
	anchorobj=dprfindObj('m'+ahref);
	anchorobj.scrollIntoView(1);
}

function setSelRange(inputEl, selStart, selEnd) { 
	if (inputEl.setSelectionRange) 
	{ 
		inputEl.focus(); 
		inputEl.setSelectionRange(selStart, selEnd); 
	} 
	else if (inputEl.createTextRange) 
	{ 
		var range = inputEl.createTextRange(); 
		range.collapse(true); 
		range.moveEnd('character', selEnd); 
		range.moveStart('character', selStart); 
		range.select(); 
	} 
}

function expandIt(whichEl) {
	whichEl.style.display = (whichEl.style.display == "none" ) ? "" : "none";
}

function edittimer(secstogo,returnurl) {
	if(js_ok) {
		var timeroffset=0;
		var today=new Date();
		if(secstogo>0) {
			edittimerend=today/1000+secstogo;
			editreturnurl=returnurl;

			timeroffset=secstogo-(Math.round(secstogo/10)*10);
		}

		var i_browser_time=Math.round(today/1000);			// Seconds
		var tobj=dprfindObj('edittimertext');

		var secs=edittimerend-i_browser_time;

		if(secs<20) {
			alert('Sorry, you ran out of editing time, returning you to the original message.');
			window.location=editreturnurl+'&refresh=edittimeout';
		}

		var minsremaining=Math.floor(secs/60);
		var secsremaining=Math.floor(Math.floor(secs-(minsremaining*60))/10)*10;
		var outputstring=minsremaining+' minutes';

		if(secsremaining>0) {
			outputstring=outputstring+' and '+secsremaining+' seconds';
		}

		tobj.innerHTML=outputstring;
		setTimeout("edittimer(0,'')",10000+(timeroffset*1000));

	}
}

function messagepostaction(x) {
	if(x==1) {
		document.messagepost.action='message_post.asp';
		document.messagepost.submit();
	} else {
		document.messagepost.action='message.asp';
		document.messagepost.submit();
	}
}

function searchsubmit() {
	document.searchform.go.disabled=true;
	document.searchform.submit();
}

function messagedisablebuttons() {
	if(navname == "Microsoft Internet Explorer") {
		document.messageform.postbutton.disabled=true;
		document.messageform.previewbutton.disabled=true;
		document.messageform.undobutton.disabled=true;
		document.messageform.cancelbutton.disabled=true;
	}
}

function forumbookmark(checkid,subscribe,messageid) {
	var sflag, bflag, tflag, ret;
	
	var objb=dprfindObj('bookmarkcheck'+checkid);
	var objs=dprfindObj('subscribecheck'+checkid);
	var objspinner=dprfindObj('ajaxspinner'+checkid);
	
	var seed=Math.round((new Date())/500);	
	
	if(!bookmarkdisabled) {
		bookmarkdisabled=true;
		objb.disabled=true;
		if(objs) objs.disabled=true;
		objspinner.style.visibility='visible';
	
		if(!subscribe){
			if(!objb.checked) {
				if(objs) objs.checked=0;
			}
		} else {
			if(objs.checked && !objb.checked) {
				objb.checked=1;
			}
		}
		
		if(objs) sflag=objs.checked; else sflag=false;
		bflag=objb.checked;
		tflag=(i_thismessagepos==1);
	
		$.ajax({  
		  type: "GET",  
		  url: server_read+"/forums/messagebookmark.asp",  
		  data: "b="+bflag+"&s="+sflag+"&t="+tflag+"&m="+messageid+"&z="+seed, 
		  success: function(html) {
		  	ret=setTimeout(function() {
				objspinner.style.visibility='hidden';
				objb.disabled=false;
				if(objs) objs.disabled=false;
				bookmarkdisabled=false;
	        }, 200);
		  },
		  error: function(html) {
		  	alert('Unfortunately there was a problem recording your bookmark. '+html.responseText + '.');
	
			objspinner.style.visibility='hidden';
			objb.disabled=false;
			if(objs) objs.disabled=false;

			bookmarkdisabled=false;
		  }
		});
	}
}

function forumloadmeshlist() {
	var seed=fGetCookie('sess_meshseed');
	if(seed==null) {
		seed=Math.round((new Date())/500);
		fSetSessCookie('sess_meshseed',seed);
	}
	document.write('<script src="/forums/usermeshlist.asp?'+seed+'" language="javascript"></script>');
}

function forumuserignore(checkid,ignoreuserid,spinner) {
	var obj=dprfindObj('ignorecheck'+checkid);
	var objrefresh=dprfindObj('ignorerefresh');
	var objspinner=dprfindObj(spinner);
	var dflag;
	
	var seed=Math.round((new Date())/500);
	
	if(!ignoredisabled) {
		ignoredisabled=true;
		obj.disabled=true;
		objspinner.style.visibility='visible';
		
		$.ajax({  
		  type: "GET",  
		  url: server_read+"/forums/userignore.asp",  
		  data: "d="+!(obj.checked)+"&i="+ignoreuserid+"&z="+seed, 
		  success: function(html) {
		  	ret=setTimeout(function() {
				objspinner.style.visibility='hidden';
				obj.disabled=false;
				fSetSessCookie('sess_meshseed',seed);
				if(i_ignorecheckboxes>1) forumignorecheckboxesflat(ignoreuserid,obj.checked);

				ignoredisabled=false;
	        }, 200);
		  },
		  error: function(html) {
		  	alert('Unfortunately there was a problem recording your preference. '+html.responseText + '.');

			objspinner.style.visibility='hidden';
			obj.disabled=false;
			obj.checked=1-obj.checked;

			ignoredisabled=false;
		  }
		});
	}
}

function forumignorecheckboxes(numchecks) {
	var obj,j,id;
	
	i_ignorecheckboxes=numchecks;
	
	for(j=1;j<=numchecks;j++) {
		obj=dprfindObj('ignorecheck'+j);
		if(obj) {
			id=obj.value.split("-")[1];
			obj.checked=(userignorelist[id]);
		}
	}
}

function forumignorecheckboxesflat(id,setval) {
	var obj,j;
	
	for(j=1;j<=i_ignorecheckboxes;j++) {
		obj=dprfindObj('ignorecheck'+j);
		if(obj) {
			if(obj.value.split("-")[1]==id)
				obj.checked=setval;
		}
	}
}

function messageaction(x) {
	var problem="";

	switch(x) {
	case 0:
	case 1:
		if(js_ok) {

			if(document.messageform.message.value=="") {
				problem="Message is a required field, please enter the text of your message.";
				jumpto=document.messageform.message;
			} else {
				if(document.messageform.message.value.length>maxmessagelength) {
					problem="Your message is too long, maximum length is " + maxmessagelength+ " characters.\nPlease trim the message, remove unwanted quoted text from\nolder messages.";
					jumpto=document.messageform.message;
				}
			}
			if(document.messageform.email) if(document.messageform.email.value=="") {
				problem="Email is a required field, please enter your email address.";
				jumpto=document.messageform.email;
			}
			if(document.messageform.name) if(document.messageform.name.value=="") {
				problem="Name is a required field, please enter your name.";
				jumpto=document.messageform.name;
			}
			if(document.messageform.subject.value=="") {
				problem="Subject is a required field, please enter a message subject.";
				jumpto=document.messageform.subject;
			}
			if(problem=="") {
				if(x==1) {
					document.messageform.post.value="Preview";
				} else {
					document.messageform.post.value="Post";
				}
				messagedisablebuttons();
				document.messageform.submit();
			} else {
				alert("Problem:\n" + problem);
				jumpto.focus();
			}
		} else {
			messagedisablebuttons();
			document.messageform.submit();
		}
		break;
	case 2:
		if(confirm('Undo - clear any typed text, are you sure?'))
				document.messageform.reset();
				document.messageform.message.focus();
		break;
	case 3:
		if(confirm('Cancel - return to previous page, are you sure?')) {
				messagedisablebuttons();
				history.go(-1);
		}
		break;
	}
}

function messageload() {
	if (js_ok) 
	{
		// move the selection caret to start of message box (only if subject isn't selected and message caret is at the end)
		var message = document.getElementById('message');
		var subject = document.getElementById('subject');
		var caretPositionInMessage = GetCaretIndex(message);
		if (IsElementFocused(subject) == false && caretPositionInMessage == message.value.length)
		{
			setSelRange(message,0,0);
			message.scrollIntoView(false); // 'false' scrolls bottom of element to bottom of page
		}
		
		// add tab-key handler for subject line (to push caret to BEGINNING of message box for ALL browsers)
		document.messageform.subject.onkeydown = function (e)
		{
			e = e||event;
			if (e.keyCode == 9)
			{
				setSelRange(document.messageform.message,0,0);
				e.cancelBubble = true;
				if (e.preventDefault)
				{
					e.preventDefault();
				}
				return false;
			}
		};
		
		/*i_edit=fGetQuerystring('edit');
		if(i_edit==1) {
			document.messageform.message.focus();
		} else{
			document.messageform.subject.focus();
			document.messageform.subject.select();
		}*/
	}
}

function GetCaretIndex (inputBox) 
{
	// try the firefox way
	if ("selectionStart" in inputBox) 
	{
		return inputBox.selectionStart;
	}

	//and now, the blinkered IE way
	var bookmark = document.selection.createRange().getBookmark();
	var selection = inputBox.createTextRange();
	selection.moveToBookmark(bookmark);

	var before = inputBox.createTextRange();
	before.collapse(true);
	before.setEndPoint("EndToStart", selection);

	return before.text.length;
}


function IsElementFocused (el)
{
	if (document.activeElement)
	{
		return document.activeElement == el;
	}
	return false;
}

function js_email() {
	var email,k;

	email='';
	for(k=0;k<email_addr.length;k++) {
		ch=email_addr.charCodeAt(k) ^ 3;
		document.write(String.fromCharCode(ch));
	}
}

function dprforumjump(me) {
	window.location=server_read + "/forums/forum.asp?forum=" + me.options[me.selectedIndex].value;
}

function forumprodinfo(txt) {
	var newtxt,pos;

	// Wouldn't it be nice to use .replace, however old netscape doesn't support it
	// newtxt=txt.replace("/ /g","+");

	newtxt=txt;

	while(newtxt.indexOf(" ")>0) {
		pos=newtxt.indexOf(" ");
		newtxt=newtxt.substring(0,pos) + "+" + newtxt.substring(pos+1);
	}

	window.location="/reviews/prodinfo.asp?keyw=" + newtxt;
}

function fGetCookieCrumb(sName,sCrumb)
{
  var aCookie = unescape(document.cookie).split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) {
		var aArr=aCookie[i];
		aArr=aArr.substr(sName.length+1)
		aArr=aArr.split("&");
		for (var j=0; j < aArr.length; j++)
		{
			aCrumb=aArr[j].split("=");
			if (sCrumb==aCrumb[0])
				return aCrumb[1];
		}
  	}
  }
  return null;
}

function fGetCookie(sName)
{
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  return null;
}

function fSetSessCookie(sName,sVal)
{
	document.cookie=sName+'='+sVal+'; path=/; domain='+cookie_domain;
}


function fGetQuerystring(sName)
{
  var aQS = window.location.search.substring(1).split("&");

  for (var i=0; i < aQS.length; i++)
  {
    var aCrumb = aQS[i].split("=");
    if (sName == aCrumb[0])
		return unescape(aCrumb[1]);
  }
  return null;
}

function foruminit(dataarray) {
	var today=new Date();

	// These are page variables which are used elsewhere but are preset here
	i_forum=safeNumber(fGetQuerystring('forum'),1000);
	i_message=safeNumber(fGetQuerystring('message'),10000);
	i_threadmode=fGetCookie('threadmode');
	i_browser_time=today/1000;
	i_server_time_diff=fGetCookie('sess_timediff');

	if(!i_server_time_diff) {
		i_server_time=dataarray.time;

		if(dataarray.time!=0) {
			// Nearest second
			i_server_time_diff=Math.round(i_browser_time-(dataarray.time*86400));

			fSetSessCookie('sess_timediff',i_server_time_diff);
		}
	} else {
		if(dataarray.time==0) {
			i_server_time=(i_browser_time-i_server_time_diff)/86400;
		} else {
			i_server_time=dataarray.time;
		}
	}

	// Get the last visited and session last visited cookies
	var lastvisit=fGetCookieCrumb('lastvisit',i_forum);
	var sesslastvisit=fGetCookieCrumb('sess_lastvisit',i_forum);

	if(sesslastvisit!='') {
		i_last_visit=sesslastvisit;
		i_this_visit=lastvisit;
	} else {
		i_last_visit=lastvisit;
	}
}

function forumhideflatignored() {
	if(userignorelist) {
		document.write('<style>');
		for(i in userignorelist) {
			document.write('.author-'+i+' { display: none } ');
			document.write('#authorignored-'+i+' { display: block } ');
		}
		document.write('</style>');
	}
}

function forumflatshowignored(messageid) {
	var obj=dprfindObj('message-'+messageid);
	var objbuttons=dprfindObj('messagebuttons-'+messageid);
	
	if(obj) {
		if(obj.style.display=='block') {
			obj.style.display='none';
			objbuttons.style.display='none';
		} else {
			obj.style.display='block';
			objbuttons.style.display='block';
		}
	}
}


function forumthreadlistrender() {
	var i,message,lastsubject,subjalt,isthis;
	var forumthreadrowtrim,hasignorelist;
	var ohtml='',isnew=0,linkclass='',textclass='';

	// Does this page contain an inline userignorelist array?
	hasignorelist=(userignorelist) ? true:false;
	
	// Preset page variables
	foruminit(threaddata);
	
	for(i in threaddata.messages) {
	
		// Get the message info from the threaddata array (inline JSON)
		message=threaddata.messages[i];
	
		// If the subject is an exclamation mark then use the last subject (bandwidth saver)
		if(message.s=='!') {
			subject=lastsubject;
		} else {
			subject=message.s;
			lastsubject=message.s;
		}
		
		// This flag is set if this message is the one currently being read
		isthis=(message.m==i_message);

		if(isthis) {
			highlight='sel';
		} else if(message.f>0) {
			highlight='selg';
		} else {
			highlight='';
		}
	
		// Work out the new flags
		if(message.d>i_this_visit) {
			isnew=2
		} else if(message.d>i_last_visit) {
			isnew=1
		} else {
			isnew=0
		}
	
		// Check to see if there's a userignorelist array and if so preset some classes
		if(hasignorelist) {
			ignore=(userignorelist[message.x]) ? true:false;
			linkclass=(ignore) ? ' class="ignoregreylink"':'';
			textclass=(ignore) ? ' class="ignoregrey"':'';
			adminlogo=(useradmins[message.x]) ? '<img src="'+imgserver+'/forums/images/adminlogo.gif" width="13" height="13" align="top" title="Administrator" style="padding-left: 2px">':'';
		} else
			ignore=false;
		
		// Preset cell TD's depending on highlighting
		td='<td class="forumscell'+highlight+'">';
		tdl='<td class="forumscellleft'+highlight+'">';
		tdr='<td class="forumscellright'+highlight+' align="center">';
	
		// We used to have to do it this way (IE6)
		//		spacer='';
		//		for(k=0;k<level;k++) spacer+='&nbsp;&nbsp;&nbsp;';
	
		// Calculate the indent
		leftpadding=10+(message.l*8);
		
		// If not the message being read the construct a link, otherwise no link
		if(!isthis) {
			mhref='<a href="' + server_read +'/forums/read.asp?forum=' + i_forum;
			mhref+='&message=' + message.m + '" title="' + subject.replace(/"/g,"'") +'"' + linkclass + '>';
			mhrefclose='</a>';
			thmess=(ignore) ? 'message_ignore':'message';

			// If this is the first new message we've seen then remember that
			if((isnew)&&(i_nextnewmessage==0)) i_nextnewmessage=message.m;
		} else {
			i_thismessagepos=parseInt(i)+1;
			mhref='<span' + textclass+ '>';
			mhrefclose='</span>';
			thmess=(ignore) ? 'message_open_ignore':'message_open';
		}
	
		// Link to the users profile
		authhref='<a href="' + server_forum + '/members/?User=' + message.x + '"' + linkclass + '>';
	
		// If it's new then the space we have for the subject line is reduced
		forumthreadrowtrim=(isnew) ? cforumthreadrowtrim-4:cforumthreadrowtrim;
	
		// Trim subject if necessary
		subject=texttrim(subject,Math.round(forumthreadrowtrim-(message.l*1.5)));
	
		// Begin constructing the row, starting with the icon and subject
		ohtml+='<tr>' + tdl + '<div style="padding-left: '+leftpadding+'px;">';
		ohtml+=mhref + '<img src="' + imgserver + '/forums/images/' + thmess;
		ohtml+='.gif" width="16" height="16" border="0" align="top"></a>&nbsp;';
		ohtml+=mhref + subject + mhrefclose;
		
		// New indicator
		switch(isnew) {
			case 1:
			ohtml+= forumnewindicate;
			break;

			case 2:
			ohtml+= forumnew2indicate;
			break;
		}
		
		ohtml+='</div></td>';
		
		// Author
		ohtml+=td + '&nbsp;' + authhref + message.a + adminlogo + '</a></td>';
		
		// Date posted
		ohtml+=tdr + '<span' + textclass+ '>' + forumstimeago(message.d) + '</span></td>';
		
		// End of message row
		ohtml+='</tr>';
	}
	
	// Output everything in one go
	document.write(ohtml);
}

function forumrender() {
	var messhref,newhref,authhref,thmess,td,subjlen,subjalt,authoralt;
	var forumrowtrim,hasignorelist,linkclass,textclass,iconsuffix;
	var ohtml='', iohtml='',rowhtml;
	
	// Preset page variables
	foruminit(forumdata);

	// Does this page contain an inline userignorelist array?
	hasignorelist=(userignorelist) ? true:false;

	// Preset some html elements to save space and time
	td='<td class="forumscell">';
	tdc='<td class="forumscellc">';
	tdl='<td class="forumscellleft">';
	tdr='<td class="forumscellright" align="center">';

	for(i in forumdata.threads) {
	
		// Get the thread info from the forumdata array (inline JSON)
		thread=forumdata.threads[i];
		
		// If this thread is 'new' then we don't have as much space for the subject
		forumrowtrim=(thread.n>0) ? cforumrowtrim-4:cforumrowtrim;
	
		subjalt=thread.s.replace(/"/g,"'");
		
		// Check to see if there's a userignorelist array and if so preset some classes
		if(hasignorelist) {
			ignore=(userignorelist[thread.x]) ? true:false;	
			linkclass=(ignore) ? ' class="ignoregreylink"':'';
			textclass=(ignore) ? ' class="ignoregrey"':'';
			iconsuffix=(ignore) ? 'i':'';
			adminlogo=(useradmins[thread.x]) ? '<img src="'+imgserver+'/forums/images/adminlogo.gif" width="13" height="13" align="top" title="Administrator" style="padding-left: 2px">':'';
		}
			
		// Thread OP has images
		if(thread.c>0)
			subjalt+=" (" + thread.c + ((thread.c>1) ? " images":" image") + ")";
	
		// Set up links depending on thread view mode (threaded / flat)
		if(i_threadmode!='flat') {
			mhref='<a href="' +server_read+ '/forums/read.asp?forum=' + i_forum + '&message=' + thread.m + '" title="' + subjalt+ '"' + linkclass+ '>';
			lhref='<span'+textclass +'>'; lhrefsuffix='</span>';
		} else {
			mhref='<a href="' +server_read+ '/forums/readflat.asp?forum=' + i_forum + '&thread=' + thread.m + '" title="' + subjalt+ '"' + linkclass+ '>';
			lhref='<a href="' +server_read+ '/forums/readflat.asp?forum=' + i_forum + '&thread=' + thread.m + '&message=latest" title="Skip to latest message posted"' + linkclass+ '>';
			lhrefsuffix='</a>';
		}
	
		newhref='<a href="' +server_read+ '/forums/readnew.asp?forum=' + i_forum + '&thread=' + thread.m + '" title="Skip to latest message posted"' + linkclass+ '>';
		authhref='<a href="' +server_forum+ '/members/?User=' + thread.x + '" title="' + thread.a +'"' + linkclass+ '>';
	
		// Begin constructing the thread row
		rowhtml= '<tr>' + tdl + '&nbsp;&nbsp;';
		
		// Icon
		rowhtml+= mhref + '<img src="' + imgserver + '/forums/images/' + thread.i + iconsuffix + '.gif" width="24" height="16" border="0" align="top"></a>&nbsp;';

		// Subject
		rowhtml+= mhref + texttrim(thread.s,forumrowtrim) + '</a>';
		
		// 'New' indicator
		switch(thread.n) {
			case 1:
			rowhtml+= newhref + forumnewindicate + '</a>';
			break;

			case 2:
			rowhtml+= newhref + forumnew2indicate + '</a>';
			break;
		}

		rowhtml+= '</td>';
		
		// Author
		rowhtml+= td + '&nbsp;' + authhref + texttrim(thread.a,14) + adminlogo + '</a></td>';

		// Last post
		rowhtml+= tdc + lhref + thread.l + lhrefsuffix + '</td>';

		// Number of posts
		rowhtml+= tdr + '<span'+textclass +'>' + thread.p + '</span></td>';
		
		// End of thread row
		rowhtml+= '</tr>';
		
		if(splitforumsignore) {
			if(ignore) iohtml+=rowhtml;
				else ohtml+=rowhtml;
		} else
			ohtml+=rowhtml;
	}
	
	if(splitforumsignore&&(iohtml.length>0)) {
		ohtml+='<tr height="20"><td class="forumscellleft">&nbsp;';
		ohtml+='<div style="left: 190px; width: 570px; background: #555; text-align: center; display:inline; position: absolute"><span>';
		ohtml+='Threads started by users on your ignore list</span></div>';
		ohtml+='</td><td class="forumscell" colspan="2">&nbsp;</td>'+tdr+'&nbsp;</td></tr>';
		ohtml+=iohtml;
	}
	
	// Output everything in one go
	document.write(ohtml);
}

function texttrim(txt,len) {
	if(txt.length>len) {
		alttitle=txt;
		return txt.substr(0,len-2)+'...';
	} else {
		alttitle='';
		return txt;
	}
}

function disablelink(o) {
//	o.disabled=1;
}

function forumnavbuttons() {
	if(dprfindObj('threadnavnext')) {
		nnext=dprfindObj('threadnavnext');
		nprev=dprfindObj('threadnavprev');
		nnextnew=dprfindObj('threadnavnextnew');

		if(i_thismessagepos==i_messagecnt)
			disablelink(nnext);
		if(i_thismessagepos==1)
			disablelink(nprev);
		if(i_nextnewmessage==0)
			disablelink(nnextnew);
	}
}

function forumskipignoredmessages(incv) {
	var skipid=i_thismessagepos+incv;
	
	while((userignorelist[threaddata.messages[skipid-1].x]==1) && (skipid<threaddata.messages.length) && (skipid>1)) 
		skipid+=incv;
		
	if(userignorelist[threaddata.messages[skipid-1].x]!=1)
		return skipid;
}

function forumthreadnav(action) {
	var newhref='',naverr='';
	var defhref=server_read + '/forums/read.asp?forum='+i_forum;
	
	hasignorelist=(userignorelist) ? true:false;
	
	switch(action) {
		case 'next':
		if(i_thismessagepos<threaddata.messages.length) {
			if(hasignorelist)
				newid=forumskipignoredmessages(1);
			else
				newid=i_thismessagepos;
			
			if(newid>0) {
				i_thismessagepos=newid;
				newhref=defhref+'&message='+threaddata.messages[i_thismessagepos-1].m;
			} else {
				naverr='This is the last message in this thread (not ignored).';
			}
		} else {
			naverr='This is the last message in this thread.';
		}
		break;

		case 'prev':
		if(i_thismessagepos>1) {
			if(hasignorelist)
				newid=forumskipignoredmessages(-1);
			else
				newid=i_thismessagepos-1;
			
			if(newid>0) {
				i_thismessagepos=newid;
				newhref=defhref+'&message='+threaddata.messages[i_thismessagepos-1].m;
			} else {
				naverr='This is the first message in this thread (not ignored).';
			}
		} else {
			naverr='This is the first message in this thread.';
		}
		break;

		case 'nextnew':
		if(i_nextnewmessage!=0) {
			newhref=defhref+'&message='+i_nextnewmessage;
		} else {
			naverr='There are no new messages beyond this point.';
		}
		break;


	}
	if(newhref!='')
		window.location=newhref;

	if(naverr!='')
		self.status=naverr;

}

function forumstimeago(stime) {
	var today=new Date();
	var arbt=(i_server_time*1440)-(stime*1440);
	var t='';

	if(i_server_time!=0) {
		if(arbt<60) {
			arbt=Math.round(arbt);
			if(arbt==0) arbt=1;
			t=t+arbt+' min';
		} else if(arbt<1440) {
			arbt=Math.round(arbt/60);
			t=arbt+' hour';
		} else if(arbt<40320) {
			arbt=Math.round(arbt/1440);
			t=arbt+' day';
		}

		if(t!='') {
			if(arbt>1) t=t+'s';
			t=t+' ago';
		} else {
			stime=(10592+stime)*86400000;
			var itime=new Date(stime);
			t=itime.getDate()+' '+months[itime.getMonth()]+' '+itime.getFullYear();
		}
	} else {
		stime=(10592+stime)*86400000;
		var itime=new Date(stime);
		t=itime.getDate()+' '+months[itime.getMonth()]+' '+itime.getFullYear();
	}


	return t;
}


function zoomimg(imgid,zm) {
	embedimg=document.getElementById('embedimg' + imgid);
	imgwid=embedimg.width;
	imghei=embedimg.height;

	if(imgdims.length<imgid) imgdims[imgid]=[imgwid,imghei];
	else {
		if(!imgdims[imgid]) imgdims[imgid]=[imgwid,imghei]
	}

	if(zm>0) {
		embedimg.width=imgwid*zm;
		embedimg.height=imghei*zm;
		expandimg(imgid,3);
	} else {
		embedimg.width=imgdims[imgid][0];
		embedimg.height=imgdims[imgid][1];
		expandimg(imgid,3);
	}
}

function expandimg(imgid,flag) {
	imgcontain=document.getElementById('imgcontain' + imgid);
	bufferimg=document.getElementById('bufferimg' + imgid);
	embedimg=document.getElementById('embedimg' + imgid);
	imgicon=document.getElementById('iconimg'+imgid);

	if(flag==2)	if(imgcontain.style.position=='absolute') { flag=0 } else { flag=1 };
	if(flag==3)	if(imgcontain.style.position=='absolute') { flag=1 } else { flag=0 };


	imgwid=embedimg.width;
	imghei=embedimg.height;

	if(imgwid>0) {
		if(flag==1) {
			if(imgwid>540) {
				midpoint=475-Math.round(imgwid/2);
				if(midpoint<10)  midpoint=10;

				if(ismsie) {
					imgcontain.style.width=imgwid+4;
				} else {
					imgcontain.style.width=imgwid;
				}
				imgcontain.style.left=midpoint;
				imgcontain.style.position='absolute';
				imgcontain.style.borderStyle='solid';
				imgcontain.style.borderColor='#333333';
				imgcontain.style.borderWidth=2;
				bufferimg.style.height=imghei+1;
				if(imgicon.width==22) imgicon.src="/images/imgexpand1.gif";
			} else {
				imgcontain.style.width=540;
				bufferimg.style.height=1;
				imgcontain.style.borderStyle='none';
				imgcontain.style.position='static';
				if(imgicon.width==22) imgicon.src="/images/imgexpand0.gif";
			}
		} else {
			imgcontain.style.width=540;
			bufferimg.style.height=1;
			imgcontain.style.borderStyle='none';
			imgcontain.style.position='static';
			if(imgicon.width==22) imgicon.src="/images/imgexpand0.gif";
		}
	}
}

function mouseoverimg(imgid) {
		imgcontain=document.getElementById('imgcontain' + imgid);
		imgicon=document.getElementById('iconimg'+imgid);
		embedimg=document.getElementById('embedimg' + imgid);
		imgwid=embedimg.width;

		if (imgwid>488)	{
			imgicon.width=22;
			if(imgcontain.style.position=='absolute') {
				imgicon.src="/images/imgexpand1.gif";
			} else {
				imgicon.src="/images/imgexpand0.gif";
			}
		}
}

function mouseoutimg(imgid) {
		imgicon=document.getElementById('iconimg'+imgid);
		imgicon.src="/images/one.gif";
		imgicon.width=13;
}