﻿document.domain = "fanshu.com";
var docEle = function() {
    return document.getElementById(arguments[0]) || false;
}
function openNewDiv() {
    var _id = "newDiv";
    if (docEle(_id)) document.body.removeChild(docEle(_id));
    //新弹出层
    var newDiv = document.createElement("div");
    newDiv.id = _id;
    newDiv.style.position = "absolute";
    newDiv.style.zIndex = "9999";
    newDivWidth = 160;
    newDivHeight = 40;
    newDiv.style.width = newDivWidth + "px";
    newDiv.style.height = newDivHeight + "px";
    newDiv.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - newDivWidth / 2 - 100) + "px";
    newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth / 2 - newDivWidth / 2 - 70) + "px";
    newDiv.innerHTML = "<img src='../Images/16.gif' /><span style='font-size:14px; font-weight:bold; color:#000'>页面加载中,请稍后...</span>";
    newDiv.style.padding = "0px";
    document.body.appendChild(newDiv);
    //弹出层滚动居中
    function newDivCenter() {
        newDiv.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - newDivHeight / 2) + "px";
        newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth / 2 - newDivWidth / 2) + "px";
    }
    if (document.all) {
        window.attachEvent("onscroll", newDivCenter); 
    } else {
        window.addEventListener('scroll', newDivCenter, false);
    }
}
function ClearDivFr() {
    setTimeout("document.body.removeChild(docEle('newDiv'))", 500);
}
function GotoPage(url) {
    location.href = url;
}
function search() {
    var inputtext = document.getElementById("inputText");
    var objSelect = document.getElementById("selected");
    var selectValue = "";
    if (inputtext.value == "") {
        alert("请输入搜索词！");
        return;
    }
    else {
        for (i = 0; i < objSelect.length; i++) {
            if (objSelect[i].selected == true) {
                selectValue = objSelect[i].value;
            }
        }
        window.location.href = "http://search.fanshu.com/s.cgi?fg=1&s=&o=0&w=" + encodeURI(inputtext.value) + "&m=" + selectValue;
    }
}
function search2() {
    var inputtext = document.getElementById("inputText2");
    var objSelect = document.getElementById("selected2");
    var selectValue = "";
    if (inputtext.value == "") {
        alert("请输入搜索词！");
        return;
    }
    else {
        for (i = 0; i < objSelect.length; i++) {
            if (objSelect[i].selected == true) {
                selectValue = objSelect[i].value;
            }
        }
        window.location.href = "http://search.fanshu.com/s.cgi?fg=1&s=&o=0&w=" + encodeURI(inputtext.value) + "&m=" + selectValue;
    }
}
function showHref() {
    var dIf = document.getElementById("dIf");
    if (dIf.style.display == "") {
        dIf.style.display = "none";
    } else {
        dIf.style.display = "";
    }
}

//catalogs
function fillList(metaId,page,full){
    //判断显示状态
    var play=document.getElementById("catalogs");
    if(play.style.display=="none")
    {
    //显示状态
    popmenu("cataname", "catalogs", 20);
    var catalogReq = new Apabi.io.Request();
    var _id = "newCatalog";
    catalogReq.id=_id;
    catalogReq.url = Apabi.siteUrl +"/services/EBookService.ashx";
    catalogReq.method = "post";
    catalogReq.postContent = "do=fill&id="+metaId+"&page="+page+"&full="+full;
    catalogReq.mimetype = "text/plain";
    catalogReq.load = function(type, result, http){
        Apabi.ById("catalogs").innerHTML = result; 
        if(Apabi.ById("catacount").value>7){
            play.style.height="400px";
            play.style.width="300px";}
        else{
            play.style.height="30px";
            play.style.width="150px";}
    }
        

        
    catalogReq.error = function(){};
    Apabi.io.Bind(catalogReq);
    }
    else{
    play.style.display = "none";
    }
    
}

function FontSelect(metaId,page)
{
    var index=document.getElementById("selectFont").selectedIndex;
    
    var fontReq=new Apabi.io.Request();
       fontReq.url = Apabi.siteUrl +"/services/EBookService.ashx";
    fontReq.method = "post";
    fontReq.postContent = "do=font&id="+metaId+"&page="+page+"&type="+index;
    fontReq.mimetype = "text/plain";
    
    fontReq.load = function(type, result, http){
        document.getElementsByName("iframeL")[0].src=result;
    }
    fontReq.error = function(){};
    Apabi.io.Bind(fontReq);
}

function gotoInputPage(metaId,full){
if(full=="st")
{
location.href ="ReadFullBook.aspx?metaId="+metaId+"&page="+document.getElementById("textfield").value+"&st=2";
}
else
{
location.href ="ReadBook.aspx?metaId="+metaId+"&page="+document.getElementById("textfield").value;
}
}