// ==UserScript==
// @name Abc Forums 1.1.2
// @author DD32
// @namespace http://dd32.id.au/ 
// @version 1.1.2
//	changelog for 0.9 
//						First Version
// Changelog trimmed.	
//
//	changelog for 0.9.5
//						Tweaked regular expressions slightly
//						Added new quote format. <Q>....</Q>
//						Fixed a bug introduced in 0.9.4.0, Watermark was applied to all pages, even when not modified, this would cause certain pages to fail to work correctly.
//						Removed ability to use Quickreply more than once.
//						Added cb88s to the statistics for TT (Hadnt had the url on hand whilst editing the script in the past.
//						Added REMOVE_CLEAR button for the reply window, Causes <BR> to apear in messages and isnt used by many anyway.		
//						Added QUICKREPLY_QUOTE to insert quoted text into the reply to the post; New lines are lost, as well as any formating.
//
//	changelog for 0.9.5.1
//						Added new chat/goodnight threads.
//						*BUG* Quickreply multiple times in FF doesnt play nicely, also, quickreply was broke completely in 0.9.5
//						Fixed above Bug.
//						Added QUICKREPLY_LOCATION to set the quickreply button to the left or right, right is the default.
//	changelog for 0.9.6
//						Changed Chat thread.
//						Added TRANSFORM_IMAGES; Dr. ZAx, Hope you dont mind, just copied the section from your script for now..
//						Added Pinned thread 'Posting on topic' to TT
//						Added SSSF+SG+GA quicklinks.. 
//						TBI(to be implemented): Added "Back To thread" on the reply window.
//						Removed "Custom Stylesheet" option as its no longer needed, FF/O support it themselves.
//						Location of script changed. http://dd32.hacked.in/tt/abcforum.user.js
//	changelog for 0.9.6.1
//						Corrected Watermark grammar/spelling.
//						Added HiJackThis exemption.
//						*BUG* QuickReply only worked for TechTalk
//						*BUG* Forumids > 99 dont work.
//						Updated SSSF Chat threads(To the lab: Update them all at once PLEEEASE! :P)
//	changelog for 1.0
//						Code Redesigned, Hopefully its much faster now, Forum/Formatting data converted to objects which hold most of the needed data.
//						ADDED: Back to thread link
//						ADDED: RSS support in the links list assuming the forum has a valid feed, Thanks Dr. ZAx
//						THOUGHT: VB6 IE6/7 Toolbar/extension for those who dont use IE/Opera, Would make it more accessable to the majority of users. any thoughts from anyone else reading my changelog?
//	changelog for 1.0.1 / 1.0.2
//						Change: *..* ".." changed to match a maximum of 10 words.. shouldnt work accross quotes now either.
//						Change: Changed the above to match words rather than characters.
//						Added: &amp;#0000; => &#0000;
//	changelog for 1.0.2
//						Bug Fix: Image insertion only worked for lowercase extensions.
//						UPDATE: February threads.
//	changelog for 1.0.3
//						ADDED: Stopword "O23 - Service:"
//						REMOVED: cb88's stats: ,"http:\/\/tokyo3.org\/tt\/" Seems dead  6/Feb/07
//						ADDED: support for www.something.aaa and something.com links.
//						ADDED: links on the postIDs to direct to the individual post. (hidden links)
//						REMOVED: Removed the "Back to thread" link from reply windows, Seemed useless, May create the thread subject as a link back to the thread maybe.
//						BUG: Quick reply quoting wasnt working in Latest Opera build, Means its broken in a series of opera builds, Latest version may be required. (Opera <9 wasnt affected AFAIK
//						CHANGE: DD32's Statistics moved location.
//						CHANGE: Only process posts less than 1500 characters.. (Hopefully will speed up presentation)
//	changelog for 1.0.3b
//						BUG: formatBody() wasnt working in Greasemonkey, FF doesnt support .innerText... But both Opera and FF support .textContent
//	changelog for 1.0.4
//						CHANGE: Changed post conversion limit from 1500char to 2500 char.
//						CHANGE: changed the regular expression for matching body, === to ==
//						CHANGE: DD32's Statistics moved location(again).
//						CHANGE: Allow $,! in URL's
//						UPDATE: March URLS: SSSF, TT
//	changelog for 1.0.4b
//						CHANGE: Regression in Firefox: <scr ipt> cannot be in the JS again..
//	changelog for 1.0.4c
//						CHANGE: DD32's stats => dd32.id.au
// 	changelog for 1.0.5
//						CHANGE: Bold/Italic matches upto 250 characters now instead of words, much faster.
//						BUG: oops.. Missed a dot in dd32.id.au
//						ADDED: Automatic Update checker.
//						CHANGE: April threads
//						ADDED: If quoting and login form is shown, Opera now copies that quoted text into the reply after login.
//						ADDED: Allow linebreaks in quoted data.
//	changelog for 1.0.6
//						REMKOVE: GA support :(
//						ADDED: Stopword "Logfile of Trend Micro HijackThis"
//						ADDED: Stopword of <!>
//						CHANGE: May threads
//						FIX: SG: Recipies -> recipes
//	changelog for 1.0.7
//						BUG: <!> wasnt working, corrected to &lt;!&gt;
//						June Threads....
//	changelog for 1.0.8
//						July threads...
//	changelog for 1.0.9
//						August Threads
//						Save incomplete posts.
//	changelog for 1.0.9a
//						FFF
//	changelog for 1.0.9b
//						Save Incomplete posts modification
//	changelog for 1.0.10
//						September Threads
// 	changelog for 1.0.11
//						October threads
//						Workaround for post "creeps" in the post id linking
//						Opera 9.5 hacks
//	changelog for 1.0.12
//						November threads
//	changelog for 1.0.13
//						Added more hacks in for Opera 9.5, Moved from hard coded HTML to using DOM createElement
//						Jan 08 threads
//	changelog for 1.0.13.1
//						FF Fix: Doesnt like iframe style being set.
//	changelog for 1.1
//						Opera 9.5 released, Check hacks.
//						update threads to June 08
//
// changelog for 1.1.1
//						update threads to June 09 (by starling_bird)
//	changelog for 1.1.2
//						update TT chatthread Sept 09
// @description Make the ABC forums easier to use.
//	see http://www.howtocreate.co.uk/operaStuff/userJavaScript.html for details
// @include http://www2b.abc.net.au/*
// ==/UserScript==

var forumData = Array();
forumData[18]  = 
{"name":"TechTalk","postCreep":"1","postPrefix":"http:\/\/www2b.abc.net.au\/science\/techtalk\/newposts\/000\/","regularsLink":"http:\/\/techtalkwiki.net\/regulars\/","fastreply":[{"id":"727860","name":"Chat"},{"id":"712332","name":"GoodNight"},{"id":"85449","name":"Back 
Later"},{"id":"389294","name":"Posting on Topic"}],"pinned":[],"colours":{"background":"#000033","foreground":"#FFFFFF","text":"#FFFFFF"},"special":[{"name":"RSS","url":"http:\/\/tools.techtalkwiki.net\/feed\/","appendTid":"true"},{"name":"Wiki","url":"http:\/\/techtalkwiki.net\/","appendTid":"false"},{"name":"Search","url":"http:\/\/techtalkwiki.net\/search\/","appendTid":"false"},{"name":"Stats","url":["http:\/\/dd32.id.au\/techtalk-statistics\/","http:\/\/techtalkwiki.net\/statistics\/"],"appendTid":"false"}]};

forumData[19]  = {"name":"Scribbly Gum","postCreep":"0","postPrefix":"http:\/\/www2b.abc.net.au\/science\/scribblygum\/newposts\/000\/","regularsLink":"http:\/\/scribblygumwiki.net\/regulars\/","fastreply":[{"id":"421212","name":"Chat"},{"id":"195472","name":"BBL"}],"pinned":[{"url":"http:\/\/www2b.abc.net.au\/science\/scribblygum\/newposts\/287\/topic287906.shtm","name":"Happy Birthday"}],"colours":{"background":"#F7ECDC","foreground":"#44446E","text":"#44446E"},"special":[{"name":"RSS","url":"http:\/\/tools.scribblygumwiki.net\/feed\/","appendTid":"true"},{"name":"Wiki","url":"http:\/\/scribblygumwiki.net\/","appendTid":"false"},{"name":"Photos","url":"http:\/\/scribblygumwiki.net\/monthlyphotographythreads","appendTid":"false"},{"name":"Recipes","url":"http:\/\/scribblygumwiki.net\/indextorecipes","appendTid":"false"},{"name":"Search","url":"http:\/\/scribblygumwiki.net\/search\/","appendTid":"false"},{"name":"Stats","url":"http:\/\/scribblygumwiki.net\/statistics\/","appendTid":"false"}]};

forumData[20]  = {"name":"SSSF","postCreep":"3","postPrefix":"http:\/\/www2b.abc.net.au\/science\/k2\/stn\/newposts\/000\/","fastreply":[{"id":"4178769","name":"Chat"},{"id":"2693380","name":"GoodNight"}],"pinned":[{"url":"http:\/\/www2b.abc.net.au\/science\/k2\/stn\/newposts\/2693\/topic2693387.shtm","name":"Happy Birthday"}],"colours":{"background":"#FFFFFF","foreground":"#000000","text":"#FFFFFF"},"special":[{"name":"Wiki","url":"http:\/\/sisyphus.pbwiki.com\/","appendTid":"false"},{"name":"FAQ","url":["http:\/\/www2b.abc.net.au\/science\/k2\/stn\/faq.htm","http:\/\/www2b.abc.net.au\/science\/k2\/stn\/notfaq.htm"],"appendTid":"false"}]};

var formattingData = new Object();
formattingData = {
	stopItems:[ "&lt;!&gt;", "Logfile of HijackThis", "Logfile of Trend Micro HijackThis", "O9 - Extra", "O23 - Service" ],
	formatting:[
					{
						incase: "&lt;",
						strSearch: /&lt;([I|B|U])&gt;(.*?)&lt;\/(\1)&gt;/ig,
						strReplace: "<$1>$2</$1>"
					},
					{
						incase: "\"",
						strSearch: /"([\w\s]{1,250})"/ig,
						strReplace: "<I>\"$1\"</I>"
					},
					{
						incase: "*",
						strSearch: /\*([\w\s]{1,250})\*/ig,
						strReplace: "<B>*$1*</B>"
					},
					{
						incase: "&amp;",
						strSearch: /\&amp;#(\d*?);/ig,
						strReplace: "&#$1;"
					},
					{
						incase: "&lt;Q&gt;",
						strSearch: /&lt;Q&gt;(<BR>|<BR\/>)(.*?)(<BR>|<BR\/>)*&lt;\/Q&gt;(<BR>|<BR\/>)*/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$2</i></BLOCKQUOTE><BR>"
					},
					{
						incase: false,
						strSearch: /(\*|=|-|_|\.)\1{1,}(<BR>|<BR\/>)(.*?)(<BR>|<BR\/>)\1{2,}(<BR>|<BR\/>)*/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$3</i></BLOCKQUOTE><BR>"
					},
					{
						incase: false,
						strSearch: /(.*?)(<BR>|<BR\/>)(\*|=|-|_|\.){1}\3{4,}(<BR>|<BR\/>)+/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$1</i></BLOCKQUOTE><BR>"
					},
					{
						incase: false,
						strSearch: /(\&lt;|\&gt;){1,}(<BR>|<BR\/>)+(.*?)(<BR>|<BR\/>)(\&lt;|\&gt;){1,}(<BR>|<BR\/>)*/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$3</i></BLOCKQUOTE><BR>"
					},
					{
						incase: "�",
						strSearch: /�(.*?)�/g,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>�$2�</i></BLOCKQUOTE><BR>"
					},
					{
						incase: "[quote]",
						strSearch: /\[quote\](.*?)\[\/quote\](<BR>|<BR\/>)/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$1</i></BLOCKQUOTE><BR>"
					},
					{
						incase: "&gt;",
						strSearch: /^(&gt;){1,4}(.*?)(&lt;){1,4}(<BR>|<BR\/>)+/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$2</i></BLOCKQUOTE><BR>"
					},
					{
						incase: "&gt;",
						strSearch: /^(&gt;)+(.*?)(<BR>|<BR\/>)+/ig,
						strReplace: "<BLOCKQUOTE><SMALL>Quote:</SMALL><BR><I>$2</i></BLOCKQUOTE><BR>"
					},
					{
						incase: "http",
						strSearch:  /(http|https):\/\/([a-z0-9\.=\/_~?\-&;:\+,#$%^!@\*\{\}]*)/img,
						strReplace: '<A HREF="$1://$2" TARGET="_BLANK">$1://$2</A>'
					},
					{
						incase: "www.",
						strSearch:  /(<BR>|<BR\/>|\s)www\.([a-z0-9\.=\/_~?\-&;:\+,#$%^!@\*\{\}]*)/img,
						strReplace: '$1<A HREF="http://www.$2" TARGET="_BLANK">www.$2</A>'
					},
					{
						incase: ".com",
						strSearch:  /(<BR>|<BR\/>|\s)([a-z0-9]*)\.com([a-z0-9\.=\/_~?\-&;:\+,#!$%^@\*\{\}]*)/img,
						strReplace: '$1<A HREF="http://$2.com$3" TARGET="_BLANK">$2.com$3</A>'
					},
					{
						incase: false,
						strSearch: /(<BR>|<BR\/>)/ig,
						strReplace: "$1\n"
					}
					]
};
//Lastone must be last (new lines on <BR> for quoting with linebreaks)

//document.addEventListener("DOMContentLoaded", 'abcforum', false);

function abcforum() {
switch(location.pathname) {
	/********************************************/
	case "/forumcentral/main.asp":
		if( location.search.indexOf("frmstatus=4") > -1 ) //Post just went through, clear out the remember cookie
			forgetCookie("remember");
		break;
	/********************************************/
	case "/forumcentral/addpost.asp":
		if( document.body.getElementsByTagName('input')[0].type=='text'){
			var pid=false; //If pid = false, then it must be a new thread
			var subjectbox = document.body.getElementsByTagName('input')[0];
			var submitbutton = document.body.getElementsByTagName('input')[1];
			var clearbutton = document.body.getElementsByTagName('input')[2];
		} else {
			//Its a Reply
			var submitbutton = document.body.getElementsByTagName('input')[2];
			var clearbutton = document.body.getElementsByTagName('input')[3];
			var pid = document.body.getElementsByTagName('input')[0].value;
			var subjectbox = false;
		}

		var replybox = document.body.getElementsByTagName('textarea')[0];
		var fid = document.body.getElementsByTagName('form')[0].action.split('=')[1];
		
		/* Resize/recolour the Subject box */
		if(subjectbox) {
			subjectbox.size = '';
			subjectbox.style.width = '500px';
			if( forumData[fid].colours.background ) {
				subjectbox.style.backgroundColor = forumData[fid].colours.background;
				subjectbox.style.color = forumData[fid].colours.foreground;
			}
		}
		if(replybox) {
			/* Resize/ecolour the Reply box */
			replybox.cols = '';
			replybox.rows = '';
			replybox.style.width = '99%';
			replybox.style.height = '300px';
			
			/* Recolour the reply box/subject box for the forum is known*/
			if( forumData[fid].colours.background ) {
				replybox.style.backgroundColor = forumData[fid].colours.background;
				replybox.style.color = forumData[fid].colours.foreground;
			}
			do_post_remember();
		}
		/* Remove the Clear button if it exists. */
		clearbutton.outerHTML = '';
		/* Focus the Replybox, or the Subjectbox */
		if( pid )
			replybox.focus();
		else
			subjectbox.focus();

		break;
	/********************************************/
	case "/forumcentral/list.asp":
		var fid = location.search.split('&')[0].split('=')[1];
		/* Insert any Fast Reply threads */
		for(var i in forumData[fid].fastreply)
			document.body.innerHTML += '<FORM style="margin-top:0px;margin-bottom:0px;" METHOD="POST" ACTION="/forumcentral/addpost.asp?forum=' + fid + '" Target="main"><INPUT TYPE="HIDDEN" NAME="parentid" VALUE="' + forumData[fid].fastreply[i].id + '"><INPUT type="hidden" name="reply" value="reply"/><input type="submit" value="' + forumData[fid].fastreply[i].name + '" name="subject" style="margin-top:0px;margin-bottom:0px;border: 1px solid #FFFFFF;color: Black;background-color: white;height: 19px !important;max-height: 19px !important;min-height: 19px !important;margin: 1px;" /></FORM>';
		/* Insert any Pinned threads */
		for(var i in forumData[fid].pinned)
			document.body.innerHTML += '<a target="main" href="' + forumData[fid].pinned[i].url + '">' + forumData[fid].pinned[i].name + '</a><br>';
		break;
	case "/forumcentral/login.asp":
		if( location.hash.substring(1) != '' )
			document.forms[1].action += location.hash;
		break;
	/********************************************/
	default:
		/********************************************/
		if(location.pathname.indexOf('/post') > -1){
			//Its a post we're dealing with!.
			var table_cells = document.body.getElementsByTagName('td');
			/* Insert the Quick Reply */
			insert_custom_javascript();
			var postForm = document.body.getElementsByTagName('form')[0];
			var fid = postForm.action.split('=')[1];
			var pid = document.body.getElementsByTagName('input')[0].value;
			postForm.innerHTML += '<input style="margin-top:0px;border: 1px solid #000000;color: Black;background-color: white;height: 21px !important;max-height: 21px !important;min-height: 21px !important;margin: 1px;display: inline; float: right;" type="button" value="Quick Reply"  onmousedown="quick_reply(\''+fid+'\',\''+pid+'\',this);" />';
			/* Transform the Text of the post. */
			if(table_cells[4].textContent.length <= 2500)
				table_cells[4].innerHTML = formatText(table_cells[4].innerHTML);
			/* document.body.innerHTML += "<a href='http://Post-length:" + table_cells[4].textContent.length + "/'>Post Length</a>"; */
			/* Add a hidden link to the postid. */
			table_cells[3].innerHTML = "<a style=\"text-decoration:none;color:"+forumData[fid].colours.text+"\" href=\""+location.pathname+"\">" + table_cells[3].innerHTML + "</a>";
			//table_cells[3].innerHTML = table_cells[3].innerHTML.replace(/post id: (\d*)/,"<a style=\"text-decoration:none;color:"+forumData[fid].colours.text+"\" href=\""+forumData[fid].postPrefix+"post$1.shtm\">post id: $1</a>");
			/* Tranform any Image links into Images */
			linkImages();
			/* Insert the special links section */
			table_cells[4].innerHTML = insert_special_links(fid) + table_cells[4].innerHTML;
			/* Apply a watermark to this page to specify that the userScript is in use */
			insert_watermark();
			insert_update();
		/********************************************/
		} else if(location.pathname.indexOf('/topic') > -1){
			//Its a Thread that needs dealing with
			var table_cells = document.body.getElementsByTagName('td');
			var num = table_cells.length/5; //Number of posts in the thread, 5 table cells per post
			
			/*Insert the Quick Reply*/
			insert_custom_javascript();
			var postForm = document.body.getElementsByTagName('form')[num-1];
			var fid = postForm.action.split('=')[1];
			var pid=document.body.getElementsByTagName('input')[0].value;
			postForm.innerHTML += '<input style="margin-top:0px;border: 1px solid #000000;color: Black;background-color: white;height: 21px !important;max-height: 21px !important;min-height: 21px !important;margin: 1px;display: inline; float: right;" type="button" value="Quick Reply"  onmousedown="quick_reply(\''+fid+'\',\''+pid+'\',this);" />';
			
			/* Loop through the posts in the thread */
			for(var post = 0; post < num; post++) { 
				/* If content length is less than 1,000 characters */
				if( table_cells[ (parseInt(post)*5+4) ].textContent.length <= 2500)
					table_cells[ (parseInt(post)*5+4) ].innerHTML = formatText(table_cells[ (parseInt(post)*5+4) ].innerHTML);
					/* Transform the content of the linked thread */
					/* (parseInt(post)*5+4) = parseInt(post)*5: Work out the first cell 0 of each post, +4: skip over to the post cell. */
					
				/* Add a link to the postID */
				//table_cells[ (parseInt(post)*5+3) ].innerHTML = table_cells[ (parseInt(post)*5+3) ].innerHTML.replace(/post id: (\d*)/,"<a style=\"text-decoration:none;color:"+forumData[fid].colours.text+"\" href=\""+forumData[fid].postPrefix+"post$1.shtm\">post id: $1</a>");
				//Stupid post numbers being out of wack.
				var mat = table_cells[ (parseInt(post)*5+3) ].innerHTML.match(/post id: (\d*)/);
				var claimedpost = parseInt(mat[1]);
				if( parseInt(forumData[fid].postCreep) > 0 )
					claimedpost += parseInt(forumData[fid].postCreep);
					
				table_cells[ (parseInt(post)*5+3) ].innerHTML = "<a style=\"text-decoration:none;color:"+forumData[fid].colours.text+"\" href=\""+forumData[fid].postPrefix+"post" + claimedpost + ".shtm\">" + table_cells[ (parseInt(post)*5+3) ].innerHTML + "</a>";
			}
			/* Display the number of posts in the Thread */
			table_cells[2].innerHTML += "&nbsp;&nbsp;<SMALL>(Posts:" + num + ")</SMALL>";
			/* Tranform any Image links into Images */
			linkImages();
			/* Insert the special links section */
			table_cells[4].innerHTML = insert_special_links(fid) + table_cells[4].innerHTML;
			/* Apply a watermark to this page to specify that the userScript is in use */
			insert_watermark();
		}
} //End Switch
}//end abcforum function

function formatText(strbody) {
	var debug = false;
	if(debug)
		var beforedate; var afterdate; var seconds;
	/* StopItems are Strings of text which, if exist in the post, indicates that the post should not be formatted, This may be to prevent potentially malicious links being linked mainly. */
	for(var i in formattingData.stopItems)
		if(strbody.indexOf(formattingData.stopItems[i]) >= 0)
			return strbody;
	/* Do all the reformating */
	for(var i in formattingData.formatting) {
		if(formattingData.formatting[i].incase === false || strbody.indexOf(formattingData.formatting[i].incase) >= 0) {
			if(debug)
				beforedate=new Date();
			strbody = strbody.replace( formattingData.formatting[i].strSearch, formattingData.formatting[i].strReplace);
			if(debug) {
				afterdate=new Date();
				seconds = afterdate.getSeconds()-beforedate.getSeconds();
				if(seconds > 1)
					alert(formattingData.formatting[i].strSearch+" Took "+seconds+" seconds to execute");
			}
		}
	}
	return strbody;
}
function insert_watermark() {
	document.body.innerHTML += "<div style=\"font-size:10px;\">This page's appearance has been modified by <A href=\"http://techtalkwiki.net/user_scripts\" target=\"_BLANK\">DD32's User Javascript file</a> for Opera and Firefox.</div>";
}
function insert_special_links(fid) {
	if( forumData[fid].special ) {
		var tid = document.body.getElementsByTagName('input')[0].value; //Thread ID
		var str = '<div style="float:right; font-size:small; margin-left: 5px;">';
		for(var i in forumData[fid].special) {
			if(typeof(forumData[fid].special[i].url) == 'string') {
				// Its a straight up Link.. 
				if(forumData[fid].special[i].appendTid == "true") //Seems we need the threadID included.
					str += '<a href="' + forumData[fid].special[i].url + tid + '" target="_BLANK">' + forumData[fid].special[i].name + '</a><br>';
				else
					str += '<a href="' + forumData[fid].special[i].url + '" target="_BLANK">' + forumData[fid].special[i].name + '</a><br>';
			} else {
				//It wasnt a string, therefor, we assume it must be an array of items.
				str += forumData[fid].special[i].name;
				for(var j in forumData[fid].special[i].url) {
					if(j != 0)
						str += "/"; //If this isnt the first in a array of results, then include a seperating slash.
					if(forumData[fid].special[i].appendTid == true) //Seems we need the threadID included.
						str += '<a href="' + forumData[fid].special[i].url[j] + tid + '" target="_BLANK">' + (parseInt(j)+1) + '</a>';
					else
						str += '<a href="' + forumData[fid].special[i].url [j] + '" target="_BLANK">' + (parseInt(j)+1) + '</a>';
				}
				str += "<br>";
			}
		}
		str += '</div>'; 
		return str;
	}
	return '';
}
function linkImages() {
	/* Thanks to Dr. ZAx for this code, Modified slightly by DD32 */
	var links = document.getElementsByTagName("a");
	for (i=0; i<links.length; i++){
		var currentLink = links[i];
		var linkHrefParts = currentLink.href.split(".");
		var extension = linkHrefParts[linkHrefParts.length - 1].replace("/","");
		if( extension.toLowerCase() in { jpeg:1, jpg:1, gif:1, png:1, bmp:1 } ) {
			var img = document.createElement('img');
			var br = document.createElement('br');
			currentLink.parentNode.insertBefore(img,currentLink.nextSibling);
			currentLink.parentNode.insertBefore(br,currentLink.nextSibling);
			img.src = currentLink.href;
		}
	}
}
function insert_custom_javascript() {
	//Attach QuickReply and GetSelection Javascript code to the document.
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.defer = false;
	var js = '';
	if( window.opera != null ) //FF Stupidities :)
		js += '<scr'+'ipt type="text/javascript">';
	js += "\
	function getSel(){ \
		if (window.getSelection) \
			return window.getSelection(); \
		else if (document.getSelection) \
			return document.getSelection(); \
		else if (document.selection) \
			return document.selection.createRange().text; \
		else \
			return false; \
	} \
	function quick_reply(forumid, parentid, button){ \
		button.disabled='disabled'; \
		var selected = getSel().toString(); \
		if ( selected != '' ) \
			selected = selected.replace(/\\r/g,'').replace(/\\n/g,'\\n'); \
		var url = 'http://www2b.abc.net.au/forumcentral/addpost.asp?forum=' + forumid + '&parentid=' + parentid + '#' + encodeURIComponent(selected); \
		var ifr = document.createElement('iframe'); \
		ifr.src = url; \
		ifr.width = '99%'; \
		ifr.height = '500px'; \
		var body = document.getElementsByTagName('body').item(0); \
		void(body.appendChild(ifr)); \
	}";
	if( window.opera != null )
		js += '</scr'+'ipt>';
	script.innerHTML = js;
	var head = document.getElementsByTagName('head').item(0);
	void(head.appendChild(script)); //Insert the script into the head of the current document.
}
function insert_update() {
	return; //Disabled for now.
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.defer = false;
	script.src = 'http://www.gmodules.com/ig/proxy?url=http%3A%2F%2Fdd32.id.au%2Fuserscript-update.php%3Fversion%3D1.1.0';
	//script.src = 'http://dd32.id.au/userscript-update.php?version=1.0.11';
	var head = document.getElementsByTagName('head').item(0);
	void(head.appendChild(script));
}

function do_post_remember() {
	var replybox = document.body.getElementsByTagName('textarea')[0];
	/* Do a QuickReplyInsert if applicable */
	if( location.hash.substring(1) != '' )
		replybox.value = "===\n" + decodeURIComponent(location.hash.substring(1)) + "\n===\n\n" + replybox.value;

	if( window.opera == null )
		return; //Sorry, But you FF'ers dont get this :)

	var value = getCookie();
	value = decodeURI(value);
	
	if( value != '' && value != null && value != 'null' )
		replybox.value += value.replace(/<BR>/g,'\n').replace(/<E>/,'=');
	
	window.setInterval(
					   function() {
						   	//var value = document.body.getElementsByTagName('textarea')[0].value.replace(/\r/g,'').replace(/\n/g,'<BR>').replace(/=/g,'<H>').replace(/<colon>/g,';');
							var value = document.body.getElementsByTagName('textarea')[0].value.replace(/\r/g,'').replace(/\n/g,'<BR>').replace(/=/,'<E>');
							if( value == '' || value == null )
								return;
							value = encodeURI(value);
							var date = new Date();
							date.setTime(date.getTime()+(1*60*60*1000)); //1 Hour
							var expires = "; expires="+date.toGMTString();
							document.cookie = "remember="+value+expires+"; path=/";
						}
					   ,2500);
	/*var submitform = document.body.getElementsByTagName('form')[0];
	submitform.onsubmit = function(){
								var date = new Date();
								date.setTime(date.getTime()+(-1*60*60*1000)); //1 Hour
								var expires = " expires="+date.toGMTString();
								document.cookie = "remember=;"+expires+"; path=/";
							}*/
}
function forgetCookie(name) {
	var date = new Date();
	date.setTime( date.getTime() + (-1*60*60*1000) ); //1 Hour
	var expires = " expires=" + date.toGMTString();
	document.cookie = name + "=;" + expires + "; path=/";
}
function getCookie() {
	var nameEQ = "remember=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
	}
	return null;	
}

abcforum();
