//misc
function toggle(element) 
{
	document.getElementById(element).style.display = (document.getElementById(element).style.display == 'none' ) ? '' : 'none';
}

function newtopic_set_focus()
{
	if ( document.getElementById('post_table').style.display == '' )
	{
		document.forms['newtopic'].elements['title'].focus();
	}
}

function newreply_set_focus()
{
	if ( document.getElementById('reply_table').style.display == '' )
	{
		document.forms['form_reply'].elements['text'].focus();
	}
}

function newikomentar_set_focus()
{
	if ( document.getElementById('ikomentar_table').style.display == '' )
	{
		document.forms['form_ikomentar'].elements['komentar'].focus();
	}
}

function newtkomentar_set_focus()
{
	if ( document.getElementById('tkomentar_table').style.display == '' )
	{
		document.forms['form_tkomentar'].elements['komentar'].focus();
	}
}

// quote
function do_insert(author, text)
{
	document.getElementById('reply_table').style.display = ''; //show reply form
	var text_field = document.forms["form_reply"].elements["text"];

	var code_start = '[q]';
	var code_end = '[/q]';
	var line_end = '\n';

	if ( document.selection )
	{
		var str = document.selection.createRange().text;
		text_field.focus();
		sel = document.selection.createRange();
		sel.text = code_start + author + ' > ' + text + code_end + line_end;
		sel.select();
		return;
	}
	else if ( text_field.selectionStart || text_field.selectionStart == '0' )
	{
		var startPos = text_field.selectionStart;
		var endPos = text_field.selectionEnd;
		text_field.value = text_field.value.substring(0, startPos) + code_start  + author + ' > ' + text + code_end + line_end + text_field.value.substring(endPos, text_field.value.length + 3);
		text_field.selectionStart = startPos + text.length + 21; 
		text_field.selectionEnd = startPos + text.length + 21; 
		text_field.focus();
		return;
	} 
	else
	{
		text_field.value += text;
		return;
	}
}

function do_quote(author, text)
{ 
	if ( text == '')
		alert('1) Izaberite (highlight) tekst koji zelite citirati\n2) Kliknite "Citiraj" iznad te poruke');
	else
		do_insert(author, text);
}

function do_sel() 
{ 
	if (document.getSelection) 
		selection=document.getSelection(); 
	else if (document.selection) 
		selection=document.selection.createRange().text; 
	else if (window.getSelection) 
		selection=window.getSelection(); 
	else 
		selection=''; 
}

//email
function eml(d,r,n)
{
	document.location.href = 'mai' + '' + 'lt' + 'o' + ':' + n + '@' + d; 
}

function resize_postarea()
{	
	if ( document.newtopic.text.rows == 9 )
	{
		document.forms['newtopic'].elements['text'].rows = 22;
		document.forms['newtopic'].elements['post_size'].value = " Smanji ";
	}
	else
	{
		document.forms['newtopic'].elements['text'].rows = 9;
		document.forms['newtopic'].elements['post_size'].value = " Povecaj ";
	}

	document.forms['newtopic'].elements['text'].focus();
}

function resize_replyarea()
{	
	if ( document.form_reply.text.rows == 9 )
	{
		document.forms['form_reply'].elements['text'].rows = 22;
		document.forms['form_reply'].elements['reply_size'].value = " Smanji ";
	}
	else
	{
		document.forms['form_reply'].elements['text'].rows = 9;
		document.forms['form_reply'].elements['reply_size'].value = " Povecaj ";
	}

	document.forms['form_reply'].elements['text'].focus();
}