/**
 * @param obj
 * @param evType
 * @param fn
 */
function disabled_addEvent(obj, evType, fn) {
	if (obj.addEventListener)
		obj.addEventListener(evType, fn, true);
	else if (obj.attachEvent)
		obj.attachEvent("on" + evType, fn);
}

/**
 * 
 */
function focusMessageInput() {
	if (top.document.postform)
		top.document.postform.msg.focus();
}

/**
 * @param num
 */
function placeImage(num) {
	top.document.postform.msg.value = top.document.postform.msg.value + '<'
			+ num + '>';
	focusMessageInput();
}

/**
 * @param from
 * @param to
 * @param toname
 * @param isprivate
 */
function startMessage(from, to, toname, isprivate) {
	// PRIVATE COMMENT
	// isprivate = false; //отключение привата
	if ((from != to) && (to != 0) && (toname)) {
		top.document.postform.to.value = to;
		top.document.postform.toname.value = toname;
		top.isPrivMsg = isprivate;
		if (isprivate) {
			top.document.postform.toname.title = 'Кликните для ОТКЛЮЧЕНИЯ режима привата для "' + toname + '"';
			top.document.postform.toname.style.color = '#008800';
			top.document.postform.toname.style.backgroundColor = '#FFFFCC';
			top.document.postform.toname.style.borderColor = '#FF0000';
			top.document.postform.msg.title = 'Приватное сообщение для "' + toname + '"';
			top.document.postform.msg.style.backgroundColor = '#FFFFCC';
			top.document.postform.msg.style.borderColor = '#FF0000';
			top.document.postform.postbutton.title = 'Отправить приват "' + toname + '"';
			top.document.postform.postbutton.style.backgroundColor = '#FFFFBB';
		} else {
			top.document.postform.toname.title = 'Кликните для ВКЛЮЧЕНИЯ режима привата для "' + toname + '"';
			top.document.postform.toname.style.color = '#008800';
			top.document.postform.toname.style.backgroundColor = '#FFFFFF';
			top.document.postform.toname.style.borderColor = '#00FF00';
			top.document.postform.msg.title = 'Обращение к "' + toname + '"';
			top.document.postform.msg.style.backgroundColor = '#FFFFFF';
			top.document.postform.msg.style.borderColor = '#00FF00';
			top.document.postform.postbutton.title = 'Отправить обращение к "' + toname + '"';
			top.document.postform.postbutton.style.backgroundColor = '#DDEECC';
		}
	}
	focusMessageInput();
}

/**
 * @param from
 */
function switchPrivate(from) {
	if (top.document.postform.to.value > 0) {
		startMessage(from, top.document.postform.to.value,
				top.document.postform.toname.value, !top.isPrivMsg);
	}
	focusMessageInput();
}

/**
 */
function clearMessage() {
	top.document.postform.to.value = '';
	top.document.postform.toname.value = 'Всем';
	top.isPrivMsg = false;
	top.document.postform.msg.value = '';
	top.document.postform.toname.title = 'Сообщение всем пользователям в общий канал';
	top.document.postform.toname.style.color = '#000000';
	top.document.postform.toname.style.backgroundColor = '#EEEEEE';
	top.document.postform.toname.style.borderColor = '#888877';
	top.document.postform.msg.title = 'Сообщение всем пользователям в общий канал';
	top.document.postform.msg.style.backgroundColor = '#FFFFFF';
	top.document.postform.msg.style.borderColor = '#888877';
	top.document.postform.postbutton.title = 'Отправить сообщение в общий канал';
	top.document.postform.postbutton.style.backgroundColor = '#EEEEEE';
	focusMessageInput();
}

/**
 * @return none
 */
function sendMessage() {
	if (top.document.postform.msg.value && top.postframe.readySubmit) {
		top.postframe.readySubmit = false;
		if (!top.isPrivMsg) {
			top.postframe.document.postform.to.value = '0';
			if ((top.document.postform.to.value > 0)
					&& (top.document.postform.msg.value.charAt(0) != "/"))
				top.document.postform.msg.value = top.document.postform.toname.value
						+ ', ' + top.document.postform.msg.value;
		} else {
			top.postframe.document.postform.to.value = top.document.postform.to.value;
		}
		top.postframe.document.postform.msg.value = top.document.postform.msg.value;
		top.postframe.document.postform.submit();

		// очищаем строку
		// if (!top.isPrivMsg) clearMessage();
		// else top.document.postform.msg.value = '';
		top.document.postform.msg.value = '';
	}
	focusMessageInput();
	return false;
}

/**
 * @return none
 */
function sendTema() {
	if (top.postframe.readySubmit) {
		top.postframe.readySubmit = false;
		top.postframe.document.temaform.tema.value = top.document.temaform.tema.value;
		top.postframe.document.temaform.submit();
	}
	focusMessageInput();
	return false;
}
