﻿/* JavaScript Core 1.0 */
var _=function( id ){return new _.fn.init( id )}
_.fn = _.prototype = {
	_$:null,
    $:null,
    isS:function(){return (this.$.style.display != 'none')},//Is Show
	h:function(){if(this.$==null){alert(this._$)} this.$.style.display = 'none';return this},//Hide
	s:function(){this.$.style.display = '';return this},//Show
	s2:function(){this.$.style.display = 'block';return this},//Show
	c:function(n){if(n==null)return this.$.className;else this.$.className = n;return this},//Class
	id:function(vel){if(vel==null)return this.$.id;else this.$.id = vel;return this},//ID
	t:function(t){if(t==null)return this.$.innerHTML;else this.$.innerHTML = t;return this},//HTML
	v:function(vel){if(vel==null)return this.$.value;else this.$.value = vel;return this},//Value
	a:function(n,v){if(v==null)return this.$.getAttribute(n);else this.$.setAttribute(n,v);return this},//Attribute
	ae:function(n,v){if(v==null)return eval('this.$.'+n);else eval('this.$.'+n+'='+v);return this},//Attribute EVAL
	p:function(){return new _.fn.init( this.$.parentNode )}, // Parent node
	tn:function(n){return this.$.getElementsByTagName(n)}, // Get Element by TagName
	c_af:function(el){this.$.insertBefore(el,this.$.firstChild)}, // Insert control at 0
	init:function(id){this._$=id;if(typeof id == "string")this.$ = document.getElementById(id); else this.$ = id} // constructor
}
_.fn.init.prototype = _.fn;

/*ajax*/
_.ajaxObj = null;
_.ajaxQueue = new Array();
_.get = function(url,func,f) {
    if(!f) _.ajaxQueue.push({u:url,f:func});
    if(_.ajaxObj!=null && !f)return;
    if (window.XMLHttpRequest){_.ajaxObj = new XMLHttpRequest()} else if (window.ActiveXObject) {_.ajaxObj = new ActiveXObject("Microsoft.XMLHTTP")}
    _.ajaxObj.onreadystatechange = _.got;
    _.ajaxObj.open("GET", url, true);
    _.ajaxObj.send(null);
}
_.got = function() {
  if (_.ajaxObj.readyState == 4) {
      if (_.ajaxObj.status == 200) {
	     if(_.ajaxQueue[0].f!=null)
		    _.ajaxQueue[0].f(_.ajaxObj.responseText)
      }
      _.ajaxQueue.splice(0, 1);
      if(_.ajaxQueue.length>0){
	    _.get(_.ajaxQueue[0].u,_.ajaxQueue[0].f,true);
      }else{
	    _.ajaxObj = null
      }
  }
}
/*--end ajax*/
_.url = function(u){window.location.href = u}

function foreach(arr, f){
    for(var _i=0;_i<arr.length;_i++)
        f(arr[_i])
}

// Core End
window.location.querystring = (function() {   
    var result = {};   
    var querystring = window.location.search;   
    if (!querystring)   
        return result;   
    var pairs = querystring.substring(1).split("&");   
    var splitPair;   
    for (var i = 0; i < pairs.length; i++) {   
        splitPair = pairs[i].split("=");   
        result[splitPair[0]] = splitPair[1];
    }   
    return result;   
})(); 

_.qs = function(name){
    var val = window.location.querystring[name];
    if(val==null||val=='')
        val = '0';
    var filter = /^\d*$/i
    if(!filter.test(val))
        val = '0';
    return eval(val)
}
_.qsStr = function(name){
	var val = window.location.querystring[name];
    if(val==null||val=='')
        return '';
    else
		return decodeURI(val.replace(/\+/g,"%20"));
}

_.wnd = function(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen,left,top) {
	var int_windowLeft = (left==null)?(screen.width - a_int_windowWidth) / 2:left;
	var int_windowTop = (top==null)?(screen.height - a_int_windowHeight) / 2:top;
	var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=no,menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
	var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
	if (parseInt(navigator.appVersion) >= 4) {
		obj_window.window.focus();
	}
	return false;
}
function fotoPopUp(e){return _.wnd(e.href, 'photo_popup', 987, 707, 1, 0, 0, 0, 0, 1, 0)}
function videoPopUp(e){return _.wnd(e.href, 'video_popup', 805, 610, 1, 0, 0, 0, 0, 1, 0)}

var _astro = {
    over:function(e){
        var p = _(e).p()
        while(p.$.tagName.toUpperCase()!='TABLE'){
            p = p.p()
        }
        _(_(p.tn('td')[1]).tn('a')[0]).c('astrotd2')
    },
    out:function(e){
        var p = _(e).p()
        while(p.$.tagName.toUpperCase()!='TABLE'){
            p = p.p()
        }
        _(_(p.tn('td')[1]).tn('a')[0]).c('astrotd')
    }
}
var _pil = {
    cur:1,
    over:function(i){
        _('pil'+_pil.cur).h()
        _pil.cur=i
        _('pil'+i).s()
        _(_('pilH1').tn('h1')[0]).t(_('pilA'+i).t())
    }
}
/*** All Projects ***/
var _svs = {
	show:function(){
		_('svs').h()
		_('svs2').s()
		_('svsList').s2()
	},
	hide:function(e){
		if(_('svs').$==null) return;
		
		if(_('svs').isS())
			return;
		e = e || event;
		var t = e.target || e.srcElement;
		while(t!=null){
			if(t.id=="svsList")
				return;
			t=t.parentNode
		}
		_('svs').s()
		_('svs2').h()
		_('svsList').h()
	}
}
document.onclick = _svs.hide;
// All Projects 

/*** Search ***/
var _sch = {
	select:function(e){
		if(_(e).c()=='sel')
			return;
		if(_(e).id()=='_ssite'){
			_(e).c('sel')
			_('_sweb').c('')
		}else{
			_(e).c('sel')
			_('_ssite').c('')
		}
	},
	click:function(){
		var svalue = escape(_('_stxt').v())
		if(_('_ssite').c()=='sel')
			_.url('/search.htm?text='+svalue);
		else
			window.open('http://search.oboz.ua/search.aspx?k='+svalue, '_blank');
	}
}
// Search


/* Comment */
var _host = '/';
function InitCommment(){
	var r = 0; while(r < 0.1){r = Math.random()} 
	var d = Math.floor(r*100000000)
	document.write("<input type='hidden' name='d' value='"+d+"' />");
	document.write("<img src='"+_host+"handler/ch.ashx?d="+d+"' style='float:left;margin-right:5px' />");
	_('author').v(_.qsStr('auth'));
	_('text').v(_.qsStr('text'));
}
function trim(string){return string.replace(/(^\s+)|(\s+$)/g, "")}
function validate(){
	_('errorAuth').h();_('errorText').h();_('errorCode').h();
	if(trim(_('author').v()).length==0) {_('errorAuth').s(); return false}
	if(trim(_('text').v()).length==0) {_('errorText').s(); return false}
	_('addComment').$.submit();
	return false;
}
function comentParent(id,e,page){
	if(id == _('parent').v() && !page){
		var ac = _('addComment');
		if(ac.isS()) ac.h(); else ac.s();
		if(id==0) _('btnCom').c(_('btnCom').c()=='opn'?'cls':'opn');
		return false
	}
	if(_('parent').v()==0)_('btnCom').c('cls');
	_('parent').v(id);
	if(id==0)_('btnCom').c('opn')
	if(!page)_('addComment').s();
	var tmp = _("addComment").$;
	_("addComment").$.parentNode.removeChild(_("addComment").$);
	e.parentNode.parentNode.appendChild(tmp);
	return false;
}
var curP = 1;
function rate(id,b){_.get(_host+'handler/rateComment.ashx?nid='+_('nid').v()+'&cid='+id+'&p='+curP+(b?'&positive=1':''),rateEnd)}
function rateEnd(d){eval('var i = '+d);_('t'+i.id).t(i.t);_('p'+i.id).t(i.p);_('n'+i.id).t(i.n)}
function commPage(p){
	curP = p;
	var url = _host+'news/'+_('nid').v()+'/comments'+((p==1)?('.htm'):('/'+p+'.htm'))
	_.get(url,commPageEnd); 
	_.url("#comment")
}
function commPageEnd(d){comentParent(0, _('btnCom').$,true);_('addComment').h();_('comBody').t(d)}