// JavaScript Document
var blnBold = false
var blnItalic = false
var blnUnderline = false
var blnCenter = false
var blnLeft = false
var blnRight = false
var blnIMG = false
var blnCODE = false
var blnQUOTE = false


function storeCaret (textEl) {
	if (textEl.createTextRange) 
		textEl.caretPos = document.selection.createRange().duplicate();
	}
function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text =
		caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text + ' ' : text;
		}
	else
		textEl.value  += text;
}
function getText() {
	if (document.post.content.createTextRange && document.post.content.caretPos) {
		return document.post.content.caretPos.text;
	} else {
		return '';
	}
}
function jsInsert(text) {
	if (document.post.content.createTextRange && document.post.content.caretPos) {
		var caretPos = document.post.content.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.post.content.focus();
	} else {
		document.post.content.value += text;
		document.post.content.focus();
	}
}
function jsBold() {
	var text = getText()
	if (text != "") {
		jsInsert('[b]' + text + '[/b]')
	} else if (blnBold == false) {
		blnBold = true
		jsInsert('[b]')
	} else {
		blnBold = false
		jsInsert('[/b]')
	}
}
function jsItalic() {
	var text = getText()
	if (text != "") {
		jsInsert('[i]' + text + '[/i]')
	} else if (blnItalic == false) {
		blnItalic = true
		jsInsert('[i]')
	} else {
		blnItalic = false
		jsInsert('[/i]')
	}
}
function jsUnderline() {
	var text = getText()
	if (text != "") {
		jsInsert('[u]' + text + '[/u]')
	} else if (blnUnderline == false) {
		blnUnderline = true
		jsInsert('[u]')
	} else {
		blnUnderline = false
		jsInsert('[/u]')
	}
}
function jsLeft() {
	var text = getText()
	if (text != "") {
		jsInsert('[align="left"]' + text + '[/align]')
	} else if (blnLeft == false) {
		blnLeft = true
		jsInsert('[align="left"]')
	} else {
		blnLeft = false
		jsInsert('[/align]')
	}
}

function jsCenter() {
	var text = getText()
	if (text != "") {
		jsInsert('[align="center"]' + text + '[/align]')
	} else if (blnCenter == false) {
		blnCenter = true
		jsInsert('[align="center"]')
	} else {
		blnCenter = false
		jsInsert('[/align]')
	}
}
function jsRight() {
	var text = getText()
	if (text != "") {
		jsInsert('[align="right"]' + text + '[/align]')
	} else if (blnRight == false) {
		blnRight = true
		jsInsert('[align="right"]')
	} else {
		blnRight = false
		jsInsert('[/align]')
	}
}
function jsQuote() {
	var text = getText()
	if (text != "") {
		jsInsert('[quote]' + text + '[/quote]')
	} else if (blnQUOTE == false) {
		blnQUOTE = true
		jsInsert('[quote]')
	} else {
		blnQUOTE = false
		jsInsert('[/quote]')
	}
}
function jsCODE() {
	var text = getText()
	if (text != "") {
		jsInsert('[code]' + text + '[/code]')
	} else if (blnCODE == false) {
		blnCODE = true
		jsInsert('[code]')
	} else {
		blnCODE = false
		jsInsert('[/code]')
	}
}
function jsIMG() {
	var text = getText()
	if (text != "") {
		jsInsert('[img]' + text + '[/img]')
	} else if (blnIMG == false) {
		blnIMG = true
		jsInsert('[img]')
	} else {
		blnIMG = false
		jsInsert('[/img]')
	}
}

function jsUrl() {
	//o0mBBSurl.document.close()
	window.open('../forum/popup_postnew.asp','Add Url','width=200,height=50')
}