//--------------------------------------------------------------------------------
function user_mouseover(tag) {
	document.getElementById(tag).style.filter = 'alpha(opacity=95)';
}
function user_mouseout(tag) {
	document.getElementById(tag).style.filter = 'alpha(opacity=40)';
}
function StoreCaret(text) {
	if (text.createTextRange) {
		text.caretPos = document.selection.createRange().duplicate();
	}
}
	
//--------------------------------------------------------------------------------
function AddSelectedText(Open, Close) {
var SelField = document.post.content;
var TxtFeld  = document.post.content;

	if (SelField.createTextRange && SelField.caretPos && Close == '\n') {
		var caretPos = SelField.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? Open + Close + ' ' : Open + Close;
		SelField.focus();
	} else if (SelField.caretPos) {
		SelField.caretPos.text = Open + SelField.caretPos.text + Close;
	} else {
		SelField.value += Open + Close;
		SelField.focus();
	}}
//--------------------------------------------------------------------------------
/* add new functions */
function getCP (ctrl) {
	var CP = 0;
	// IE Support
	if (document.selection) {
		/* do nothing */
	}
	// Other browsers support
	else if (ctrl.selectionStart || ctrl.selectionStart == '0') {
		CP = ctrl.selectionStart;
	}

	spos = ctrl.scrollTop;
	return (CP);
}
function setCP (ctrl, pos){
	// Other browsers support
	ctrl.scrollTop = spos;
	if(ctrl.setSelectionRange) {
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	// IE Support
	else if (ctrl.createTextRange) {
		/* do nothing */
	}
}
//--------------------------------------------------------------------------------
function InsertCode(code, info, type, error) {
var SelField = document.post.content;
var TxtFeld  = document.post.content;
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
				&& (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
				&& (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

var savedPos = getCP(SelField);

	if (code == 'url' || code == 'mail') 
	{
		if (code == 'url') var url = prompt(info, 'http://');
		if (!url) url='';
		if ((clientVer >= 4) && is_ie && is_win)
		{
			selection = document.selection.createRange().text;
			if (!selection)
			{
				var title = prompt(type, type);
				if ( url == '' )
					AddSelectedText('[' + code + ']' + title + '[/' + code + ']', '\n');
				else
					AddSelectedText('[' + code + '=' + url + ']' + title + '[/' + code + ']', '\n');
			}
			else
			{
				if ( url == '' )
					AddSelectedText('[' + code + ']', '[/' + code + ']');
				else
					AddSelectedText('[' + code + '=' + url + ']', '[/' + code + ']');
			}
		}
		else if (TxtFeld.selectionEnd && (TxtFeld.selectionEnd - TxtFeld.selectionStart > 0))
		{
			if ( url == '' )
				mozWrap(TxtFeld, '[' + code + ']', '[/' + code + ']');
			else
				mozWrap(TxtFeld, '[' + code + '=' + url + ']', '[/' + code + ']');
		}
		else
		{
			if ( url == '' )
				mozWrap(TxtFeld, '[' + code + ']', '[/' + code + ']');
			else
				mozWrap(TxtFeld, '[' + code + '=' + url + ']', '[/' + code + ']');
		}
	} 
	else if (code == 'color' || code == 'family' || code == 'size') 
	{
		if ((clientVer >= 4) && is_ie && is_win) {
			AddSelectedText('[' + code + '=' + info + ']', '[/' + code + ']');
		} else if (TxtFeld.selectionEnd && (TxtFeld.selectionEnd - TxtFeld.selectionStart > 0)) {
			mozWrap(TxtFeld, '[' + code + '=' + info + ']', '[/' + code + ']');
		}
	}
	else if (code == 'read' || code == 'format' || code == 'country' || code == 'released' || code == 'style' || code == 'tracks' || code == 'hr') 
	{
		if ((clientVer >= 4) && is_ie && is_win) {
			AddSelectedText('[' + code + ']', '');
		} else {
			mozWrap(TxtFeld, '[' + code + ']', '');
		}
	}
	else
	{
		if ((clientVer >= 4) && is_ie && is_win)
		{
			var selection = false;
			selection = document.selection.createRange().text;
			AddSelectedText('[' + code + ']', '[/' + code + ']');
		}
		else
		{
			mozWrap(TxtFeld, '[' + code + ']', '[/' + code + ']');
		}
	}
	setCP(SelField, savedPos);
}
//--------------------------------------------------------------------------------
function mozWrap(txtarea, open, close)
{

		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		if (selEnd == 1 || selEnd == 2)
				selEnd = selLength;

		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + open + s2 + close + s3;
		txtarea.focus();
		return;
}
//--------------------------------------------------------------------------------
function FieldName(text, which) {
	if (text.createTextRange) {
		text.caretPos = document.selection.createRange().duplicate();
	}
	if (which != "") {
		var Field = eval("document.post."+which);
		SelField = Field;
		TxtFeld  = Field;
	}
}
//--------------------------------------------------------------------------------
function emoticon(text)
{
var txtarea = document.post.content;
	text = ' ' + text + ' ';
	txtarea.value  += text;
	txtarea.focus();
}
