/**
* extra_topic.js
*
* @author Christian Knerr (cback)
* @package CBACK_Forum
* @version 1.0.0
* @since 04.06.2008 - 14:00:04
* @copyright (c) 2009 CBACK Software - www.cback.net
*/

var mq_inactive = TPL_PATH + '/images/multi_quote.png';
var mq_active	= TPL_PATH + '/images/multi_quote_active.png';
var multiquotes = new Array();
var useratfeat	= '';
var userids		= new Array();
var routeimgs	= new Array();

function atfeature_add(user, piddefinition)
{
	for ( i = 0; i < userids.length; i++ )
	{
		if ( userids[i] == user )
		{
			return;
		}
	}
	userids[userids.length] = user;
	useratfeat = useratfeat + '<input type="button" class="button" style="font-weight:bold;width:400px;text-align:left;padding:4px;margin-bottom:2px;" onclick="cback_dlg_close();add_to_editor(\'\', \'[b]@' + user + '[/b] \');" value="#'+ piddefinition + ': ' + user + '" /><br />';
}

function mquote_add(pid)
{
	var elfound = false;
	var tmpar	= new Array();
		
	for( i = 0; i < multiquotes.length; i++ )
	{
		if( multiquotes[i] != '' )
		{
			if( multiquotes[i] == pid )
			{
				elfound=true;
			}
			else
			{
				tmpar[tmpar.length] = multiquotes[i];
			}
		}
	}

	if ( elfound == false )
	{
		document.getElementById('mquote_icon_'+pid).src = mq_active;
		tmpar[tmpar.length] = pid;
	}
	else
	{
		document.getElementById('mquote_icon_'+pid).src = mq_inactive;
	}
	
	multiquotes = tmpar;
}


function gen_mquote_reply(fid, tid)
{
	var quote_add = '';
	
	for( i = 0; i < multiquotes.length; i++ )
	{
		if( multiquotes[i] != '' )
		{
			quote_add = quote_add + multiquotes[i] + ';';
		}
	}
	
	if ( quote_add != '' && quote_add != ';' )
	{
		window.location.href = 'post.' + PHP_EXTENSION + '?mode=reply&f=' + fid + '&t=' + tid + '&quote=' + quote_add;
	}
	else
	{
		window.location.href = 'post.' + PHP_EXTENSION + '?mode=reply&f=' + fid + '&t=' + tid;
	}
}

function imgresizerouter(param1, param2)
{
	for ( i = 0; i < routeimgs.length; i++ )
	{
		if ( param1 == routeimgs[i] )
		{
			window.open(param1, param2);
			break;
		}
	}
}

function selCodeBox(elementId)
{
	var element = elementId;
	if ( document.selection )
	{
		var range = document.body.createTextRange();
		range.moveToElementText(element);
		range.select();
	}
	if ( window.getSelection )
	{
		var range = document.createRange();
		range.selectNodeContents(element);
		var blockSelection = window.getSelection();
		blockSelection.removeAllRanges();
		blockSelection.addRange(range);
	}
}

if ( !IS_IE6 )
{
	window.onload = function resizeimg()
	{
		var listcounter	= document.getElementsByTagName('img');
		var maxwith		= 620;
		
		for ( i = 0; i < listcounter.length; i++ )
		{	
			if ( listcounter[i].className == 'postimage' && listcounter[i].width > maxwith )
			{
				routeimgs[routeimgs.length]			= listcounter[i].src;
				listcounter[i].width				= maxwith;
				listcounter[i].style.cursor			= 'pointer';
				listcounter[i].style.background		= '#000000 url(' + TPL_PATH + '/images/buttons/resized_img_' + JS_LANGCODE + '.png) bottom left no-repeat';
				listcounter[i].style.paddingBottom	= '20px';
			}
			else if ( listcounter[i].className == 'postimage' )
			{
				listcounter[i].onclick				= 'void(0)';
			}
		}
	}
}