/*
    проект l2top.ru компании © GDTeam, 2006-2008.
    разработчик crocodile
    //--------------------------------------------------------------------------
    библиотека JS функций для работы блогов l2top
*/

//инициируем аякс

ajax = new AJAXQueryC("/ajax/ajaxBlog.php", "");

//-----------------------------------------------------------------------------
    function blogVoteDec(id, i) {
        ajax.addCall('voteMark'+i, 'id='+id+'&act=dec', '');
        itm=document.getElementById('voteArrow'+i);
        itm.innerHTML = '';
        disable();
    }
//-----------------------------------------------------------------------------
    function blogVoteInc(id, i) {
        ajax.addCall('voteMark'+i, 'id='+id+'&act=inc', '');
        itm=document.getElementById('voteArrow'+i);
        itm.innerHTML = '';
        disable();
    }
//-----------------------------------------------------------------------------
	var
	    comentFlash = -1;
	    cat_id = 0;

	function crCom(id) {
	    if (comentFlash>-1)
	        document.getElementById('comment_'+comentFlash).innerHTML = '';
	    document.getElementById('comment_'+id).innerHTML = '<form action="/?top=blog" method="post">'+
	    '<input name="hidAct" type="hidden" value="topAns">'+
	    '<input name="com_id" type="hidden" value="'+id+'">'+
	    '<input name="cat_id" type="hidden" value="'+cat_id+'">'+
	    '<textarea name="text" rows=3 cols=1></textarea>'+
	    '<br>&nbsp;<button type="submit">Отправить</button>'+
	'</form>';
	    comentFlash = id;
	}
//-----------------------------------------------------------------------------
    function eSCom(id) {
        text = document.getElementById('commentText'+id).innerHTML;
        while(text.indexOf('<BR>')>0)
            text = text.replace('<BR>','');
        while(text.indexOf('<br>')>0)
            text = text.replace('<br>','');
        //text = BBEsc(text);
        itm = document.getElementById('comment'+id);
        itm.innerHTML = '<div align=center><form action="/?top=blog" method="post">'
                        +'<input name="hidAct" type="hidden" value="editComment">'
                        +'<input name="id" type="hidden" value="'+id+'">'
                        +'<textarea name="text" rows=8 cols=90 style="width: 90%;">'+text
                        +'</textarea><br><button  type="submit" style="margin: 2px; width: 100px;">применить</button></form></div>';
    }
//-----------------------------------------------------------------------------
function disable() {
        if (document.getElementById('makeVote') != null) {
	        v = document.getElementById('makeVote').innerHTML;
	        if (v>1) {
	            document.getElementById('makeVote').innerHTML = v-1;
	            return;
	        }
            document.getElementById('makeVote').innerHTML = v-1;
        } else {
            return;
        }
     /*   for (i=1; i<15; i++) {
            itm=document.getElementById('commVoteButton'+i+'r');
            if (itm==null) {
                return false;
            }
            itm.innerHTML = '<img src="images/voteUD.gif" alt="Up" border="0">';
            itm.style.color = '#bbb';
            itm=document.getElementById('commVoteButton'+i+'l');
            itm.innerHTML = '<img src="images/voteDD.gif" alt="Down" border="0">';
            itm.style.color = '#bbb';
        }  */
    }
//-----------------------------------------------------------------------------
    function BBC(itm, code) {
        //прямая вставка бб кода
        insertTag(code, itm);
    }
//-----------------------------------------------------------------------------
    function BBCAddUrl(itm) {
        //вставка бб кода урл
        var url = prompt( "Введите полный url адрес", "http://");
        if (url==null || url=='') {            alert("Вы не указали адрес!");            return;
        }
        var desc = prompt( "Введите описание", "Описание");
        if (desc==null || desc=='') {
            alert("Вы не указали описание!");            return;
        }
        code = "[link url='"+url+"']"+desc+"[/link]";
        insertTag(code, itm);    }
//-----------------------------------------------------------------------------
    function BBCAddUser(itm) {    	//вставка бб кода ник
        var name = prompt( "Введите имя пользователя", "");
        if (name==null || name=='') {
            alert("Вы не указали имени!");
            return;
        }
        code = "[l2topuser name='"+name+"']"
        insertTag(code, itm);
    }
//-----------------------------------------------------------------------------
    function BBCAddCut(itm) {
    	//вставка бб кода cut
        var text = prompt( "Введите имя метки", "");
        if (text==null) {
            return;
        }
        code = "[l2topcut text='"+text+"']"
        insertTag(code, itm);
    }
//-----------------------------------------------------------------------------

    function SVProc(t, itm, id, scr) {        //функция оценивания комментариев блога
        //отменяем цвета у заменяемых кнопок
        if (itm.id=="SVM1_"+id || itm.id=="SVM2_"+id || itm.id=="SVM3_"+id || itm.id=="SVM4_"+id) {
            document.getElementById("SVM1_"+id).className = "NA";
            document.getElementById("SVM2_"+id).className = "NA";
            document.getElementById("SVM3_"+id).className = "NA";
            document.getElementById("SVM4_"+id).className = "NA";
        } else if (itm.id=="SVM6_"+id || itm.id=="SVM7_"+id) {            document.getElementById("SVM7_"+id).className = "NA";
            document.getElementById("SVM6_"+id).className = "NA";        }
        //перекрашиваем цвет данной кнопки
        itm.className = 'sellect';
        ajax.addCall(scr+id, 'id='+id+'&act='+t, '');
    }
//-----------------------------------------------------------------------------

