fw.Libs.load([
	'http://link.members.webs.com/JS/checkLogin.jsp',
	'../images.webs.com/JS/mootools.js',
	'../images.webs.com/JS/bbBox.js',
	'../images.webs.com/static/JS/fwPaging.html'
]);

var fwForum = new Class({
	
	type: 'forum',
	page: 1,
	editBoxes: {},
	maxPostLen: 1800,
	
	initialize: function(ownerID, options){
		this.options = Object.extend({
			imagePath: 'http://images.freewebs.com/Images/Forums/',
			skin: 'blue',
			write: true,
			adminMode: false,
			offsite: false,
			autoscroll: false,
			linksOpenNewWindow: false
		}, options || {});
		
		Object.extend(String.prototype, {
			truncateAsTitle: function(len, elip){
				if(!elip) elip = true;
				if(this.length+2 > len)
					return '<span title="' + this + '">' + this.substr(0, len) + (elip ? '&hellip;' : '') + '</span>';
				return this;
			}
		});
		
		var loc = (location.href+'');
		if(loc.indexOf('freewebs.com')>-1 && loc.indexOf('EditPage')>-1){
			this.options.adminMode = true;
			this.options.linksOpenNewWindow = true;
		}
			
		this.ownerID = ownerID;
		this.userType = (ownerID == fwuser.id) ? 'admin' : (fwuser.loggedIn ? 'member' : false);
		this.containerID = this.type + ownerID;
		this.adminMode = this.options.adminMode ? true : (this.userType=='admin' ? 'site' : false);
		this.imagePath = this.options.imagePath;
		this.skin = this.options.skin;
		this.isOffsite = this.options.offsite;
		
		this.prepare();
		if(this.options.write) this.write();
		this.instance = fw.Instances.add(this);
	},
	
	getURL: function(params){
		var qob = {};
		var qsplit = (location.href+'').split('?');
		var qstring = qsplit[1];
		if(qstring){
			var pairs = qstring.split('&');
			pairs.each(function(p){
				var name = p.split('=')[0];
				var value = p.split('=')[1];
				qob[name] = unescape(value);
			});
		}
		Object.extend(qob, {
			topicID:'',
			forumID:'',
			page:'',
			scroll:'',
			reportedPosts:''
		}, params);
		Object.extend(qob, params);
		var arr = [];
		for(var name in qob){
			if(qob[name])
				arr.push(name + '=' + escape(qob[name]));
		}
		return qsplit[0] + (arr.length > 0 ? '?' : '') + arr.join('&');
	},

	prepare: function(){
		this.setSkin(this.options.skin);
		this.removeStack = [];
		this.forumID = fw.Request.getParameter('forumID');
		this.topicID = fw.Request.getParameter('topicID');
		this.reportedPosts = fw.Request.getParameter('reportedPosts');
		this.isBoard = !(this.forumID || this.topicID || this.reportedPosts);
		this.page = fw.Request.getParameter('page') || this.page;
		this.scroll = fw.Request.getParameter('scroll');
		if(this.reportedPosts) this.forumID = this.topicID = 'admin';
		
		//main wrapper
		this.HTML = '<div class="fwForum" id="' + this.containerID + '"><a id="forumTop" name="forumTop"></a>';
		
		//control panel
		if(!this.adminMode || this.adminMode=='site'){
			this.HTML += '<div id="userPanel">';
			//logged in
			if(fwuser.loggedIn){
				this.HTML += '<span style="float:right; padding-right:5px; padding-top:-4px; padding-bottom:4px;"><b>' + fwuser.username + '</b> ('+this.userType+')</span>';
				this.HTML += '<a ' + this.getPngStyle('logOut.html', 51, 16) + 'href="http://link.members.webs.com/s/login/logout?next=' + encodeURIComponent(location) + '"></a>';
				if(this.adminMode)
					this.HTML += '<a id="toggleAdminLink" ' + this.getPngStyle((Cookie.get(this.id + 'adminMode') == 'hide' ? 'show' : 'hide') + 'Admin.png', 82, 16) + 'href="" onclick="fw.Instances.get(\''+this.containerID+'\').toggleAdminMode(); return false;"></a>';
			}
			//logged out
			else {
				this.HTML += '<a ' + this.getPngStyle('register.html', 56, 16) + 'href="http://link.members.webs.com/reloginLite.jsp?showSignup=1&amp;forumID=' + this.ownerID + '&amp;next=' + encodeURIComponent(location) + '"></a>';
				this.HTML += '<a ' + this.getPngStyle('logIn.html', 51, 16) + 'href="http://link.members.webs.com/reloginLite.jsp?showLogin=1&amp;next=' + encodeURIComponent(location) + '&amp;forumID=' + this.ownerID + '"></a>';
			}
			this.HTML += '<span id="statusText">Loading...</span></div>';
		}

		//admin - add category
		if(this.adminMode){
			var hide = '';
			if(!this.isBoard)
				hide = ' style="visibility:hidden;"';
			this.HTML += '\
			<div id="adminPanel"><table class="category"><tr>\
				<td><div'+hide+'>New&nbsp;Category:</div></td>\
				<td style="width:60%"><div'+hide+'><input id="newCatName" type="text"></div></td>\
				<td'+hide+'><div style="padding-left:5px; width:68px;"><a ' + this.getPngStyle('addcat.html', 68, 16) + 'class="addCat" href="#"></a></div></td>\
				<td style="width:40%;">\
				' + (this.adminMode!='site' ? '\
					<span id="statusText">Loading...</span>\
				' : '') + '\
				</td>\
				<td><div style="width:' + (this.isOffsite ? 85 : 160) + 'px;">\
				<a ' + this.getPngStyle('reportedPosts.html', 82, 16) + 'href="?reportedPosts=1' + (this.forumID ? '&amp;forumID='+this.forumID : '') + (this.topicID ? '&amp;topicID='+this.topicID : '') + '&amp;page=1"' + (this.options.linksOpenNewWindow ? ' target="_blank"' : '') + '></a>\
				' + (!this.isOffsite ? '\
					<a ' + this.getPngStyle('chooseSkin.html', 68, 16) + 'href="#" onclick="fw.Instances.get(\''+this.containerID+'\').toggleSkinChooser(); return false;"></a></div></td>\
				' : '') + '\
			</tr></table></div>';
		}
		
		//html for post areas
		var postAreaHTML = '<div><table><tr> <td class="paging"></td> <td class="postLink"></td> </tr></table></div>';
		
		//structure
		this.HTML += '\
		<div id="nav"></div>\
		<div style="clear:left; padding-top:10px; padding-bottom:2px;" id="upperPostArea" class=".fw-secondary">' + postAreaHTML + '</div>\
		<div id="bbBoxUpper"></div>\
		<ul id="board"></ul>\
		<div style="clear:left;" id="lowerPostArea" class=".fw-secondary">' + postAreaHTML + '</div>\
		<div id="bbBoxLower"></div>';

		//close main wrapper
		this.HTML += '</div>';
	},
	
	toggleAdminMode: function(){
		this.adminMode = !this.adminMode;
		Cookie.set(this.id + 'adminMode', this.adminMode ? 'show' : 'hide');
		$('toggleAdminLink').style.cssText = this.getPngStyle((this.adminMode ? 'hide' : 'show') + 'Admin.png', 82, 16, true);
		
		$S('td.drag, td.edit, td.close, td.delete, td.sticky, td.permissions, div.addCategory, div.addForum').each(function(el){
				el.style.display = this.adminMode ? '' : 'none';
		}.bind(this));
	},
	
	getPngStyle: function(src, width, height, inline){
		return (inline ? '' : 'style="') + 'margin-right:3px; display:-moz-inline-box; display:inline-block; float:left; cursor:pointer; width:'+width+'px; height:'+height+'px; background:url(' + this.imagePath+src + ') !important; background:transparent; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.imagePath+src + '\', sizingMethod=\'scale\')' + (inline ? '' : '"') + ' ';		
	},
	
	write: function(){
		document.write(this.HTML);
		if(window.attachEvent)
			window.setTimeout(this.activate.bind(this), 1);
		else
			this.activate();
	},

	activate: function(){
		this.controlPanel = this.adminMode ? $('adminPanel') : $('controlPanel');
		this.container = $(this.containerID);
		this.nav = $('nav');
		this.upperPostArea = $('upperPostArea');
		this.bbBoxUpper = $('bbBoxUpper');
		this.board = $('board');
		this.lowerPostArea = $('lowerPostArea');
		this.bbBoxLower = $('bbBoxLower');
		
		var width = window.$('board').offsetWidth;
		//if(width < 650)
		//	this.thinAdmin = true;
		this.chopNameLen = width > 400 ? (width - 300) / 18 : 15;
		
		if(this.reportedPosts || this.topicID)
			this.populateTopic();
		else if(this.forumID && !this.topicID)
			this.populateForum();
		else
			this.populateBoard();
		
		//create post boxes
		this.bbBoxUpper.bbBox = this.createBbBox('bbBox1', this.bbBoxUpper);
		if(this.topicID) this.bbBoxLower.bbBox = this.createBbBox('bbBox2', this.bbBoxLower);
		
		//inject mootools hack
		if(document.compatMode && document.compatMode == "BackCompat"){
			Object.extend(fx.Height.prototype, {
				increase: function() {
					this.element.style.height = (this.now < 1 ? 1 : this.now) + "px";		
				},
				toggle: function() {
					if (this.element.offsetHeight > 1) this.custom(this.element.offsetHeight, 0);
					else this.custom(0, this.element.scrollHeight);
				}
			});
		}

		this.populateNav();
	},
	
	createBbBox: function(id, el){
		return new bbBox(id,{
			showActionButtons: true,
			hideTabs: false,
			width: 700,
			height: 250,
			style: true,
			showName: true,
			showEmail: true,
			emailDesc: ' (Email will be used only to alert you of replies to this topic.)',
			showSubject: this.topicID ? false : true,
			showLogin: fwuser.loggedIn ? true : this.options.showLogin,
			onPost: function(){
				if(this.forumID && !this.topicID)
					this.postTopic(el);
				else if(this.topicID)
					this.postReply(el);
				return false;
			}.bind(this),
			onCancel: function(){ el.fx.toggle(); }.bind(this),
			write: false
		});
	},
	
	populatePostArea: function(){
		if(this.postDiv) return;
		if(this.reportedPosts) return;
		
		if(this.topicJSON && this.topicJSON.closed) {
			this.lowerPostArea.getElement('.postLink').innerHTML = '<div class="closedMessage">this topic is closed</div>';
			return;
		}

		//add post links and bbBox effects
		if(!this.isBoard){
			
			var postLinkHTML = '<a class="newPostLink" href="#">' + (this.topicID ? '<img src="'+this.imagePath+'newReply.gif">' : '<img src="'+this.imagePath+'newTopic.gif">') + '</a>';
			
			//create post links
			this.upperPostArea.getElement('.postLink').innerHTML = postLinkHTML;
			if(this.topicID) this.lowerPostArea.getElement('.postLink').innerHTML = postLinkHTML;
			
			//create bbBoxes
			this.bbBoxUpper.innerHTML = this.bbBoxUpper.bbBox.HTML;
			if(this.topicID) this.bbBoxLower.innerHTML = this.bbBoxLower.bbBox.HTML;
			$('bbBox1').style.marginBottom = '10px';
			
			//attach effects
			this.bbBoxUpper.fx = new Fx.Height(this.bbBoxUpper, {duration: 150}).set(0);
			if(this.topicID){
				this.bbBoxLower.fx = new Fx.Height(this.bbBoxLower, {duration: 250}).set(0);
				this.bbBoxLower.fx.increase = function(){
					this.setStyle(this.element, this.property, this.now);
					if(Window.getScrollTop() + Window.getHeight() < this.element.getTop() + this.now)
						window.scrollTo(0, this.element.getTop() - Window.getHeight() + this.now + 10);
				}.bind(this.bbBoxLower.fx);
			}
			
			this.upperPostLink = this.upperPostArea.getElement('.newPostLink');
			this.upperPostLink.onclick = function(){
				if(this.forumJSON && this.forumJSON.userIsAllowed || this.topicJSON && this.topicJSON.userIsAllowed){
					this.bbBoxUpper.fx.toggle();
				} else {
					this.doLoginRedirect();
				}
				return false;
			}.bind(this);
			
			if(this.topicID){
				this.lowerPostLink = this.lowerPostArea.getElement('.newPostLink');
				this.lowerPostLink.onclick = function(){
					if(this.forumJSON && this.forumJSON.userIsAllowed || this.topicJSON && this.topicJSON.userIsAllowed){
						this.bbBoxLower.fx.toggle();
					} else {
						this.doLoginRedirect();
					}
					return false;
				}.bind(this);
			}
			
			this.bbBoxUpper.bbBox.activate();
			this.bbBoxUpper.bbBox.resize('100%');
			
			if(this.topicID){
				this.bbBoxLower.bbBox.activate();
				this.bbBoxLower.bbBox.resize('100%');
			}
		}
	},
	
	doLoginRedirect: function(){
		location = 'http://link.members.webs.com/reloginLite.jsp?next=' + encodeURIComponent(location) + '&forumID=' + this.ownerID;
	},
	
	setSkin: function(skin, noCache){
		this.skin = skin;
		fw.Css.load('http://link.members.webs.com/Members/Forums/fwForum.css.jsp?skin=' + skin + (noCache ? '&' + Math.random() : ''));
		if(noCache) $('skin' + skin).addClass('selected');
	},
	
	deselectSkin: function(){
		this.skinChooser.getElements('a').each(function(el){ el.removeClass('selected'); });
	},
	
	populateSkinChooser: function(){
		var self = this;
		this.skinChooser = new Element('div')
			.setProperty('id', 'skinChooser')
			.setHTML('Choose a Skin: ')
			.injectAfter(this.controlPanel);
		['blue','green','red','pink','light','fire','water','silver','forest','ice','plum','mint','dark','desert'].each(function(skin){
			var a = new Element('a').addClass('skinLink');
			if(skin == self.skin) a.addClass('selected');
			a.id = 'skin' + skin;
			a.href = '#';
			a.innerHTML = skin;
			a.onclick = function(){
				self.deselectSkin();
				this.addClass('selected');
				self.setSkin(skin, true);
				return false;
			}
			self.skinChooser.appendChild(a);
		});
		
		var save = new Element('a').addClass('imgLink').adopt(
			new Element('img').setProperty('src', this.imagePath + '/save.png')
		).injectInside(this.skinChooser);

		var cancel = new Element('a').addClass('imgLink').adopt(
			new Element('img').setProperty('src', this.imagePath + '/cancel.png')
		).injectInside(this.skinChooser);
		
		save.onclick = this.saveSkin.bind(this);
		
		cancel.onclick = function(){
			this.deselectSkin();
			this.setSkin(this.options.skin, true);
			this.toggleSkinChooser();
			return false;
		}.bind(this);
	},
	
	saveSkin: function(){
		this.options.skin = this.skin;
		this.dispatch('board', 'setSkin', {
			callback: 'toggleSkinChooser',
			statusMsg: 'Saving...',
			data:{
				skinName: this.options.skin
			}
		});
		return false;
	},
	
	toggleSkinChooser: function(response){
		if(response && response.error){
			alert(response.error.msg);
			return;	
		}
		
		if(!this.skinChooser)
			this.populateSkinChooser();
		else
			this.skinChooser.toggleClass('hidden');
			
		if(this.skinChooserCallback) this.skinChooserCallback();
		return false;
	},
	
	populateTopic: function(response){
		if(!response){
			this.dispatch('topic', 'list', {
				callback: 'populateTopic',
				statusMsg: 'Loading Posts...',
				data: {
					page: this.page,
					topicID: this.topicID,
					forumID: this.forumID,
					reportedPosts: this.reportedPosts || false
				}
			});
			return;
		}

		if(response.error){
			alert(response.errorMsg)
			return;
		}
		
		this.topicJSON = response.topic;
		this.forumName.innerHTML = this.topicJSON.forumName;
		this.topicSubject.innerHTML = this.topicJSON.subject;

		this.board.innerHTML = this.getPostHTML();
		if(this.reportedPosts && !this.board.innerHTML){
			this.board.innerHTML = '<li style="padding:15px;">No posts in your forum have been reported for abuse.</li>';
		}
	
		this.resizePosts();
		
		if(this.adminMode){
			if(Cookie.get(this.id + 'adminMode') == 'hide')
				this.toggleAdminMode();
			this.attachTopicAdminEvents();
		}

		this.attachTopicEvents();
		this.populatePostArea();
		this.populatePaging();

	},
	
	resizePosts: function(){
		var padding = 20;
		$S('li.category td.postBody p').each(function(el){
			if(el.offsetHeight + padding > el.parentNode.style.height)
				el.parentNode.style.height = (el.offsetHeight - 0 + padding) + 'px';
		}.bind(this));
	},
	
	attachTopicAdminEvents: function(){
		var self = this;
		
		$S('li.category td.delete a').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var postID = fwForum.getElId(li);
				
				if(!confirm('To delete this post, click OK.')) return false;
				
				self.dispatch('post', 'delete', {
					callback: 'doRemove',
					data:{
						postID: postID
					}
				});
				
				self.removeStack.push(li);
				return false;
			}
		});	
	},
	
	loadPostCallback: function(response){
		if(response && response.error){
			alert(response.errorMsg)
			return;
		}
		var p = response.post;
		
		var li = $('post_' + p.id);
		var postID = fwForum.getElId(li);
		var bodyTD = li.getElements('table.forum td.postBody')[0];
		var editTR = li.getElements('table.forum tr.editBox')[0];
		editTR.style.display = '';
		bodyTD.style.display = 'none';
		
		if(!this.editBoxes[postID].activated){
			new Element('div').setHTML(this.editBoxes[postID].HTML).injectInside(editTR.getElement('td'));
			this.editBoxes[postID].activate();
			this.editBoxes[postID].setText(p.body);
			this.editBoxes[postID].activated = true;
		}
	},
	
	updatePostCallback: function(response){
		if(response && response.error){
			alert(response.errorMsg)
			return;
		}
		var p = response.post;
		
		var li = $('post_' + p.id);
		var editTR = li.getElements('table.forum tr.editBox')[0];
		editTR.style.display = 'none';
		var bodyTD = li.getElements('table.forum td.postBody')[0];
		bodyTD.style.display = '';
		
		bodyTD.getElements('p')[0].innerHTML = p.body;
		
		this.resizePosts();
	},
	
	attachTopicEvents: function(){
		var self = this;
		
		$S('li.category td.editPost a').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var postID = fwForum.getElId(li);
				var editTR = li.getElements('table.forum tr.editBox')[0];
				var bodyTD = li.getElements('table.forum td.postBody')[0];
				
				if(!self.editBoxes[postID]){
					self.editBoxes[postID] = new bbBox('editBox'+postID,{
						showActionButtons: true,
						hideTabs: false,
						width: bodyTD.offsetWidth,
						height: bodyTD.offsetHeight,
						style: true,
						showName: false,
						showEmail: false,
						showLogin: false,
						btn1Label: 'save',
						onPost: function(){
							self.dispatch('post', 'update', {
								callback: 'updatePostCallback',
								statusMsg:'Saving...',
								data: {
									postID: postID,
									body: encodeURIComponent(self.editBoxes[postID].getText()).substr(0, self.maxPostLen)
								}
							});
						}.bind(this),
						onCancel: function(){
							editTR.style.display = 'none';
							bodyTD.style.display = '';
						}.bind(this),
						write: false
					});
					
					self.dispatch('post', 'read', {
						callback: 'loadPostCallback',
						statusMsg:'Loading Post...',
						data: {
							postID: postID
						}
					});
				} else {
					self.loadPostCallback({
						post:{
							id: postID
						}	
					});
				}
				
				return false;
			}
		});
		
		$S('li.category td.lowerLinks a.report').each(function(el){
			if(self.reportedPosts == 1){
				el.onclick = function(){
					var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
					var postID = fwForum.getElId(li);
					self.dispatch('post', 'unreport', {
						callback: 'refreshTopic',
						data:{
							postID: postID
						}
					});
					return false;
				}
			} else {
				el.onclick = function(){
					if(!(self.topicJSON && self.topicJSON.userIsAllowed)){
						self.doLoginRedirect();
						return false;
					}
					
					var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
					var postNumber = li.getElement('span.postNumber').innerHTML;
					var postID = fwForum.getElId(li);
					
					if(!confirm('To report post #' + postNumber + ' for spam or abuse click OK.')) return false;
					
					self.dispatch('post', 'report', {
						callback: 'reportCallback',
						data:{
							postID: postID
						}
					});
					return false;
				}
			}
		});
	},
	
	refreshTopic: function(req){
		if(req && req.error){
			alert(req.errorMsg);
			return;	
		}
		this.populateTopic();
	},
	
	reportCallback: function(response){
		if(response.error){
			alert(response.errorMsg);
			return;	
		}
		alert('post reported!');
		var reportLink = $S('#post_' + response.postID + ' td.lowerLinks a.report')[0];
		var disabled = new Element('span').addClass('report').setHTML('reported!');
		reportLink.replaceWith(disabled);
	},
	
	getPostHTML: function(posts){
		if(!posts) posts = this.topicJSON.posts;
		var count = 0;
		var ret = '';
		posts.each(function(p){
			count++;
			var posterName = p.posterName;
	
            /* Second table had an inline height of 100% - removing as it seems to cause problems in Firefox -- Ryan */

			ret += '\
			<li class="category" id="post_' + p.id + '">\
				<table border="0" cellspacing="0" cellpadding="0" class="category">\
					<tr>\
						<td class="title" style="width:100%;">\
						<span class="posterName">' + (p.posterID ? '<a href="' + p.linkBackURL + '">' + posterName + '</a>' : posterName) + '</span>\
						</td>\
						<td><span class="posterTime">' + p.formattedTs.replace(/ /g, '&nbsp;') + '</span>\</td>\
					' + (p.isEditable ? '\
						<td class="editPost" style="padding:0; padding-left:4px; padding-right:1px;"><a ' + this.getPngStyle('edit.html', 36, 16) + 'href="#"><!--- ---></a></td>\
					' : '') + '\
					' + (this.adminMode ? '\
						<td class="delete" style="padding:0; padding-left:4px; padding-right:1px;"><a ' + this.getPngStyle('delete.html', 31, 16) + 'href="#"><!--- ---></a></td>\
					' : '') + '\
					</tr>\
				</table>\
				<table border="0" cellspacing="0" cellpadding="0" class="forum">\
					<tr>\
						<td class="postInfo" rowspan="' + (p.isEditable ? 3 : 2) + '">\
						' + (p.posterID ? '\
							<p class="posterImg"><a href="' + p.profileURL + '"><img src="' + p.smallImage + '"></a></p>\
						' : '') + '\
						<span class="posterType">' + (p.posterID ? (this.ownerID == p.posterID ? 'admin' : 'member') : 'anonymous') + '</span>\
						</td>\
						<td class="postBody"><div><p>' + p.body + '</p><span class="postNumber">' + ((this.page-1)*this.topicJSON.limit + count) + '</span></div></td>\
					</tr>\
					' + (p.isEditable ? '\
					<tr class="editBox" style="display:none;">\
						<td></td>\
					</tr>\
					' : '') + '\
					<tr>\
						<td class="lowerLinks"><a class="report" href="#">' + (this.reportedPosts==1 ? 'cancel report (' + p.rCount + ' report' + (p.rCount!=1?'s':'') + ')' : (p.isReported ? 'reported!' : 'report abuse')) + '</a></td>\
					</tr>\
				</table>\
			</li>';
		}.bind(this));
		return ret;
	},
	
	populateNav: function(){
		var navHTML = '';
		var separator = '<span style="font:verdana; padding-left:4px; padding-right:4px;">&gt;</span>';
		
		if(!this.isBoard)
			navHTML += '<a id="linkBoard" href="' + this.getURL({page:'', forumID:'', topicID:''}) + '">Forums</a>';
		
		if(this.forumID){
			navHTML += separator;
			if(this.topicID && !this.reportedPosts)
				navHTML += '<a id="forumName" href="'+this.getURL({page:1, forumID:this.forumID, topicID:''})+'"></a>';
			else
				navHTML += '<b id="forumName">' + (this.reportedPosts ? 'Admin' : 'loading...') + '</b>';
		}
		
		if(this.topicID)
			navHTML += separator + '<b id="topicSubject">loading...</b>';
		
		this.nav.innerHTML = navHTML;

		this.forumName = $('forumName');
		
		if(this.topicID)
			this.topicSubject = $('topicSubject');
	},

	populatePaging: function(){
		if(this.isBoard) return;
		
		this.upperPaging = this.createPaging('upperPaging');
		this.upperPostArea.getElement('.paging').innerHTML = this.upperPaging.HTML;
		this.upperPaging.activate();
		
		this.lowerPaging = this.createPaging('lowerPaging');
		this.lowerPostArea.getElement('.paging').innerHTML = this.lowerPaging.HTML;
		this.lowerPaging.activate();

		if(this.options.autoscroll)
			window.scrollTo(0, this.scroll || this.options.autoscroll || 0);
	},
	
	createPaging: function(id){
		return new fwPaging(id, {
			startPage: this.page,
			pageStyle: 'margin:0 3px 0 3px;',
			selectedPageStyle: 'font-weight:bold;',
			pageCount: this.topicID ? Math.ceil(this.topicJSON.rCount / this.topicJSON.limit) : Math.ceil(this.forumJSON.tCount / this.forumJSON.limit),
			write:false,
			onClick: function(page){
				if(this.topicID)
					location = this.getURL({page:page, forumID:this.forumID, topicID:this.topicID});
				else
					location = this.getURL({page:page, forumID:this.forumID, topicID:''});
				return false;
			}.bind(this)
		});
	},
	
	postReply: function(el){
		var errorMsg = '';
		var name = el.bbBox.getName();
		var email = el.bbBox.getEmail();
		var body = el.bbBox.getText();
		
		if(!name) errorMsg += 'Missing name. ';
		if(!body) errorMsg += 'Missing message. ';
		if(errorMsg){
			alert(errorMsg);
			return false;	
		}
		
		this.dispatch('post', 'reply', {
			callback: 'postReplyCallback',
			statusMsg: 'Posting Reply...',
			data: {
				forumID: this.forumID,
				topicID: this.topicID,
				posterName: encodeURIComponent(name),
				email: encodeURIComponent(email),
				body: encodeURIComponent(body).substr(0, this.maxPostLen)
			}
		});
	},
	
	postReplyCallback: function(response){
		if(response.error){
			alert(response.errorMsg);
			return;	
		}
		location = this.getURL({page:response.page, forumID:this.forumID, topicID:this.topicID});
	},
	
	postTopic: function(el){
		var errorMsg = '';
		var name = el.bbBox.getName();
		var email = el.bbBox.getEmail();
		var subject = el.bbBox.getSubject();
		var body = el.bbBox.getText();
		
		if(!name) errorMsg += 'Missing name. ';
		if(!subject) errorMsg += 'Missing subject. ';
		if(!body) errorMsg += 'Missing message. ';
		if(errorMsg){
			alert(errorMsg);
			return false;	
		}
		
		this.dispatch('topic', 'create', {
			callback: 'populateForum',
			statusMsg: 'Posting Topic...',
			data: {
				forumID: this.forumID,
				posterName: encodeURIComponent(name),
				email: encodeURIComponent(email),
				subject: encodeURIComponent(subject),
				body: encodeURIComponent(body).substr(0, this.maxPostLen)
			}
		});
	},
	
	populateForum: function(response){
		if(!response){
			this.dispatch('forum', 'list', {
				callback: 'populateForum',
				statusMsg:'Loading Topics...',
				data: {
					page: this.page,
					forumID: this.forumID
				}
			});
			return;
		}
		
		if(response.error){
			alert(response.errorMsg)
			return;
		}
		
		this.fadeInTopicID = 0;
		if(response.fadeInTopicID)
			this.fadeInTopicID = response.fadeInTopicID;
		
		this.forumJSON = response.forum;
		this.forumName.innerHTML = this.forumJSON.name;
		
		this.board.innerHTML = '\
		<li class="category">\
			<table border="0" cellspacing="0" cellpadding="0" class="category">\
				<tr>\
					' + (this.adminMode ? '\
						<td class="sticky"><img style="visibility:hidden;" src="'+this.imagePath+'sticky.png" /></td>\
					' : '') + '\
					<td class="title">topic</td>\
					<td class="num">posts</td>\
					<td class="num">views</td>\
					<td class="name">last post by</td>\
					' + (this.adminMode ? '\
						<td class="close"><img style="visibility:hidden;" src="'+this.imagePath+'close.png" /></td>\
					' : '') + '\
					' + (this.adminMode ? '\
						<td class="delete"><img style="visibility:hidden;" src="'+this.imagePath+'delete.png" /></td>\
					' : '') + '\
				</tr>\
			</table>\
			<ul class="topics">' + this.getTopicHTML() + '</ul>\
		</li>';
		
		if(this.adminMode){
			if(Cookie.get(this.id + 'adminMode') == 'hide')
				this.toggleAdminMode();
			this.attachForumAdminEvents();
		}
			
		this.attachForumEvents();
		if(!response.fadeInTopicID){
			this.populatePostArea();
		} else {
			this.page = 1;	
		}
		this.populatePaging();
		
		if(response.fadeInTopicID){
			var li = $('topic_' + response.fadeInTopicID);
			if(li){
				li.fx = new Fx.Height(li, {duration:250}).set(0);
				li.fx.opacity = new Fx.Opacity(li, {duration:400}).set(0);
				li.style.display = '';
				li.fx.toggle.delay(1);
				li.fx.opacity.toggle.delay(2);
			}
		}
		
		if(response.collapsePostArea){
			this.bbBoxUpper.fx.toggle();
			this.bbBoxUpper.bbBox.setSubject('');
			this.bbBoxUpper.bbBox.setText('');
		}
	},
	
	getTopicHTML: function(topics){
		if(!topics) topics = this.forumJSON.topics;
		if(!topics.length)
			return '<li class="forum"><table class="forum"><tr><td class="noPosts" colspan="5" style="padding:20px;">No Topics Posted</td></tr></table></li>';
		
		var ret = '';
		topics.each(function(t){
			ret += '<li class="forum" id="topic_' + t.id + '"' + (this.fadeInTopicID==t.id ? ' style="display:none;"' : '') + '>\
				<table border="0" cellspacing="0" cellpadding="0" class="forum">\
					<tr>\
					' + (this.adminMode && t.priority<=0 ? '\
						<td class="sticky"><a href="#" class="sticky"><img src="'+this.imagePath+'sticky.png" /></a></td>\
					' : '') + (this.adminMode && t.priority>0 ? '\
						<td class="sticky"><a href="#" class="unstick"><img src="'+this.imagePath+'unstick.png" /></a></td>\
					' : '') + '\
						<td class="description">\
							<span class="bullet' + (t.closed ? ' bulletClosed' : '') + (t.priority ? ' bulletSticky' : '') + '">&nbsp;</span>' + (t.priority>0 ? '<span class="stickyLabel">sticky:</span>' : '') + '<a class="follow" href="#"><b>' + t.subject.truncateAsTitle(35) + '</b></a>\
							<span class="postedBy">by&nbsp;' + t.posterName.truncateAsTitle(40) + '</span>\
						</td>\
						<td class="num">' + t.rCount + '</td>\
						<td class="num">' + t.vCount + '</td>\
						<td class="name">' + (t.lastPosterName == '' ? 'no posts' : t.lastPosterName.truncateAsTitle(this.chopNameLen) + '<br /><span class="timestamp">' + t.formattedTs + '</span>') + '</td>\
					' + (this.adminMode && !t.closed ? '\
						<td class="close"><a href="#" class="close"><img src="'+this.imagePath+'close.png" /></a></td>\
					' : '') + (this.adminMode && t.closed ? '\
						<td class="close"><a href="#" class="open"><img src="'+this.imagePath+'open.png" /></a></td>\
					' : '') + (this.adminMode ? '\
						<td class="delete"><a href="#" class="delete"><img src="'+this.imagePath+'delete.png" /></a></td>\
					' : '') + '\
					</tr>\
				</table>\
			</li>';
		}.bind(this));
		return ret;
	},
	
	attachForumEvents: function(){
		var self = this;
		$S('li.forum .description a.follow').each(function(el){
			var topicID = fwForum.getElId(el.parentNode.parentNode.parentNode.parentNode.parentNode);
			el.href = self.getURL({forumID:self.forumID, topicID:topicID, page:1});
		});
	},
	
	attachForumAdminEvents: function(){
		var self = this;
		
		$S('table.forum a.delete').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var topicID = fwForum.getElId(li);
				if(!confirm('To delete topic "' + li.getElements('a.follow b')[0].innerHTML + '", click OK.')) return false;
				self.dispatch('topic', 'delete', {
					callback: 'doRemove',
					data:{
						topicID: topicID
					}
				});
				self.removeStack.push(li);
				return false;
			}
		});
		
		$S('table.forum a.sticky').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var topicID = fwForum.getElId(li);
				li.override = true;
				li.onComplete = function(){
					self.dispatch('topic', 'update', {
						callback: self.page==1 ? 'populateForum' : 'voidCallback',
						data:{
							page: 1,
							topicID: topicID,
							priority: 1
						}
					});
				}
				self.removeStack.push(li);
				self.processRemoveStack();
				return false;
			}
		});
		
		$S('table.forum a.unstick').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var topicID = fwForum.getElId(li);
				li.override = true;
				li.onComplete = function(){
					self.dispatch('topic', 'update', {
						callback: 'populateForum',
						data:{
							topicID: topicID,
							priority: 0
						}
					});
				}
				self.removeStack.push(li);
				self.processRemoveStack();
				return false;
			}
		});
		
		$S('table.forum a.close').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var topicID = fwForum.getElId(li);
				self.dispatch('topic', 'update', {
					callback: 'refreshForum',
					data:{
						topicID: topicID,
						closed: true
					}
				});
				return false;
			}
		});
		
		$S('table.forum a.open').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var topicID = fwForum.getElId(li);
				self.dispatch('topic', 'update', {
					callback: 'refreshForum',
					data:{
						topicID: topicID,
						closed: false
					}
				});
				return false;
			}
		});
	},
	
	refreshForum: function(req){
		if(req && req.error){
			alert(req.errorMsg);
			return;	
		}
		this.populateForum();
	},
	
	populateBoard: function(response){
		if(!response){
			this.dispatch('board', 'list', {
				callback: 'populateBoard',
				statusMsg:'Loading Forums...'
			});
			return;
		}
		
		if(response.error){
			alert(response.errorMsg)
			return;
		}
		
		this.newCatID = 0;
		this.newForumID = 0;
		if(response.newCatID)
			this.newCatID = response.newCatID;
		if(response.newForumID)
			this.newForumID = response.newForumID;
		
		this.boardJSON = response.board;
		this.board.innerHTML = this.getBoardHTML();

		if(response.newCatID)
			var li = $('cat_' + response.newCatID);
		if(response.newForumID)
			var li = $('forum_' + response.newForumID);
		if(li){
			li.style.display = '';
			li.fx = new Fx.Height(li, {duration:250}).set(0);
		}
		
		if(this.adminMode){
			if(Cookie.get(this.id + 'adminMode') == 'hide')
				this.toggleAdminMode();
			$('newCatName').value = '';
			this.attachBoardAdminEvents();
		}
		this.attachBoardEvents();
		if(li) li.fx.toggle();
	},
	
	getGroupOptions: function(permissions){
		if(!this.boardJSON.groups) return '';
		var ret = '';
		for(var i=0; i<this.boardJSON.groups.length; i++){
			var g = this.boardJSON.groups[i];
			ret += '<option value="' + g.id + '"' + (g.id==permissions ? ' SELECTED' : '') + '>' + g.name + '</option>';
		}
		return ret;
	},

	getBoardHTML: function(categories){
		if(!categories) categories = this.boardJSON.categories;

		var ret = '';
		categories.each(function(cat){
			if(cat.forums && cat.forums.length > 0 || this.adminMode)
			ret += '<li class="category" id="cat_' + cat.id + '"' + (this.newCatID==cat.id ? ' style="display:none;"' : '') + '>\
			<table border="0" cellspacing="0" cellpadding="0" class="category">\
				<tr>\
				' + (this.adminMode ? '\
					<td class="drag"><img src="'+this.imagePath+'drag.png" /></td>\
				' : '') + '\
					<td class="title"><h2 class="category">' + cat.name + '</h2></td>\
					<td class="num">topics</td>\
					<td class="num">posts</td>\
					<td class="name">last post by</td>\
				' + (this.adminMode ? '\
					<td class="permissions' + (this.thinAdmin && !this.isOffsite ? ' hidden' : '') + '"><select style="visibility:hidden;">\
						<option value="1">Members</option>\
						<option value="0">Everyone</option>\
						' + this.getGroupOptions(0) + '\
						</select>\
					</td>\
					<td class="edit"><a href="#" class="edit"><img src="'+this.imagePath+'edit.png" /></a></td>\
					<td class="delete"><a href="#" class="delete"><img src="'+this.imagePath+'delete.png" /></a></td>\
				' : '') + '\
				</tr>\
			</table>\
			' + (cat.forums.length ? '\
				<ul class="forums">' + this.getForumHTML(cat.forums) + '</ul>\
			' : '') + '\
			' + (this.adminMode ? '\
				<div class="addForum"><div><table><tr>\
					<td class="label">Forum&nbsp;Name:</td>\
					<td class="input"><input class="forumName" type="text"></td>\
					<td class="label">Description:</td>\
					<td class="input"><input class="forumDesc" type="text"></td>\
					<td class="add"><a href="#"><img src="'+this.imagePath+'addforum.png"></a></td>\
				</tr></table></div></div>\
			' : '') + '\
			</li>';
		}.bind(this));		
		return ret;
	},
	
	getForumHTML: function(forums){
		var ret = '';
		forums.each(function(f){
			ret += '<li class="forum" id="forum_' + f.id + '"' + (this.newForumID==f.id ? ' style="display:none;"' : '') + '>\
				<table border="0" cellspacing="0" cellpadding="0" class="forum">\
					<tr>\
					' + (this.adminMode ? '\
						<td class="drag"><img src="'+this.imagePath+'drag.png" /></td>\
					' : '') + '\
						<td class="description">\
							<a class="follow" href="#"><h3>' + f.name + '</h3></a>\
							<p>' + f.desc + '</p>\
						</td>\
						<td class="num">' + f.tCount + '</td>\
						<td class="num">' + f.pCount + '</td>\
						<td class="name" style="overflow:hidden;">' + (f.lastPosterName == '' ? 'no posts' : f.lastPosterName.truncateAsTitle(this.chopNameLen) + '<br /><span class="timestamp">' + f.formattedTs + '</span>') + '</td>\
					' + (this.adminMode ? '\
						<td class="permissions' + (this.thinAdmin && !this.isOffsite ? ' hidden' : '') + '">Who&nbsp;can&nbsp;post?<br><select>\
							<option value="1"' + (f.permissions == 1 ? ' SELECTED' : '') + '>Members</option>\
							<option value="0"' + (f.permissions == 0 ? ' SELECTED' : '') + '>Everyone</option>\
							' + this.getGroupOptions(f.permissions) + '\
							</select>\
						</td>\
						<td class="edit"><a href="#" class="edit"><img src="'+this.imagePath+'edit.png" /></a></td>\
						<td class="delete"><a href="#" class="delete"><img src="'+this.imagePath+'delete.png" /></a></td>\
					' : '') + '\
					</tr>\
				</table>\
			</li>';
		}.bind(this));
		return ret;
	},

	attachBoardEvents: function(){
		var self = this;
		$S('li.forum .description a.follow').each(function(el){
			var forumID = fwForum.getElId(el.parentNode.parentNode.parentNode.parentNode.parentNode);
			el.href = self.getURL({page:1, forumID:forumID, topicID:''});
			if(self.options.linksOpenNewWindow){
				el.href = self.boardJSON.linkBackUrl + '?forumID=' + forumID;
				el.target = '_blank';
			}
		});
	},

	attachBoardAdminEvents: function(){
		var self = this;
		new Sortables($S('#board li.category'), {
			injectInside: self.container,
			handles: $S('#board table.category td.drag img'),
			onStart: function(){
				self.orderTmp = fwForum.getIdOrder('#board li.category');
			},
			onComplete: function(){
				var newOrder = fwForum.getIdOrder('#board li.category').reverse();
				if(self.orderTmp.toString() !== newOrder.toString()){
					this.dispatch('category', 'setOrder', {
						statusMsg: 'Saving...',
						data:{
							catIDs: newOrder
						}
					});
				}
			}.bind(this),
			onDrag: function(e){
				
			}
		});

		new Sortables($S('#board li.forum'), {
			injectInside: self.container,
			handles: $S('#board li.forum td.drag img'),
			onStart: function(){
				self.orderTmp = fwForum.getIdOrder('#board ul.forums li.forum');
			},
			onComplete: function(){
				var newOrder = fwForum.getIdOrder('#board ul.forums li.forum');
				if(self.orderTmp.toString() !== newOrder.toString()) 
				this.dispatch('forum', 'setOrder', {
					statusMsg: 'Saving...',
					data:{
						forumIDs: newOrder
					}
				});
			}.bind(this)
		});
		
		$S('td.permissions select').each(function(el){
			el.onchange = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var forumID = fwForum.getElId(li);
				
				self.dispatch('forum', 'update', {
					data:{
						forumID: forumID,
						permissions: el.value
					}
				});
				return false;
			}
		});

		$S('div.addForum a').each(function(el){
			el.onclick = function(){
				var div = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var catLI = $(div.parentNode.parentNode);
				var forumUL = catLI.getElements('ul.forums')[0];
				var inputName = div.getElements('input.forumName')[0];
				var inputDesc = div.getElements('input.forumDesc')[0];
				
				var newName = inputName.value;
				var newDesc = inputDesc.value;
				if(!newName){
					alert('Please enter a forum name.');
					return false;	
				}
				
				self.dispatch('forum', 'create', {
					callback: 'populateBoard',
					data:{
						catID: fwForum.getElId(catLI),
						name: encodeURIComponent(newName),
						description: encodeURIComponent(newDesc)
					}
				});
				
				return false;
			}
		});
		
		$S('#adminPanel a.addCat').each(function(el){
			el.onclick = function(){
				var newName = $('newCatName').value;
				if(!newName){
					alert('Please enter a category name.');
					return false;	
				}
				
				self.dispatch('category', 'create', {
					callback: 'populateBoard',
					data:{
						name: encodeURIComponent(newName)
					}
				});
				
				return false;
			}
		});
		
		$S('ul.forums a.delete').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var forumID = fwForum.getElId(li);
				if(!confirm('To delete forum "' + li.getElements('a.follow h3')[0].innerHTML + '", click OK.')) return false;
				
				self.dispatch('forum', 'delete', {
					callback: 'doRemove',
					data:{
						forumID: forumID
					}
				});
				
				self.removeStack.push(li);
				return false;
			};
		});

		$S('table.category a.delete').each(function(el){
			el.onclick = function(){
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				var catID = fwForum.getElId(li);
				
				if(!confirm('To delete category "' + li.getElements('td.title h2')[0].innerHTML + '", click OK.')) return false;
				
				self.dispatch('category', 'delete', {
					callback: 'doRemove',
					data:{
						catID: catID
					}
				});
				
				self.removeStack.push(li);
				return false;
			};
		});
		
		$S('table.category a.edit').each(function(el){
			el.onclick = function(){
				
				var revertCancelButton = function(){
					this.getElements('img')[0].src = self.imagePath + 'edit.png';
					this.isBeingEdited = false;
				}.bind(this);
				
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				
				//cancel action
				if(this.isBeingEdited){
					li.getElements('td.title')[0].innerHTML = this.cancelHTML;
					revertCancelButton();
					return false;
				}
				
				this.isBeingEdited = true;
				this.getElements('img')[0].src = self.imagePath + 'cancel.png';
				this.cancelHTML = li.getElements('td.title')[0].innerHTML;

				li.getElements('td.title')[0].innerHTML = '<input class="text category" type="text" value="'+li.getElements('td.title h2')[0].innerHTML.makeSafe()+'" /><a href="#" class="save"><img class="save" src="'+self.imagePath+'save.png" /></a>';
				
				li.getElements('a.save').each(function(el){
					el.onclick = function(){
						var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
						var newTitle = li.getElements('input')[0].value;
						li.getElements('td.title')[0].innerHTML = '<h2 class="category">' + newTitle.makeSafe() + '</h2>';
						revertCancelButton();
						
						self.dispatch('category', 'update', {
							statusMsg: 'Saving...',
							data:{
								catID: fwForum.getElId(li),
								name: encodeURIComponent(newTitle)
							}
						});
						return false;
						
					};
				});
				return false;
			};
		});
		
		$S('table.forum a.edit').each(function(el){
			el.onclick = function(){
				var revertCancelButton = function(){
					this.getElements('img')[0].src = self.imagePath + 'edit.png';
					this.isBeingEdited = false;
					self.attachBoardEvents();
				}.bind(this);
				
				var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
				
				//cancel action
				if(this.isBeingEdited){
					li.getElements('td.description')[0].innerHTML = this.cancelHTML;
					revertCancelButton();
					return false;
				}
				
				this.isBeingEdited = true;
				this.getElements('img')[0].src = self.imagePath + 'cancel.png';
				this.cancelHTML = li.getElements('td.description')[0].innerHTML;
				
				li.getElements('td.description')[0].innerHTML = '<input class="text title" type="text" value="'+li.getElements('td.description h3')[0].innerHTML.makeSafe()+'" /><br /><input class="text description" type="text" value="'+li.getElements('td.description p')[0].innerHTML.makeSafe()+'" /><a href="#" class="save"><img class="save" src="'+self.imagePath+'save.png" /></a>';
				
				//save action
				li.getElements('a.save').each(function(el){
					el.onclick = function(){
						var li = $(this.parentNode.parentNode.parentNode.parentNode.parentNode);
						var newTitle = li.getElements('input')[0].value;
						var newDesc = li.getElements('input')[1].value;
						
						li.getElements('td.description')[0].innerHTML = '<a class="follow" href="#"><h3>' + li.getElements('input')[0].value.makeSafe() + '</h3></a><p>' + li.getElements('input')[1].value.makeSafe() + '</p>';
						revertCancelButton();
						
						self.dispatch('forum', 'update', {
							statusMsg: 'Saving...',
							data:{
								forumID: fwForum.getElId(li),
								name: encodeURIComponent(newTitle),
								description: encodeURIComponent(newDesc)
							}
						});
						return false;
					};
				});
				return false;
			};
		});
	},
	
	processRemoveStack: function(){
		this.removeStack.each(function(el){
			el.fx = new Fx.Height(el, {duration:200});
			el.fx.opacity = el.effect('opacity', {duration:250});
			if(el.parentNode.childNodes.length > 1 || el.override)
				el.fx.options.onComplete = function(){ if(el.onComplete) el.onComplete(); el.remove() };
			el.fx.toggle();
			el.fx.opacity.custom(1, 0);
			this.removeStack.remove(el);
		}.bind(this));
	},
	
	doRemove: function(response){
		if(response && response.error){
			this.removeStack.pop();
			alert(response.errorMsg)
			return false;
		}
		this.processRemoveStack();
		this.populatePaging();
	},
	
	showBusy: function(msg){
		$('statusText').style.visibility = 'visible';
		msg = msg || 'Please Wait...'
		$('statusText').innerHTML = msg.replace(' ', '&nbsp;');
		this.isBusy = true;
	},
	
	hideBusy: function(){
		$('statusText').style.visibility = 'hidden';
		this.isBusy = false;
	},
	
	voidCallback: function(response){
		if(response.error){
			alert(response.errorMsg);
			return false;
		}
	},
	
	dispatch: function(section, action, options){
		if(this.isBusy) return false;
		
		options = Object.extend({
			statusMsg: 'Please Wait...',
			callback: 'voidCallback'
		}, options || {});
		
		this.showBusy(options.statusMsg);
		fw.jjax.req('http://link.members.webs.com/Members/Forums/Dispatcher.jsp', {
			appendTo: this.container,
			postBody: Object.extend({
				ownerID: this.ownerID,
				section: section,
				action: action,
				callback: 'fw.Instances.get("'+this.containerID+'").hideBusy(); fw.Instances.get("'+this.containerID+'").' + options.callback
			}, options.data || {}) 
		});
	}
	
});

fwForum.getElId = function(el){
	return el.id.split('_')[1];
}

fwForum.getIdOrder = function(sel){
	var ids = [];
	$S(sel).each(function(el){
		ids.push(fwForum.getElId(el));
	});
	return ids;
}

