document.toHide = new Object();
document.panelIds = new Object();
document.submissions = new Object();
document.comments = new Array();
document.submission = -1;

function setDivText(id, text) {
	var d = getDiv(id);
	if (d) {
		d.innerHTML = text;
	} else {
		alert('No matching tag found for ' + id + ' - please contact us so we can fix the problem.');
	}
}

function getDiv(id) {
	var d = document.getElementById(id);
	if (!d) {
		if (document.all) {
			d = document.all[id];
		}
		if (!d) {
			if (document.layers) {
				result = document.layers[id];
			}
		}
	}
	return d;
}

function createXmlHttp() {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return null;
			}
		}
	}
	return xmlHttp;
}

function startEditMode() {
	document.userinfo.edit = true;
	setAbout();
	setFeatures();
	setPicture();
	setDivText('share', document.sharetext);
	setDivText('favorite', '<a href="javascript:stopEditMode();" class="Button">VIEW PROFILE</a><br><br>');
}

function stopEditMode() {
	document.userinfo.edit = false;
	setAbout();
	setFeatures();
	setPicture();
	document.sharetext = getDiv('share').innerHTML;
	setDivText('share', '');
	setDivText('favorite', '<a href="javascript:startEditMode();" class="Button">EDIT PROFILE</a><br><br>');
}

function addFavorite(user) {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			setDivText('favorite', '');
		}
	}
	postParameters(xmlHttp, "/do/favorite", "user=" + user);
}

function removeFavorite(user) {
	document.location = '/do/favorite?action=delete&user=' + user;
}

function getSummaryFormatTableRows(title, text, thumbnail, link) {
	var lineCount = text.split("<br>").length;
	var t = '<tr bgcolor="#d0d0d0"><td height="60" width="60" rowspan="2" valign="top"><a href="';
	t += link;
	t += '"><img src="';
	t += thumbnail;
	t += '" width="60" height="60" border="0"></a></td><td height="14" width="1"><img src="/i/clear.gif" border="0" height="14" width="1"></td><td width="436" bgcolor="#d0d0d0" valign="top">';
	t += title;
	t += '</td></tr><tr><td height="38" width="1"><img src="/i/clear.gif" border="0" height="38" width="1"></td><td rowspan="2" valign="top">';
	t += text;
	t += '</td></tr><tr><td height="';
	t += (lineCount * 8);
	t += '" width="1"><img src="/i/clear.gif" border="0" height="';
	t += (lineCount * 8);
	t += '" width="1"></td><td height="1"><img src="/i/clear.gif" border="0" width="1" height="1"></td></tr>';
	return t;
}

function appendChat(doc) {
	var entries = doc.getElementsByTagName("e");
	var t = '<table cellpadding="2" cellspacing="0" width="500" border="0">';

	for (var i = 0; i < entries.length; i++) {
		var user = getText(entries[i], "u");
		var text = getText(entries[i], "x");
		var time = parseInt(getText(entries[i], "t"));

		if (user.charAt(0) == '#') {
			t += '<tr><td><img src="/i/blank.gif" border="0" width="1" height="1"></td>';
			t += '<td colspan="2">' + getDateString(time) + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
			t += '<i><a href="/' + user.substring(1) + '">' + user.substring(1) + '</a> ';
			t += text;
			t += '</i></td></tr>';
		} else {	  
			var title = getDateString(time) + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/' + user + '">' + user + '</a>';
			var thumbnail = '/u/tuser.' + user.toLowerCase() + '.jpg';
			t += getSummaryFormatTableRows(title, text, thumbnail, '/' + user);
		}
	}
	t += '</table>';
	setDivText('chattext', t);

	var online = doc.getElementsByTagName("online")[0];
	var users = online.getElementsByTagName("u");
	var v = '';
	for (var i = 0; i < users.length; i++) {
		v += '<a target="#" href="/';
		v += getElementText(users[i]);
		v += '">';
		v += getElementText(users[i]);
		v += "</a> ";
	}
	setDivText('lCHAT', 'CHAT (' + users.length + ')');
	setDivText('chatusers', v);
}

function appendOldChat(doc) {
	var entries = doc.getElementsByTagName("e");
	var t = '<table cellpadding="1" cellspacing="0" width="600" border="0">';
	var color = false;
	for (var i = 0; i < entries.length; i++) {
		if (color) {
			t += '<tr bgcolor="#d0d0d0">';
		} else {
			t += '<tr>';
		}
		color = !color;
		t += '<td width="95" valign="top">';
		t += getDateString(parseInt(getText(entries[i], "t")));
		t += '&nbsp;&nbsp;</td><td align="right" width="70" valign="top">';
		t += '<a target="#" href="/';
		t += getText(entries[i], "u");
		t += '">';
		t += getText(entries[i], "u");
		t += '</a>:&nbsp;&nbsp;</td><td valign="top">';
		t += getText(entries[i], "x");
		t += "</td></tr>";
	}
	t += '</table>';
	setDivText('chattext', t);

	var online = doc.getElementsByTagName("online")[0];
	var users = online.getElementsByTagName("u");
	var v = "<b>ONLINE</b>: ";
	for (var i = 0; i < users.length; i++) {
		v += '<a target="#" href="/';
		v += getElementText(users[i]);
		v += '">';
		v += getElementText(users[i]);
		v += "</a> ";
	}
	setDivText('lCHAT', "CHAT (" + users.length + ")");
	setDivText('chatusers', v);
}

function getDateString(time, doYear) {
	var d = new Date();
	d.setTime(time);
	var result = '';
	if (doYear) {
		if (d.getYear() < 2000) {
			result += (1900 + d.getYear()) + ".";
		} else {
			result += (d.getYear()) + ".";
		}
	}
	result += (d.getMonth() < 10) ? ("0" + (d.getMonth() + 1)) : (d.getMonth() + 1);
	result += '.';
	result += (d.getDate() < 10) ? ("0" + d.getDate()) : (d.getDate());
	result += ' ';
	var am = true;

	if (d.getHours() == 0) {
		result += '12:';
	} else if (d.getHours() <= 12) {
		result += (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
		result += ":";
		if (d.getHours() == 12) {
			am = false;
		}
	} else {
		am = false;
		result += ((d.getHours() - 12) < 10) ? "0" + (d.getHours() - 12) : (d.getHours() - 12);
		result += ':';
	}

	result += (d.getMinutes() < 10) ? ("0" + d.getMinutes()) : d.getMinutes();
	result += ' ';
	result += am ? "AM" : "PM";
	return result;
}

function startChat() {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			setTimeout("startChat();", 5000);
			appendChat(xmlHttp.responseXML.documentElement);
		}
	}
	postParameters(xmlHttp, "/chatx.jsp", "last=-1");
}

function clearChat() {
	var xmlHttp = createXmlHttp();
	postParameters(xmlHttp, "/chatx.jsp", "clear=clear");
}

function addChatEntry() {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			appendChat(xmlHttp.responseXML.documentElement);
		}
	}
	var text = document.getElementById('entry');
	if (text) {
		text = text.value;
		document.getElementById('entry').value = '';
	}
	var params = "text=" + escape(text);
	postParameters(xmlHttp, "/chatx.jsp", params);
}

function updateDivText(text, number) {
	var value = text;
	if (number > 0) {
		value += ' (' + number + ')';
	}
	setDivText("l" + text, value);
}

function setTestMessage(msg) {
	setDivText("test", msg);
}

function getSidebarButton(title, id, image) {
	var result = '<a alt="' + title;
	result += '" href="javascript:setSidebar(\'' + id + '\');">';
	result += '<img src="/i/' + image + '" width="40" height="40" border="0"></a>';
	result += "&nbsp;&nbsp;&nbsp;";
	return result;
}

function setSidebar(tttype) {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			var t = "";
			if (xmlHttp.responseXML && xmlHttp.responseXML.documentElement) {

				var doc = xmlHttp.responseXML.documentElement;

				var submissions = doc.getElementsByTagName("s");
				var s;
				var id;
				t += '<b>';

				var chatcount = getText(doc, "cc");
				var usercount = getText(doc, "userc");
				var mailcount = getText(doc, "mc");
				var updatecount = getText(doc, "uc");

				if (document.userloggedin) {
					if (chatcount) updateDivText("CHAT", chatcount);
					if (mailcount) updateDivText("MAIL", mailcount);
					if (usercount) updateDivText("USERS", usercount);	
					if (updatecount) updateDivText("UPDATES", updatecount);
				}
				
				var selected = getText(doc, "t");
				t += '<table cellpadding="0" cellspacing="5" border="0" align="center">';
				for (var i = 0; i < submissions.length; i++) {
					s = submissions[i];
					id = getText(s, "i");
					document.submissions[id] = createSubmission(s);
					t += "<td>" + document.submissions[id].toHtml() + "</td>";
				}
				t += '</tr>';
				t += '<tr><td colspan="' + submissions.length + '" height="20"><div id="sdetail"></div>';
				t += '</td></tr></table>';
			}
			setDivText("sidebar", t);
			setTimeout("setSidebar(null);", 60000);
		}
	}
	postParameters(xmlHttp, "/do/sidebar", "type=" + tttype);
}

function Menu(text, id, image) {
	this.show = Submission_show;
	this.hide = Submission_hide;
	this.setPosition = Submission_setPosition;
	this.stopHide = Submission_stopHide;
	this.startHide = Submission_startHide;
	this.toHtml = Menu_toHtml;
	this.text = text;
	this.id = id;
	this.image = image;
	return this;
}

function Menu_toHtml() {
	var result = '<div onMouseOver="document.submissions[' + this.id + '].stopHide();" onMouseOut="document.submissions[';
	result += this.id + '].startHide();" class="Popup" id="' + this.id;
	result += '">' + this.text + '</div>';
	result += '<a onMouseOver="document.submissions[' + this.id;
	result += '].show(this);" onMouseOut="document.submissions[' + this.id + '].startHide();" class="Plain" href="#"><img src="/i/' + this.image + '" width="40" height="40" border="0"></a>';
	return result;
}

function createSubmission(s) {
	return new Submission(getText(s, "i"), getText(s, "ti"), getText(s, "u"), getText(s, "time"), getText(s, "ty"), getText(s, "tn"), getText(s, "r"));
}

function createComment(s) {
	return new Comment(getText(s, "i"), getText(s, "u"), getText(s, "t"), getText(s, "text"));
}

function startEditAbout() {
	var t = '<b>EDIT INFO</b><br><br><textarea rows="10" cols="50" id="about">';
	t += unescape(document.userinfo.about.replace(/\+/g, " "));
	t += '</textarea><br><br><a class="Button" href="javascript:saveEditAbout();">SAVE</a>&nbsp;<a class="Button" href="javascript:cancelEditAbout();">CANCEL</a><br><br>';
	setDivText('userabout', t);
}

function startEditPicture() {
	var t = '<b>EDIT PICTURE</b><br><br><iframe name="pictureframe" id="pictureframe" src="/user_picture_edit.jsp" name="right" scrolling="auto" frameborder="0" align="center" height="320" width="275"></iframe>';
	t += '<br><br><a class="Button" href="javascript:saveEditPicture();">SAVE</a>&nbsp;<a class="Button" href="javascript:cancelEditPicture();">CANCEL</a><br><br>';
	setDivText('userpicture', t);
}

function startAddComment(id) {
	var t = '<b>ADD COMMENT</b><br><br><textarea rows="10" cols="50" id="';
	t += id;
	t += '-';
	t += 'text"></textarea><br><br><a class="Button" href="javascript:addComment(\'';
	t += id;
	t += '\');">SAVE</a>&nbsp;<a class="Button" href="javascript:initAddComment(\'';
	t += id;
	t += '\');">CANCEL</a><br><br>';
	setDivText(id, t);
}

function startSendMail(id) {
	var t = '<b>SEND MAIL</b><br><form name="mailform"><br>TO: ';
	if (id == 'mailmain') {

			t += '<select id="to">';
			for (var f in document.favorites) {
				t += '<option>' + f + '</option>';
			}
			t += '</select> (<i>Add users to favorites to send mails</i>)';
			for (var mailId in document.mails) {
				if (getDiv('mail' + mailId)) initMail('mail' + mailId);
			}


	} else {
		initMail('mailmain');
		var mailId = id.substring(4);
		for (var mId in document.mails) {
			if (mailId != mId) {
				if (getDiv('mail' + mId)) initMail('mail' + mId);
			}
		}
		t += document.mails[mailId];
		t += '<input type="hidden" id="response" value="';
		t += mailId;
		t += '"><input type="hidden" id="to" value="';
		t += document.mails[mailId];
		t += '">';
	}
	t += '<br><br><textarea rows="10" cols="50" id="text"></textarea><br><br><a class="Button" href="javascript:sendMail(\'' + id + '\');">SEND</a> <a href="javascript:initMail(\'' + id + '\');" class="Button">CANCEL</a><br><br></form>';
	setDivText(id, t);
}

function initMail(id) {
	var t;
	if (id == 'mailmain') {
		t = '<a href="javascript:startSendMail(\'' + id + '\');" class="Button">SEND MAIL</a>';
	} else {
		t = '<a href="javascript:startSendMail(\'' + id + '\');" class="Button">RESPOND</a>'; 
	}
	setDivText(id, t);
}

function sendMail() {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.location = '/mail.jsp';
		}
	}
	var sel = document.mailform["to"];
	var to = '';
	if (sel && sel.options) {
		to	= sel.options[sel.selectedIndex].text;
	} else {
		to = document.getElementById('to').value;
	}

	var text = document.getElementById('text');
	if (text) {
		text = text.value;
	}
	var response = document.getElementById('response');
	if (response) {
		response = response.value;
	} else {
		response = -1;
	}
	var parameters = 'to=' + to + '&text=' + escape(text) + '&response=' + response;
	postParameters(xmlHttp, '/do/mail', parameters);
}

function addComment(id) {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if (xmlHttp.responseXML && xmlHttp.responseXML.documentElement) {
				var doc = xmlHttp.responseXML.documentElement;
				var comments = doc.getElementsByTagName("c");
				document.comments = new Array();
				for (var i = 0; i < comments.length; i++) {
					document.comments[document.comments.length] = createComment(comments[i]);
				}
				setComments();
			}
			initAddComment(id);
		}
	}
	var parameters = "";
	if (document.submission > 0) {
		parameters += "message-id=" + document.submission;
	} else if (document.profile > 0) {
		parameters += "user-id=" + document.profile;
	}
	parameters += "&text=" + escape(document.getElementById(id + '-text').value);
	if (document.comments.length > 0) {
		parameters += "&last=" + document.comments[document.comments.length - 1].id;
	}
	postParameters(xmlHttp, "/do/comment", parameters, id);
}

function setComments() {
	var t = 'NONE YET.<br><br>';
	if (document.comments.length > 0) {
		t = '';
		for (var i = 0; i < document.comments.length; i++) {
			t += document.comments[i].toHtml();
		}
	}
	setDivText("comments", t);
}

function initAddComment(id) {
	var t = '<a href=\"javascript:startAddComment(\'' + id + '\');\" class=\"Button\">ADD COMMENT</a><br><br>';
	setDivText(id, t);
}

function initSidebarPreference() {
	var t = document.userpref["SIDEBAR"];
	t += '<br><br><a class="Button" href="javascript:startEditSidebarPreference();">EDIT</a>';
	setDivText('sidebarpref', t);
}

function startEditSidebarPreference() {
}

function cancelEditPicture() {
	setPicture();
}

function cancelEditAbout() {
	setAbout();
}

function getMin(value1, value2) {
	var result = value1;
	if (value2 < value1) {
		result = value2;
	}
	return result;
}

function startEditFeatures() {
	var t = '<b>EDIT FEATURES</b><br><br>';
	var count = 0;
	for (var i in document.userinfo.submissions) {
		count++;
	}
	var min = getMin(count, 8);
	for (var i = 0; i < min; i++) {
		t += '<select id="feature';
		t += i;
		t += '" name="feature';
		t += i;
		t += '"><option value="-1"></option>';
		for (var j in document.userinfo.submissions) {
			t += '<option value="';
			t += document.userinfo.submissions[j].id;
			t += '" ';
			if (document.userinfo.features[i] && (document.userinfo.features[i] == document.userinfo.submissions[j].id)) {
				 t += 'selected="selected"';
			}
			t += '>';
			t += document.userinfo.submissions[j].id;
			t += ': ';
			t += unescape(document.userinfo.submissions[j].title).replace(/\+/g, " ");;
			t += '</option>';
		}
		t += '</select> ';
	}
	t += '<br><br><a class="Button" href="javascript:saveEditFeatures();">SAVE</a>&nbsp;<a class="Button" href="javascript:cancelEditFeatures();">CANCEL</a><br><br>';
	setDivText('userfeatures', t);
}

function cancelEditFeatures() {
	setFeatures();
}

function search(type) {	
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			var t = '<b>SEARCH RESULTS</b><br><span style="background:#000000;"><img src="/i/blank.gif" border="0" height="1" width="600"></span><br><img src="/i/blank.gif" border="0" width="1" height="6"><br>';
 
			if (xmlHttp.responseXML && xmlHttp.responseXML.documentElement) {
				var doc = xmlHttp.responseXML.documentElement;
				var submissions = doc.getElementsByTagName("s");
				var s;
				if (submissions.length == 0) {
					t += 'NO RESULTS IN ' + (type == 'submissions' ? "SUBMISSIONS" : "COMMENTS") + '.<br><br>';
				} else {
					for (var i = 0; i < submissions.length; i++) {
						s = createSubmission(submissions[i]);
						t += s.toSimpleHtml() + '<br><br>';
					}
				}
			}
			setDivText('results', t);
		}
	}
	var parameters = 'type=' + type + '&text=' + escape(document.getElementById("search").value);
	postParameters(xmlHttp, "/do/search", parameters);
}

function saveEditAbout() {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.userinfo.about = escape(xmlHttp.responseText);
			setAbout();
		}
	}
	var parameters = 'about=' + escape(document.getElementById("about").value);
	postParameters(xmlHttp, "/do/userabout", parameters);
}

function postParameters(xmlHttp, target, parameters, loadingdiv) {
	xmlHttp.open("POST",target,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
	
	if (loadingdiv) {
		var d = getDiv(loadingdiv);
		if (d) {
			d.innerHTML = '<img src="/i/loading.gif" width="32" height="32" border="0">';
		}
	}
}

function getSelectValue(selectName) {
	var s = document.getElementById(selectName);
	return s.options[s.selectedIndex].value;
}

function saveEditFeatures() {
	var xmlHttp = createXmlHttp();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState == 4) {
			var t = "";
			if (xmlHttp.responseXML && xmlHttp.responseXML.documentElement) {
				var doc = xmlHttp.responseXML.documentElement;
				var submissions = doc.getElementsByTagName("s");
				document.userinfo.features = new Array();
				for (var i = 0; i < submissions.length; i++) {
					document.userinfo.features[document.userinfo.features.length] = createSubmission(submissions[i]).id;
				}
				setFeatures();
			}
		}
	}
	var parameters = "";
	var count = 0;
	for (var i in document.userinfo.submissions) {
		count++;
	}
	var min = getMin(count, 8);
	for (var i = 0; i < min; i++) {
		parameters += 'feature';
		parameters += i;
		parameters += '=';
		parameters += escape(getSelectValue('feature' + i));
		parameters += '&';
	}
	postParameters(xmlHttp, "/do/userfeatures", parameters);
}

function saveEditPicture() {
	if (document.frames) {
		document.frames["pictureframe"].document["imageupload"].submit();
	} else {
		document.getElementById("pictureframe").contentWindow.document["imageupload"].submit();
	}
}

function setAbout() {
	var t =  unescape(document.userinfo.about.replace(/\+/g, " "));

	t = t.replace(/\n/g, "<br>");
	if (document.userinfo.edit) {
		t += '<br><br><a class="Button" href="javascript:startEditAbout();">CHANGE</a><br><br>';
	}
	setDivText("userabout", t);
}


function showType(type) {
	var t = '<table cellpadding="0" cellspacing="0" border="0"><tr>';
	var submissions = new Array();
	for (var i in document.userinfo.submissions) {
		submissions[submissions.length] = document.userinfo.submissions[i];
	}
	var count = 0;
	for (var i = submissions.length - 1; i >= 0 && count < 8; i--) {
		var s = submissions[i];
		if (s.type == type) {
			t += '<td width="60" align="center" valign="top"><a style="border: 0px; padding: 1px;" href="/';
			t += s.id;
			t += '">';
			t += '<img src="/u/';
			t += s.thumbnail;
			t += '" width="60" height="60" border="0"></a><br>';
			t += unescape(s.title).replace(/\+/g, " ");
			t += '</td><td width="8"><img src="/i/clear.gif" border="0" width="8" height="1"></td>';
			count++;
		}
	} 
	t += '</tr></table>';
	setDivText('userfeatures', t);
	setDivText('ftitle', type + " SUBMISSIONS");
}

function setFeatures() {
	var t = '<table cellpadding="0" cellspacing="0" border="0"><tr>';
	if (document.userinfo.features.length > 0) {
		for (var i = document.userinfo.features.length - 1; i >= 0; i--) {
			var s = document.userinfo.submissions[document.userinfo.features[i]];
			t += '<td width="60" align="center" valign="top"><a style="border: 0px; padding: 1px;" href="/';
			t += s.id;
			t += '">';
			t += '<img src="/u/';
			t += s.thumbnail;
			t += '" width="60" height="60" border="0"></a><br>';
			t += unescape(s.title).replace(/\+/g, " ");
			t += '</td><td width="8"><img src="/i/clear.gif" border="0" width="8" height="1"></td>';
		}
	} else {
		t += '<td>NONE YET.</td>';
	}
	t += '</tr></table>';
	if (document.userinfo.edit) {
		t += '<br><br><a class="Button" href="javascript:startEditFeatures();">CHANGE FEATURES</a><br><br><br>';
	}
	setDivText('userfeatures', t);
	setDivText("ftitle", "FEATURED SUBMISSIONS");
}

function setPicture() {
	var t = '<img src="/u/' + unescape(document.userinfo.picture.replace(/\+/g, " ")) + '" width="200" height="200" border="0">';
	if (document.userinfo.edit) {
		t += '<br><br><a class="Button" href="javascript:startEditPicture();">CHANGE</a><br><br>';
	}
	setDivText('userpicture', t);
}

function getElementText(element) {
	var result = element.text;
	if (!(result)) {
		result = element.textContent;
	}
	return result;
}

function getText(parent, childName) {
	var result = parent.getElementsByTagName(childName)[0].text;
	if (!(result)) {
		result = parent.getElementsByTagName(childName)[0].textContent;
	}
	return result;
}

function Comment(id, user, time, text) {
	this.id = id;
	this.user = user;
	this.time = time;
	this.text = text;
	this.toHtml = Comment_toHtml;
	return this;
}

function Comment_toHtml() {
	var t = '<div id="comment-';
	t += this.id;
	t += '"><table cellpadding="2" cellspacing="0" width="500" border="0">';
	var title = '<b>' + this.time + '&nbsp;&nbsp;&nbsp;&nbsp;<a target="#" href="/' + this.user + '">' + this.user + '</a></b>';
	t += getSummaryFormatTableRows(title, this.text, '/u/tuser.' + this.user.toLowerCase() + '.jpg', '/' + this.user);
	return t;
}

function NewsItem(title, text, thumbnail, link) {
	this.title = title;
	this.text = text;
	this.thumbnail = thumbnail;
	this.link = link;
	this.toHtml = NewsItem_toHtml;
}

function NewsItem_toHtml() {
	var result = '<table cellpading="2" cellspacing="0" border="0">';
	result += getSummaryFormatTableRows(this.title, this.text, this.thumbnail, this.link);
	result += '</table>';
	return result;
}

function Submission(id, title, username, time, type, thumbnail, rating) {
	this.id = id;
	this.title = title;
	this.username = username;
	this.time = time;
	this.type = type;
	this.thumbnail = thumbnail;
	this.rating = rating;
	this.toHtml = Submission_toHtml;
	this.toSimpleHtml = Submission_toSimpleHtml;
	this.show = Submission_show;
	this.hide = Submission_hide;
	this.startHide = Submission_startHide;
	this.stopHide = Submission_stopHide;
	this.setPosition = Submission_setPosition;
	return this;
}

function Submission_toSimpleHtml() {
	var ttitle = '<b><a class="Plain" href="/' + this.id + '/' + escape(this.title) + '">' + this.title + '</a></b>';
	var txt = 'SUBMITTED BY <a class="Plain" href="/' + this.username + '">' + this.username + '</a><br>' + getDateString(this.time, true) + ' | RATING: ' + this.rating + ' | TYPE: ' + this.type;
	if (this.content) {
		txt += "<br><br>" + this.content;
	}
	var result = '<table cellpadding="2" cellspacing="0" border="0" width="500">';
	result += getSummaryFormatTableRows(ttitle, txt, '/u/' + this.thumbnail, '/' + this.id + '/' + escape(this.title));
	result += '</table>';
	return result;
}

function Submission_toHtml() {
	/*
	var result = '<div onMouseOver="document.submissions[' + this.id + '].stopHide();" onMouseOut="document.submissions[';
	result += this.id + '].startHide();" class="Popup" id="' + this.id;
	result += '"><table cellpadding="0" cellspacing="0" border="0"><tr><td colspan="2" nowrap="nowrap" valign="top">';
	result += '<a class="Plain" href="/' + this.id + '/' + escape(this.title) + '">';
	result += '<b><a class="Plain" href="/' + this.id + '/' + escape(this.title) + '">' + this.title + '</a></b>';
	result += '<br>SUBMITTED BY <a class="Plain" href="/' + this.username + '">' + this.username + '</a><br>';
	result += getDateString(this.time, true) + ' | RATING: ' + this.rating + ' | TYPE: <a href="/' + this.username + '/';
	result += this.type + '">' + this.type + '</a>';
	result += '</td></tr></table></div>';
	*/
	var result = '<a onMouseOver="document.submissions[' + this.id;
	result += '].show();" onMouseOut="document.submissions[' + this.id + '].startHide();" class="Plain" href="/';
	result += this.id + '"><img src="/u/' + this.thumbnail + '" width="40" height="40" border="0"></a>';
	return result;
}

function Submission_show() {
	var d = getDiv("sdetail");
	var t = this.title + " - " + this.type + " SUBMITTED BY " + this.username;
	d.innerHTML = t;
	
	/*

	if (obj.offsetLeft > 0 && obj.offsetTop > 0 && navigator.appName != "Microsoft Internet Explorer") {
		this.setPosition(obj.offsetLeft - 1, obj.offsetTop + 60);
	} else {
		var x = findPosX(obj);
		var y = findPosY(obj);
		if (isInternetExplorer()) {
			x -= 1;
			y += 49;
		}
		this.setPosition(x + 1, y + 11);
	}
	
	hideAll();
	if (getDiv(this.id) != null) {
		document.toHide[this.id] = false;
		if (document.layers) {
			document.layers[this.id].visibility = "show";
		} else {
			document.getElementById(this.id).style.visibility = "visible";
		}
	}
	*/
}

function isInternetExplorer() {
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function Submission_setPosition(x, y) {
	if (document.layers) {
		document.layers[this.id].left = x;
		document.layers[this.id].top = y;
	} else {
		document.getElementById(this.id).style.left = x;
		document.getElementById(this.id).style.top = y;
	}
}

function Submission_hide(id) {
	if (getDiv(this.id) != null) {
		if (document.toHide[this.id]) {
			if (document.layers) {
				document.layers[this.id].visibility = "hide";
			} else {
				document.getElementById(this.id).style.visibility = "hidden";
			}
		}
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}


function hideAll() {
	for (var i in document.submissions) {
		document.submissions[i].hide();
	}
}

function Submission_startHide() {
	document.toHide[this.id] = true;
	setTimeout("document.submissions[" + this.id + "].hide();", 1000);
}

function Submission_stopHide() {
	document.toHide[this.id] = false;
}
