﻿//购买操作记录函数
function MasterRecoder(masterID, coin, currentCoin, vip) 
{
    if (vip == 'True') 
    {
        coin = 0;
    }
    if (coin > 0) 
    {
        Dialog.Confirm('查看该用户的操作记录需要' + coin + '个金币，需购买才能查看，确定购买？', function() 
        {
            if (!IsLogined) 
            {
                Dialog.Tip('对不起，您还未登录，按确定登录！', 'Alert', function() 
                {
                    UserLogin();
                });
                return;
            }

            if (currentCoin < coin) 
            {
                Dialog.Tip('对不起，购买需要 ' + coin + ' 个金币，您当前只有 ' + currentCoin + ' 个金币，请到充值中心：<a href="http://pay.lqz.cn/Topup.aspx" target="_blank">http://pay.lqz.cn</a>充值。', 'Alert');
            }
            else 
            {
                //by shuaishuai 需要在本页面完成购买 2010-02-22
                //创建一个虚拟的input，用于post
                DomNode.AddButtonToForm('tbMasterID', masterID, 'form_buyuserrecord');
                AjaxRequest.Post('btBuyUserRecord', function(content) 
                {
                    if (content['Status'] == 'Success') 
                    {
                        Dialog.Tip('购买成功，您已被扣除 ' + coin + ' 金币，可以查看该用户的操作记录了', 'Success', function() 
                        {
                            var returnUrl = StringHelper.Clear(location.href, '#');
                            GoUrl(returnUrl);
                        });
                    }
                    else 
                    {
                        Dialog.Tip(content['Tip'], content['Status']);
                    }
                });
                //location.href = url;
            }
        });

    }
    else 
    {
        Dialog.Confirm('确定要收藏吗？', function() 
        {
            if (!IsLogined) 
            {
                Dialog.Tip('对不起，您还未登录，按确定登录！', 'Alert', function() 
                {
                    UserLogin();
                });
                return;
            }

            DomNode.AddButtonToForm('tbMasterID', masterID, 'form_buyuserrecord');
            AjaxRequest.Post('btBuyUserRecord', function(content) 
            {
                if (content['Status'] == 'Success') 
                {
                    Dialog.Tip('收藏成功', 'Success');
                }
                else 
                {
                    Dialog.Tip(content['Tip'], content['Status']);
                }
            });


        });
    }
}

function getsum() {
    $('.vTotal').each(function(i) {
        var vTotal = 0;
        $(this).parent().parent()
    .find('td:nth-child(' + (i + 8) + '),th:nth-child(' + (i + 8) + ')')
    .each(function(i) {
        if (!isNaN($(this).text())) {
            vTotal += parseFloat($(this).text());
        }
    });
    var value = vTotal.toString();
    if (value.indexOf(".") > 0) {
        value = value.substring(0, value.indexOf(".") + 3);
    }
        $('#sum').html(value);
    });
}

function checkUserLogin() {
    if (!IsLogined) {
        Dialog.Tip("该操作需要登录，您还没有登陆，点击确定立即登陆", "Alert", function() 
        {
            UserLogin();
        });
        return false;
    }
    return true;
}


function OperaStock(flag) {
    if (checkUserLogin()) {
        if (flag == 0) {
            Dialog.Show('买入股票', '700', '540', '/Dialog/_PracticeBuy.aspx');
        }
        if (flag == 1) {
            Dialog.Show('卖出股票', '700', '540', '/Dialog/_PracticeSell.aspx');
        }
        if (flag == 2) {
            Dialog.Show('撤销委托', '760', '540', '/Dialog/_PracticeCancel.aspx');
        }
        if (flag == 3) {
            Dialog.Show('成交委托', '760', '560', '/Dialog/_PracticeDeal.aspx');
        }
        if (flag == 4) {
            location.href = "/PracticeAccount.aspx";
        }
        if (flag == 5) {
            location.href = "/PracticeIndex.aspx";
        }
    }
}

function MatchOperaStock(flag, matchID) {
    if (checkUserLogin()) {
        if (flag == 0) {
            Dialog.Show('买入股票', '700', '540', '/Dialog/_MatchBuy.aspx?matchID='+matchID);
        }
        if (flag == 1) {
            Dialog.Show('卖出股票', '700', '540', '/Dialog/_MatchSell.aspx?matchID=' + matchID);
        }
        if (flag == 2) {
            Dialog.Show('撤销委托', '760', '540', '/Dialog/_MatchCancel.aspx?matchID=' + matchID);
        }
        if (flag == 3) {
            Dialog.Show('成交委托', '760', '560', '/Dialog/_MatchDeal.aspx?matchID=' + matchID);
        }
    }
}

function UserLogin() {
    Dialog.Show('用户登陆', '350', '220', '/Dialog/_UserLogin.aspx');
}

function Regeister() {
    Dialog.Show('用户注册', '450', '240', '/Dialog/_Register.aspx');
}

//设置选择菜单
function setlichoose(id) {
    $('#divdaohang > li').each(function(){
        $(this).attr('class','itemhover1');
    });
    $('#'+id).attr('class','itemhover2');
}

$(function() {
    $('#a_regiter').click(function() {
        Regeister();
    });
    
    $('#a_msg').click(function() {
        Dialog.Show('我的消息', '650', '450', '/Dialog/_Messages.aspx');
    });

    $('#a_event').click(function() {
        Dialog.Show('操作事件', '600', '350', '/Dialog/_MyActionEvents.aspx');
    });

    $('#a_record').click(function() {
        Dialog.Show('日收益记录', '700', '440', '/Dialog/_PracticeProfit.aspx');
    });

    $('#a_masters').click(function() {
        Dialog.Show('高手收藏', '600', '400', '/Dialog/_PracticeMasterRecords.aspx?type=1');
    });
    
    if ($('#txtkeywords').length) {
        $('#txtkeywords').bind('keydown', 'return', function() {
            searchdata();
            return false;
        });
    }

    $('#a_useraction').click(function() {
    Dialog.Show('高手动态', '650', '400', '/Dialog/_PracticeMasterRecords.aspx?type=2');
    });
    
    
    
    //注册顶部菜单mouseover,out事件
    $('#divdaohang > li').each(function(){
        if($(this).attr('class')=='itemhover2'){
            return;
        }
        $(this).mouseover(function(){
            $(this).attr('class','itemhover2');
        }).mouseout(function(){
            $(this).attr('class','itemhover1');
        });
    });
    AjaxTip.Hide();
    
});

//退出登录 by shuaishuai 2010-02-22
function loginout(url) {
    AjaxRequest.Get(url,function(content){
        var returnUrl = StringHelper.Clear(location.href, '#');
        GoUrl(returnUrl);
    });
}

//查看公告
function ShowNotice(url,title){
    Dialog.Show(title, '700', '400', url);
}

//查看公告列表
function ShowAllNotice(url){
    Dialog.Show('所有公告列表', '650', '400', url);
}

//查看比赛奖励和介绍
function ShowMatchIntro(matchID, type) {
    if (type == 0) {
        Dialog.Show('比赛奖项设置', '500', '300', '/Dialog/_ShowMatchIntro.aspx?type=0&MatchID=' + matchID);
    }
    else {
        Dialog.Show('比赛简介', '500', '300', '/Dialog/_ShowMatchIntro.aspx?type=1&MatchID=' + matchID);
    }
}
//发布个股博弈,我发布的博弈
function ShowGuess(type,flag,opentime) {
    if (!IsLogined) {
        UserLogin();
        return;
    }
    if (type == 0) {
        if (opentime == 'True') {
            Dialog.Show('发布个股博弈', '400', '220', '/Dialog/_CreateGuessStock.aspx');
        }
        else {
            Dialog.Tip('对不起,当前不能发布博弈', 'Alert');
        }
    }
    if (type == 1) {
        Dialog.Show('我发布的博弈', '760', '500', '/Dialog/_CreateGuessStock.aspx?flag=true');
    }
}
//查看用户博弈信息
function ShowGuessUserInfo(userID, userName) {
    if (!IsLogined) {
        UserLogin();
        return;
    }
    Dialog.Show(userName+'的博弈信息', '700', '500', '/Dialog/_ShowGuessUser.aspx?UserID=' + userID);
}

//创建比赛,我创建的比赛，我参加的比赛
function MatchOperat(type) {
    if (!IsLogined) {
        UserLogin();
        return;
    }
    if (type == 0) {
        Dialog.Show('创建比赛', '600', '500', '/Dialog/_CreateMatch.aspx');
    }
    if (type == 1) {
        Dialog.Show('我创建的比赛', '650', '450', '/Dialog/_MyCreateMatch.aspx');
    }
    if (type == 2) {
        Dialog.Show('我参加的比赛', '600', '400', '/Dialog/_MyMatch.aspx');
    }
}
//荐股弹窗
function Recomond(type, uID,userName) 
{
    if (!IsLogined) 
    {
        UserLogin();
        return;
    }
    if (type == 0) 
    {
        Dialog.Show('发布荐股', '500', '315', '/Dialog/_CreateRecomondStock.aspx');
    }
    else 
    {
        if (uID > 0) 
        {
            Dialog.Show(userName+'发布的荐股', '800', '500', '/Dialog/_MyRecomondStock.aspx?userID=' + uID);
        } 
        else 
        {
            Dialog.Show('我发布的荐股', '800', '500', '/Dialog/_MyRecomondStock.aspx');
        }
    }
}
//升级vip会员
function GetVip(url)
{
    if(!IsLogined){
        UserLogin();
        return;
    }
    Dialog.Show('升级为VIP会员', '480', '360',url);
}

//设置查看权限
function SetPermission(url)
{
    if(!IsLogined){
        UserLogin();
        return;
    }
    Dialog.Show('设置操作记录查看权限', '420', '330',url);
}

function BindStockStyleEnterEvent(){
    //by shuaishuai 注册投资风格设置回车事件 2010-02-22
    if ($('#tbStockstyle').length) {
        $('#tbStockstyle').bind('keydown', 'return', function() {
            $('#btStockStyle').click();
            return false;
        });
    }
}

function UpdateStockStyle(){
    if($('#tbStockstyle').val()==''){
        Dialog.Tip('投资风格不能为空');
        return;
    }
    
    AjaxRequest.Post('btStockStyle','ap_userinfo');
}


//滚动
function startMarquee(h, speed, delay, sid) {
    var t = null;
    var p = false;
    var o = document.getElementById(sid);
    o.innerHTML += o.innerHTML;
    o.onmouseover = function() { p = true }
    o.onmouseout = function() { p = false }
    o.scrollTop = 0;
    function start() {
        t = setInterval(scrolling, speed);
        if (!p) {
            o.scrollTop += 2;
        }
    }
    function scrolling() {
        if (p) return;
        if (o.scrollTop % h != 0) {
            o.scrollTop += 2;
            if (o.scrollTop >= o.scrollHeight / 2) o.scrollTop = 0;
        } else {
            clearInterval(t);
            setTimeout(start, delay);
        }
    }
    setTimeout(start, delay);
}


function searchdata() {
    if(!checkUserLogin()){
        return;
    }
    var typeID = $('#slcsearchtype').val();
    var key = $('#txtkeywords').val();
    if (key.length > 0 && key !='请输入关键字') {
        //练习区搜索
        GoUrl('SearchList.aspx?type=' + typeID + '&key=' + key);
    }
}

//历届比赛冠军
function moerwinusers() {
    Dialog.Show('老钱庄炒股比赛历届冠军', '760', '500', '/Dialog/_WinUsers.aspx');
}



//查看用户创建的比赛
function showUserMatch(userID, userName) {
    if (!checkUserLogin()) {
        return;
    }
    if (userID == 328482) {
        Dialog.Show(userName, '760', '500', '/Dialog/_ShowUserMatchs.aspx?userID=' + userID)
    }
    else {
        Dialog.Show(userName + '创建的比赛', '760', '500', '/Dialog/_ShowUserMatchs.aspx?userID=' + userID)
    }
}

function SetBuyPrice(val){
    $('#txtbuyprice').val(val);
}
///比赛导航选中
function setMatchUserMenuSelected(id) {
    $('#match_usermenu > li').each(function() {
        $(this).attr('class', 'itemback2_sk');
    });
    $('#' + id).attr('class', 'itemback2_sk2');
}

///弹出高手买卖股票操作对话框
function MasterOperaStock(flag) {
    if (checkUserLogin()) {
        if (flag == 0) {
            Dialog.Show('买入股票', '700', '540', '/Dialog/_MasterBuy.aspx');
        }
        if (flag == 1) {
            Dialog.Show('卖出股票', '700', '540', '/Dialog/_MasterSell.aspx');
        }
        if (flag == 2) {
            Dialog.Show('撤销委托', '760', '540', '/Dialog/_MasterCancel.aspx');
        }
        if (flag == 3) {
            Dialog.Show('成交委托', '760', '560', '/Dialog/_MasterDeal.aspx');
        }
    }
}
function MatchCheckCode(matchID) 
{
    if (!IsLogined) 
    {
        checkUserLogin();
        return;
    }
    Dialog.Show('检查比赛口令', '400', '150', '/Dialog/_CheckJionCode.aspx?matchID='+matchID);
}

///父窗口跳转
function jumpUrl() {
    var returnUrl = parentWindow.location.href;
    returnUrl = StringHelper.Clear(returnUrl, '#')
    parentWindow.GoUrl(returnUrl);
}