jx={getHTTPObject:function(){var A=false;if(typeof ActiveXObject!="undefined"){try{A=new ActiveXObject("Msxml2.XMLHTTP")}catch(C){try{A=new ActiveXObject("Microsoft.XMLHTTP")}catch(B){A=false}}}else{if(window.XMLHttpRequest){try{A=new XMLHttpRequest()}catch(C){A=false}}}return A},load:function(url,callback,format){var http=this.init();if(!http||!url){return }if(http.overrideMimeType){http.overrideMimeType("text/xml")}if(!format){var format="text"}format=format.toLowerCase();var now="uid="+new Date().getTime();url+=(url.indexOf("?")+1)?"&":"?";url+=now;http.open("GET",url,true);http.onreadystatechange=function(){if(http.readyState==4){if(http.status==200){var result="";if(http.responseText){result=http.responseText}if(format.charAt(0)=="j"){result=result.replace(/[\n\r]/g,"");result=eval("("+result+")")}if(callback){callback(result)}}else{if(error){error(http.status)}}}};http.send(null)},init:function(){return this.getHTTPObject()}}

window.onload = function(){setTimeout(function(){window.scrollTo(0, 1);}, 100);}

function clickclear(thisfield, defaulttext)
{
    if (thisfield.value == defaulttext)
    {
        thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext)
{
    if (thisfield.value == "")
    {
        thisfield.value = defaulttext;
    }
}

function vote(book_id, type, dst_block)
{
    jx.load('/rating/' + book_id + '/' + type + '/ajax', function(data){dst_block.innerHTML=data;});
    return false;
}

function toggle_collapse(className, img)
{
    var opened = getCookie('categories') == null ? new Array : getCookie('categories').split(',');

    var lis = document.getElementsByClassName(className);
    if (lis.length > 0)
    {
        if (lis[0].style.display == 'none')
        {
            img.src = '/images/up.png'
            for (var i = 0; i < lis.length; i++)
            {
                lis[i].style.display = 'block';
            }

            opened[opened.length] = className.substr(1);
            opened.length++;
        }
        else
        {
            img.src = '/images/down.png'
            for (var i = 0; i < lis.length; i++)
            {
                lis[i].style.display = 'none';
            }

            for (var i = 0; i < opened.length; i++)
            {
                if (opened[i] == className.substr(1))
                {
                    opened[i] = 0;
                }
            }
        }
    }

    var today  = new Date();
    var expire = new Date();
    expire.setTime(today.getTime() + 3600000 * 24 * 365);
    setCookie('categories', opened.join(','), expire.toGMTString(), "/");
}

function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
