﻿var realy_logout = 'Вы действительно хотите выйти?';
var textcut = '';
var tag = '';
var param = '';
var cutid = ''

function getrandom() {
	var min_random = 0;
	var max_random = 100;
	max_random++;
	var range = max_random - min_random;
	var n = Math.floor(Math.random()*range) + min_random;
	return n;
}

function clockon() {
	thistime = new Date();
	var hours = thistime.getHours();
	var minutes = thistime.getMinutes();
	var seconds = thistime.getSeconds();
	if (eval(hours) <10) {hours = "0" + hours}
	if (eval(minutes) < 10) {minutes = "0" + minutes}
	if (seconds < 10) {seconds = "0" + seconds}
	thistime = hours + ":" + minutes + ":" + seconds
	if (document.all) {clock.innerHTML = thistime}
	if (document.layers) {
		document.clock.document.write ('<div id = "clock" style = "position:absolute; visibility:visible; font-family:Arial,sans-serif; color:#000000; top:150px; left:150px">' +thistime+ '</div>');
		document.close();
	}
	var timer=setTimeout ("clockon()", 200);
}

function FixTags(id) {
var txt=document.getElementById('x'+id).innerHTML;
	if (txt.indexOf('[admin]')!=-1){txt=txt.replace(/\[admin\]([^\[]+)\[\/admin\]/g,'<span class="adminmess">---<br>$1</span>');}
	if (txt.indexOf('[h1]')!=-1){txt=txt.replace(/\[h1\]([^\[]+)\[\/h1\]/g,'<h1>$1</h1>')}
	if (txt.indexOf('[h2]')!=-1){txt=txt.replace(/\[h2\]([^\[]+)\[\/h2\]/g,'<h2>$1</h2>')}
	if (txt.indexOf('[h3]')!=-1){txt=txt.replace(/\[h3\]([^\[]+)\[\/h3\]/g,'<h3>$1</h3>')}
	if (txt.indexOf('[tt]')!=-1){txt=txt.replace(/\[tt\]([^\[]+)\[\/tt\]/g,'<tt>$1</tt>')}
	if (txt.indexOf('[space]')!=-1){txt=txt.replace(/\[space\]([^\[]+)\[\/space\]/g,'<blockquote class="spaceblock">$1</blockquote>')}
	if (txt.indexOf('[mrq]')!=-1){txt=txt.replace(/\[mrq\]([^\[]+)\[\/mrq\]/g,'<marquee onmouseover="this.scrollAmount=0" onmouseout="this.scrollAmount=4" scrollamount="4" scrolldelay="5" direction="right" class="mrqtag">$1</marquee>')}
	if (txt.indexOf('[bg=')!=-1){txt=txt.replace(/\[bg=([^\[]+)\]([^\[]+)\[\/bg\]/g,'<span style="background: $1">$2</span>')}
	if (txt.indexOf('[bg]')!=-1){txt=txt.replace(/\[bg\]([^\[]+)\[\/bg\]/g,'<span style="background: black\; color:white">$1</span>')}
	if (txt.indexOf('[nlist=')!=-1){txt=txt.replace(/\[nlist=([^\[]+)\]([^\[]+)\[\/nlist\]/g,'<ol type="$1" class="numlist">$2</ol>')}
	if (txt.indexOf('[nlist]')!=-1){txt=txt.replace(/\[nlist\]([^\[]+)\[\/nlist\]/g,'<ol class="numlist">$1</ol>')}
	if (txt.indexOf('[off=')!=-1){txt = txt.replace(/\[off=([^\[]+)\]([^\[]+)\[\/off\]/g,'<a href="#" onclick="this.nextSibling.style.display = this.nextSibling.style.display == \'block\' ? \'none\' : \'block\'\; return false\;" class="cutlink">$1</a><div class="cutarea" style="display:none\;">$2</div>')}
	if (txt.indexOf('[off]')!=-1){txt = txt.replace(/\[off\]([^\[]+)\[\/off\]/g,'<a href="#" onclick="this.nextSibling.style.display = this.nextSibling.style.display == \'block\' ? \'none\' : \'block\'\; return false\;" class="cutlink">Cut</a><div class="cutarea" style="display:none\;">$1</div>')}
	if (txt.indexOf('[bord=')!=-1){txt=txt.replace(/\[bord=([^\[]+)\]([^\[]+)\[\/bord\]/g,'<fieldset class="bordarea"><legend class="bordhead">$1</legend>$2</fieldset>')}
	if (txt.indexOf('[bord]')!=-1){txt=txt.replace(/\[bord\]([^\[]+)\[\/bord\]/g,'<fieldset class="bordarea"><legend class="bordhead">Информация</legend>$1</fieldset>')}
	if (txt.indexOf('[inf=')!=-1){txt=txt.replace(/\[inf=([^\[]+)\]([^\[]+)\[\/inf\]/g,'<div class="inf'+'$1'+'">'+'$2'+'</div>')}
	if (txt.indexOf('[inf]')!=-1){txt=txt.replace(/\[inf\]([^\[]+)\[\/inf\]/g,'<div class="infhelp">$1</div>')}	
	if (txt.indexOf('[alert]')!=-1){txt=txt.replace(/\[alert\]([^\[]+)\[\/alert\]/g,'<a href="#" onclick="bbalert(\'$1\')\;return false">Информация</a>')}
	if (txt.indexOf('[ximg]')!=-1){txt=txt.replace(/\[ximg\]([^\[]+)\[\/ximg\]/g,'<div class="downimg" onclick="this.outerHTML=\'<img src="$1">\'">Подгружаемая картинка</div>')}
document.getElementById('x'+id).innerHTML=txt
}

function hs(id) {
	var e=document.getElementById(id).style;	
	if(e.display=='none') e.display='';
	else e.display='none';
}

function set_cookie(cook_name,cook_value) { 
	var exp = new Date(); 
	var cook_time = exp.getTime() + (365*24*60*60*1000);
	exp.setTime (cook_time); 
	document.cookie=cook_name+'='+cook_value+'; expires=' + exp.toGMTString() + 'mh;';
} 

function get_cookie(Name) { 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function load_cookie() { 
	document.all.tobn.value=get_cookie('mychat');
}

function obnov() { 
	if(document.all.tobn.value!=0) {
		window.chat.location.href='/gb'; 
	setTimeout('obnov()', document.all.tobn.value) 
	}
}

function sendpost() {
	window.chat.addform.message.value=mgs.value;
	mgs.value='';
	return window.chat.checkform(window.chat.document.forms.addform)
}

function emoticon(code){
	if (code != ""){
		var txtarea = document.addform.message;
		code = ' ' + code + ' ';
		if (document.selection) {
			txtarea.focus();
			var txtContent = txtarea.value;
			var str = document.selection.createRange();
			if (str.text == ""){
				str.text = code;
			} else if (txtContent.indexOf(str.text) != -1){
				str.text = code + str.text;
			} else {
				txtarea.value = txtContent + code;
			}
		} else {
			txtarea.value = txtarea.value + code;
		}
	}
}

function initsubs(){
	link=document.getElementsByTagName('a');
	hideForums=new Array('Утилиты','Импорт','Заплатки');
	for(k=0;k<hideForums.length;k++){
		for(i=0;i<link.length;i++){
			if(link[i].className=='forum' && link[i].innerHTML==hideForums[k]){
				link[i].parentNode.parentNode.style.display='none';
			}
		}
	}
}

function bbalert(text){
	var txt=text.replace(/<BR>/g,'\n');
	alert(txt)
}

function fixfiles(id){
	document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace(/·/g,'<br>')
}

function runforelem(findclass,func){
	var line = document.getElementsByTagName('*');
	for (var i = 0; i < line.length; i++){
		if (line[i].className == findclass){
			func(line[i])
		}
	}
}

function forumsh(elem){
	trs = elem.parentNode.getElementsByTagName('TR')	
	for (var i=1; i<trs.length; i++){
		ishide = trs[i].style.display
		elem.parentNode.getElementsByTagName('TR')[i].style.display = ishide == 'none' ? '' : 'none'
	}
}

function sendmessage(){
	window.chat.document.addform.message.value=document.info.mess.value;
	document.info.mess.value=''
	window.chat.gbsafe('addform');
}

function savetext(text){
	if (text.lenght>2048){
		alert('Слишком большое содержание')
	} else {
		text=text.replace(/\n/g,'<br>')
		set_cookie('textkeeper',text)
	}
}

function hideps(){
	if (window.chat.document.getElementById('pagesBlock2')) {
		window.chat.document.getElementById('pagesBlock2').style.display='none'
		setTimeout('hideps()',0)
		return
	}
	setTimeout('hideps()',1000)
}