﻿//搜索文本框得到焦点后清空文本
function judge()
{
    document.getElementById("t_search").value='';
}
function press()
{
    if(window.event.keyCode==13)
        search(0);
}
//切换页面
function search(isrigor)
{
    var tmpvalue=document.getElementById('t_search').value;
    var tmptxt=StranLink_Obj.innerHTML;
    if(tmptxt.indexOf("简")>-1)
        tmpvalue=StranText(tmpvalue,0,1);
    if(tmpvalue=='' || tmpvalue=='请输入搜索字符')
        location="/search.aspx";
    else
        location="/search.aspx?key="+escape(tmpvalue)+"&istitle="+document.getElementById('s_title').value+"&isrigor="+isrigor;
    return false;
}
function iscrip()
{
    if(GetUrlParam('iscrip')=='true')
        document.getElementById('scrip').innerHTML='　　<a href="/user/scrip.aspx"><img src="/image/newscrip.gif" alt="新纸条" />您有未读纸条</a>';
}
//添加推荐
function acommend(tid)
{
    document.getElementById("scommend").src='/operate.aspx?tid='+tid+"&type=1";
    return false;
}
//添加到本地书库
function alocal(tid,title)
{
    document.getElementById("slocal").src='/operate.aspx?tid='+tid+"&type=2&title="+escape(title);
    return false;
}
//添加到我的书窝
function amybook(tid)
{
    document.getElementById("smybook").src='/operate.aspx?tid='+tid+"&type=3";
    return false;
}
//添加书签
function abmark(tid,cid)
{
    document.getElementById("bmark").src='/operate.aspx?tid='+tid+"&type=4&cid="+cid;
    return false;
}
//评论字符数检测
function jcomment()
{
    var length=document.getElementById("t_comment").value.length;
    if(length<6 || length>2000)
    {
        alert('评论内容长度为 6-2000 字符！');
        return false;
    }
    return true;
}
//提取链接串后面的参数
function GetUrlParam( paramName )
{
    var sValue = unescape(location.search).match(new RegExp("[\?\&]" + paramName + "=([^\&]*)(\&?)","i"));
    return sValue ? sValue[1] : sValue;
}
//章节浏览前后箭头按键事件
function cKeyDown(eventTag)
{
    var event = eventTag||window.event;
    var key = event.charCode||event.keyCode;
    if(key==37 && document.getElementById("cup")!=null)
        clickObj("cup");
    else if(key==39 && document.getElementById("cdown")!=null)
        clickObj("cdown");
    else if(key==13 && document.getElementById("cdetail")!=null)
        clickObj("cdetail");
}
function clickObj(o)
{
    var o=document.getElementById(o);   
    if(document.all && typeof(document.all)=="object")   //IE   
        o.fireEvent("onclick");   
    else   
    {   
        var e=document.createEvent('MouseEvent');   
        e.initEvent('click',false,false);   
        o.dispatchEvent(e);   
    }   
}
//请求章节内容
function crequest(cud)
{
    var tid=document.getElementById("h_tid").value;
    var cid=document.getElementById(cud).value;
    if(cid==0)
        location='/book/'+tid+'/index.html';
    else
    {
        document.getElementById('content').innerHTML = '<img src="/image/loading.gif" /> <span style="color:Green;font-size:16px;font-weight:bold;">内容请求中………</span>';
        if(navigator.userAgent.indexOf("MSIE")>0){
            document.getElementById("cread").src='/content.aspx?tid='+tid+"&cid="+cid;
        }
        else
            location=document.getElementById(cud=="h_up"?"cup":"cdown").href;
        location='#nindex';
    }
    return false;
}
//请求章节群内容
function arequest(tid,cid)
{
    if(document.getElementById("cr"+cid)!=null)
    {
        document.getElementById('cid'+cid).innerHTML = '<img src="/image/loading.gif" /> <span style="color:Green;font-size:12px;">内容请求中………</span>' + document.getElementById('cid' + cid).innerHTML;
        document.getElementById("cr"+cid).src = '/acontent.aspx?tid=' + tid + "&cid=" + cid;
    }
    location='#cid'+cid;
    return false;
}
function setSize(size)
{
    var fsize=parseInt(document.getElementById('fsize').innerHTML)+size;
    if(fsize>11 && fsize<31)
    {
        document.getElementById("fsize").innerHTML=fsize;
        document.getElementById("content").style.fontSize=fsize+'px';
        var histroy=getCookie('color_size');
        var bcolor='blue';
        if(histroy != "")
            bcolor=histroy.split('_')[0];
        setCookie_(bcolor, fsize);
    }
    else
        alert('字体大小：12-30(px)');
}
function setColor(bcolor)
{
	var colorValue = '';
	var borderValue = '';
	var fontValue = '';
	switch(bcolor){
		case 'blue':
		colorValue = 'DFF4FF';
	    borderValue = 'D1DCEE';
	    fontValue = '000101';
		break;
		case 'yellow':
		colorValue = 'FFF5D6';
	    borderValue = 'FCA76B';
	    fontValue = '660000';
		break;
		case 'green':
		colorValue = 'F8F7ED';
	    borderValue = 'B2D696';
	    fontValue = '265800';
		break;
		case 'pink':
		colorValue = 'FEDBEF';
	    borderValue = 'F3B0D6';
	    fontValue = '660066';
		break;
		case 'red':
		colorValue = 'FFF1E1';
	    borderValue = 'FCA76B';
	    fontValue = '660000';
		break;
		case 'brown':
		colorValue = '52443C';
	    borderValue = '52443C';
	    fontValue = 'FFFFCC';
		break; 
		default:
		colorValue = 'DFF4FF';
	    borderValue = 'D1DCEE';
	    fontValue = '000101';
		break;
	}
    document.getElementById("blue").innerHTML="";
    document.getElementById("yellow").innerHTML="";
    document.getElementById("green").innerHTML="";
    document.getElementById("pink").innerHTML="";
    document.getElementById("red").innerHTML="";
    document.getElementById("brown").innerHTML="";
    document.getElementById(bcolor).innerHTML="<img src=\"/image/click.gif\">";
    document.getElementById("chapter").style.backgroundColor='#'+colorValue;
    document.getElementById("chapter").style.borderColor='#'+borderValue;
    document.getElementById("chapter").style.color='#'+fontValue;
    
    var histroy=getCookie('color_size');
    var fsize=16;
    if(histroy != "")
        fsize=parseInt(histroy.split('_')[1]);
    setCookie_(bcolor, fsize);
}
function setStyle()
{
    var histroy=getCookie('color_size');
    var bcolor='blue';
    var fsize=16;
    if(histroy != "")
    {
        bcolor=histroy.split('_')[0];
        fsize=parseInt(histroy.split('_')[1]);
    }
    setColor(bcolor);
    document.getElementById("fsize").innerHTML=fsize;
    setSize(0);
}
function getCookie(name)
{
	var my_cookie = document.cookie;
	var start = my_cookie.indexOf(name + "=");
	if (start == -1) return '';
	
	start += name.length + 1; //1 stands of '='
	
	var end = my_cookie.indexOf(";" ,start);
	if (end == -1) end = my_cookie.length;
	return my_cookie.substr(start, end - start);
}
function setCookie_(color, size) 
{
	document.cookie = "color_size=" + color + "_" + size + "; path=/; expires=Thursday,01-Jan-2088 00:00:00 GMT;";
}
//排行榜
function orderc(type)
{
	document.getElementById("o_day").style.backgroundImage='url()';
	document.getElementById("o_week").style.backgroundImage='url()';
	document.getElementById("o_hits").style.backgroundImage='url()';
	document.getElementById("o_"+type).style.backgroundImage='url(/image/menuselect.gif)';
	document.getElementById("uday").style.display='none';
	document.getElementById("uweek").style.display='none';
	document.getElementById("uhits").style.display='none';
	document.getElementById("u"+type).style.display='';
	return false;
}
function clearLocal() 
{
    if(confirm('您确定要清除本地Cookie书库吗？'))
	    document.cookie = "topicid=; path=/;expires=Thursday,01-Jan-1888 00:00:00 GMT;";
}
function topbook()
{
    mode=document.getElementById('h_mode').value;
    type=document.getElementById('h_type').value;
    if(mode=='over')
        mode='all';
    else
       mode='over';
    location='/top/'+mode+'/'+type+'.html'
}
function topbookcurrent()
{
    type=document.getElementById('h_type').value;
    switch(type)
    {
        case 'day':
            type="点击日榜";
            break;
        case 'week':
            type="点击周榜";
            break;
        case 'total':
            type="点击总榜";
            break;
        case 'commend':
            type="推荐总榜";
            break;
        case 'favor':
            type="收藏榜";
            break;
    }
    document.getElementById("red").innerHTML=type;
}
function tvcurrent()
{
    var sValue = location.match(new RegExp("tv/([0-9]*)","i"));
    var type=sValue ? sValue[1] : "19";
    switch(type)
    {
        case '20':
            type="内地电视剧情";
            break;
        case '21':
            type="新港台电视剧情";
            break;
        case '22':
            type="欧美电视剧情";
            break;
        case '23':
            type="日韩电视剧情";
            break;
        case '24':
            type="卡通动漫剧情";
            break;
        case '25':
            type="电影剧情介绍";
            break;
        default:
            type="剧情介绍";
            break;
    }
    document.getElementById("red").innerHTML=type;
}
//以下创建的XMLHttpRequest对象在IE、FireFox下兼容！
var xmlHttp = window.XMLHttpRequest?(new XMLHttpRequest()):(new ActiveXObject("Microsoft.XMLHTTP"));
//评论内容
function rcomment(tid, page)
{
    var url = "/comment.aspx?tid="+tid+"&page="+page;
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = resultcomment;
    xmlHttp.send(null);
}
function resultcomment()
{
    if (xmlHttp.readyState == 4 && xmlHttp.status==200)
        document.getElementById('ccomment').innerHTML=xmlHttp.responseText;
}
function logonjudge()
{
    var txtUserName=document.getElementById("txtUserName").value
    var txtPassword=document.getElementById("txtPassword").value
//    var t_validate=document.getElementById("t_validate").value
    if(txtUserName.length==0)
    {
        alert("用户名有误！");
        return false;
    }
    if(txtPassword.length<3 ||txtPassword.length>20)
    {
        alert("密码有误！");
        return false;
    }
//    if(t_validate.length!=3)
//    {
//        alert("验证码有误！");
//        return false;
//    }
    return true;
}
function autoSize()
{
    var width=document.getElementById('NovelCover').width;
    var height=document.getElementById('NovelCover').height;
    if(width>198)
    {
        document.getElementById('NovelCover').height=height*(198/width);
        document.getElementById('NovelCover').width=198;
    }
    else if(height>287)
    {
        document.getElementById('NovelCover').width=width*(287/height);
        document.getElementById('NovelCover').height=287;
    }
}
function BuyTicket(tid,type)
{
    document.getElementById("ticket").src="/operate.aspx?tid="+tid+"&type="+type+"&time=" + Math.random();
    return false;
}
function reportError(tid,cid)
{
    if(confirm('您确定该章节内容缺失吗？'))
        document.getElementById("error").src="/operate.aspx?tid="+tid+"&cid="+cid+"&type=10";
    return false;
}
function rreply(tid,cid)
{
    var str='<div class="comment">'
            +'<form id="form1" action="/detail.aspx?tid='+tid+'&cid='+cid+'" method="post" onsubmit="return jcomment();">'
             +'<input id="h_tid" name="h_tid" type="hidden" value="'+tid+'" />'
             +'<textarea id="t_comment" name="t_comment" cols="60" rows="5"></textarea>'
             +'<input id="Button1" type="submit" value="发 表" />'
             +'</form>'
         +'</div>';
    if(document.getElementById('r'+cid).innerHTML.indexOf('<DIV class=comment>')==-1)
        document.getElementById('r'+cid).innerHTML+=str;
    else
        document.getElementById('r'+cid).innerHTML=document.getElementById('r'+cid).innerHTML.substring(0,document.getElementById('r'+cid).innerHTML.indexOf('<DIV class=comment>'));
    return false;
}
function limitSpeak()
{
    if(document.getElementById('txtUserName').value=='')
    {
        alert('您要屏蔽的用户名不得为空！');
        return false;
    }
}