// JavaScript Document
// formatering af tekst i forum og i artikler
function insertSmiley(smiley){
	document.Form.text.value=document.Form.text.value + ' ' + smiley + ' ';
	document.Form.text.focus();
}

function makeBold() {
sT = document.selection.createRange();
sTxt = sT.text;
if(!sTxt.length > 0) { return( false); }
sT.text = "[B]" + sTxt + "[/B]";
}
function makeItalic() {
sT = document.selection.createRange();
sTxt = sT.text;
if(!sTxt.length > 0) { return( false); }
sT.text = "[I]" + sTxt + "[/I]";
}
function makeUnderstreget() {
sT = document.selection.createRange();
sTxt = sT.text;
if(!sTxt.length > 0) { return( false); }
sT.text = "[U]" + sTxt + "[/U]";
}
function makeLink() {
sT = document.selection.createRange();
sTxt = sT.text;
if(!sTxt.length > 0) { return( false); }
sT.text = "[url=" + sTxt + "]" + sTxt + "[/url]";
}
function makeCitat() {
sT = document.selection.createRange();
sTxt = sT.text;
if(!sTxt.length > 0) { return( false); }
sT.text = "[CITAT]" + sTxt + "[/CITAT]";
}
function makeLarge() {
sT = document.selection.createRange();
sTxt = sT.text;
if(!sTxt.length > 0) { return( false); }
sT.text = "[SIZE=5]" + sTxt + "[/SIZE]";
}

function insertText(elname, what) {
	if (document.forms['inputform'].elements[elname].createTextRange) {
		document.forms['inputform'].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.forms['inputform'].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms['inputform'].elements[elname].value += what;
		document.forms['inputform'].elements[elname].focus();
	}
}


function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.inputform.text.createTextRange && document.inputform.text.caretPos) {
		var caretPos = document.inputform.text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.inputfom.text.focus();
	} else {
	document.inputform.text.value  += text;
	document.inputform.text.focus();
	}
}

function usimg_list_jump()
{
goto = "user.list.php?type=img&cat_id=";
cat_id = document.getElementById("usimg_list").value;
document.location.href=goto+cat_id;
}
