﻿//刷新iframe框架，带搜索
function iframeRefrash(iframeId,src, controlId, isIframePage) {
    var iframe;
    if (isIframePage && isIframePage == "1") {
        iframe = window.top.document.getElementById(iframeId);
    }
    else {
        iframe = document.getElementById(iframeId);
    }
    if (!iframe) {
        return;
    }
    if (!src) {
        src = iframe.src;
    }
    if (controlId) {
        var controlValue = $("#txtStockInfo").val();
        if (controlValue && controlValue != "股票代码/拼音/首字母") {
            src += "?keyword=" + encodeURI(controlValue);
        }
        else {
            alert("请输入股票代码或股票名字");
            return;
        }
    }
    iframe.src = src;
}

var thisTime = new Date();
function SetChangeTime() {
    var reflashTimeFrom = new Date(thisTime.getFullYear() + "/" + thisTime.getMonth() + "/" + thisTime.getDay() + " " +"15:30:00");
    var time = new Date(thisTime.getFullYear() + "/" + thisTime.getMonth() + "/" + thisTime.getDay() + " " + thisTime.getHours() + ":" + thisTime.getMinutes() + ":" + thisTime.getSeconds());
    ChangeIframeLocation();
    var timeSpan;
    if (reflashTimeFrom - time > 0) {
        timeSpan = reflashTimeFrom - time;
    }
    else {
        var reflashTimeTo = new Date(thisTime.getFullYear() + "/" + thisTime.getMonth() + "/" + thisTime.getDay() + " " + "17:00:00");
        timeSpan = reflashTimeTo - time;
    }
    setTimeout("ChangeIframeLocation()", timeSpan);
}

function ChangeIframeLocation() {

    var chatRoom = "/ZiXun/Iframe/ChatRoom.aspx";
    var hudong = "/ZiXun/Iframe/HuDong.aspx";
    var temp = "";
    var time = new Date();
    var hudongHeight = "455px";
    var chatRoomHeight = "350px";
    if (time.getHours() >= 15 && time.getHours() <= 16) {
        if (time.getHours() == 15 && time.getMinutes() >= 30 || (time.getHours() > 15 && time.getHours() < 17)) {
            temp = chatRoom;
            chatRoom = hudong;
            hudong = temp;

            chatRoomHeight = "319px";
            hudongHeight = "486px";
        }
    }

    $("#iframeChatRoom").attr("src", chatRoom);
    $("#iframeChatRoom").load(function() {
        $("#iframeChatRoom").contents().find("#livelist").css("height", chatRoomHeight);
        $("#iframeChatRoom").contents().find("#refrashLink").attr("href", "javascript:iframeRefrash('iframeChatRoom','" + chatRoom + "','','1')");
    });
    
    $("#iframeHuDong").attr("src", hudong);
    $("#iframeHuDong").load(function() {
        $("#iframeHuDong").contents().find("#livelist").css("height", hudongHeight);
        $("#iframeHuDong").contents().find("#refrashLink").attr("href", "javascript:iframeRefrash('iframeHuDong','" + hudong + "','','1')");
    });
}

function f_GetRank(m, q, count) {
    for (var i = 1; i <= count; i++) {
        if (i == q) {
            $("#tab_" + m + "_" + i).css("display", "block");
            if (q == 1) { $("#" + m + "_" + i).attr("class", "on star"); }
            else { $("#" + m + "_" + i).attr("class", "on"); }
        }
        else {
            $("#tab_" + m + "_" + i).css("display", "none");
            $("#" + m + "_" + i).removeClass("on");
        }
    }
}
//根据回复类型获得咨询列表
function GetQueryByRestore(checkbox) {
    if (checkbox.checked) {
        window.top.document.getElementById("iframeQueryOnlineNoneRestore").src = "/ZiXun/Iframe/QueryOnlineRestoredList.aspx?restore=0"
    }
    else {
        window.top.document.getElementById("iframeQueryOnlineNoneRestore").src = "/ZiXun/Iframe/QueryOnlineRestoredList.aspx?restore=1"
    }
}
var scrollRepeat;
var scrollMain;
var scrollContent;
//设置滚动条自动滚动
function scrollQuestion() {
    var checkbox = $("#checkbox");
    if (checkbox.attr("checked") == true) {
        setScolling();
    }
}

var MyMar;//滚动条定时器

var speed = 80    //滚动速度值，值越大速度越慢

//设置滚动状态
function setScolling() {
    scrollMain = $("#livelist")[0];
    scrollContent = $("#divScrollContent")[0];
    scrollRepeat = $("#divScrollRepeat")[0];
    //scrollRepeat.innerHTML = scrollContent.innerHTML    //克隆demo2为demo1
    var checkbox = $("#checkbox");
    if (checkbox.attr("checked") == true) {
        MyMar = setInterval(Marquee, speed)//鼠标移开时重设定时器
    }
    else {
        clearInterval(MyMar);
    }
    //MyMar = setInterval(Marquee, speed);        //设置定时器
    scrollMain.onmouseover = function() { clearInterval(MyMar) }     //鼠标经过时清除定时器达到滚动停止的目的
    scrollMain.onmouseout = function() {
            var checkbox = $("#checkbox");
            if (checkbox.attr("checked") == true) {
                MyMar = setInterval(Marquee, speed)//鼠标移开时重设定时器
            }    
        }
}
//设置是否自动滚动
//function ckbChange() {
//    if (!scrollRepeat) {
//        scrollRepeat = $("#divScrollRepeat")[0];
//    }
//    if (!scrollMain) {
//        scrollMain = $("#livelist")[0];
//    }
//    if (!scrollContent) {
//        scrollContent = $("#divScrollContent")[0];
//    }
//    var checkbox = $("#checkbox");
//    if (checkbox.attr("checked") == true) {
//        MyMar = setInterval(Marquee, speed)//鼠标移开时重设定时器
//    }
//    else {
//        clearInterval(MyMar);
//    }
//}

//开始滚动
function Marquee() {
    if (scrollRepeat.offsetTop - scrollMain.scrollTop * 1.3 <= 0) {    //当滚动至demo1与demo2交界时
        scrollMain.scrollTop -= scrollContent.offsetHeight    //demo跳到最顶端
    } else {
        scrollMain.scrollTop = scrollMain.scrollTop + 1;
    }

    //alert(demo1.offsetHeight + "：" + demo.scrollTop);
}
//清空搜索框的初试字符串
function clearTextboxValue(textbox) {
    if (textbox.value == "股票代码/拼音/首字母") {
        textbox.value = "";
    }
}



//Ajax提交评论
function SubmitReply(newsId) {
    if (!newsId || newsId < 0) {
        return;
    }
    var content = $("#textarea").val();
    if (!content) {
        alert("请输入评论内容！");
        return;
    }

    $("#btnCommitReply").css("disabled", true);
    $.post("/AjaxPage/ZiXun/CommitReply.aspx", { newsId: newsId, content: content, date: new Date() }, onReplySubmmitSuccess);
}

function SubmitReplyForChatRoom(newsId) {
    if (!newsId || newsId < 0) {
        alert("没有找到相关新闻");
        return;
    }
    var content = $("#textarea").val();
    if (!content) {
        alert("请输入评论内容！");
        return;
    }

    $("#btnCommitReply").css("disabled", true);
    $.post("/AjaxPage/ZiXun/CommitReply.aspx", { newsId: newsId, content: content, date: new Date(), type: 1 }, onReplySubmmitSuccess);
}

//Ajax评论提交成功
function onReplySubmmitSuccess(result) {
    if (typeof result != 'undefined') {
        if (result == -1) {
            alert("提交成功,请等待审核");
        }
        else if (result == 0) {
            alert("请登录后再提交评论");
            window.location = "/Register/Login.aspx";
        }
        else if (result == -2) {
            alert("请输入评论内容");
        }
        else {
            alert("提交成功");
            var control = $("#replyHead")[0];
            if (control) {
                $("#replyHead").prepend(result);
            }
            else {
                $.post("/AjaxPage/Public/CheckCustomerType.aspx", { date: new Date() }, function(typeResult) {
                    if (typeof result != 'undefined') {
                        $("#livelist").prepend(result);
                    }

                });
                
            }
            $("#textarea").val("");
        }
    }
}


var rId = 0;
//Ajax提交评论反对支持无聊
function SubmitReplyAttribute(replyId, agressNum, againstNum, boredNum) {
    if (!replyId || replyId < 0) {
        return;
    }
    var canCommit = 0;
    if (agressNum && agressNum > 0) {
        canCommit += 1;
    }
    if (againstNum && againstNum > 0) {
        canCommit += 1;
    }
    if (boredNum && boredNum > 0) {
        canCommit += 1;
    }
    if (canCommit != 1) {
        return;
    }
    rId = replyId;
    //$("#btnCommitQuery").css("disabled", true);
    $.post("/AjaxPage/ZiXun/SetReplyAttribute.aspx", { replyId: replyId, agressNum: agressNum, againstNum: againstNum, boredNum: boredNum }, onReplySuccess);
}
//Ajax评论反对支持无聊提交成功
function onReplySuccess(result) {
    if (typeof result != 'undefined') {
        if (result > 0) {
            alert("提交成功");
            if (result == 1) {
                $("#Agree" + rId)[0].innerText = "支持(" + (parseInt($("#agree" + rId + "Hid").val()) + 1) + ")";
                document.getElementById("agree" + rId + "Hid").value = parseInt($("#agree" + rId + "Hid").val()) + 1;
            }
            else if (result == 2) {
                $("#Against" + rId)[0].innerText = "反对(" + (parseInt($("#against" + rId + "Hid").val()) + 1) + ")";
                document.getElementById("against" + rId + "Hid").value = parseInt($("#against" + rId + "Hid").val()) + 1;
            }
            else if (result == 3) {
                $("#Bored" + rId)[0].innerText = "无聊(" + (parseInt($("#bored" + rId + "Hid").val()) + 1) + ")";
                document.getElementById("bored" + rId + "Hid").value = parseInt($("#bored" + rId + "Hid").val()) + 1;
            }
            $("#Agree" + rId).attr("href", "javascript:void(0)");
            $("#Against" + rId).attr("href", "javascript:void(0)");
            $("#Bored" + rId).attr("href", "javascript:void(0)");
        }
        else {
            alert("提交失败，请稍候重试");
        }
    }
}
//获得评论
function GetReply(channelId) {
    $.post("/AjaxPage/News/GetReplyAjax.aspx", { channelId: channelId }, function(result) {
        $("#livelist").html(result);
    });
}


//获取在线咨询列表
function GetQueryOnline(restoreType, pageSize, controlId) {
    $.post("/AjaxPage/ZiXun/GetQueryOnline.aspx", { restoreType: restoreType, pageSize: pageSize }, function(result) {
        if (controlId == "") {
            controlId = "queryContent";
        }
        $("#" + controlId).html(result);
    });
}
//Ajax提交在线咨询
function SubmitQueryOnline() {
    
    var StockNo = $("#txtStockNo").val();
    var Question = $("#textarea").val();
    if (!StockNo) {
        alert("请输入股票号");
        return;
    }

    if (!Question) {
        alert("请输入咨询内容");
        return;
    }
    $("#btnCommitQuery").css("disabled", true);    
    $.post("/AjaxPage/ZiXun/CommitQueryOnline.aspx", { StockNo: StockNo, Question: Question },function(result) {
        if (typeof result != 'undefined') {	
        if (result > 0) {		
            iframeRefrash("iframeQueryOnlineNoneRestore","", "", "0"); 
            alert("提交成功");
            clearText();
            var popDiv = $("#popDiv")[0];
            if (popDiv) {
                closeDiv();
            }
        }
        else if (result == -1) {
            alert("股票号输入错误");
        }
        else if (result == -2) {
            alert("咨询内容输入错误");
        }
        else if (result == -3) {
            alert("请登录后再提交评论");
        }
        else {
            alert("提交失败，请稍候重试");
        }
        document.getElementById("btnCommitQuery").disabled = false;
    }
    });
}
//Ajax提交在线咨询
function SubmitQueryOnlineType2(divId) {
    var StockNo = $("#txtStockNo").val();
    var Question = $("#textarea").val();
    if (!StockNo) {
        alert("请输入股票号");
        return;
    }

    if (!Question) {
        alert("请输入咨询内容");
        return;
    }

    $("#btnCommitQuery").css("disabled", true);
    $.post("/AjaxPage/ZiXun/CommitQueryOnline.aspx", { StockNo: StockNo, Question: Question, returnString: "true" }, function(result) {
        if (typeof result != 'undefined') {
            if (result == -1) {
                alert("股票号输入错误");
            }
            else if (result == -2) {
                alert("咨询内容输入错误");
            }
            else if (result == -3) {
                alert("请登录后再提交评论");
            }
            else {
                alert("提交成功");
                clearText();
                var popDiv = $("#popDiv")[0];
                if (popDiv) {
                    closeDiv();
                }
                $("#" + divId).prepend(result); //queryContent
            }
            document.getElementById("btnCommitQuery").disabled = false;
        }
    });
}


//Ajax在线咨询提交成功
function onSuccess(result) {		
    if (typeof result != 'undefined') {	
        if (result > 0) {		
            iframeRefrash("iframeQueryOnlineNoneRestore","", "", "0"); 
            alert("提交成功");
            clearText();
            var popDiv = $("#popDiv")[0];
            if (popDiv) {
                closeDiv();
            }
        }
        else if (result == -1) {
            alert("股票号输入错误");
        }
        else if (result == -2) {
            alert("咨询内容输入错误");
        }
        else if (result == -3) {
            alert("请登录后再提交评论");
        }
        else {
            alert("提交失败，请稍候重试");
        }
        document.getElementById("btnCommitQuery").disabled = false;
    }
}

//弹出在线咨询提交层
function showDiv() {
    document.getElementById('popDiv').style.display = 'block';
    document.getElementById('popIframe').style.display = 'block';
    document.getElementById('bg').style.display = 'block';
}
//关闭在线咨询提交层
function closeDiv() {
    document.getElementById('popDiv').style.display = 'none';
    document.getElementById('bg').style.display = 'none';
    document.getElementById('popIframe').style.display = 'none';

}

//清除文本框文字
function clearText() {
    document.getElementById("txtStockNo").value = "";
    document.getElementById("textarea").value = "";
}

function span_Tab(span) {
    span.className = "on";
    if (span.id == "span1") {
//        document.getElementById("iframeQueryOnlineNoneRestore").src = "Iframe/QueryOnline_InIndexPage.aspx";
        document.getElementById("span2").className = "";
        GetQueryOnline(2,6,"");
    }
    else {
        GetQueryOnline(1,6,"");

        //        document.getElementById("iframeQueryOnlineNoneRestore").src = "Iframe/QueryOnline_InIndexPage.aspx?restoreType=1";
        document.getElementById("span1").className = "";
    }
}
