var isSelected = false;
var smile_n=1;
var site= 'http://hyperjump.ru';
// Разрешенные смайлики

var sm = new Array(
	'crazy',17,24,1, 'laugh',20,20,1, 'hehe',15,15,1, 'smile',15,15,1, 'conf',15,22,1, 'ponder',21,15,1, 'dkn',31,15,1, 'wow',15,20,1, 'wow2',32,17,1, 'nerv',15,16,1, 'shy',15,16,1, 'red',15,20,1, 'sad',23,23,1,    'dry',15,15,1, 'despair',15,15,1, 'cry',16,16,1, 'cry2',38,19,1, 'help',27,28,1, 'spot',22,15,1, 'goodbad',22,21,1, 'shuffle',24,24,1, 'kult',31,16,1, 'angel',15,23,1,    'beer',15,15,1, 'yes',15,15,1, 'no',15,15,1, 'ok',22,16,1, 'wink',15,15,1, 'happy',15,15,1,    'agree',50,20,1, 'greedy',61,20,1, 'proud',25,21,1, 'idea',26,27,1, 'umn',40,40,1, 'old',32,28,1, 'celebrity',57,38,1, 'metal',26,28,1, 'str',35,25,1, 'bulldog',26,23,1,    'jaw',27,20,1, 'mad',29,18,1, 'wall',25,20,1, 'acid',40,24,1, 'bayan',39,30,1, 'kluv',54,24,1, 'sotona',37,31,1, 'csotona',31,31,1,    'crzswans',74,22,1,
	'gent',15,21,2, 'rupor',38,18,2, 'dont',22,18,2, 'dunno',25,15,2, 'mol',30,24,2, 'king',21,22,2, 'sleep',32,22,2, 'lick',15,15,2, 'chupa',27,22,2,    'cop',15,21,2, 'miner',50,22,2, 'jeer',26,16,2, 'stupid',20,15,2, 'stupid2',20,20,2, 'protest',26,22,2, 'rtfm',24,23,2, 'tongue',15,15,2, 'tongue2',30,24,2,    'tost',43,23,2, 'fire',35,25,2, 'row',50,25,2, 'fly',56,26,2, 'doctor',35,32,2, 'late',32,27,2,    'nobody',29,27,2, 'friday',57,28,2, 'swans',74,22,2, 'privet',27,29,2, 'priva',56,24,2,    'hi',31,28,2, 'hello',25,27,2, 'joy',31,36,2, 'imhere',23,34,2, 'popcorn',35,35,2, 'die',30,40,2, 'die2',24,36,2, 'smoke',20,20,2,    'smoke2',34,38,2, 'digger',33,33,2, 'bye',41,30,2, 'ban',41,38,2, 'congr',47,43,2, 'work',55,44,2,
	'rose',15,15,3, 'heart',16,14,3, 'flashka',20,19,3, 'nail',32,26,3, 'rev',40,25,3, 'pester',54,24,3, 'kulich',66,29,3,    'boogi',100,20,3, 'tango',64,24,3, 'poshl',43,22,3, 'poshl2',42,23,3,    'lady',15,19,3, 'vantuz',60,30,3, 'love',40,21,3, 'hug',48,20,3, 'hug2',40,20,3, 'wedding',43,21,3,    'flowers',28,29,3, 'divin',38,33,3, 'obm',37,22,3, 'farewell',40,36,3, 'soska',51,20,3, 'lesom',47,29,3,    'preved',90,40,3, 'newyear',45,41,3, 'serenade',33,56,3,
	'cowb',44,29,4, 'guns',45,30,4, 'boks',62,28,4, 'nun',40,28,4, 'rambo',27,22,4, 'yessir',34,34,4,    'nunu',26,22,4, 'susel',70,29,4, 'monstr',35,30,4, 'kruger',34,27,4, 'hul',63,24,4,    'naem',30,32,4, 'budo',54,37,4, 'horse',60,40,4, 'grenade',52,34,4, 'sdaus',35,36,4,    'm60',51,18,4, 'rocket',100,33,4, 'duel',97,32,4,    'croco',59,29,4, 'robbery',50,30,4, 'maniac',70,25,4, 'loser',52,28,4,    'broken',80,20,4, 'what',65,27,4, 'naezd',65,35,4, 'snowfight',51,24,4, 'crazyny',74,30,3
);

function ins(ch) {
	var bbopen="["+ch+"]";
	var bbclose="[/"+ch+"]";
	var txtarea = document.form1.topicmess;

	if (isSelected) {
		if (txtarea.createTextRange && txtarea.caretPos) {
			var caretPos = txtarea.caretPos;
			caretPos.text = bbopen+caretPos.text+bbclose;
			storeCaret(txtarea);
			if (txtarea.caretPos.text=="") {
				isSelected=false;
				txtarea.focus();
			}
		}
	} else if (txtarea.selectionEnd) { // Mozilla
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + bbopen + s2 + bbclose + s3;
		txtarea.focus(selEnd);
	} else {
		txtarea.value += bbopen + bbclose;
	}
}

function sml(text) {
	var txtarea = document.form1.topicmess;
	txtarea.focus();
	var add= ":"+text+":";
	if (txtarea.createTextRange && txtarea.caretPos) {
		txtarea.caretPos.text += add;
	} else if (txtarea.selectionEnd) { // Mozilla
		var selStart = txtarea.selectionStart;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart,txtarea.textLength);
		txtarea.value = s1 + add + s2;
	} else {
		txtarea.value  += add;
	}	
}

var	smilepopup;

function hideSmiles() {
	if (smilepopup.style.display=='block') {
		smilepopup.style.display = 'none';
		removeEvent(document.getElementById('SMILEAREA'), 'click', hideSmiles);
//		removeEvent(document.getElementById('tz_main_block'), 'click', hideSmiles);
//		removeEvent(document.getElementsByTagName('table')[0],'click', hideSmiles);
	}
}
function td1(n, d) {
	return '<td style=\'text-align: center;\' '+(n==d?'':('onclick="smiles('+d+')" onMouseOver="this.style.backgroundColor=\'white\'" onMouseOut="this.style.backgroundColor=\'#555555\'" bgcolor="#555555"'))+'><B>'+d+'</B></td>';
}
function SmilesShowHide()
{
	if (smilepopup && smilepopup.style.display=='block') {
		smilepopup.style.display = 'none';
		}
		else
		{
		smiles();
		}
}
function smiles(n){
	smile_n = (n = n || smile_n);
	var width = 290;
	var height = 245;	
	var s1='<table width="100%" border=0 cellspacing=0 cellpadding=0 style="cursor:pointer;cursor:hand;border:0;font:10pt verdana,arial,helvetica,tahoma,sans-serif"><tr align=center>'+
		td1(n,1)+td1(n,2)+td1(n,3)+td1(n,4)+
		'</tr><tbody id="SMILEAREA"><tr><td align=center colspan=4 style="padding:3px">';
	for (var i=0; i < sm.length; i+=4) if(sm[i+3] == n)
		s1 += '<IMG SRC="'+site+'/i/smiles/'+sm[i]+'.gif" WIDTH="'+sm[i+1]+'" HEIGHT="'+sm[i+2]+'" BORDER="0" ALT="'+sm[i]+'" onclick="sml(\''+sm[i]+'\');hideSmiles();" onMouseOver="this.style.backgroundColor=\'white\'" onMouseOut="this.style.backgroundColor=\'\'"> ';	
	
	if (!smilepopup) {	
		smilepopup = document.createElement("DIV");
		smilepopup.style.display = 'none';
		smilepopup.style.border = '1px solid #fff';
		smilepopup.style.position = 'absolute';
		smilepopup.style.zIndex = '300';
		smilepopup.style.background = '#000';
		smilepopup.style.margin = '-280px 0 0 0';
		smilepopup.style.right = '152px';
		smilepopup.style.height = height+'px';
		smilepopup.style.width = width+'px';
		smilepopup.id = 'SMILEPOPUP';
		document.body.appendChild(smilepopup);
		smilepopup = document.getElementById('SMILEPOPUP');				
	}
	s1 += '</tbody></tr></table>';
	smilepopup.innerHTML = '<TABLE border=0 cellspacing=0 cellpadding=0 style="cursor:pointer;cursor:hand;">'+s1+'</TABLE></BODY>';
	smilepopup.style.display = 'block';
	//setTimeout("addEvent(document.getElementById('SMILEAREA'), 'click', hideSmiles)", 200);

}


var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/
function callServer(gp,str) {

  // Создать URL для подключения
  var url = "http://hyperjump.ru/"+str;
//  + escape(state);

  // Открыть соединение с сервером
  xmlHttp.open(gp, url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = updatePage;

  // SПередать запрос
  xmlHttp.send(null);
}
function updatePage() {
  if (xmlHttp.readyState == 4) {
	document.getElementById("newtop").innerHTML=xmlHttp.responseText;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
function shownewtop(gp,str)
{
callServer(gp,str);
}
