/*  Cookes */ 
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; domain=."+domain+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
/* end Cookes */ 

/* CANSEL BUBLe */
function stopB(e){
    if(!e)e=window.event;
    e.cancelBubble=true;
}

function send(id) {
    new ajax("/send/", {postBody: "a=" + id, onComplete: function (res) {} });
    return false;
}

function sendComplain( table_id, usernick ) {
	if(confirm('Вы уверенны, что хотите сообщить администрации сайта о том, что пользователь "' + usernick + '" нарушает Правила комментирования и размещения контента?')){new ajax("/exec/complain.php", {postBody: "table_id=" + table_id + "&item_id=" + comment_itemID + "&tablename=" + comment_tablename, onComplete: function (res) {_('complain_link_'+table_id).style.display='none';_('complain_margin_'+table_id).style.display='none';alert('Спасибо за сотрудничество!'+"\n"+'Сообщение о нарушении было отправлено и будет рассмотрено администрацией в ближайшее время');}});}
    return false;
}

function _(e) {
    return document.getElementById(e) ? document.getElementById(e) : false;
}

function getClientHeight(block_id) { return _(block_id).clientHeight; }

function truncate_ul_block( div_id, ul_id, height ) {

    if (!height) height = 0;

    var ul         = _(div_id);
    var ul_height  = getClientHeight(div_id) + height;

    var div_height = getClientHeight(ul_id);

    if (parseInt(ul.getElementsByTagName('li').length) != 0 )
    {
        while (ul_height > div_height)
        {
            var ddos = parseInt(ul.getElementsByTagName('li').length) - 1;

            if (ddos > 0 )
            {
                _(div_id).removeChild(_(div_id).getElementsByTagName('li')[ddos]);
                ul_height  = getClientHeight(div_id) + height;
                div_height = getClientHeight(ul_id);
            }
        }
    }
}

function truncate_text(h_title, h_news, height, detail_id){

    String.prototype.cut = function()
                                    {
                                        return this.substring(0, this.lastIndexOf(" "));
                                    };

    if (!height) height = 125;

    title = getClientHeight(h_title);
    news  = getClientHeight(h_news);
    str   = _(h_news).innerHTML;

    while( (title + news) > height )
    {
        str = str.cut();
        _(h_news).innerHTML = str + "...";
        title = getClientHeight(h_title);
        news  = getClientHeight(h_news);

        if (str.length == 0)
        { 
            str = "";
            _(h_news).innerHTML = str;
            break;
        }
    }
    
    if(_(detail_id))
        _(h_news).innerHTML = _(h_news).innerHTML + ' ' + _(detail_id).innerHTML;
    
}

ffvinc.counter = 0;
ffvinc.classNames = new Array('1.2', '1.4');

function ffvinc($)
{
	 _('0097f').style.fontSize = (function(){
		return function ()
		{
			if ($ == "+")
			{
				ffvinc.counter++
				if ( ffvinc.counter < ffvinc.classNames.length)
				{
					_("fav").src = "http://k.img.com.ua/static/img/korr-plus-na.gif";
					_("minus").src = "http://k.img.com.ua/static/img/korr-minus.gif";
					return ffvinc.classNames[ffvinc.counter]
				}
				else
				{
					ffvinc.counter = ffvinc.classNames.length - 1;
					return ffvinc.classNames[ffvinc.counter]
				}
			}
			
			if ($ == "-")
			{
				ffvinc.counter--
				if ( ffvinc.counter > 0 )
				{
					return ffvinc.classNames[ffvinc.counter]
				}
				else
				{
					_("fav").src = "http://k.img.com.ua/static/img/korr-plus.gif";
					_("minus").src = "http://k.img.com.ua/static/img/korr-minus-na.gif";
					ffvinc.counter = 0;
					return ffvinc.classNames[ffvinc.counter]
				}
			}
		}();
	})() + "em";
}

function switchTheme( id, docid, tabname, func, showText )
{
	var Aj = new XHConn();
    Aj.connect("/exec/micro/switchTheme.php","POST","id="+id+"&docid="+docid+"&tabname="+tabname+"&func="+func,function(res){if(res && res.responseText){if (showText) {_('switchThemeCount'+showText).innerHTML=res.responseText;}else{_('switchTheme'+id).innerHTML=res.responseText;} }});
}