var style_cookie;var style_cookie_txt;var style_cookie_site;var kumod_set=false;var ispage;var is_entering=false;if(!Array.prototype.indexOf){
    Array.prototype.indexOf=function(B){
        var A=this.length;var C=Number(arguments[1])||0;C=(C<0)?Math.ceil(C):Math.floor(C);if(C<0){
            C+=A
            }for(;C<A;C++){
            if(C in this&&this[C]===B){
                return C
                }
            }return -1
        }
    }var Utf8={
    encode:function(B){
        B=B.replace(/\r\n/g,"\n");var A="";for(var D=0;D<B.length;D++){
            var C=B.charCodeAt(D);if(C<128){
                A+=String.fromCharCode(C)
                }else{
                if((C>127)&&(C<2048)){
                    A+=String.fromCharCode((C>>6)|192);A+=String.fromCharCode((C&63)|128)
                    }else{
                    A+=String.fromCharCode((C>>12)|224);A+=String.fromCharCode(((C>>6)&63)|128);A+=String.fromCharCode((C&63)|128)
                    }
                }
            }return A
        },
    decode:function(A){
        var B="";var C=0;var D=c1=c2=0;while(C<A.length){
            D=A.charCodeAt(C);if(D<128){
                B+=String.fromCharCode(D);C++
            }else{
                if((D>191)&&(D<224)){
                    c2=A.charCodeAt(C+1);B+=String.fromCharCode(((D&31)<<6)|(c2&63));C+=2
                    }else{
                    c2=A.charCodeAt(C+1);c3=A.charCodeAt(C+2);B+=String.fromCharCode(((D&15)<<12)|((c2&63)<<6)|(c3&63));C+=3
                    }
                }
            }return B
        }
    };function replaceAll(B,D,C){
    var A=B.indexOf(D);while(A>-1){
        B=B.replace(D,C);A=B.indexOf(D)
        }return B
    }function insert(D){
    var B=document.forms.postform.message;if(B){
        if(B.createTextRange&&B.caretPos){
            var C=B.caretPos;C.text=C.text.charAt(C.text.length-1)==" "?D+" ":D
            }else{
            if(B.setSelectionRange){
                var E=B.selectionStart;var A=B.selectionEnd;B.value=B.value.substr(0,E)+D+B.value.substr(A);B.setSelectionRange(E+D.length,E+D.length)
                }else{
                B.value+=D+" "
                }
            }B.focus()
        }
    }function quote(b,a){
    var v=eval("document."+a+".message");v.value+=">>"+b+"\n";v.focus()
    }function checkhighlight(){
    var A;if(A=/#i([0-9]+)/.exec(document.location.toString())){
        if(!document.forms.postform.message.value){
            insert(">>"+A[1])
            }
        }if(A=/#([0-9]+)/.exec(document.location.toString())){
        highlight(A[1])
        }
    }function highlight(D,F){
    if(F&&ispage){
        return
    }var B=document.getElementsByTagName("td");for(var C=0;C<B.length;C++){
        if(B[C].className=="highlight"){
            B[C].className="reply"
            }
        }var E=document.getElementById("reply"+D);if(E){
        E.className="highlight";var A=/^([^#]*)/.exec(document.location.toString());document.location=A[1]+"#"+D
        }
    }function get_password(A){
    var E=getCookie(A);if(E){
        return E
        }var D="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";var E="";for(var C=0;C<8;C++){
        var B=Math.floor(Math.random()*D.length);E+=D.substring(B,B+1)
        }set_cookie(A,E,365);return(E)
    }function togglePassword(){
    var C=(navigator.userAgent.indexOf("Safari")!=-1);var F=(navigator.userAgent.indexOf("Opera")!=-1);var B=(navigator.appName=="Netscape");var A=document.getElementById("passwordbox");var E;if((C)||(F)||(B)){
        E=A.innerHTML
        }else{
        E=A.text
        }E=E.toLowerCase();var D="<td></td><td></td>";if(E==D){
        var D="<td class=\"postblock\">Mod</td><td><input type=\"text\" name=\"modpassword\" size=\"28\" maxlength=\"75\">&nbsp;<acronym title=\"Distplay staff status (Mod/Admin)\">D</acronym>:&nbsp;<input type=\"checkbox\" name=\"displaystaffstatus\" checked>&nbsp;<acronym title=\"Lock\">L</acronym>:&nbsp;<input type=\"checkbox\" name=\"lockonpost\">&nbsp;&nbsp;<acronym title=\"Sticky\">S</acronym>:&nbsp;<input type=\"checkbox\" name=\"stickyonpost\">&nbsp;&nbsp;<acronym title=\"Raw HTML\">RH</acronym>:&nbsp;<input type=\"checkbox\" name=\"rawhtml\">&nbsp;&nbsp;<acronym title=\"Name\">N</acronym>:&nbsp;<input type=\"checkbox\" name=\"usestaffname\"></td>"
        }if((C)||(F)||(B)){
        A.innerHTML=D
        }else{
        A.text=D
        }return false
    }function toggleOptions(D,C,B){
    if(document.getElementById("opt"+D)){
        if(document.getElementById("opt"+D).style.display==""){
            document.getElementById("opt"+D).style.display="none";document.getElementById("opt"+D).innerHTML=""
            }else{
            var A="<td class=\"label\"><label for=\"formatting\">Formatting:</label></td><td colspan=\"3\"><select name=\"formatting\"><option value=\"\" onclick=\"javascript:document.getElementById('formattinginfo"+D+"').innerHTML = 'All formatting is performed by the user.';\">Normal</option><option value=\"aa\" onclick=\"javascript:document.getElementById('formattinginfo"+D+"').innerHTML = '[aa] and [/aa] will surround your message.';\"";if(getCookie("kuformatting")=="aa"){
                A+=" selected"
                }A+=">Text Art</option></select> <input type=\"checkbox\" name=\"rememberformatting\"><label for=\"rememberformatting\">Remember</label> <span id=\"formattinginfo"+D+"\">";if(getCookie("kuformatting")=="aa"){
                A+="[aa] and [/aa] will surround your message."
                }else{
                A+="All formatting is performed by the user."
                }A+="</span></td><td><input type=\"button\" value=\"Preview\" class=\"submit\" onclick=\"javascript:postpreview('preview"+D+"', '"+B+"', '"+D+"', document."+C+".message.value);\"></td>";document.getElementById("opt"+D).innerHTML=A;document.getElementById("opt"+D).style.display=""
            }
        }
    }function getCookie(name){
    with(document.cookie){
        var regexp=new RegExp("(^|;\\s+)"+name+"=(.*?)(;|$)");var hit=regexp.exec(document.cookie);if(hit&&hit.length>2){
            return Utf8.decode(unescape(replaceAll(hit[2],"+","%20")))
            }else{
            return""
            }
        }
        }function set_cookie(C,D,E){
    if(E){
        var B=new Date();B.setTime(B.getTime()+(E*24*60*60*1000));var A="; expires="+B.toGMTString()
        }else{
        A=""
        }document.cookie=C+"="+D+A+"; path=/"
    }function set_stylesheet(H,B,D){
    if(B){
        set_cookie("kustyle_txt",H,365)
        }else{
        if((D)||(!D)){
            set_cookie("kustyle_site",H,365);set_cookie("kustyle",H,365)
            }else{
            set_cookie("kustyle",H,365)
            }
        }var C=document.getElementsByTagName("link");var F=false;for(var E=0;E<C.length;E++){
        var A=C[E].getAttribute("rel");var G=C[E].getAttribute("title");if(A.indexOf("style")!=-1&&G){
            C[E].disabled=true;if(H==G){
                C[E].disabled=false;F=true
                }
            }
        }if(!F){
        set_preferred_stylesheet()
        }
    }function set_preferred_stylesheet(){
    var B=document.getElementsByTagName("link");for(var C=0;C<B.length;C++){
        var A=B[C].getAttribute("rel");var D=B[C].getAttribute("title");if(A.indexOf("style")!=-1&&D){
            B[C].disabled=(A.indexOf("alt")!=-1)
            }
        }
    }function get_active_stylesheet(){
    var B=document.getElementsByTagName("link");for(var C=0;C<B.length;C++){
        var A=B[C].getAttribute("rel");var D=B[C].getAttribute("title");if(A.indexOf("style")!=-1&&D&&!B[C].disabled){
            return D
            }
        }return null
    }function get_preferred_stylesheet(){
    var B=document.getElementsByTagName("link");for(var C=0;C<B.length;C++){
        var A=B[C].getAttribute("rel");var D=B[C].getAttribute("title");if(A.indexOf("style")!=-1&&A.indexOf("alt")==-1&&D){
            return D
            }
        }return null
    }function delandbanlinks(){
    if(!kumod_set){
        return
    }var B=document.getElementsByTagName("span");var E;var A;for(var C=0;C<B.length;C++){
        E=B[C];if(E.getAttribute("class")){
            if(E.getAttribute("class").substr(0,3)=="dnb"){
                A=E.getAttribute("class").split("|");var D="&#91;<a href=\""+ku_cgipath+"/manage_page.php?action=delposts&boarddir="+A[1]+"&del";if(A[3]=="y"){
                    D+="thread"
                    }else{
                    D+="post"
                    }D+="id="+A[2]+"\" title=\"Delete\" onclick=\"return confirm('Are you sure you want to delete this post/thread?');\">D</a>&nbsp;<a href=\""+ku_cgipath+"/manage_page.php?action=delposts&boarddir="+A[1]+"&del";if(A[3]=="y"){
                    D+="thread"
                    }else{
                    D+="post"
                    }D+="id="+A[2]+"&postid="+A[2]+"\" title=\"Delete &amp; Ban\" onclick=\"return confirm('Are you sure you want to delete and ban the poster of this post/thread?');\">&amp;</a>&nbsp;<a href=\""+ku_cgipath+"/manage_page.php?action=bans&banboard="+A[1]+"&banpost="+A[2]+"\" title=\"Ban\">B</a>&#93;";B[C].innerHTML=D
                }
            }
        }
    }function togglethread(A){
    if(hiddenthreads.toString().indexOf(A)!==-1){
        document.getElementById("unhidethread"+A).style.display="none";document.getElementById("thread"+A).style.display="block";hiddenthreads.splice(hiddenthreads.indexOf(A),1);set_cookie("hiddenthreads",hiddenthreads.join("!"),30)
        }else{
        document.getElementById("unhidethread"+A).style.display="block";document.getElementById("thread"+A).style.display="none";hiddenthreads.push(A);set_cookie("hiddenthreads",hiddenthreads.join("!"),30)
        }return false
    }function toggleblotter(C){
    var B=document.getElementsByTagName("li");var A=new Array();var D;for(i=0,iarr=0;i<B.length;i++){
        att=B[i].getAttribute("class");if(att=="blotterentry"){
            D=B[i];if(D.style.display=="none"){
                D.style.display="";if(C){
                    set_cookie("ku_showblotter","1",365)
                    }
                }else{
                D.style.display="none";if(C){
                    set_cookie("ku_showblotter","0",365)
                    }
                }
            }
        }
    }function expandthread(C,A){
    if(document.getElementById("replies"+C+A)){
        var B=document.getElementById("replies"+C+A);B.innerHTML="Разворачиваем тред...<br><br>"+B.innerHTML;new Ajax.Request(ku_boardspath+"/expand.php?board="+A+"&threadid="+C,{
            method:"get",
            onSuccess:function(E){
                var D=E.responseText||"наверно что-то случилось (пустой ответ)";B.innerHTML=D;delandbanlinks();addpreviewevents();
            },
            onFailure:function(){
                alert("Что-то сломалось...")
                }
            })
        }return false
    }function quickreply(A){
    if(A==0){
        document.getElementById("posttypeindicator").innerHTML="new thread"
        }else{
        document.getElementById("posttypeindicator").innerHTML="ответ на "+A+" [<a href=\"#postbox\" onclick=\"javascript:quickreply('0');\" title=\"Отмена\">x</a>]"
        }document.postform.replythread.value=A
    }function getwatchedthreads(C,B){
    if(document.getElementById("watchedthreadlist")){
        var A=document.getElementById("watchedthreadlist");A.innerHTML="Загрузка избранных тредов...";new Ajax.Request(ku_boardspath+"/threadwatch.php?board="+B+"&threadid="+C,{
            method:"get",
            onSuccess:function(E){
                var D=E.responseText||"наверно что-то случилось (пустой ответ)";A.innerHTML=D
                },
            onFailure:function(){
                alert("Что-то сломалось...")
                }
            })
        }
    }function addtowatchedthreads(B,A){
    if(document.getElementById("watchedthreadlist")){
        new Ajax.Request(ku_boardspath+"/threadwatch.php?do=addthread&board="+A+"&threadid="+B,{
            method:"get",
            onSuccess:function(D){
                var C=D.responseText||"наверно что-то случилось (пустой ответ)";alert("Тред добавлен в список избранных.");getwatchedthreads("0",A)
                },
            onFailure:function(){
                alert("Что-то сломалось...")
                }
            })
        }
    }function removefromwatchedthreads(B,A){
    if(document.getElementById("watchedthreadlist")){
        new Ajax.Request(ku_boardspath+"/threadwatch.php?do=removethread&board="+A+"&threadid="+B,{
            method:"get",
            onSuccess:function(D){
                var C=D.responseText||"наверно что-то случилось (пустой ответ)";getwatchedthreads("0",A)
                },
            onFailure:function(){
                alert("Что-то сломалось...")
                }
            })
        }
    }function hidewatchedthreads(){
    set_cookie("showwatchedthreads","0",30);if(document.getElementById("watchedthreads")){
        document.getElementById("watchedthreads").style.display="none"
        }
    }function showwatchedthreads(){
    set_cookie("showwatchedthreads","1",30);window.location.reload(true)
    }function checkcaptcha(A){
    if(document.getElementById(A)){
        if(document.getElementById(A).captcha){
            if(document.getElementById(A).captcha.value==""){
                alert("Пожалуйста, введите капчу.");document.getElementById(A).captcha.focus();return false
                }
            }
        }return true
    }function expandimg(I,H,F,C,G,E,A){
    element=document.getElementById('thumb'+I);var FF='<img src="'+F+'" alt="'+I+'" class="thumb" width="'+E+'" height="'+A+'">';var D='<img src="'+F+'" alt="'+I+'" class="thumb" height="'+A+'" width="'+E+'">';var B='<img class=thumb height='+A+' alt='+I+' src="'+F+'" width='+E+'>';if(element.innerHTML.toLowerCase()==FF||element.innerHTML.toLowerCase()==D||element.innerHTML.toLowerCase()==B){
        element.innerHTML='<img src="'+H+'" alt="'+I+'" class="thumb" height="'+G+'" width="'+C+'">'
        }else{
        element.innerHTML=D;
    }
    }function postpreview(D,A,C,B){
    if(document.getElementById(D)){
        new Ajax.Request(ku_boardspath+"/expand.php?preview&board="+A+"&parentid="+C+"&message="+escape(B),{
            method:"get",
            onSuccess:function(F){
                var E=F.responseText||"наверно что-то случилось (пустой ответ)";document.getElementById(D).innerHTML=E
                },
            onFailure:function(){
                alert("Что-то сломалось...")
                }
            })
        }
    }function set_inputs(id){
    if(document.getElementById(id)){
        with(document.getElementById(id)){
            if(!name.value){
                name.value=getCookie("name")
                }if(!em.value){
                em.value=getCookie("email")
                }if(!postpassword.value){
                postpassword.value=get_password("postpassword")
                }
            }
            }
    }function set_delpass(id){
    if(document.getElementById(id).postpassword){
        with(document.getElementById(id)){
            if(!postpassword.value){
                postpassword.value=get_password("postpassword")
                }
            }
            }
    }
    /*window.onunload=function(A){if(style_cookie){var B=get_active_stylesheet();set_cookie(style_cookie,B,365)}if(style_cookie_txt){var B=get_active_stylesheet();set_cookie(style_cookie_txt,B,365)}if(style_cookie_site){}};*/
    window.onload=function(D){/*addpreviewevents();*/
        delandbanlinks();
        checkgotothread();
        checknamesave();
        checkhighlight();
        if(document.getElementById("watchedthreads")){
            var C=new Draggable("watchedthreads",{
                handle:"watchedthreadsdraghandle",
                onEnd:function(){
                    E()
                    }
                });var A=new Resizeable("watchedthreads",{
                resize:function(){
                    B()
                    }
                });function E(){
                set_cookie("watchedthreadstop",document.getElementById("watchedthreads").style.top,30);set_cookie("watchedthreadsleft",document.getElementById("watchedthreads").style.left,30)
                }function B(){
                var F=document.getElementById("watchedthreads").offsetWidth;var G=document.getElementById("watchedthreads").offsetHeight;set_cookie("watchedthreadswidth",F,30);set_cookie("watchedthreadsheight",G,30)
                }
            }

        var textbox = document.getElementById('message');
        if(textbox)
        {
            textbox.onfocus=function(){is_entering = true;}
            textbox.onblur=function(){is_entering = false;}
        }

    };
    if(style_cookie){
        var cookie=getCookie(style_cookie);var title=cookie?cookie:get_preferred_stylesheet();set_stylesheet(title)
    }
    if(style_cookie_txt){
        var cookie=getCookie(style_cookie_txt);var title=cookie?cookie:get_preferred_stylesheet();set_stylesheet(title,true)
    }
    if(style_cookie_site){
        var cookie=getCookie(style_cookie_site);var title=cookie?cookie:get_preferred_stylesheet();set_stylesheet(title,false,true)
    }
    if(getCookie("kumod")=="yes"){
        kumod_set=true
    }

function updatenewpostscount() {
    new Ajax.Request(ku_boardspath + '/newpostscount.php?last=' + getCookie('kus_lastvisit'),{
        method:'get',
        onSuccess: function(transport){
            var response = transport.responseText;var resp = response.split('@');var arr = resp[0].split(';');for(var i = 0; i < arr.length; i++){
                var pair = arr[i].split('='); if(document.getElementById('newposts_' + pair[0])){
                    if(pair[1] == 0) {
                        document.getElementById('newposts_' + pair[0]).innerHTML = '';
                    } else {
                        document.getElementById('newposts_' + pair[0]).innerHTML = ' (' + pair[1] + ')';
                    }
                    }
                }document.getElementById('refreshnewposts').innerHTML = '<a href="#" onclick="javascript:updatenewpostscount();return false" target="_self">Обновить</a>';set_cookie('kus_lastvisit', resp[1], 365);
        },
        onFailure: function(){
            alert('Something went wrong...')
        }
        });document.getElementById('refreshnewposts').innerHTML = 'Ищем новые посты...';
}

var mp3playerid = 0;
function expandmp3(id, path){
    if (mp3playerid == id)
    {
        document.getElementById('player'+id).innerHTML = '';
        document.getElementById('player'+id).style.display = 'none';
        mp3playerid = 0;
    } else {
        if(mp3playerid != 0)
        {
            document.getElementById('player'+mp3playerid).innerHTML = '';
            document.getElementById('player'+mp3playerid).style.display = 'none';
        }

        document.getElementById('player'+id).innerHTML = '<embed src="http://www.0chan.ru/mediaplayer.swf?type=mp3&file='+path+'" width="320" height="20">';
        document.getElementById('player'+id).style.display = 'block';
        mp3playerid = id;
    }
}

var swfplayerid = 0;
function expandswf(id, path, w, h){
    if (swfplayerid == id)
    {
        document.getElementById('swfplayer'+id).innerHTML = '';
        document.getElementById('swfplayer'+id).style.display = 'none';
        swfplayerid = 0;
    } else {
        if(swfplayerid != 0)
        {
            document.getElementById('swfplayer'+swfplayerid).innerHTML = '';
            document.getElementById('swfplayer'+swfplayerid).style.display = 'none';
        }

        document.getElementById('swfplayer'+id).innerHTML = '<embed src="'+path+'" width="'+w+'" height="'+h+'">';
        document.getElementById('swfplayer'+id).style.display = 'block';
        swfplayerid = id;
    }
}

function checknamesave(){
    var checkd;
    if(getCookie('name') != '') {
        checkd = true;
    } else {
        checkd = false;
    }
    var doc = document.getElementById('save');
    if (doc != null) doc.checked = checkd;
}
function checkgotothread(){
    var checkd; 
    if(getCookie('gotothread') == 'on') {
        checkd = true;
    } else {
        checkd = false;
    }
    document.getElementById('gotothread').checked = checkd;
}

function navigatepages (event)
{
   
	if (!document.getElementById) return;
        if (is_entering) return;
	if (window.event) event = window.event;

	if (event.ctrlKey)
	{

		var link = null;
		var href = null;

                var docloc = document.location.toString();
                if (docloc.indexOf('/res/') != -1) return;
                if (docloc.indexOf('.html') == -1 || docloc.indexOf('board.html') != -1) {
                    var page = 0;
                    var docloc_trimmed = docloc.substr(0, docloc.lastIndexOf('/') + 1);
                } else {
                    var page = docloc.substr((docloc.lastIndexOf('/') + 1));
                    page = (+page.substr(0, page.indexOf('.html')));
                    var docloc_trimmed = docloc.substr(0, docloc.lastIndexOf('/') + 1);
                }
                if (page == 0) {
                    var docloc_valid = docloc_trimmed;
                } else {
                    var docloc_valid  = docloc_trimmed + page + '.html';
                }
                if(match=/#s([0-9]+)/.exec(docloc)) {
                    var relativepost = (+match[1]);
                } else {
                    var relativepost = -1;
                }
                var maxthreads = 0;
                while(document.getElementsByName('s'+(++maxthreads)).length>0){}

                switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
                {
                        case 0x25: // ctrl+left
                                link = document.getElementById('prevPage');
                                break;
                        case 0x27: // ctrl+right
                                link = document.getElementById('nextPage');
                                break;

                        case 0x28: // ctrl+down
                            if (relativepost == maxthreads - 1) {
                                break; //var newrelativepost = 0;
                            } else {
                                var newrelativepost = relativepost + 1;
                            }
                            href = docloc_valid + '#s' + newrelativepost;
                            break;

                        case 0x26: // ctrl+up
                            if (relativepost == -1 || relativepost == 0) {
                                break; //var newrelativepost = maxthreads - 1;
                            } else {
                                var newrelativepost = relativepost - 1;
                            }
                            href = docloc_valid + '#s' + newrelativepost;
                            break;

                        case 0x24: // ctrl+home
                                document.location = docloc_trimmed;
                                break;
                }

                if (link && link.action) document.location = link.action;
                if (href) document.location.href = href;
	}
}
 

if (window.document.addEventListener) {
   window.document.addEventListener("keydown", navigatepages, false);
} else {
   window.document.attachEvent("onkeydown", navigatepages);
}