var cookie={ //v2.1
	secs:{'min':6,'mins':6,'hour':360,'hours':360,'day':8640,'days':8640,'week':60480,'weeks':60480,'month':259200,'months':259200,'year':3153600,'years':3153600},
	Get:function(n){var re=new RegExp(n+'=([^;]*);?','gi');var r=re.exec(document.cookie)||[];return unescape(r.length>1?r[1]:null)},
	Set:function(n,v,e,p,d,s){var t=new Date;u=e.split(' ');if(e)t.setTime(t.getTime()+(parseInt(u[0])*parseInt(cookie.secs[u[1]]+'0000')));document.cookie=n+'='+escape(v)+'; '+(!e?'':'; expires='+t.toUTCString())+(!p?'; path=/':'; path='+p)+(!d?'':'; domain='+d)+(!s?'':'; secure');}, 
	Del:function(n,p,d){var t=cookie.Get(n);document.cookie=n+'='+(!p?'; path=/':'; path='+p)+(!d?'':'; domain='+d)+'; expires=Thu, 01-Jan-70 00:00:01 GMT';return t},
	Sup:function(){cookie.Set('c',true);return cookie.Del('c')}
};
function newWin(url,name,width,height,scroll)
{
	window.open(url,name,'status=0,width='+width+',height='+height+',top='+(screen.availHeight/2 - height/2)+',left='+(screen.availWidth/2 - width/2)+',scrollbars='+(typeof scroll == 'undefined' ? 'no' : 'yes'));
	return false;
}
function set_limit(limit)
{
	cookie.Set('limit',limit,'3 months');
	window.location.reload(true);
}
function set_columns(columns)
{
	cookie.Set('columns',columns,'3 months');
	window.location.reload(true);
}

function smile(s, tb)
{
	tb=document.getElementById(tb);
	getActiveText(tb);
	AddText(' '+s+' ', tb);
}
function getActiveText(tb)
{
	tb.focus();
	if(!document.all||(document.all&&!document.selection)) return false;
	var sel=document.selection;
	var rng=sel.createRange();
	if(rng!=null && (sel.type=="Text"||sel.type=="None")) text=rng.text;
	if(rng!=null && tb.createTextRange) tb.caretPos=rng.duplicate();
	return true;
}

// #############################################################################
function AddText(NewCode, tb)
{
	if(typeof(tb.createTextRange)!="undefined"&&tb.caretPos)
	{
		var caretPos=tb.caretPos;
		caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==' '?NewCode+' ':NewCode;
		caretPos.select();
	} else if(tb.selectionStart||tb.selectionStart=='0')
	{
		var start_selection=tb.selectionStart;
		var end_selection=tb.selectionEnd;
		var start=(tb.value).substring(0, start_selection);
		var middle=NewCode;
		var end=(tb.value).substring(end_selection, tb.textLength);

		tb.value=start+middle+end;
		tb.focus();
		tb.selectionStart=end_selection+middle.length;
		tb.selectionEnd=start_selection+middle.length;
		getActiveText(tb);
		return;
	} else tb.value+=NewCode;
	tb.focus();
	getActiveText(tb);
}