/* Common */
/*
function $(id) {
    return document.getElementById(id);
}
*/
function show(el) {
    el.style.display = '';
}

function hide(el) {
    el.style.display = 'none';
}

function visible(el) {
    return el.style.display == 'none' ? false : true;
}

/*  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 ) {
    if (confirm('Вы уверенны, что хотите сообщить администрации сайта о том, что пользователь нарушает Правила комментирования и размещения контента?'))
    {
        new ajax("/exec/complain.php", {postBody: "table_id=" + table_id + "&item_id=" + comment_itemID + "&tablename=" + comment_tablename, 
            onComplete: 
                function (res) { 
                    alert('Спасибо за сотрудничество! Сообщение о нарушении было отправлено и будет рассмотрено администрацией в ближайшее время!');
                    document.getElementById('complain_send').style.display = 'none';
                } 
            });
    }
    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){

    String.prototype.cut = function()
                                    {
                                        return this.substring(0, this.lastIndexOf(" "));
                                    };

    if (!height) height = 160;

    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;
        }
    }
}

function Enlarge_height(elem,h) {

	div = _(elem);

	if (div && h) {
		div.setAttribute('style', "height: " + h + "px;");
		if (document.all) 
			document.all[elem].style.height = h;
	
	}

}


function h_n_left() {
	if( count_news != 0 )  {
		_('all_news_'+ cur_news).style.display = 'none';
		cur_news = cur_news - 1;
		if (cur_news <= 0) 
			cur_news = count_news;			

		_(name_div+ cur_news).style.display = 'block';  

		truncate_text( 'newsDayBottom_'+cur_news, 'h_n_header_'+cur_news);
	}

	return false;
}

function h_n_right() {

	if( count_news != 0 )  {
		_('all_news_'+ cur_news).style.display = 'none';
		cur_news = cur_news + 1;

		if (cur_news > count_news) 
			cur_news = 1;			

		_(name_div + cur_news).style.display = 'block';  

		truncate_text( 'newsDayBottom_'+cur_news, 'h_n_header_'+cur_news);

	}
	return false;
}

function truncate_table( div_id, table_id, height ) {
	
	if (!height) height = 0;

    var div         = _(div_id);
    var t         = _(table_id);
    var div_height  = getClientHeight(div_id) + height;

    var table_height = getClientHeight(table_id);

    if (parseInt(t.getElementsByTagName('tr').length) != 0 )
    {
        while (table_height > div_height)
        {
            var ddos = parseInt(t.getElementsByTagName('tr').length) - 1;

            if (ddos > 0 )
            { 
               t.rows[ddos].parentNode.removeChild(t.rows[ddos]);
              
                div_height  = getClientHeight(div_id) + height;
                table_height = getClientHeight(table_id);
            }
        }
    }
}


ffvinc.counter = 0;
ffvinc.classNames = new Array('1.2', '1.4');

function ffvinc($)
{
	 _('article').style.fontSize = (function(){
		return function ()
		{
			if ($ == "+")
			{
				ffvinc.counter++
				if ( ffvinc.counter < ffvinc.classNames.length)
				{
					_("fav").className = "vmid curr";
					_("minus").className = "vmid";
					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").className = "vmid";
					_("minus").className = "vmid curr";
					ffvinc.counter = 0;
					return ffvinc.classNames[ffvinc.counter]
				}
			}
		}();
	})() + "em";
}

