﻿//2011年08月29日最后更新
function $(id) {
    return document.getElementById(id);
}
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function hide(id) {
    document.getElementById(id).style.display = "none";
}
function show(id) {
    document.getElementById(id).style.display = "";
}
function bodyLoad() {
    var cookie = new my_Cookie();
    var customService;
    var ck = cookie.Get("customService");
    if (ck == "") {
        customService = new my_CustomService("customService", "right", "middle", true);
    }
    else {
        var arr = ck.split("_");
        customService = new my_CustomService("customService", arr[0], arr[1], true);
    }
    if (typeof (bodyLoad1) == "function") {
        bodyLoad1();
    }
}
function beforeUnload() {
    var cookie = new my_Cookie();
    if (cookie.Get("addFavorite") != "true") {
        if (window.confirm("建议您把“股投网”添加到收藏夹！")) {
            addFavorite();
        }
    }
}
function showTvProgram() {
    var t = new Date();
    var hour = t.getHours(), minute = t.getMinutes();
    var m = t.getHours() * 60 + t.getMinutes();
    var lastOnPlay = null, lastReadyFor = 0;
    var readyFor = "";
    var play = "";
    var suggest = "";
    var str = "<span class='name2'>直播：</span> ";
    //如果2个是同一个时间开始，不同时间结束，那么迟结束的那个文本带时间，早结束的不要带，迟的放前面
    var tvList = new Array(
    [0, 1 * 60, '00：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（重播：财经夜行线＋首席评论）</a>'],
    [1 * 60, 2 * 60, '01：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（今日股市）</a>'],
    [1 * 60 + 45, 2 * 60 + 45, '01：45 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（公司与行业）</a>'],
    [1 * 60 + 50, 2 * 60 + 23, '01：50 <a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（经济半小时：观经济大势）</a>'],
    [6 * 60, 7 * 60, '06：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（今日股市）</a>'],
    [7 * 60, 9 * 60, '07：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（财经早班车）</a>'],
    [9 * 60, 12 * 60, '09：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（市场零距离）</a>'],
    [9 * 60, 11 * 60 + 50, '<a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（交易时间）</a>'],
    [12 * 60, 12 * 60 + 40, '12：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（财经中间站）</a>'],
    [13 * 60, 16 * 60, '13：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（市场零距离）</a>'],
    [13 * 60, 15 * 60, '<a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（交易时间）</a>'],
    [16 * 60, 16 * 60 + 30, '16：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（今日期市）</a>'],
    [17 * 60, 17 * 60 + 25, '17：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（第一地产）</a>'],
    [18 * 60, 19 * 60, '18：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（今日股市）</a>'],
    [18 * 60, 18 * 60 + 43, '<a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（市场分析室）</a>'],
    [19 * 60, 20 * 60, '19：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（谈股论金）</a>'],
    [20 * 60, 21 * 60, '20：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（公司与行业）</a>'],
    [20 * 60 + 30, 21 * 60 + 20, '20：30 <a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（经济信息联播：把握经济脉搏）</a>'],
    [21 * 60, 22 * 60, '21：00 <a href="http://www.yicai.com/video/" target="_blank">上海第一财经（财经夜行线＋首席评论）</a>'],
    [21 * 60 + 20, 21 * 60 + 55, '21：20 <a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（经济半小时：观经济大势）</a>'],
    [23 * 60, 23 * 60 + 35, '23：00 <a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（经济半小时：观经济大势）</a>'],
    [23 * 60 + 35, 24 * 60 + 45, '23：35 <a href="http://bugu.cntv.cn/live_channel2/index.shtml" target="_blank">CCTV2（环球财经连线）</a>']
    );
    for (var i = 0; i < tvList.length; i++) {
        if (tvList[i][0] <= m && m < tvList[i][1]) {
            lastOnPlay = i;
            if (play == "") {
                play = tvList[i][2];
            }
            else {
                if (tvList[i - 1][0] == tvList[i][0]) {
                    play += " " + tvList[i][2];
                }
                else {
                    play += " " + tvList[i][2];
                }
            }
            if (tvList[i - 1] && tvList[i - 1][1] < m && tvList[i][0] > m) {
                lastReadyFor = i;
            }
        }
        else {
            if (lastOnPlay == i - 1 || (tvList[i - 1] && tvList[i - 1][1] < m && tvList[i][0] > m)) {
                readyFor = tvList[i][2];
                lastReadyFor = i;
            }
            else if (tvList[i][0] == tvList[lastReadyFor][0]) {
                readyFor += " " + tvList[i][2];
            }
            else if (tvList[i][0] < tvList[lastReadyFor][0] + 30) {
                readyFor += " " + tvList[i][2];
            }
        }
    }
    if (hour >= 7 && hour < 9) {
        suggest = '<a href="/tuijian/" target="_blank">查看本站的“推荐”栏目，看看有什么好股票。</a> <a href="http://guba.eastmoney.com/" target="_blank">持仓的朋友可以到股吧看看自己股票有什么消息。</a></br>要上厕什么的赶快去，不要等开盘再做这种事！';
    }
    if (hour == 9 && minute < 15) {
        suggest = "准备在9点15分以涨停价买入特停、重大利好等等可能开盘涨停的股票，不合适就撤单！（注意：9:15-9:20可以撤单，9:20-9:25不可以撤单）";
    }
    else if (hour == 9 && minute < 30) {
        suggest = "查看开盘涨停、封大量跌停、突然放量的股票！";
    }
    if (hour == 10 && minute < 30) {
        suggest = "准备关注停牌一小时的股票（建议建一个版块，专门放每天的停盘一小时的股票）沪市：必须要在复牌后挂单有效。 深市：可在集合竞价时挂单，但不参与开盘集合竞价，而是在复盘时竞价。 ";
    }
    if (play != "") {
        str += "正在播放：" + play;
    }
    if (readyFor != "") {
        if (str != "") {
            str += " ";
        }
        str += "即将播放：" + readyFor;
    }
//    if (suggest != "") {
//        if (str != "") {
//            str += "</br>";
//        }
//        str += "我们建议：" + suggest;
//    }
    $("tvLive").innerHTML = str;
}
function copyToClipboard(txt) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", txt);
    } else if (navigator.userAgent.indexOf("Opera") != -1) {
    window.location = txt;
    } else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("您的firefox安全限制限制您进行剪贴板操作，请打开’about:config’将signed.applets.codebase_principal_support’设置为true’之后重试");
            return false;
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip)
            return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans)
            return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = txt;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip)
            return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
    }
    alert('复制成功！');
    return false;
}
function setHomePage(obj) {
    var url = "http://www.gutou.com";
    try {
        obj.style.behavior = "url(#default#homepage)";
        obj.setHomePage(url);
        obj.style.behavior = "";
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        }
    }
}
function addFavorite() {
    if (document.all) {
        window.external.addFavorite("http://www.gutou.com", "股投网");
    }
    else if (window.sidebar) {
        window.sidebar.addPanel("股投网", "http://www.gutou.com", "");
    }
    var cookie = new my_Cookie();
    cookie.Set("addFavorite", "true");
}
function my_Cookie() {
    this.Get = function(nm) {
        var m = "";
        if (window.RegExp) {
            var re = new RegExp(";\\s*" + nm + "=([^;]*)", "i");
            m = re.exec(';' + document.cookie);
        }
        return (m ? unescape(m[1]) : "");
    }
    this.Set = function(nm, val) {
        var exp = "";
        var dt = new Date();
        dt.setTime(dt.getTime() + 31536000000);
        exp = "; expires=" + dt.toGMTString();
        document.cookie = nm + "=" + escape(val) + exp + ";path=/";
    }
    this.Del = function(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null) {
            document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
        }
    }
}
function my_String() {
    function replaceOneToOne(str, from, to)//把一个from替换成一个to
    {
        var reg = new RegExp(from, "g");
        return str.replace(reg, to);
    }
    this.ReplaceOneToOne = function(str, from, to) {
        return replaceOneToOne(str, from, to);
    }
    this.ReplaceAllToOne = function(str, from, to)//连续的几个from替换成一个to
    {
        str = str.replace(/([ ]+)/g, from)
        return replaceOneToOne(str, from, to);
    }
}
function my_Position() {
    var _styleX, _styleY, _dom, _gap = 2, _lastScrollY = 0, _lastScrollX = 0, _slide, _percent = 0.1;
    var _scorllLeft, _scorllTop, _clientWidth, _clientHeight;
    this.GetDom = function() {
        return _dom;
    }
    this.GetTop = function() {
        if (_dom.style.top == "") {
            return 0;
        }
        else {
            return _dom.style.top;
        }
    }
    this.SetTop = function(value) {
        _dom.style.top = value + "px";
    }
    this.GetLeft = function() {
        if (_dom.style.left == "") {
            return 0;
        }
        else {
            return _dom.style.left;
        }
    }
    this.SetLeft = function(value) {
        _dom.style.left = value + "px";
    }
    this.GetStyleX = function() {
        return _styleX;
    }
    this.SetStyleX = function(x) {
        _styleX = x;
    }
    this.GetStyleY = function() {
        return _styleY;
    }
    this.SetStyleY = function(y) {
        _styleY = y;
    }
    this.GetScreenLeft = function()//这里left等等，都是dom要定位到相应位置时要得到的值，而不是屏幕的值，这里处理掉了dom的尺寸和间隙的尺寸
    {
        return document.body.scrollLeft + _gap;
    }
    this.GetScreenCenter = function() {
        return document.body.scrollLeft + parseInt((document.body.clientWidth - _dom.offsetWidth) / 2);
    }
    this.GetScreenRight = function() {
        return document.body.scrollLeft + document.body.clientWidth - _dom.offsetWidth - _gap;
    }
    this.GetScreenTop = function() {
        return document.body.scrollTop + _gap;
    }
    this.GetScreenMiddle = function() {
        return document.body.scrollTop + parseInt((document.body.clientHeight - _dom.offsetHeight) / 2);
    }
    this.GetScreenBottom = function() {
        return document.body.scrollTop + document.body.clientHeight - _dom.offsetHeight - _gap;
    }
    this.SetPosition = function(value)//"absolute"
    {
        _dom.style.position = value;
    }
    this.Init = function(id, styleX, styleY, slide)//初始化dom出现的位置
    {
        _dom = document.getElementById(id);
        this.SetStyleX(styleX);
        this.SetStyleY(styleY);
        _slide = false;
        this.MoveTo(styleX, styleY);
        _slide = slide;
        this.SetPosition("absolute");
    }
    this.MoveTo = function(x, y) {
        _styleX = x;
        _styleY = y;
        if (_slide == true) {
            var xFrom, xTo, yFrom, yTo, diff;
            if (x == "left") {
                xTo = this.GetScreenLeft();
            }
            else if (x == "center") {
                xTo = this.GetScreenCenter();
            }
            else if (x == "right") {
                xTo = this.GetScreenRight();
            }
            xFrom = parseInt(this.GetLeft());
            diff = _percent * (xTo - xFrom);
            if (diff > 0) {
                diff = Math.ceil(diff);
            }
            else {
                diff = Math.floor(diff);
            }
            this.SetLeft(xFrom + diff);
            if (y == "top") {
                yTo = this.GetScreenTop();
            }
            else if (y == "middle") {
                yTo = this.GetScreenMiddle();
            }
            else if (y == "bottom") {
                yTo = this.GetScreenBottom();
            }
            yFrom = parseInt(this.GetTop());
            diff = _percent * (yTo - yFrom);
            if (diff > 0) {
                diff = Math.ceil(diff);
            }
            else {
                diff = Math.floor(diff);
            }
            this.SetTop(yFrom + diff);
        }
        else {
            if (x == "left") {
                this.SetLeft(this.GetScreenLeft());
            }
            else if (x == "center") {
                this.SetLeft(this.GetScreenCenter());
            }
            else if (x == "right") {
                this.SetLeft(this.GetScreenRight());
            }
            if (y == "top") {
                this.SetTop(this.GetScreenTop());
            }
            else if (y == "middle") {
                this.SetTop(this.GetScreenMiddle());
            }
            else if (y == "bottom") {
                this.SetTop(this.GetScreenBottom());
            }
        }
    }
}
function my_CustomService(id, styleX, styleY, slide) {
    var position = new my_Position();
    if (id) {
        var str = "";
        str += '<table cellpadding="0px" cellspacing="0px" style="text-align:center;width:110px;">';
        str += '<tr><td height="55" background="/image/customService_t.gif"></td></tr>';
        str += '<tr><td height="24" background="/image/customService_m.gif">';
        str += QQ1("43512967");
        str += '</td></tr><tr><td height="24" background="/image/customService_m.gif">';
        str += WangWang1("colorrabbit");
        str += '</td></tr><tr><td height="42" background="/image/customService_m.gif">';
        str += MSN1();
        str += '</td></tr><tr><td id="customServiceButton" style="cursor:pointer;text-decoration:underline;color:#333333;" height="22" onclick="this.CS" background="/image/customService_m.gif"><select id="' + id + 'Select"><option>客服移到</option><option value="left_top">左上</option><option value="left_middle">左中</option><option value="left_bottom">左下</option><option value="center_top">中上</option><option value="center_middle">中间</option><option value="center_bottom">中下</option><option value="right_top">右上</option><option value="right_middle">右中</option><option value="right_bottom">右下</option></select></td></tr><tr><td height="21" background="/image/customService_b.gif"></td></tr></table>';
        $(id).innerHTML = str;
        position.Init(id, styleX, styleY, slide);
        setInterval(customServiceInterval, 10);
        document.getElementById(id + "Select").onchange = moveCustomService;
    }
    function MoveTo(x, y) {
        position.MoveTo(x, y);
    }
    this.SetSlide = function(slide) {
        position.SetSlide(slide);
    }
    function moveCustomService() {
        var dom = document.getElementById(id + "Select");
        var temp = dom.options[dom.selectedIndex].value;
        if (temp != "") {
            var arr = temp.split("_");
            MoveTo(arr[0], arr[1]);
            var cookie = new my_Cookie();
            cookie.Set("customService", temp);
        }
    }
    function customServiceInterval() {
        position.MoveTo(position.GetStyleX(), position.GetStyleY());
    }
    this.QQ = function(qq, style) {
        return QQ1(qq, style)
    }
    function QQ1(qq, style) {
        if (qq != null && qq.length > 0) {
            if (style == "s") {
                style = "4";
            }
            else {
                style = "1";
            }
            return "<a href='tencent://message/?uin=" + qq + "&Site=" + qq + "&Menu=yes'><img class='customServiceImage' border='0' src='http://wpa.qq.com/pa?p=1:" + qq + ":" + style + "' alt='QQ:" + qq + "'/></a>";
        }
        else {
            return "";
        }
    }
    this.MSN = function(msn) {
        return MSN1(msn);
    }
    function MSN1(msn) {
        if (msn != null && msn.length > 0) {
            return "<a target='_blank' href='http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=" + msn + "&mkt=zh-cn'><img class='customServiceImage' alt='MSN:" + msn + "' style='border-style: none;' src='http://messenger.services.live.com/users/" + msn + "/presenceimage?mkt=zh-cn'/></a>";

        }
        else {
            return '<iframe scrolling="no" frameborder="0" src="/msn.htm" width="80" height="32"></iframe>';
        }
    }
    this.WangWang = function(wangwang, style) {
        return WangWang1(wangwang, style);
    }
    function WangWang1(wangwang, style) {
        if (wangwang != null && wangwang.length > 0) {
            if (style == "s") {
                style = "2";
            }
            else {
                style = "1";
            }
            return "<a target='_blank' href='http://amos.im.alisoft.com/msg.aw?v=2&uid=" + wangwang + "&site=cntaobao&s=1&charset=utf-8'><img class='customServiceImage' alt='旺旺:" + wangwang + "' border='0' src='http://amos.im.alisoft.com/online.aw?v=2&uid=" + wangwang + "&site=cntaobao&s=" + style + "&charset=utf-8'/></a>";
        }
        else {
            return "";
        }
    }
}
function refurbishCheckCode() {
    var c = new my_CheckCode();
    c.Refurbish();
}
function checkCheckCode() {
    var c = new my_CheckCode();
    return c.Check();
}
function my_CheckCode() {
    this.Check = function() {
        var checkCodeInfo = document.getElementById("checkCodeInfo");
        var cookie = new my_Cookie();
        var c1 = document.getElementById("checkCode").value.toLowerCase();
        var c2 = cookie.Get("checkCode").toLowerCase();
        if (c1.length == 0) {
            checkCodeInfo.innerHTML = "验证码不能为空！";
            return false;
        }
        else if (c1 == c2) {
            checkCodeInfo.innerHTML = "<img src='/image/register_right.gif'/>";
            return true;
        }
        else {
            checkCodeInfo.innerHTML = "验证码错误！";
            return false;
        }
    }
    this.Refurbish = function() {
        var randomnum = Math.random();
        var imgCheckCode = document.getElementById("imgCheckCode");
        imgCheckCode.src = "/checkCode.aspx?" + randomnum;
    }
}
function searchResultOnmouseover(tr) {
    tr.style.backgroundColor = "#eeeeee";
}
function searchResultOnmouseout(tr) {
    tr.style.backgroundColor = "#ffffff";
}
function my_Date() {
    this.ChineseDate = function(v) {
        var dt = new Date(v);
        var m = "0" + (dt.getMonth() + 1);
        var d = "0" + dt.getDate();
        return dt.getFullYear() + "年" + m.substring(m.length - 2) + "月" + d.substring(d.length - 2) + "日 ";
    }
    this.ChineseDateWithHour = function(v) {
        var dt = new Date(v);
        var m = "0" + (dt.getMonth() + 1);
        var d = "0" + dt.getDate();
        var h = "0" + dt.getHours();
        return dt.getFullYear() + "年" + m.substring(m.length - 2) + "月" + d.substring(d.length - 2) + "日" + h.substring(h.length - 2) + "点";
    }
    this.ChineseDateWithMinute = function(v) {
        var dt = new Date(v);
        var m = "0" + (dt.getMonth() + 1);
        var d = "0" + dt.getDate();
        var h = "0" + dt.getHours();
        var mi = "0" + dt.getMinutes();
        return dt.getFullYear() + "年" + m.substring(m.length - 2) + "月" + d.substring(d.length - 2) + "日" + h.substring(h.length - 2) + "点" + mi.substring(mi.length - 2) + "分";
    }
    this.ChineseDateWithSecond = function(v) {
        var dt = new Date(v);
        var m = "0" + (dt.getMonth() + 1);
        var d = "0" + dt.getDate();
        var h = "0" + dt.getHours();
        var mi = "0" + dt.getMinutes();
        var s = "0" + dt.getSeconds();
        return dt.getFullYear() + "年" + m.substring(m.length - 2) + "月" + d.substring(d.length - 2) + "日" + h.substring(h.length - 2) + "点" + mi.substring(mi.length - 2) + "分" + s.substring(s.length - 2) + "秒";
    }
    this.ChineseDayOfWeek = function(v) {
        var dt = new Date(v);
        return "星期" + "天一二三四五六 ".charAt(dt.getDay());
    }
    this.DateString = function(v) {
        var dt = new Date(v);
        var m = "0" + (dt.getMonth() + 1);
        var d = "0" + dt.getDate();
        return dt.getFullYear() + m.substring(m.length - 2) + d.substring(d.length - 2);
    }
    this.Compare = function(str1, str2) {
        var d1 = new Date(str1);
        var d2 = new Date(str2);
        if (Date.parse(d1) - Date.parse(d2) > 0) {
            return 1;
        }
        else if (Date.parse(d1) - Date.parse(d2) == 0) {
            return 0;
        }
        else {
            return -1;
        }
    }
}
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

