//<![CDATA[
function $(id){return document.getElementById(id);}
function $$(id){return document.createElement(id);}
function $$$(id){document.write(id);}
function che(id){
    if(!$(id)) return;
    $(id).style.display = $(id).style.display == 'none' ? 'block' : 'none';
}
function opnpopup(w,h,title,srcs){
	myWin= open("","displayWindow","width="+w+",height="+h+",status=no,toolbar=no,menubar=no,resizable=no");
	myWin.document.open();
	myWin.document.write("<html><head><title>"+title+"</title></head><body style='margin:0;padding:0;'><center><a href='javascript:window.close();void(0);'><img src='"+srcs+"' width='"+w+"' height='"+h+"' border='0' /></a></center></body></html>");
	myWin.document.close();
}
function getjsvar(asmode,url){
    newurl = '/onliner.js?';
    if(asmode) newurl += 'mode='+asmode;
    else       newurl += 'first='+firstgeturl+'&langid='+langid+'&sectid='+sectid+'&artid='+artid+((url)?('&'+url):'');
    newurl += '&time='+time().getTime();
    firstgeturl = 0;
    var span = null;
	var span = document.createElement('SPAN');
    $('jsdiv').appendChild(span);
    span.style.display = 'none';
    span.innerHTML = 't <s'+'cript></' + 'script>';
    var s = span.getElementsByTagName("script")[0];
    s.language = "JavaScript";
    s.type = "text/javascript";
    if(s.setAttribute) s.setAttribute('src',newurl); else s.src = newurl;
}
function vidm(n,t){
	c = new Array (2,0,1,1,1,2);
	return t[(n%100>4 && n%100<20)? 2:c[Math.min(n%10,5)]];
}
function timeBershad(){
   x = new Date(time().getUTCFullYear(),time().getUTCMonth(),time().getUTCDate(),time().getUTCHours()+3,time().getUTCMinutes(),time().getUTCSeconds());
   x.setTime(x.getTime());
   return x;
}
function time(){return new Date()}
function leadingZero(x){return (x>9)?x:'0'+x;}
function bertab(a,t,num){
	try{
		var td, tr = a, div;
		var node, i, remJ = [], curTD = 0;
		if(div = $(t+"_" + num)){
			div.style.display = "";
			for(i = 0;i<20; i++){
				if($(t+"_" +i))
				if(i != num)$(t+"_" +i).style.display = "none";
				else $(t+"_" + i).style.display = "block";
			}
		}
		while(tr.parentNode && tr.nodeName.toLowerCase() != "tr"){
			if(tr.nodeName.toLowerCase() == "td") td = tr;
			tr = tr.parentNode;
		}
		for(i=0;i<tr.childNodes.length;i++){
			node = tr.childNodes[i];
			if(node.nodeType != 1) continue;
			if(node.nodeName.toLowerCase() != "td") continue;
            if(node.firstChild.className != "lft" && node.firstChild.className != "lft first" && node.firstChild.className != "lst") continue;
			if(node == td) {node.className = "act"; curTD = 1;}
			else {node.className = curTD ? "aftact" : "pas"; curTD = 0;}
		}
	}catch(e){return false;}
	a.blur();
	return false;
}
function dog(user,server,subj){
	var eil = user+unescape('%40')+server;
	$$$('<a href="mailto:'+eil+((subj) ? '?subject='+subj : '')+'">'+eil+'</a>');
}
function mkhttp(url,data,handler){
	var x = (window.ActiveXObject) ? (new ActiveXObject("Microsoft.XMLHTTP")):(new XMLHttpRequest());
	x.open(data?'POST':'GET',url,(typeof(handler) != 'undefined' && handler)?true:false);
    if(data) x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    x.send(data?data:null);
	if(handler) if(typeof(x.onload) != 'undefined')	x.onload = function(){handler(x);}
    else x.onreadystatechange = function(){if(x.readyState == 4) handler(x);}
	return x;
}
function avote_handler(x){
	if(x.responseXML && (d = x.responseXML.documentElement) && d.tagName == 'ok'){
		var tmp = x.responseXML.getElementsByTagName('ok');
		return true;
	}else return false;
}
function multiVoteIt(absn,act,elem,t){
	var oRate = new makeObj("rate" + absn);
	var eList = oRate.elem.childNodes.length;
	var eImg = oRate.elem.childNodes;
	if(!act) for(i=0;i<=elem;i++) eImg[i].src = tmp[i].src;
	if(act==1){
		for(i=0;i<eList;i++) tmp[i] = new Image();
		for(i=0;i<=elem;i++) tmp[i].src = eImg[i].src;
		if(!isRate[absn]){
			for(i=0;i<=elem;i++) eImg[i].src = star_o.src;
			oRate.elem.style.cursor = "pointer";
		}
	}
	if(act == 2 && !isRate[absn]){
		vCount[absn]++;
		ball = elem + 1;
		vSum[absn] += ball;
		rating = Math.round(vSum[absn] * 10 / vCount[absn]) / 10;
		oRate.elem.className = "def";
		isRate[absn] = 1;
		var x = mkhttp(basehref+'/xml/avote?mode='+t+'&artid='+absn+'&sectid='+sectid+'&ball='+ball,null,avote_handler);
		for(i=0;i<eList;i++){
			eImg[i].src = '/upload/tmp/star_' + ((i <= rating - 1) ? 'f' : (i + 0.5 <= rating ? 'h' : 'e')) + '.gif';
			tmp[i].src = eImg[i].src;
		}
		alert('Ваш голос враховано. Дякуємо!');
	}else if(act == 2){
        alert('Ви вже голосували. Дякуємо!');
    }
}
function makeObj(obj){
	this.elem = $(obj);
	this.css = this.elem ? this.elem.style : null;
	return this;
}
function displayTime(){
   $('disp').innerHTML = eval(outputTime);
   setTimeout('displayTime()',1000);
}
function repltime(dat,def,c){
		var m = new Date(dat*1000);
		var md = m.getDate();
		var u =new Date(dat*1000);
		u.setDate(u.getDate()+1);
		if((timeBershad().getTime()-m.getTime()) < (3600*24*30*1000))
			if(md == timeBershad().getDate())
				$$$('<span class="green">Сьогодні</span>'+(c?',':'')+' ');
			else if(u.getDate() == timeBershad().getDate())
				$$$('<span class="blue">Вчора</span>'+(c?',':'&nbsp;&nbsp;&nbsp;')+' ');
        else $$$(def+(c?',':'')+' ');
}
function em(f,lib,tm,w,h){
	if(w!=''&&h!='')	var wh = 'width="'+w+'" height="'+h+'"';
	else var wh = '';
	$$$('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '+wh+' id="picture" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+f+'?'+tm+'" /><param name="quality" value="high" /><PARAM NAME=FlashVars VALUE="'+lib+'"><PARAM NAME=wmode VALUE="transparent"><param name="bgcolor" value="#eaeff4" /><embed src="'+f+'?'+tm+'" quality="high" wmode="transparent" FlashVars="'+lib+'" bgcolor="#eaeff4" '+wh+' name="picture" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}
function B_Load(){
	this.wib = screen.width;
	this.heb = screen.height;
	this.documes = ($ || document.createElement || document.getElementsByTagName) ? true : false;
	this.objects = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
	this.types = 'load';
    this.addsevent = function(func){
    	if(this.objects.addEventListener){
    	this.objects.addEventListener(this.types,func,false);
    	return true;
    	}else if (this.objects.attachEvent)
    	this.objects.attachEvent("on" + this.types,func);
    	else return false;
    }
    this.findobj = function(obj){
    	this.parent = window.document;
    	if(this.parent[obj]){ return this.parent[obj]; }
    	if(this.parent.all && this.parent.all[obj]){ return this.parent.all[obj]; }
    	if(this.parent.layers && this.parent.layers[obj]){ return this.parent.layers[obj]; }
    	if(this.parent.getElementById && this.parent.getElementById(obj)){ return this.parent.getElementById(obj); }
    	return null;
    }
}
function B_Hint(){
    this.show = function(obj,str){
    	var hint = B.findobj('hint');
    	if(!obj)return;
    	if(!B.documes)return;
    	if(!hint)return;
        if(!hint.style)return;
    	hint.className = 'hint';
    	hint.style.left = 15+'px';
    	hint.style.top = 19+'px';
      obj.onmouseout = function(advance){
      	hint.style.width = '';
      	hint.style.visibility = 'hidden';
      	if(hint.firstChild) hint.removeChild(hint.firstChild);
      	hint.appendChild(document.createTextNode(str));
    	};
      obj.onmousemove = function(advance){
      	hint.style.width = '';
      	hint.innerHTML = str;
      	vc = document.getElementsByTagName((document.compatMode && document.compatMode=="CSS1Compat") ? "HTML":"BODY")[0];
      	if(!vc) return;
      	x = window.event ? event.clientX + vc.scrollLeft : advance.pageX;
      	y = window.event ? event.clientY + vc.scrollTop : advance.pageY;
      	vcwidth = vc.clientWidth ? vc.clientWidth + vc.scrollLeft : window.innerWidth + window.pageXOffset;
      	vcheight = vc.innerHeight ? window.innerHeight + window.pageYOffset : vc.clientHeight + vc.scrollTop;
      	if((x + hint.offsetWidth + 15) > vcwidth)
            hint.style.left = (x - hint.offsetWidth - 4)+'px';
      	else
            hint.style.left = (x + 15)+'px';
      	if((y + hint.offsetHeight + 19) > vcheight)
            hint.style.top = (y - hint.offsetHeight)+'px';
      	else
            hint.style.top = (y + 19)+'px';
      	hint.style.opacity = '.87';
      	hint.style.filter = "alpha(opacity:87)";
      	hint.style.visibility = 'visible';
    	}
    }
    this.initialize = function(){
    	var hint = document.createElement("DIV");
    	hint.setAttribute('id','hint');
    	document.getElementsByTagName('body')[0].appendChild(hint);
    	hint.style.visibility = 'hidden';
    	var hintmarker = ['img','a','tr','td','area'];
    	var textmarker = ['alt','title','title','title','title'];
    	var lenmarker = hintmarker.length;
    	for(var i=0; i<lenmarker; i++) {
    	atr = document.getElementsByTagName(hintmarker[i]);
    	for(var j=0; j<atr.length; j++)
    	if(viewhint=atr[j].getAttribute(textmarker[i])){
    	atr[j].removeAttribute(textmarker[i]);
    	HINT.show(atr[j],viewhint);
    	}
    	}
    }
}
function chlogin(obj){
	var err = '';
	if(!obj.elements['f[login]'].value) 	err += 'Не вказано логін\r\n';
	if(!obj.elements['f[passwd]'].value)	err += 'Не вказано пароль\r\n';
	if(err){
		alert(err);
		return false;
	}
	return true;
}
function insteg(id,aTag,eTag){
    $(id).focus();
    if(typeof document.selection != 'undefined'){
        var range = document.selection.createRange();
        var insText = range.text;
        range.text = aTag + insText + ((eTag) ? eTag : '');
        range = document.selection.createRange();
        if(insText.length == 0 && eTag) range.move('character', -eTag.length);
        else range.moveStart('character',aTag.length+insText.length+((eTag) ? eTag.length : 0));
        range.select();
    }else if(typeof $(id).selectionStart != 'undefined'){
        var start = $(id).selectionStart;
        var end = $(id).selectionEnd;
        var insText = $(id).value.substring(start, end);
        $(id).value = $(id).value.substr(0, start) + aTag + insText + ((eTag) ? eTag : '') + $(id).value.substr(end);
        var pos;
        if(insText.length == 0) pos = start + aTag.length;
        else pos = start + aTag.length + insText.length + ((eTag) ? eTag.length : 0);
        $(id).selectionStart = pos;
        $(id).selectionEnd = pos;
    }
}
function addsendmess(touser){
    sendmess(window.prompt('Написати повідомлення:',''),touser);
}
function sendmess(mess,touser){
    if(!mess || mess == ' ' || !touser){
        return;
    }
    if(!userid){
        alert('Помилка! Ви не авторизовані або час Вашої сесії вийшов.');
        return;
    }
  	var url =  encodeURI(basehref+'/xml/sendsmessage/?mess='+mess+'&touser='+touser);
  	var h = mkhttp(url);
    if(!h) return false;
  	if(!h.responseXML.getElementsByTagName("status")[0].firstChild) return;
  	if(h.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue == 1){
        alert('Дякуємо, Ваше повідомлення успішно надіслано.');
    }else{
        alert('Помилка! Ви не авторизовані або час Вашої сесії вийшов.');
    }
}
function addrate(obj,absn,art,sect,rate,type){
    if(type == 2){
  	    var url =  basehref+'/xml/avote?mode='+type+'&rate='+rate+'&commid='+absn+'&sectid='+sect+'&artid='+art;
  	    var h = mkhttp(url);
  	    if(!h) return false;
        obj.onclick = null;
        obj.src = '/upload/tmp/plus2.gif';
        obj.blur();
  	    var res = h.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue;
        if(res < 1){alert('Ви вже голосували');return;}
        if($('mark_'+absn)) $('mark_'+absn).innerHTML = res;
        alert('Дякуємо, Ваш голос враховано.');
    }
}
function SetCookie(name,value){
    var argv    = SetCookie.arguments;
    var argc    = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path    = (argc > 3) ? argv[3] : null;
    var domain  = (argc > 4) ? argv[4] : null;
    var secure  = (argc > 5) ? argv[5] : false;
    document.cookie = name + "="+escape(value)+((expires==null)?"":(";expires="+expires.toGMTString()))+((path==null)?"/":("; path=" +path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}
function GetCookie(name){
    var arg  = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i    = 0;
    while (i < clen){
        var j = i + alen;
        if(document.cookie.substring(i, j) == arg) return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if(i==0) break;
    }
    return null;
}
function getCookieVal(offset){
    var endstr = document.cookie.indexOf (";",offset);
    if (endstr == -1)endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset,endstr));
}
function DeleteCookie(name){
    var exp  = new Date();
    var cval = GetCookie (name);
    exp.setTime (exp.getTime() - 1);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function gallery(){
    this.full       = null;
    this.imgwdth    = 159;
    this.name       = 'gall';
    this.basehref   = null;
    this.id         = 0;
    this.licount    = 0;
    this.resetauto  = null;
    this.colls      = 4;
    this.start = function(){
      	$("sl_wrapper").style.overflow = "hidden";
      	var ul = $$("ul");
      	ul.setAttribute("id", "ul");
    	var sl_set = $("sl_set");
    	sl_set.style.top = 0+"px";
    	sl_set.style.left = 0+"px";
    	this.licount = sl_set.getElementsByTagName("li").length;
        if($('th_all')) $('th_all').innerHTML = this.licount;
    	sl_set.max_x = ((this.licount%this.colls == 0)?this.licount-this.colls:this.licount-(this.colls-1)) * this.imgwdth;
    	sl_set.max_y = this.licount * 1;
    	var width = (this.licount * this.imgwdth)+0;
    	sl_set.style.width = width + "px";
    }
    this.movesl = function(elementID,final_x,final_y,interval) {
        if(!$(elementID)) return false;
        var elem = $(elementID);
        if(elem.movement) clearTimeout(elem.movement);
        var xpos = parseInt(elem.style.left);
        var ypos = parseInt(elem.style.top);
        if(xpos == final_x && ypos == final_y) return true;
        if(final_x <= -elem.max_x) final_x = -elem.max_x;
        if(final_x > 0) final_x = 0;
        if(xpos < final_x){var dist = Math.ceil((final_x - xpos)/10);xpos = xpos + dist;}
        if(xpos > final_x){var dist = Math.ceil((xpos - final_x)/10);xpos = xpos - dist;}
        if(xpos <= -elem.max_x)xpos = -elem.max_x;
        if(xpos > 0)xpos = 0;
        elem.style.left = xpos + "px";
        elem.style.top = ypos + "px";
        var repeat = this.name+".movesl('"+elementID+"',"+final_x+","+final_y+","+interval+")";
        elem.movement = setTimeout(repeat,interval);
    }
    this.left = function(){
        var sl_set = $("sl_set");
        var x = parseInt(sl_set.style.left);
        if(x % this.imgwdth  == 0) this.movesl("sl_set",x+this.imgwdth*this.colls,0,5);
    }
    this.right = function(){
        var sl_set = $("sl_set");
        var x = parseInt(sl_set.style.left);
        if(x % this.imgwdth == 0) this.movesl("sl_set",x-this.imgwdth*this.colls,0,5);
    }
    this.prv = function(){
        if(this.id < 1) return;
        this.opnfull(this.id-1);
        this.resetauto = true;
    }
    this.nxt = function(){
        if(this.id > this.licount) return;
        this.opnfull(this.id+1);
        this.resetauto = true;
    }
    this.hint = function(t){
        if($('gallhint')) $('gallhint').innerHTML = t;
    }
    this.clearhint = function(){
        if($('gallhint')) $('gallhint').innerHTML = '';
    }
    this.autofull = function(){
        if(this.resetauto) return;
        this.opnfull(this.id);
        if(this.id > this.licount-(this.colls-2)) this.id = 0;
        else this.id++;
        setTimeout(this.name+'.autofull()',10000);
    }
    this.opnfull = function(id,src){
        if(!this.full) return;
        if(!src && $('sr_img')) if($('a_'+id)) src = $('a_'+id).href; else return;
        this.id = id;
        var i = 0;
        k = $('li_'+i);
        while(k){
            if($('fulldiv_'+i))$('fulldiv_'+i).style.display = 'none';
            k.className = '';
            i++;
            k = $('li_'+i);
        }
        $('li_'+this.id).className = 'sel';
        if($('th_num'))         $('th_num').innerHTML = parseInt(this.id)+1;
        if($('thiscount'))      $('thiscount').innerHTML = ((this.id*1)+1)+'/'+this.licount;
        if($('titletxt'))       $('titletxt').innerHTML = $('full_'+parseInt(this.id)).title;
        if($('thisfulhr'))      $('thisfulhr').href = src;
        if($('fulldiv_'+id))    $('fulldiv_'+id).style.display = 'block';
        if($('sr_img'))         $('sr_img').style.background = "#979797 url('"+src+ "') no-repeat center center";
        if(this.basehref)       document.location.href = this.basehref+'#img-'+this.id ;
    }
}
function sendTxtError(evt){
	evt = (evt)?evt :((window.event)?window.event : null);
	if (evt) {
		if (evt.keyCode == 10 || (evt.keyCode == 13 && evt.ctrlKey)) {
			var oInit = {
				maxlen: 256,
				wText:  {
					Big: "Виділено занадто багато тексту",
					NoSupport: "Ваш браузер не підтримує таку функцію",
					Error: "Помилка в тексті",
					Send: "Надіслати повідомлення про помилку авторам?\nВи залишитесь на цій же сторінці",
					Mark: "<помилка>",
                    Sencs: "Дякуємо за допомогу!"
				}
			}
			var sel = null;
			sel = (parent.getSelection) ? parent.getSelection() : ((parent.document.getSelection) ? parent.document.getSelection() : ((document.selection.createRange) ? document.selection.createRange().text : null));
			if(sel == null) {
				alert(oInit.wText.NoSupport);
				return;
			}
            sel += '';
			if(sel.length > oInit.maxlen){
				alert(oInit.wText.Big);
				return;
			}
			if(sel == "") return;
			if(confirm(oInit.wText.Error + "\n" + oInit.wText.Mark + sel + oInit.wText.Mark + "\n\n" + oInit.wText.Send)){
		        re = /\r/g;
				sel = sel.toString().replace(re, " ");
		        re = /\n/gi;
				sel = sel.toString().replace(re, " ");
                var url =  basehref+'/xml/senderror?txterr='+sel+'&useragent='+navigator.userAgent+'&docloc='+document.location.href;
        	    var h = mkhttp(url);
                alert(oInit.wText.Sencs);
			}
		}
    }
}
function cntrentererror(){
    if (!((navigator.appName.indexOf("Netscape")!=-1 && eval(navigator.appVersion.substring(0,1)) < 5) || (isOpera && verOpera < 7))) {
    	document.onkeypress = sendTxtError;
        if($('cntrlEnter')){
            $('cntrlEnter').innerHTML = 'Якщо Ви помітили помилку, виділіть текст з помилкою і натисніть Ctrl+Enter щоб повідомити про це редакцію.';
            $('cntrlEnter').style.display = 'block';
        }
    }
}
function ticker(text,pos,dir){
    var zeilen = tickermsg.length;
    if(!text) var text = tickermsg[ticnextm];
    $('ticker').innerHTML = text.substring(0,pos);
    pos += dir;
    if(pos > text.length)
        setTimeout('ticker("'+text+'",'+pos+','+(-dir)+')', ticdelay*100);
    else{
        if(pos<0){
            if(++ticnextm >= tickermsg.length) ticnextm = 0;
            text = tickermsg[ticnextm];
            dir = -dir;
        }
        setTimeout('ticker("'+text+'",'+pos+','+dir+')', ticdelay);
    }
}
var userid  = 0;
var artid   = 0;
var sectid  = 0;
var langid  = 1;
firstgeturl = 1;
var h_name  = ['годину','години','годин'];
var m_name  = ['хвилину','хвилини','хвилин'];
var days    = ['неділя ','понеділок','вівторок','середа','четвер','п\'ятниця','субота','неділя'];
var months  = ['січня','лютого','березня','квітня','травня','червня','липня','серпня','вересня','жовтня','листопада','грудня'];
var member = new Array();
var commentisvoted = new Array();
var nocomment = null;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
if(isOpera) var verOpera = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("Opera")+6));
brshd = new Array();
star_o      = new Image();
star_o.src  = "/upload/tmp/star_o_small.gif";
tmp         = new Array(star_o.src);
isRate      = new Array();
vCount      = new Array();
vSum        = new Array();
var issallrate= new Array();
var tickermsg= new Array();
var ticdelay  = 30;
var ticnextm  = 0;
var yandex_direct_place = 'yandex_direct';
var yandex_market_place = 'yandex_market';
var outputTime = "days[timeBershad().getDay()]+', '+timeBershad().getDate()+' '+months[timeBershad().getMonth()]+', в Бершаді '+leadingZero(timeBershad().getHours())+':'+leadingZero(timeBershad().getMinutes())+':'+leadingZero(timeBershad().getSeconds())";
var B = new B_Load();
var HINT = new B_Hint();
if(B.objects)B.addsevent(HINT.initialize);
//]]>