// hitung jumlah karakter
function hitung()
{
	document.form1.jumlah.value = document.form1.comment.value.length;
}

function addText(elname, wrap1, wrap2) {
	if (document.selection) { // for IE
		var str = document.selection.createRange().text;
		document.forms['inputform'].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms['inputform'].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//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 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}

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) {
	var txtarea = document.forms['inputform'].elements['content'];
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

b_help = "Bold text: [b] text [/b]  (alt+b)";
i_help = "Italic text: [i] text [/i]  (alt+i)";
u_help = "Underline text: [u] text [/u]  (alt+u)";
c_help = "Code display: [code] code [/code]  (alt+c)";
m_help = "Insert email: [mail] email address [/mail]  (alt+m)";
p_help = "Insert image: [img] http://image_url [/img]  (alt+p)";
w_help = "Insert URL: [url] http://url [/url] or [url=http://url] URL text [/url]  (alt+w)";
a_help = "Text Alignment: [align=left] text [/align]";
f_help = "Font color: [color=red] text [/color]  Tip: you can also use color=#FF0000";
s_help = "Font size: [size=12] text [/size]";
q_help = "Insert swf or swc: [flash] http://swf_url [/flash]  (alt+q)";

// Shows the help messages in the helpline window
function helpline(help)
{
	document.forms['inputform'].helpbox.value = eval(help + "_help");
}

//checkbox untuk private messsage
function select_switch(status)
{
	for (i = 0; i < document.privmsg_list.length; i++)
	{
		document.privmsg_list.elements[i].checked = status;
	}
}
//select username pada search username
function refresh_username(selected_username)
{
	opener.document.forms['inputform'].username.value = selected_username;
	opener.focus();
	window.close();
}
//new window
var win = null;
function NewWindow(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
	if(win.window.focus)
    {
    	win.window.focus();
    }
}