/*==============================================================================
     FAQ 1.0 / by Inferno.13 / E-mail: inferno.13@mail.ru / ICQ: 390-582-196
==============================================================================*/
var n_cache=[],c_cache=[],comm_edit_id,s_id,e_id;

function RunAjaxJS(a,b){var c=new Date,d=false;c=c.getTime();var e=/<script.*?>(.|[\r\n])*?<\/script>/ig,f=e.exec(b);if(f!=null){var g=Array(f.shift());for(d=true;f;){f=e.exec(b);f!=null&&g.push(f.shift())}for(e=0;e<g.length;e++)b=b.replace(g[e],'<span id="'+c+e+'" style="display:none;"></span>')}$("#"+a).html(b);if(d){d=/<script.*?>((.|[\r\n])*?)<\/script>/ig;for(e=0;e<g.length;e++){var h=document.getElementById(c+""+e);f=h.parentNode;f.removeChild(h);d.lastIndex=0;h=d.exec(g[e]);f=f.appendChild(document.createElement("script"));
f.text=h[1];h=g[e].substring(g[e].indexOf(" ",0),g[e].indexOf(">",0)).split(" ");if(h.length>1)for(var j=0;j<h.length;j++)if(h[j].length>0){var i=h[j].split("=");i[1]=i[1].substr(1,i[1].length-2);f.setAttribute(i[0],i[1])}}}}

function ShowLoading(a){a&&$("#loading-layer-text").html(a);a=($(window).width()-$("#loading-layer").width())/2;var b=($(window).height()-$("#loading-layer").height())/2;$("#loading-layer").css({left:a+"px",top:b+"px",position:"fixed",zIndex:"99"});$("#loading-layer").fadeTo("slow",0.6)}function HideLoading(){$("#loading-layer").fadeOut("slow")}

function ShowProfile_faq_13(a,b){if(dle_user_profile==a&&document.getElementById("dleprofilepopup")){$("#dleprofilepopup").dialog("open");return false}dle_user_profile=a;dle_user_profile_link=b;ShowLoading("");$.get(dle_root+"engine/ajax/profile.php",{name:a,skin:dle_skin},function(c){HideLoading("");ShowPopupProfile(c)});return false}

function dropdownmenu_faq_13(a,b,c,d){if(window.event)event.cancelBubble=true;else b.stopPropagation&&b.stopPropagation();b=$("#dropmenudiv");if(b.is(":visible")){clearhidemenu();b.fadeOut("fast");return false}b.remove();$("body").append('<div id="dropmenudiv" style="display:none;position:absolute;z-index:100;width:165px;"></div>');b=$("#dropmenudiv");b.html(c.join(""));d&&b.width(d);c=$(document).width()-15;d=$(a).offset();if(c-d.left<b.width())d.left-=b.width()-a.offsetWidth;b.css({left:d.left+"px",top:d.top+
a.offsetHeight+"px"});b.fadeTo("fast",0.9);b.mouseenter(function(){clearhidemenu()}).mouseleave(function(){delayhidemenu()});$(document).one("click",function(){hidemenu()});return false}

function doFavorites_faq_13(a,b){ShowLoading("");$.get(dle_root+"engine/ajax/favorites.php",{fav_id:a,action:b,skin:dle_skin},function(c){HideLoading("");$("#fav-id-"+a).html(c)});return false}

function ShowBild_faq_13(a){window.open(dle_root+"engine/modules/imagepreview.php?image="+a,"","resizable=1,HEIGHT=200,WIDTH=200, top=0, left=0, scrollbars=yes")}

function ajax_cancel_comm_edit_faq_13(a){n_cache[a]!=""&&$("#comm-id-"+a).html(c_cache[a]);return false}function ajax_save_comm_edit(a,b){var c="";comm_edit_id=a;c=dle_wysiwyg=="yes"?$("#dleeditcomments"+a).html():$("#dleeditcomments"+a).val();ShowLoading("");$.post(dle_root+"engine/ajax/editcomments.php",{id:a,comm_txt:c,area:b,action:"save"},function(d){HideLoading("");c_cache[comm_edit_id]="";$("#comm-id-"+a).html(d)});return false}

function MenuNewsBuild_faq_13(a,b)
    {
      var c=[];
      if(dle_admin!="")
        {
          c[0]="<a onclick=\"ajax_prep_for_edit('"+a+"', '"+b+'\'); return false;" href="#">'+menu_short+"</a>";
          c[1]="<a onclick=\"dle_news_delete ('"+a+'\'); return false;" href="#">'+dle_del_news+"</a>";
        }
      return c;
    }

function MenuCommBuild_faq_13(a,b,n)
    {
        var c=[];
        c[0]="<a onclick=\"ajax_comm_edit_faq_13('"+a+"', '"+b+'\', \''+n+'\'); return false;" href="#">'+menu_short+"</a>";
        return c;
    }

function ajax_comm_edit_faq_13(a,b,n)
    {
        if(!c_cache[a]||c_cache[a]=="")
        c_cache[a]=$("#comm-id-"+a).html();
        ShowLoading("");
        $.get(dle_root+"engine/ajax/faq_editcomments.php",{
            news_id:n,
            id:a,
            area:b,
            action:"edit"},
        function(c){
          document.getElementById("dropmenudiv").style.display = "none";          
          HideLoading("");
          RunAjaxJS("comm-id-"+a,c);
          setTimeout(function(){
                $("html:not(:animated)"+(!$.browser.opera?",body:not(:animated)":"")).animate({scrollTop:$("#comm-id-"+a).position().top-70},700)},100)});
        return false;
    }

function ajax_save_comm_edit_faq_13(a,b,n)
    {
        var c="";
        comm_edit_id=a;
        c=dle_wysiwyg=="yes"?$("#dleeditcomments"+a).html():$("#dleeditcomments"+a).val();
        ShowLoading("");$.post(dle_root+"engine/ajax/faq_editcomments.php",{
          news_id:n,
          id:a,
          comm_txt:c,
          area:b,
          action:"save"},
        function(d){HideLoading("");
        c_cache[comm_edit_id]="";
        $("#comm-id-"+a).html(d)});
        return false;
    }

function dle_ins_faq_13(a,n)
    {
        if(!document.getElementById("dlecommentsform"+n))return false;
        var b=document.getElementById("dlecommentsform"+n).comments,c="";
        if(dle_wysiwyg=="no")b.value+=dle_txt!=""?dle_txt:"[b]"+a+"[/b],\n";
        else{c=dle_txt!=""?dle_txt:"<b>"+a+"</b>,<br />";
        tinyMCE.execInstanceCommand("comments"+n,"mceInsertContent",false,c,true)}}

function doAddComments_faq_13(n)
    {
        var a=document.getElementById("dlecommentsform"+n);

        if(dle_wysiwyg=="yes")
            {
                document.getElementById("comments"+n).value=$("#comments"+n).html();
                var b="wysiwyg";
            }
        else b="";

        if(document.getElementById("name-"+n)) name = document.getElementById("name-"+n).value; else name = "name";
        if(document.getElementById("mail-"+n)) mail = document.getElementById("mail-"+n).value; else name = "mail";

        if(document.getElementById("comments"+n)) comm = document.getElementById("comments"+n).value; else comm = "";

        if(comm==""||name=="")
            {
                DLEalert(dle_req_field,dle_info);
                return false;
            }

        var c=document.getElementById("sec_code-"+n)?document.getElementById("sec_code-"+n).value:"";

        if(a.recaptcha_response_field) var d=Recaptcha.get_response(),e=Recaptcha.get_challenge();
        else e=d="";

        var f=document.getElementById("allow_subscribe"+n)?document.getElementById("allow_subscribe"+n).checked==true?"1":"0":"0";
        ShowLoading("");
        $.post(dle_root+"engine/ajax/faq_addcomments.php",{
            post_id:a.post_id.value,
            comments:comm,
            name:name,
            mail:mail,
            editor_mode:b,
            skin:dle_skin,
            sec_code:c,
            recaptcha_response_field:d,
            recaptcha_challenge_field:e,
            allow_subscribe:f},function(g){
              if(document.getElementById("sec_code-"+n)){
                document.getElementById("sec_code-"+n).value="";
                //reload(n);
                var rndval = new Date().getTime();
                document.getElementById('dle-captcha-'+n).innerHTML = '<img src="/engine/modules/antibot.php?rndval=' + rndval + '" border="0" width="120" height="50" alt="" /><br /><a onclick="reload_'+n+'('+n+'); return false;" href="#">обновить, если не виден код</a>';
              }
              HideLoading("");
              RunAjaxJS("dle-ajax-comments-"+n,g);
              if(g!="error"&&document.getElementById("blind-animation-"+n)){
                $("html"+(!$.browser.opera?",body":"")).animate({scrollTop:$("#dle-ajax-comments-"+n).position().top-70},1100);
                setTimeout(function(){$("#blind-animation-"+n).show("blind",{},1500)},1100)}});
}

function insert_list(a){DLEprompt(text_enter_list,a,dle_prompt,function(b){if(b!=""){listitems+="[*]"+b+"\n";insert_list("")}else if(listitems){doInsert(list_open_tag+listitems+list_close_tag,"",false);ie_range_cache=null}},true)}
