function abl_c(el){
	var el=el.parentNode.childNodes[1];
	if (el.style.display=='block'){el.style.display='none';}else el.style.display='block';
}

function doload_2(object,element,path,ection_start,ection_end)
{        if (ection_start){eval(ection_start);}
         var req = new JsHttpRequest();
         req.onreadystatechange = function() {
            if (req.readyState == 4) {   
                //debugger;  
                //alert(req.responseText);
                //alert(req.responseJS);
                 if (element!== undefined){if (document.getElementById(element) && req.responseText) {document.getElementById(element).innerHTML = req.responseText;}}
                 if (req.responseJS){eval(req.responseJS);}
                 
                 var temp=typeof(ection_end);
                 if (typeof(ection_end)=="string"){eval(ection_end);}
                 if (typeof(ection_end)=="function"){ection_end();}
            }
        }
        req.open(null, path, true);
        req.send(object);
}

function check_email(email){
  var Reg_str = new RegExp("^[0-9a-z_-]([.]?[0-9a-z_-])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$","ig");
  if (Reg_str.test(email)) return true; else {return false;}
}


   function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;

    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
 
function Submit(ev, fn){if (ev.keyCode==13){fn();}}

function check_all(name_records,val){
   var List=document.getElementsByName(name_records);
    for (var i = 0; i < List.length; i++) {
        List[i].checked=val;
    }
}

function js_show_blok(s,h) {
    ss = document.getElementById(s).style;
    hh = document.getElementById(h).style;
    if (ss.display != 'none' ) {
        ss.display = 'none';
        hh.display = 'inline';
    } else if ( ss.display == 'none' ) {
        ss.display = 'inline';
        hh.display = 'none';
    }
    return false;
}

function center(text)
{  //if (!text){text="Подождите, идет обработка данных";}
   var main=this.document.body;
   var div_1=document.createElement('div');
   div_1.id='wait_fon';
   div_1.className='fon';
   div_1.style.height=main.scrollHeight;
   main.appendChild(div_1);
                             
   var div=document.createElement('div');
   div.id='wait_div';
   div.className='cd';
   div.innerHTML=text;
   div_1.appendChild(div);
   var img_p=parseInt(div.offsetWidth)/2-16;
   div.style.marginLeft=-img_p;

   var img=document.createElement('img');
}
 function restrictions_symbol(max, id_txt, id_counter){
     var txt=document.getElementById(id_txt);
     var counter=document.getElementById(id_counter);
     var kol=txt.value.length;
     counter.innerHTML=max-kol;
     counter.innerHTML=max-kol-1;
     if (counter.innerHTML<0) counter.innerHTML=0;
     if (kol>=(max-1))
     {counter.innerHTML>=max;
     txt.value=txt.value.substring(0,max-1);
     }
}

function check_capcha(str){
    doload_2({'act':'check_capcha','str':str},'capcha_er','/inc/ajax_response.php5','wait()','stop_wait();');
}
/////////////////// Функции авторизации при наличии модуля "users" ///////////////////////////////////////

 
$(document).ready(function() {
        //$("#loginform").hide();   
        $("#loginform > span.close").click(function(e){
            $("#loginform").fadeOut(); //stop_wait();           
        });
        
        $("#authorize").click(function(e){
            login_form();
        });
        
        $("div.lock > span.submit").click(function(e){
          //  wait();
            $("#loginform").show();
              
        });
        
        $("#signin_submit").click(function(e){
            $("#loging_report").html('<center><img alt="Подождите" src="/images/sys/load.gif"></center>'); 
            loging();             
        });


    $("form#signin").submit(function() {
      return false;
    });
    
    $("input.cancel_submit").click(function(e) {
            $("#loginform").fadeOut(); 
            stop_wait();
    });
    
    $("#resend_password_link").click(function(e) {
            remind_form();
    });             
});
//setTimeout(fn(), sec);
function loging(){
   doload_2({'action':'loging','login':document.getElementById('user_login').value,'pas':document.getElementById('user_pas').value},'loging_report','/inc/modules/user/user_response.php5');
}
function logout(){
   doload_2({'action':'logout'},'','/inc/modules/user/user_response.php5','wait()','stop_wait();');  
   window.location = "/?logoff=1";
}
function remind_form(){
    $("#remind").css("display", "block");
    $("#signin_menu").css("display", "none");   
    $("#loginform > h2").text('Восстановление пароля');
}
function login_form(){
    $("#remind").css("display", "none");
    $("#signin_menu").css("display", "block");   
    $("#loginform > h2").text('Авторизация пользователя');
}

function remind(login){ 
    if(check_email(login)){
        doload_2({'action':'remind','login':login},'remind_report','/inc/modules/user/user_response.php5');
    }else {$("#remind_report").text('Ненерный формат e-mail');}
}

//  m_alert //
function m_alert(title,text){$("body").append('<div class="wait"><p align="center">'+text+'</p></div>');$(".wait").dialog({position:["center","center"],modal:true,title:title,buttons:{"Продолжить":function(){$(this).dialog("close");}}});}

//  wait   //   
function wait(text)
//{$("body").append('<div class="wait"><p align="center">Выполняется обработка данных<br><br><img src="/images/sys/load.gif"></p></div>');$(".wait").dialog({position:["center","center"],modal:true,title:'Подождите, пожалуйста',close:function(event,ui){$(".wait").remove();}});}
{$("body").append('<div class="wait"><p align="center">'+(text?text:'Выполняется обработка данных')+'<br><br><img src="/images/sys/load.gif"></p></div>');$(".wait").dialog({position:["center","center"],modal:true,title:'Подождите, пожалуйста',close:function(event,ui){$(".wait").remove();}});}

//  stop_wait   //
function stop_wait(){$(".wait").dialog('destroy');$(".wait").remove();}

//  addEvent    //
function addEvent(obj,name,func){if(obj.addEventListener){obj.addEventListener(name,func,false);}
else if(obj.attachEvent){obj.attachEvent('on'+name,func);}
else{throw'Error'};}

//  removeEvent    //
function removeEvent(obj,name,func){if(obj.removeEventListener){obj.removeEventListener(name,func,false);}
else if(obj.detachEvent){obj.detachEvent('on'+name,func);}
else{throw'Error'};}

//  NewBookmarks    //
function NewBookmarks(){this.domain=location.href+'/';this.domain=this.domain.substr(this.domain.indexOf('://')+3);this.domain=this.domain.substr(0,this.domain.indexOf('/'));this.location=false;this.div='';this.selection=function(){var sel;if(window.getSelection)sel=window.getSelection();else if(document.selection)sel=document.selection.createRange();else sel='';if(sel.text)sel=sel.text;return encodeURIComponent(sel);}
this.url=function(system){var title=encodeURIComponent(document.title);var url=encodeURIComponent(location.href);switch(system){case 1:return'http://memori.ru/link/?sm=1&u_data[url]='+url+'&u_data[name]='+title;case 2:return'http://bobrdobr.ru/addext.html?url='+url+'&title='+title;case 3:return'http://www.google.com/bookmarks/mark?op=add&bkmk='+url+'&title='+title;case 4:return'http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&lurl='+url+'&lname='+title;case 5:return'http://twitter.com/home?status='+title+' '+url;case 6:return'http://del.icio.us/post?v=4&noui&jump=close&url='+url+'&title='+title;case 7:return'http://text20.ru/add/?source='+url+'&title='+title+'&text='+this.selection();case 8:return'http://news2.ru/add_story.php?url='+url;case 9:return'http://www.mister-wong.ru/index.php?action=addurl&bm_url='+url+'&bm_description='+title;case 10:return'http://moemesto.ru/post.php?url='+url+'&title='+title;case 11:return'http://smi2.ru/add/?url='+url+'&precaption='+title;case 12:return'http://www.vaau.ru/submit/?action=step2&url='+url;case 13:return'http://myscoop.ru/add/?URL='+url+'&title='+title;case 14:return'http://www.linkstore.ru/servlet/LinkStore?a=add&url='+url+'&title='+title;case 15:return'http://www.ruspace.ru/index.php?link=bookmark&action=bookmarkNew&bm=1&url='+url+'&title='+title;case 16:return'http://www.100zakladok.ru/save/?bmurl='+url+'&bmtitle='+title;}}
this.show=function(element){if(this.timeout)clearTimeout(this.timeout);var left=0,top=0;var style=this.div.style;while(element){left+=element.offsetLeft;top+=element.offsetTop;element=element.offsetParent;}
style.left=left+'px';style.top=top+'px';style.visibility='visible';}
this.init=function(){var titles=new Array('Memori','БобрДобр','Закладки Google','Яндекс.Закладки','Twitter','del.icio.us','Текст 2.0','News2','Мистер Вонг','МоёМесто','СМИ 2','Ваау!','AddScoop','LinkStore','RuSpace','Сто Закладок');var div=document.createElement('div');div.className='Bookmarks';html='<b style="display:block;float:left;width:258px;height:20px;overflow:hidden;margin:0px 0;padding:3;background-color:transparent;font:bold 11px arial;color:#666;text-decoration:none"></b>';for(var i=0;i<16;i++){html+='<a href="'+this.url(i+1)+'" style="display:block;float:left;width:108px;height:16px;overflow:hidden;margin:1px 0;padding:0 0 0 24px;background-color:transparent;background:url(/images/sys/bookmarks_panel.png) no-repeat -266px '+(-i*16)+'px;font:normal 12px arial;color:#666;text-decoration:none;text-align:left" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" onclick="return Bookmarks.go('+(i+1)+');">'+titles[i]+'</a>';}
addEvent(div,"mouseout",function(){div.style.visibility='hidden';});addEvent(div,"mouseover",function(){div.style.visibility='visible';});div.innerHTML=html;this.div=div;document.body.insertBefore(div,document.body.firstChild);document.write('<div class="bookmarks_button" onmouseover="Bookmarks.show(this);"></div>');}}
////////////////////////////////////////////////////
function send_comment(block,parent,u){
    if ($("#comment_text").attr('value').length=='0'){m_alert("Ошибка","Текст комментария не задан"); return false;}
    if($("#comment_subs").attr('checked')==true){var sub=1;}else{var sub=0;}                             
    var obj={'act':'comment_send','text':$("#comment_text").attr('value'),'block':block,'parent':parent,'subscription':sub}; 
    //debugger;
    if (u==0){
        if ($("#capcha").attr('status')!='Y'){m_alert("Ошибка","Значение Capcha не указано или указано не верно"); return false;}
        obj.user_name=$("#comment_name").attr('value');
        obj.user_mail=$("#comment_email").attr('value');
    } else {obj.user_id=u;}
    
    doload_2(obj,'report','/inc/ajax_response.php5'); 
}

function comment_form(b,p,o){
    $("#comment_container").remove(); 
    $("#"+o.parentNode.id).append('<div id="comment_container"></div>');
    doload_2({'act':'comment_form','block':b,'parent':p},'comment_container','/inc/ajax_response.php5','wait()','stop_wait();'); 
}

function comment_del(c){
    doload_2({'act':'comment_del','com':c},'report','/inc/ajax_response.php5','wait()'); 
}

$(document).ready(function(){$("div.cell").each( function(){$(this).find("div.block_title > a").attr('href', $(this).find("a.more").attr('href'));});});

