function addPhoto(oinsert, oattachments, url) {
	if (!url)
		url = prompt('What is the web address of the photo?\n\nTo use an image from your computer please upload\nit to an image hosting site such as imageshack.com', 'http://');

	if (!url) return;

	dojo.byId(oinsert).value += '[IMG]' + url + '[/IMG]'

	if (oattachments) {
		if (dojo.byId(oattachments).innerHTML.indexOf('Attachments') < 0)
			dojo.byId(oattachments).innerHTML = '<h2>Attachments</h2>These items may appear in your message. They will be resized as necessary to fit the available space.';

		if (dojo.byId(oattachments).innerHTML.indexOf(url) < 0)
			dojo.byId(oattachments).innerHTML += '<div class="attachment"><img src="' + url + '" alt="" /><a href="javascript:;" class="reveal" onclick="addPhoto(\'' + oinsert + '\',\'' + oattachments + '\',\'' + url + '\'); return false;">' + url + '&nbsp;<span>add&nbsp;again</span></a></div>'
	}

	dojo.byId(oinsert).focus();
}

function addVideo(oinsert, oattachments, embed) {
	if (!embed)
		embed = prompt('What is the embed code of the video?\n\nThe embed code can be found on the viewing page\nof any video host such as YouTube or MetaCafe.', '<object...');
	else
		embed = unescape(embed)

	if (!embed) return;

	if (embed.indexOf('<object') < 0 && embed.indexOf('<embed') < 0) {
		alert('Please find the proper embed code for this video.\nIt will contain <embed> and/or <object> tags.');
		return;
	}

	embed = embed.replace(/^.*?(<(object|embed).*<\/\2>).*?$/, '$1');

	dojo.byId(oinsert).value += '[VIDEO]' + embed + '[/VIDEO]'

	if (oattachments) {
		if (dojo.byId(oattachments).innerHTML.indexOf('Attachments') < 0)
			dojo.byId(oattachments).innerHTML = '<h2>Attachments</h2>These items may appear in your message. They will be resized as necessary to fit the available space.';

		embedURL = embed.match(/src=.([^'"]*)/);
		embedURL = embedURL[1]

		if (dojo.byId(oattachments).innerHTML.indexOf(embedURL.replace(/&.*/, '')) < 0) {
			embedTiny = embed.replace(/(width\s*[=:]\s*"?)\d+/g, '$1' + 75).replace(/(height\s*[=:]\s*"?)\d+/g, '$1' + 75);
			dojo.byId(oattachments).innerHTML += '<div class="attachment">' + embedTiny + '<a href="javascript:;" class="reveal" onclick="addVideo(\'' + oinsert + '\',\'' + oattachments + '\',\'' + escape(embed) + '\'); return false;">' + embedURL + '&nbsp;<span>add&nbsp;again</span></a></div>'
		}
	}

	dojo.byId(oinsert).focus();
}

function addLink(oinsert) {
	var url = prompt('What is the web address to which you want to link?', 'http://');
	var text = prompt('What text should be linked? Leave this blank to just use the web address.', '');

	if (!url) return;

	if (text)
		dojo.byId(oinsert).value += '[URL=' + url + ']' + text + '[/URL]'
	else
		dojo.byId(oinsert).value += '[URL]' + url + '[/URL]'

	dojo.byId(oinsert).focus();
}

function addQuote(oinsert, quote, author) {
	if (!quote)
		quote = prompt('What is the text that you want to quote? This quote will be included in your post.', '');

	if (!author)
		author = prompt('Who wrote the text you\'re quoting? Leave this blank if it is anonymous.', '');

	if (!quote) return;

	if (author)
		dojo.byId(oinsert).value += '[QUOTE=' + author + ']' + quote + '[/QUOTE]'
	else
		dojo.byId(oinsert).value += '[QUOTE]' + quote + '[/QUOTE]'

	dojo.byId(oinsert).focus();
}

function replyQuote(omsg) {
	omsg = omsg.parentNode.parentNode.parentNode;
	var quote = omsg.innerHTML.replace(/\n/g,'').replace(/<(br|br \/)>/gi, '\n')
	quote = quote.replace(/<div class="quote"><div>\s*([\s\S]*)\s*<\/div><\/div>/gi,'\n\n"$1"\n\n');
	quote = quote.replace(/<[^>]*>/g,'');
	quote = quote.replace(/[ \t]{2,}/g,' ');
	quote = quote.replace(/^\s+|\s+$/g,'');

	var author = omsg.parentNode.childNodes[1].innerHTML.replace(/^[\s\S]*strong>(.*?)<\/strong[\s\S]*$/i, '$1');
	addQuote('post', quote + '\n', author);
}

function addFormatting(oinsert, type, text) {
	if (!text)
		text = prompt('What text would you like to format?', '');

	if (!text) return;

	dojo.byId(oinsert).value += '[' + type + ']' + text + '[/' + type + ']'

	dojo.byId(oinsert).focus();
}



