var mes1 = 'это ссылка на сообщение';
// Имя ссылки, заголовок закладки
var tablink_idname = new Array("tablink")
// Имя закладки
var tabcontent_idname = new Array("tabcontent") 
// Число закладок
var tabcount = new Array("2")
// Активная закладка
var loadtabs = new Array("1")  

window.onload = hoverstates;
function hoverstates()
{
	var yadda = document.getElementsByTagName('div');
	for (var i=0;i<yadda.length;i++) {
		if (yadda[i].className == 'post-title')
		{
			yadda[i].onmouseover = function() { this.className = "post-title-on";};
			yadda[i].onmouseout = function() { this.className = "post-title"; };
		}
		if (yadda[i].className == 'post-pm')
		{
			yadda[i].onmouseover = function() { this.className = "post-pm-on";};
			yadda[i].onmouseout = function() { this.className = "post-pm"; };
		}
		if (yadda[i].className == 'post-pfs')
		{
			yadda[i].onmouseover = function() { this.className = "post-pfs-on";};
			yadda[i].onmouseout = function() { this.className = "post-pfs"; };
		}
		if (yadda[i].className == 'post-shopn')
		{
			yadda[i].onmouseover = function() { this.className = "post-shopn-on";};
			yadda[i].onmouseout = function() { this.className = "post-shopn"; };
		}
	}
	var yadda = document.getElementsByTagName('span');
	for (var i=0;i<yadda.length;i++) {
		if (yadda[i].className == 'page-item')
		{
			yadda[i].onmouseover = function() { this.className = "page-item-on";};
			yadda[i].onmouseout = function() { this.className = "page-item"; };
		}
	}
	var menucount=loadtabs.length; var a = 0; var b = 1; do {easytabs(b, loadtabs[a]);  a++; b++;}while (b<=menucount);
} 

/* Переключатель закладок */
function easytabs(menunr, active) {
	menunr = menunr-1;
	for (i=1; i <= tabcount[menunr]; i++){
		var ss = document.getElementById(tablink_idname[menunr]+i);
		if (ss != null)
		{
			ss.className='tab'+i;
		}
		var cc = document.getElementById(tabcontent_idname[menunr]+i);
		if (cc != null)
		{
			cc.style.display = 'none';
		}
	}
	var ss = document.getElementById(tablink_idname[menunr]+active);
	if (ss != null)
	{
		ss.className='tab'+active+' tabactive';
	}
	var cc = document.getElementById(tabcontent_idname[menunr]+active);
	if (cc != null)
	{
		cc.style.display = 'block';
	}
}

/* Перенаправление на заданный урл */
function redirect(url)
{
	if (url.options[url.selectedIndex].value != "")
	{
		location.href = url.options[url.selectedIndex].value;
	}
}
/* Перенос топика */
function redirect_topic(url)
{
	if (url.options[url.selectedIndex].value != "")
	{
		//location.href = url.options[url.selectedIndex].value;
		window.open(url.options[url.selectedIndex].value, 'GetSanction', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=500, height=500, left=32, top=16');

	}
}
/* Комментируем выделенный фрагмент */
if (document.selection||window.getSelection) {Q=true} else {var Q=false} 
var txt=''

function copyQ(nick) 
{ 
	txt='' 
	if (window.getSelection) 
	{
		txt=window.getSelection()
	}
	else 
		if (document.selection) 
		{
			txt=document.selection.createRange().text;
		}
	txt='[quote][b]'+nick+'[/b]: '+txt+'[/quote]\n';
} 

function setCaret (textObj) 
{
	if (textObj.createTextRange)
	{
		textObj.caretPos = document.selection.createRange().duplicate(); 
	} 
} 
function pasteQ(c2)
{
	if (txt!='' && document.getElementById(c2)) 
		insertAtCaret(document.getElementById(c2),txt); 
} 

function insertAtCaret (textObj, textFieldValue) 
{
	if(document.all)
	{
		if (textObj.createTextRange && textObj.caretPos && !window.opera) 
		{
			var caretPos = textObj.caretPos; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?textFieldValue + ' ' : textFieldValue; 
		}
		else
		{
			textObj.value += textFieldValue;
		}
	}
	else
	{
		if (textObj.selectionStart)
		{
			var rangeStart = textObj.selectionStart; 
			var rangeEnd = textObj.selectionEnd; 
			var tempStr1 = textObj.value.substring(0,rangeStart); 
			var tempStr2 = textObj.value.substring(rangeEnd, textObj.value.length); 
			textObj.value = tempStr1 + textFieldValue + tempStr2; 
			textObj.selectionStart=textObj.selectionEnd=rangeStart+textFieldValue.length;
		}
		else
		{
			textObj.value+=textFieldValue; 
		}
	}
}

// вставляем текст в арею
function addtxt(t,c1,c2)
{
	if (t!='' && document.getElementById(c2))
		insertAtCaret(document.getElementById(c2),t); 
}

// редактируем пост
function geteditpost(id)
{
	window.open('/eposts/'+id, 'Edit', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=545, height=430, left=32, top=16');
}
// отправляем личку
function getmail(id)
{
	window.open('/mail/'+id+'/get', 'Mail', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=545, height=430, left=32, top=16');
}
// удаляем личку
function dropmail(id, num)
{
	window.open('/mail/'+id+'/drop/'+num, 'Mail', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=545, height=430, left=32, top=16');	
}
// вызываем просмотр штрафа
function getsanction(id)
{
	window.open('/getsanction/'+id, 'GetSanction', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=500, height=500, left=32, top=16');
}
// создание новой темы
function getaddtopic(id)
{
	window.open('/newtopics/'+id, 'AddTopics', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=515, height=430, left=32, top=16');
}

// показываем информацию о пользователе
function showWA (i, action)
{
	divan = document.getElementById('sm_mes');
	image = document.getElementById(i);
	arr = objectXYWA(image);
	divan.style.left = arr[0]+'px';
	divan.style.top = arr[1]+'px';
	document.getElementById("pm").href = 'javascript: getmail(\''+action+'\');';
	clearWA();
	divan.style.visibility = 'visible';
	sndReq1(action);
}
function clearWA ()
{
	document.getElementById("icq").innerHTML = '';
	document.getElementById("nick").innerHTML = '<font color="red"><b>Подождите! Данные загружаются ...</b></font>';
	document.getElementById("dr").innerHTML = '';
	document.getElementById("zan").innerHTML = '';
	document.getElementById("wst").innerHTML = '';
	document.getElementById("xar").innerHTML = '';

	var avatar = document.getElementById("avatar");

	avatar.src = image.src;
	avatar.width = image.width;
	avatar.height = image.height;
}

function objectXYWA(obj) {
   var x = 0, y = 0;
   do {
      x += obj.offsetLeft;
      y += obj.offsetTop
   } while (typeof(obj = obj.offsetParent) != 'undefined' && obj != null);
   return [x-8,y-33]
}

function hideWA (mes)
{
	divan = document.getElementById(mes);
	divan.style.visibility = 'hidden';
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer'){
        ro = new ActiveXObject('Microsoft.XMLHTTP');
		if (!ro) { ro = new ActiveXObject("Msxml2.XMLHTTP");}
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
	
var http = createRequestObject();
	
function sndReq(action) {
    http.open('get', '/pget/'+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function sndReq1(action) {
    http.open('get', '/aget/'+action);
    http.onreadystatechange = handleResponse1;
    http.send(null);

}
function handleResponse1() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
	
        if(response.indexOf('Є' != -1)) {
            update = response.split('Є');
            document.getElementById("nick").innerHTML = update[0];
            document.getElementById("dr").innerHTML = update[1];
            document.getElementById("icq").innerHTML = update[2];
            document.getElementById("zan").innerHTML = update[3];
            document.getElementById("xar").innerHTML = update[4];
			document.getElementById("wst").innerHTML = update[5];
        }
    }
}
function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
	
        if(response.indexOf('Є' != -1)) {
            update = response.split('Є');
            document.getElementById("author").innerHTML = update[0];
            document.getElementById("data").innerHTML = update[1];
            document.getElementById("fm_text").innerHTML = update[2];
            document.getElementById("first").innerHTML = update[3];
            document.getElementById("prior").innerHTML = update[4];
            document.getElementById("next").innerHTML = update[5];
            document.getElementById("last").innerHTML = update[6];
            document.getElementById("current").innerHTML = update[7];
        }
    }
}

function hideW (mes)
{
	divan = document.getElementById(mes);
	divan.style.visibility = 'hidden';
}

function showWF (i, action)
{
	divan = document.getElementById('fm_mes');
	image = document.getElementById(i);
	arr = objectXYWF(image);
	divan.style.left = arr[0]+'px';
	divan.style.top = arr[1]+'px';
	clearWF();
	divan.style.visibility = 'visible';
	sndReq(action);
}
function objectXYWF(obj) {
   var x = 0, y = 0;
   do {
      x += obj.offsetLeft;
      y += obj.offsetTop
   } while (typeof(obj = obj.offsetParent) != 'undefined' && obj != null);
   return [x-8,y-33]
}
function clearWF ()
{
	document.getElementById("author").innerHTML = '';
	document.getElementById("data").innerHTML = '';
	document.getElementById("fm_text").innerHTML = '<font color="red"><b>сообщение загружается ...</b></font>';
	document.getElementById("first").innerHTML = '';
	document.getElementById("prior").innerHTML = '';
	document.getElementById("next").innerHTML = '';
	document.getElementById("last").innerHTML = '';
	document.getElementById("current").innerHTML = '';
}

function pfs () {
	window.open('/ipfs/1/0/brow', 'PFS', 'toolbar=0, location=0, directories=0, menuBar=0, resizable=0, scrollbars=yes, width=800, height=600, left=32, top=16');
}
function addthumb(gfile, path)
{
	eval("opener.document.new_post.newpost.value += '[thumb="+path+"]"+gfile+"[/thumb]';");
}

function addpix(gfile)
{
	eval("opener.document.new_post.newpost.value += '[img]"+gfile+"[/img]';");
} 

$(document).ready(function(){
	$('span.plus').click(
		function() {
			pid = $(this).attr('id').substr(2);
			$.post(
			  '/plugins/block/ajax/@ajax.voter.php',
			  {
			  	action: "av",
			    pid: pid
			  },
			  function (data){
				$('span#av'+pid).html(data.voter.plus);
				$('span#dv'+pid).html(data.voter.minus);
				$('div#tp'+pid).html('Проголосовали <b>ЗА:</b>&nbsp;' + data.voter.tplus);
				$('div#tm'+pid).html('Проголосовали <b>ПРОТИВ:</b>&nbsp;' + data.voter.tminus);
				$('div#tp'+pid).show();
				$('div#tm'+pid).show();				
			  },
			  "json"
			);	
		}
	);
	$('span.minus').click(
		function() {
			pid = $(this).attr('id').substr(2);
			$.post(
			  '/plugins/block/ajax/@ajax.voter.php',
			  {
			  	action: "dv",
			    pid: pid
			  },
			  function (data){
				$('span#av'+pid).html(data.voter.plus);
				$('span#dv'+pid).html(data.voter.minus);
				$('div#tp'+pid).html('Проголосовали <b>ЗА:</b>&nbsp;' + data.voter.tplus);
				$('div#tm'+pid).html('Проголосовали <b>ПРОТИВ:</b>&nbsp;' + data.voter.tminus);
				$('div#tp'+pid).show();
				$('div#tm'+pid).show();
			  },
			  "json"
			);	
		}
	);
}
);
