﻿function H$(i) { return document.getElementById(i) }
function H$$(c, p) { return p.getElementsByTagName(c) }
var scrollDiv = function() {
    function init(o) {
        this.id = o.id;
        this.at = o.auto ? o.auto : 3;
        this.o = 0;
        this.pos();
    }
    init.prototype = {
        pos: function() {
            clearInterval(this.__b);
            this.o = 0;
            var el = H$(this.id), li = H$$('li', el), l = li.length;
            var _t = li[l - 1].offsetHeight;
            var cl = li[l - 1].cloneNode(true);
            cl.style.opacity = 0; cl.style.filter = 'alpha(opacity=0)';
            el.insertBefore(cl, el.firstChild);
            el.style.top = -_t + 'px';
            this.anim();
        },
        anim: function() {
            var _this = this;
            this.__a = setInterval(function() { _this.animH() }, 20);
        },
        animH: function() {
            var _t = parseInt(H$(this.id).style.top), _this = this;
            if (_t >= -1) {
                clearInterval(this.__a);
                H$(this.id).style.top = 0;
                var list = H$$('li', H$(this.id));
                H$(this.id).removeChild(list[list.length - 1]);
                this.__c = setInterval(function() { _this.animO() }, 20);
                //this.auto();
            } else {
                var __t = Math.abs(_t) - Math.ceil(Math.abs(_t) * .07);
                H$(this.id).style.top = -__t + 'px';
            }
        },
        animO: function() {
            this.o += 2;
            if (this.o == 100) {
                clearInterval(this.__c);
                H$$('li', H$(this.id))[0].style.opacity = 1;
                H$$('li', H$(this.id))[0].style.filter = 'alpha(opacity=100)';
                this.auto();
            } else {
                H$$('li', H$(this.id))[0].style.opacity = this.o / 100;
                H$$('li', H$(this.id))[0].style.filter = 'alpha(opacity=' + this.o + ')';
            }
        },
        auto: function() {
            var _this = this;
            this.__b = setInterval(function() { _this.pos() }, this.at * 1000);
        }
    }
    return init;
} ();

document.execCommand("BackgroundImageCache", false, true);
    $(function() {
        $("#searchinput").keydown(function(event) {
            if (event.keyCode == 13) {
                $("#btnSearchStock").click();
            }
        });
    });

    function IndexSearch(i) {
        var searchinput = $("#searchinput").val();
        if (searchinput.length == 0 || searchinput == "输入代码或名称") {
            alert("请输入代码或名称！");
            return;
        }
        if (i == 0) {    //行情
            $.get('/Ajaxpage/Public/Stock.aspx', { Oper: "StockExists", stock: searchinput },
            function(data, status) {
                var d = eval("(" + data + ")");
                if (!d.res)//不存在
                    alert(d.des);
                else
                    window.location.href = "http://hudong.wlstock.com/StockBar/" + d.des + ".aspx";
            });
        }
        else {
            window.location.href = "http://hudong.wlstock.com/Hudong/SearchEx.aspx?type=0&Keyword=" + encodeURIComponent(searchinput);
        }
    }

/*检查用户是否登录*/
function CheckLogin() {
    $.get('/Ajaxpage/Register/Login.aspx', { Oper:"CheckLogin"},
        function(data, status) {
        var d = eval("("+data+")");
        if(d.res==1)//已经登录
        {
            $("#lblUserName").html(d.userName);
            $("#NotLogin").hide();
            $("#IsLogin").show();
        }
    });
}

/*登录用户注销登录*/
function SignOut() {
    $.get('/Ajaxpage/Register/Login.aspx', { Oper:"SignOut"},
        function(data, status) {
            var d = eval("("+data+")");
            if(d.res==1)//成功注销
            {
                $("#NotLogin").show();
                $("#IsLogin").hide();
            }
        });
}

/*验证输入*/
function f_CheckInput(){
    var userName=$("#username").val();
    var password=$("#password").val();
    if(userName==""){alert("请输入用户名！");return;}
    else if(password==""){alert("请输入密码！");return;}
    else{HeaderLogin();}
}

/*头文件中的登录操作*/
function HeaderLogin() {
    $.get('/Ajaxpage/Register/Login.aspx', { Oper:"Login",userName:$("#username").val(),password:$("#password").val(),ValidFlag:false},
        function(data, status) {
        var d = eval("(" + data + ")");
        if (d.res == 0)//失败
            alert(d.des);
        if (d.res == -1)//用户类型错误
            alert(d.des);
        if (d.res == -2)
            location.href = "/Register/RefuseLogin.aspx";
        if (d.res == 2)
            window.location.href = "/Register/Register_ByMobile2.aspx?M=" + d.des;
        if (d.res == 1)//登录成功
        {
            $("#lblUserName").html($("#username").val());
            $("#username").val(''); $("#password").val('');
            $("#NotLogin").hide();
            $("#IsLogin").show();
            window.open("http://FuWu.wlstock.com");
        }
    });
}

/*加入收藏夹*/
/*sURL:收藏地址*/
/*sTitle:标题*/
function AddFavorite(sURL, sTitle) 
{ 
    try 
    { 
        window.external.addFavorite(sURL, sTitle); 
    } 
    catch (e) 
    { 
        try 
        { 
            window.sidebar.addPanel(sTitle, sURL, ""); 
        } 
        catch (e) 
        { 
            alert("请使用Ctrl+D进行添加"); 
        } 
    } 
} 
