﻿var pagesize = 5;
/*Vote About */
function getPoint() {
    window.stars = document.getElementById("winstars").getElementsByTagName("img");
    window.nowselectfs = document.getElementById("nowselectfs");
    ajaxpoint("get", 0);
}

function votePoint(vpoint) {
    ajaxpoint("vote", vpoint);
}

function ajaxpoint(act, vpoint) {
    var url = interfaceurl + "?act=" + act + "&toolid=" + toolid + "&point=" + vpoint + "&rnd=" + Math.random();
    $.get(url, function(data) {
        if (data > 0) {
            $html("avgpoint", data);
            window.npoint = data;
            if (act == "vote") {
                friendsPo();
                showVoteTip("感谢您的投票！");
                getPoint();
            }
        } else if (data == -2) {
            showVoteTip("您已经投过票了！");
        } else {
            $html("avgpoint", "");
        }
        if (act == "get") {
            setStar();
            bindVoteMethod();
            setTimeout("friendsPo();", 35);
        }
    });
}
function friendsPo() {
    $id("friendsPoint").innerHTML = $id("winstars").innerHTML.replace("<br/>", "") + "<span style='color:red;padding:3px 0'>" + $id("StarInfo").innerHTML + "</span>";
    //$id("friendsPoint").innerHTML += "<span class='color_red marginlr'>" + $id("StarInfo").innerHTML + "</span>";
}
var starInfos = ["极度难用", "不值一用", "超难用", "令人失望", "没啥特别", "有点意思", "挺好用的", "非常好用", "确实极品", "极度精品"];
function setStar(npoint) {
    var hasnpoint = npoint ? true : false;
    npoint = npoint ? npoint : window.npoint;

    var btncount = window.stars.length;
    var tnpoint = Math.min(npoint, btncount);
    var mnpoint = Math.ceil(tnpoint);
    tnpoint = mnpoint - tnpoint > 0.5 ? mnpoint - 1 : mnpoint;

    for (var i = 0; i < tnpoint; i++) {
        window.stars[i].src = starsimg[i % 2 == 0 ? 2 : 3];
    }

    for (var i = tnpoint; i < btncount; i++) {
        window.stars[i].src = starsimg[i % 2 == 0 ? 0 : 1];
    }
    var innerhtml = hasnpoint ? tnpoint : window.npoint;
    if (innerhtml >= 10) { innerhtml = 10; } else { innerhtml = parseFloat(innerhtml).toFixed(1) }
    window.nowselectfs.innerHTML = innerhtml;
    $html("StarInfo", starInfos[tnpoint - 1]);
}

function bindVoteMethod() {
    var pfcount = window.stars.length;
    for (var index = 0; index < pfcount; index++) {
        bindVoteBtn(window.stars[index], index + 1, pfcount);
    }
    document.getElementById("winstars").onmouseout = function() {
        setStar();
    }
}
function bindVoteBtn(btn, point, pfcount) {
    btn.onclick = function() {
        votePoint(point);
    }
    btn.onmouseover = function() {
        setStar(point);

    }
}


var tiptimeout;
function showVoteTip(text) {
    JsTip(150, text, 0, 1500, false, "#333333", "#FFCC66");
}
function hideVoteTip() {
    HideJsTip();
}

/*Vote About End */




/*Display About*/
function ChangeCheckCode() {
    $("#img_ccode").attr("src", "../CheckImg.aspx?rnd=" + Math.random());
}


function openBottomTagOnLoad() {
    if ($queryString("action").toLowerCase() == "pl") {
        $id("Li_LeaveWord").click();

    }
}

function showAll(dom, id) {
    $id(id).style.overflow = "visible";
    $id(id).style.height = "";
    $id(id).style.width = "470px";
    dom.onclick = function() { hideSm(this, id) };
    dom.innerHTML = "收起";
}
function hideSm(dom, id, of) {
    $id(id).style.height = "190px";
    $id(id).style.width = "470px";
    $id(id).style.overflow = "hidden";
    dom.onclick = function() { showAll(this, id) };
    dom.innerHTML = "展开";
}

function showTag(dom, showid) {
    $hide("Div_Images");
    $hide("Div_Introduction")
    $class("Li_Images", "");
    $class("Li_Introduction", "");
    $show(showid);
    $class(dom, "lihover");
}


var ButtomTag_con;
function showButtomTag(index, onopen) {
    if (!ButtomTag_con) {
        ButtomTag_con = [
                [$id('Li_MayBeLike'), $id('Rec_Table')],
                [$id('Li_LeaveWord'), $id('Lw_Ccontent')]
                ]
    }
    for (var i = ButtomTag_con.length - 1; i >= 0; i--) {
        if (i == index) {
            $show(ButtomTag_con[i][1]);
            $class(ButtomTag_con[i][0], "lihover");
        } else {
            $hide(ButtomTag_con[i][1]);
            $class(ButtomTag_con[i][0], "");
        }
    }
    if (onopen) {
        onopen();
    }
}
/*Display About End*/


/* Show Leave Word */
function initPager(loadFirstPage) {
    GetRecordCount(toolid, function(data) {
        var recordcount = eval(data);
        $html("__lwcount", data);
        pagecreaterobj = new PagerCreater("lw_pager", recordcount, pagesize, 5, "#mid");
        pagecreaterobj.OnLoaded = function() {
            GetByPageIndex(toolid, pagecreaterobj.PageSize, pagecreaterobj.PageIndex);
        }
        if (loadFirstPage) {
            pagecreaterobj.Load(1);
        }
    });
}

function showUserName(data) {
    if (data == "-") {
        //' + toolid + '|login.commend
        //&nbsp;&nbsp;您目前是以游客身份发表&nbsp;&nbsp;<a href="http://user.jdbbx.com/Default.aspx?ReturnUrl=http://www.jdbbx.com/ToolsList/Tool' + toolid + '.shtml">登录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://user.jdbbx.com/Register.aspx" target="_blank">注册</a>
        data = ''
    } else {
        data = '<input type="radio" name="Lw_UserName" id="l_u_1" value="" /><label for="l_u_1">匿名</label>&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" checked="checked" id="l_u_2" name="Lw_UserName" value="' + data + '" /><label for="l_u_2">' + data + "</label>";
    }
    $("#div_userinfo").html(data);
}

function sendLeaveWord() {
    var content = $("#tb_content").val();
    if (content.length > 100) {
        JsTip(480, '评论最多允许100个字符！', 0, 3000, true, "");
        return;
    }
    if (content == "请输入您的评论，最多可输入100个中文字符") {
        JsTip(480, '请输入内容后再评论！', 0, 3000, true, "");
        return;
    }
    var checkcode = $("#tb_checkcode").val();
    if (checkcode == "4位验证码") {
        JsTip(480, '请输入验证码！', 0, 3000, true, "");
        return;
    }
    
    var username = $("input[name='Lw_UserName']:checked").val();
    if (!username) {
        username = "";
        //return;
    }
    JsTip(480, '正在发表留言，请稍候...', 0, 3000, true, "");
    var cookiestr = document.cookie;
    if (cookiestr.indexOf("canlw=1") >= 0) {
        JsTip(480, '您发表评论的频率太快了，请稍后再发表评论！', 0, 3000, true, "");
        ChangeCheckCode();
        return;
    } else {
        DoLeaveWord(toolid, content, username, checkcode, function(data) {
            var arr = data.split("|");
            JsTip(480, arr[1], 0, 3000, true, "");
            if (arr[0] == "1") {
                initPager(true);
                var date = new Date();
                var ms = 1 * 1000;
                date.setTime(date.getTime() + ms);
                var str = "canlw=1; expires=" + date.toGMTString() + ";";
                document.cookie = str;
                $("#tb_content").val("");
                $("#tb_checkcode").val("");
                //$id("Li_LeaveWord").click();
            } else if (arr[0] == -1) {
                GetUserName(function() { showUserName() });
            }
            //ChangeCheckCode();
        })
    }
}

function srollMove() {
    document.getElementById('div_DisCheckImg').style.display = 'none';
    document.getElementById('tb_checkcode').blur();
}

/* Check Code */
var checkcodeTimeout;
function toggleCheckCode(show) {
    window.clearTimeout(checkcodeTimeout);
    var spandom = $id("span_checkcode");
    var cbck = $id("tb_checkcode");
    var discbimg = $id("div_DisCheckImg");
    if (show) {
        //$html(spandom, '<span id="spabspan" style="position:absolute"><img style="margin-left:20px;" src="../CheckImg.aspx?rnd=' + Math.random() + '" width="57" height="22" /></span>');
        $html(spandom, '');
        $html(discbimg, '<img  src="../CheckImg.aspx?rnd=' + Math.random() + '" width="57" height="22" />');
        discbimg.style.display = 'block';
        discbimg.style.top = 480 + 'px';
        discbimg.style.left = 100 + 'px';
        checkcodeTimeout = setTimeout(function() {
            if ($val(cbck) == "") {
                cbck.blur();
            }
        }, 30000);
    } else {
        //discbimg.style.display = 'none';
        //$html(spandom, '<span onclick="document.getElementById(\'tb_checkcode\').focus()" style="margin-left:20px; height:22px; color:red ; cursor:pointer;">点击获取验证码</span>');
    }
}

function bindCkInput() {
    var cbck = $id("tb_checkcode");
    cbck.onfocus = function() {
        toggleCheckCode(true);
        cbck.select();
    }
    cbck.onblur = function() {
        toggleCheckCode(false);
    }
}

function changeColor(div) {
    if (div.style.color == "#a8a8a8")
        div.value = "";
    div.style.color = "#000000";
}

/*submit*/
function initSubmitBtn() {
    var cbck = $id("tb_checkcode");
    var chck2 = $id("tb_content");
    cbck.onkeypress = function() {
        if (window.event.keyCode == 13) {
            $id("btn_send").click();
            return false;
        } else {
            return true;
        }
    }
    chck2.onkeypress = function() {
        if (window.event.keyCode == 13) {
            $id("btn_send").click();
            return false;
        } else {
            return true;
        }
    }
}




/*JSTIP*/
var __JsTipTimeOut;

function JsTip(top, text, width, timeout, addscrollTop, color, bgcolor) {
    HideJsTip();
    var tipdom = $id("__jsleavewordTip");
    if (width > 0) {
        tipdom.style.width = width + "px";
    }

    if (addscrollTop) {
        var sctop = document.documentElement.scrollTop;
        if (!sctop) {
            sctop = document.body.scrollTop;
        }
        tipdom.style.top = (sctop + top) + "px";
    } else {
        tipdom.style.top = top + "px";
    }

    if (color) {
        text = '<font color="' + color + '">' + text + '</font>';
    }
    bgcolor = bgcolor ? bgcolor : "#3399cc";
    tipdom.style.backgroundColor = bgcolor;
    $html(tipdom, text);
    $show(tipdom);
    tipdom.style.left = (1000 - tipdom.offsetWidth) / 2;

    if (timeout) {
        __JsTipTimeOut = window.setTimeout(function() { HideJsTip() }, timeout);
    }
}
function HideJsTip() {
    var tipdom = $id("__jsleavewordTip");
    window.clearTimeout(__JsTipTimeOut);
    $hide(tipdom);
}

/*相关工具*/
window.ToolsInterface = '/Service/Tools3rdRec.aspx';
function GetTools(toolid) {
    var url = window.ToolsInterface + "?id=" + toolid + "&rnd=" + Math.random();
    $.get(url, function(data) {
        var dat = eval(data);
        var innerhtml = "<ul>";
        var i = 1;
        for (var tempd in dat) {
            var temp = dat[tempd];
            innerhtml += '<li>';
            innerhtml += '<div class="iconpic""><a href="/ToolsList/Tool' + temp.ToolId + '.shtml"><img onerror="this.src=\'http://soft.jdbbx.com/Pages/handPage/ToolImages/icon/icon_listb_02.gif\'" src=\"http://soft.jdbbx.com/Pages/handPage/ToolImages/icon/' + temp.ToolId + '.gif\" width="40" height="40" /></a></div>';
            innerhtml += '<div class="icontitleb"><a href="/ToolsList/Tool' + temp.ToolId + '.shtml">' + temp.ToolName + '</a><br/>' + temp.Introduction + '</div>';
            
            innerhtml += "</li>";
            i++;
        }
        innerhtml += "</ul>";
        $("#lw_tools").html(innerhtml);
    });
}

/*END*/
