﻿var refreshTimeMySub = 100000;
var currentButton = null;
var isNoFloat = null;
var subscriptionSetDialog;
var stockCoinTopUpDialog;
var UsersGradeGoupDialog;
var SubScriptionUserDialog;
var CompleteOperateDialog;
var SubscriptionRemindDialog;
var UserBugBackDialog; //用户意见反馈对话框
var InvestmentStyleDialog;
var BuyMsgDialog;
var ReplyMsgDialog;
var ApplyFinancingDialog;
var SetUserNameAndPWDBox;
var UploadImageBox;
var Msg = {
    showSubscriptionSet: function () {
        subscriptionSetDialog = new DialogBox(
        { type: 'Url', value: '/dialog/SubscriptionSet.aspx' + '?_' + Math.random() }, { showTitle: true, title: '我的订阅设置', width: 705, height: 340 }
        );
        subscriptionSetDialog.show();
    },
    stockCoinTopUp: function () {
        stockCoinTopUpDialog = new DialogBox(
        { type: 'Url', value: '/dialog/StockCoinTopUp.aspx' + '?_' + Math.random() }, { showTitle: true, title: '股币兑换', width: 466, height: 342 }
        );
        stockCoinTopUpDialog.show();
    },
    UsersGradeGoup: function () {
        UsersGradeGoupDialog = new DialogBox(
        { type: 'Url', value: '/dialog/UsersGradeGoup.aspx' + '?_' + Math.random() }, { showTitle: true, title: '升级为富豪', width: 465, height: 210 }
        );
        UsersGradeGoupDialog.show();
    },
    SubScriptionUser: function (userID) {
        SubScriptionUserDialog = new DialogBox(
        { type: 'Url', value: '/dialog/SubScriptionUser.aspx?subUserID=' + userID + '&_' + Math.random() },
        {
            showTitle: true,
            title: '用户订阅',
            width: 535,
            height: 340,
            loadFinish: function () { return true; }
        }
        );
        subscriptCoin();
        SubScriptionUserDialog.show();
    },
    CompleteOperate: function (id, title) {
        CompleteOperateDialog = new DialogBox(
        { type: 'Url', value: '/dialog/CompleteOperateDialog.aspx?completeID=' + id + '&_' + Math.random() }, { showTitle: true, title: title, width: 775, height: 190 }
        );
        CompleteOperateDialog.show();
    },
    SubscriptionRemind: function (id) {
        SubscriptionRemindDialog = new DialogBox(
        { type: 'Url', value: '/dialog/SubscriptionRemind.aspx' + '?_' + Math.random() }, { showTitle: true, title: '订阅提醒设置', width: 510, height: 220 }
        );
        SubscriptionRemindDialog.show();
    },
    SubscriptionRemind_ShiPan: function (id) {
        SubscriptionRemindDialog = new DialogBox(
        { type: 'Url', value: '/ShiPan/dialog/SubscriptionRemind.aspx' + '?_' + Math.random() }, { showTitle: true, title: '实盘订阅提醒设置', width: 510, height: 220 }
        );
        SubscriptionRemindDialog.show();
    },
    UserBugBackSubmit: function () {
        UserBugBackDialog = new DialogBox(
        { type: 'Iframe', value: '/dialog/UserBugSubmit.aspx' + '?_' + Math.random() },
        {
            showTitle: true,
            title: '意见反馈',
            width: 464,
            height: 480
        }
        );
        UserBugBackDialog.show();
        uploadIndex = 0;
    },
    InvestmentStyle: function () {
        InvestmentStyleDialog = new DialogBox(
        { type: 'Url', value: '/dialog/InvestmentStyleDialog.aspx' + '?_' + Math.random() }, { showTitle: true, title: '投资风格设置', width: 310, height: 220 }
        );
        InvestmentStyleDialog.show();
    },
    BuyMsg: function (closeCallback, IsCheckPhone) {
        if (IsCheckPhone == 0) {
            location.href = 'http://u.laoqianzhuang.com/phonecheck.aspx';
        }
        else {
            BuyMsgDialog = new DialogBox(
            { type: 'Url', value: '/dialog/BuyMsgDialog.aspx' + '?_' + Math.random() },
            { showTitle: true, title: '购买手机短信通知', width: 396, height: 330, afterClose: function () {
                if (closeCallback) {
                    var isChecked = $("#IsPhoneMsgRemind")[0].checked;
                    AjaxRequest.Get("/dialog/SubscriptionRemind.aspx", "PhoneSet_Panel", function () {
                        $("#IsPhoneMsgRemind")[0].checked = isChecked;
                    });
                }
            },
                loadFinish: function () { $("#buyMsgDialogCoin").html(currentUserCoin); return true; }
            }
            );
            BuyMsgDialog.show();
        }
    },
    ReplyUserBug: function (ID) {
        ReplyMsgDialog = new DialogBox(
        { type: 'iframe', value: '/dialog/ReplyUserBug.aspx' + '?ID=' + ID + '&_' + Math.random },
        { showTitle: true, title: '回复用户意见反馈', width: 464, height: 280 }
        );
        ReplyMsgDialog.show();
    },
    ApplyMoneyBox: function () {
        ApplyMoneyDialog = new DialogBox(
        { type: 'Url', value: '/dialog/ApplyMoneyBox.aspx' + '?_' + Math.random },
        { showTitle: true, title: '申请万元操盘', width: 396, height: 310 }
        );
        ApplyMoneyDialog.show();
    },
    ApplyFinancing: function () {
        ApplyFinancingDialog = new DialogBox(
        { type: 'url', value: '/dialog/ApplyFinancingDialog.aspx?' + '&_' + Math.random },
        { showTitle: true, title: '申请开通融资融券', width: 464, height: 280, loadFinish: function () { return true; } }
        );

        ApplyFinancingDialog.show();
    },
    SendMessageBox: function (userRecomID, gotoUserID) {
        SendMessageBoxDialog = new DialogBox(
        { type: 'url', value: '/dialog/SendMessageBox.aspx?UserRecomID=' + userRecomID + '&GetUserID=' + gotoUserID + '&_' + Math.random },
        { showTitle: true, title: '信息发送', width: 300, height: 187, loadFinish: function () { return true; } }
        );

        SendMessageBoxDialog.show();
    },
    SetUserNameAndPWD: function (id) {
        SetUserNameAndPWDBox = new DialogBox(
        { type: 'Iframe', value: '/dialog/SetUserNameAndPWD.aspx' + '?id=' + id + '&_' + Math.random() },
        {
            showTitle: true,
            title: '验证用户实盘申请',
            width: 264,
            height: 180
        }
        );
        SetUserNameAndPWDBox.show();
        uploadIndex = 0;
    },
    UploadImage: function () {
        UploadImageBox = new DialogBox(
        { type: 'Iframe', value: '/dialog/UploadImageBox.aspx' + '?_' + Math.random() },
        { showTitle: true, title: '上传图片', width: 464, height: 180, loadFinish: function () { return true; } }
        );

        UploadImageBox.show();
    }
}

function subscriptCoin() {

    UserData.getCoin(uid, function () {
        $("#subSriptionDialogCoin").html(Pay.Coin);
        $("#coin").val(Pay.Coin);
    });
}
//去掉前后空格
String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去掉左空格
String.prototype.leftTrim = function () {
    return this.replace(/^\s*/g, "");
}
//去掉右空格
String.prototype.rightTrim = function () {

    return this.replace(/\s*$/g, "");
}
//查检表单是否为空或空格,空返回false,反之true
String.prototype.isEmpty = function () {
    valueResult = this.trim();
    return valueResult.length == 0 ? true : false;
}
//Email验证
String.prototype.isEmail = function () {
    var exp = new RegExp("^\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", "ig");
    return exp.test(this);
}
//是否是数字
String.prototype.isNumber = function () {
    return /^\d+$/ig.test(this);
}
//是否是正整数或正小数
String.prototype.isDecimal = function () {
    return /^(\d+)|(\d+\.\d+)$/ig.test(this);
}
//验证电话号码和手机号码
String.prototype.isTelephone = function () {
    var exp = new RegExp("^(^(\\d{3,4})?\\d{7,8})$|(1[0-9]{10})$", "ig");
    return exp.test(this);

}
//验证日期
String.prototype.isDate = function () {
    var result = this.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/)
    //    var exp = new RegExp("^[\d]{ 4 }[\\-\/]{ 1 }[\\d]{ 1,2 }[\\-\/]{ 1 }[\\d]{ 1,2 }$", "ig");
    //    return exp.test(this);
    if (result == null) {
        return false;
    }
    else {
        return true;
    }

}
//打开URL
function GoUrl(url) {
    location.href = url;
}


function LogOut() {
    GoUrl("/SynLogin.aspx?action=logOut");
}

function gotoSubscription(userID, button, NoFloat) {

    AjaxRequest.Get("/SubscriptionUser.aspx?action=subscription&subUserID=" + userID, function (content) {
        if (content['Status'] == 'Success') {
            if (content['Tip'].indexOf("订阅成功") >= 0) {
                if (button) {
                    setSubScriptionButton(button);
                }
                if (NoFloat || isNoFloat == null) {
                }
                else {
                    $(button).css("float", "right");
                    $(button).css("margin-right", "5px");
                }
                Dialog.Success(content['Tip']);
            }
            else if (content['Tip'] == "验证成功") {
                if (button) {
                    currentButton = button;
                }

                Msg.SubScriptionUser(userID);
                // location.href = "/SubscriptionUser.aspx?subUserID=" + userID;
            }
            else {
                Dialog.Success(content['Tip']);
            }
        }
        else if (content['Tip'].indexOf("超出限制") >= 0) {
            Dialog.Alert(content['Tip'], function () {
                Msg.SubScriptionUser(userID);
            });
        }
        else if (content['Status'] == 'Alert') {
            Dialog.Alert(content['Tip']);
        }
        else {
            if (content['Tip'].indexOf("请登录后操作") >= 0) {
                Dialog.Fail(content['Tip'], function () { location.href = 'http://bbs.laoqianzhuang.com/member.php?mod=logging&action=login&referer=http%3A//s.laoqianzhuang.com/Account.aspx'; });
            }
            else {
                Dialog.Fail(content['Tip']);
            }
        }

    });
}

function gotoSubscriptionForIndex(userID, button, NoFloat) {
    AjaxRequest.Get("/SubscriptionUser.aspx?action=subscription&subUserID=" + userID, function (content) {
        if (content['Status'] == 'Success') {
            if (content['Tip'].indexOf("订阅成功") >= 0) {
                if (button) {
                    $(button).html('已订阅');
                }
                Dialog.Success(content['Tip']);
            }
            else if (content['Tip'] == "验证成功") {
                if (button) {
                    currentButton = button;
                }

                Msg.SubScriptionUser(userID);
                // location.href = "/SubscriptionUser.aspx?subUserID=" + userID;
            }
        }
        else if (content['Tip'].indexOf("超出限制") >= 0) {
            Dialog.Alert(content['Tip'], function () {
                Msg.SubScriptionUser(userID);
            });
        }
        else if (content['Status'] == 'Alert') {
            Dialog.Alert(content['Tip']);
        }
        else {
            if (content['Tip'].indexOf("请登录后操作") >= 0) {
                Dialog.Fail(content['Tip'], function () { location.href = "http://bbs.laoqianzhuang.com/member.php?mod=logging&action=login"; });
            }
            else {
                Dialog.Fail(content['Tip']);
            }
        }

    });
}

function setSubScriptionButton(button) {
    $(button).attr("disabled", true);
    $(button).removeClass("moodfm_btnpd3");
    $(button).removeClass("moodfm_btnpd1");
    $(button).addClass("moodfm_btnpd14");

    $(button).val("已订阅");
}

function ChangeSubscriptionMonth(perMonthNeedMoney, obj) {
    var currentValue = obj.options[obj.selectedIndex].value;
    var totalMoney = currentValue * perMonthNeedMoney;
    $("#subscriptMoney").text(totalMoney);
    $("#subscriptDays").text(currentValue * 30);
    $("#txtsubscriptMoney").val(totalMoney);
}

function submitSubscription(userID) {
    Dialog.Confirm("确定要订阅该用户?", function () {
        var needMoney = Number($("#txtsubscriptMoney").val());
        var youMoney = Number($("#coin").val());
        if (youMoney < needMoney) {
            Dialog.Alert("您的余额不足，不能订阅!");
            return;
        }
        AjaxRequest.Post("btOK", function (content) {
            if (content['Status'] == 'Success') {
                Dialog.Success(content['Tip']);
                setSubScriptionButton(currentButton);
                if (isNoFloat == null) {
                }
                else {
                    $(currentButton).css("float", "right");
                    $(currentButton).css("margin-right", "5px");
                }
                window.parent.SubScriptionUserDialog.close();
            }
            else if (content['Status'] == 'Alert') {
                Dialog.Alert(content['Tip']);
            }
            else {
                Dialog.Fail(content['Tip']);
            }

        });
    });
}

//新功能列表滚动
var currentShowFunction = 0;
var newFunctionCount = 7;
function ScrollFunction() {
    $('#dynamicInfoContainer > span').each(function (i) {
        if (currentShowFunction == i) {
            $(this).fadeIn('slow');
        } else {
            $(this).hide();
        }

    });
    if (currentShowFunction < newFunctionCount - 1) {
        currentShowFunction++;
    }
    else {
        currentShowFunction = 0;
    }
}


$(function () {
    var href = location.href;
    if (href.indexOf(".aspx") == -1) {
        href += "index.aspx"
    }
    AjaxRequest.Get(href, "dynamicInfoContainer", function () {
        ScrollFunction();
        setInterval(ScrollFunction, 5000);
    });
});

function SearchKeyDown() {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
        SearchClick();
    }
}

function LoginClick() {
    var UserName = $("#ls_username").val();
    var Pwd = $("#ls_password").val();
    if (UserName.isEmpty()) {
        Dialog.Alert("请输入用户名!");
        $("#ls_username").focus();
        return false;
    }
    if (UserName == 'UID/用户名/Email') {
        Dialog.Alert("请输入用户名!");
        $("#ls_username").focus();
        return false;
    }
    if (Pwd.isEmpty()) {
        Dialog.Alert("请输入密码!");
        $("#ls_password").focus();
        return false;
    }
    var IsSave;
    if ($("#ls_cookietime").attr("checked") == true) {
        IsSave = 1;
    }
    else {
        IsSave = 0;
    }

    AjaxRequest.Post("btCommonLogin", function (content) {
        if (content['Status'] == 'Success') {
            location.href = "/Account.aspx";
        }
        else {
            Dialog.Fail(content['Tip']);
        }
    });
}

function LoadFlash(width, height, userID) {
    var so = new SWFObject(ThemeVirtualPath + "/Scripts/Flash/amline.swf", "amline", width, height, "8", "#FFFFFF");
    so.addVariable("path", ThemeVirtualPath + "/Scripts/Flash/");
    so.addVariable("settings_file", encodeURIComponent(ThemeVirtualPath + "/Scripts/Flash/amline_settings.xml"));
    so.addVariable("data_file", encodeURIComponent(ThemeVirtualPath + "/FlashLineData.aspx?userID=" + userID + "&r=_" + Math.random()));
    so.addParam("wmode", "opaque");
    so.write("charts");
}

function hasStock() {
    AjaxRequest.Get("/SellStock.aspx?action=SellStock", function (content) {
        if (content['Status'] == 'Success') {
            location.href = "/SellStock.aspx";
        }
        else {
            Dialog.Fail(content['Tip']);
        }
    });
}



function showMenu(v) {
    var ctrlid = isUndefined(v['ctrlid']) ? v : v['ctrlid'];
    var showid = isUndefined(v['showid']) ? ctrlid : v['showid'];
    var menuid = isUndefined(v['menuid']) ? showid + '_menu' : v['menuid'];
    var ctrlObj = $(ctrlid);
    var menuObj = $(menuid);
    if (!menuObj) return;
    var mtype = isUndefined(v['mtype']) ? 'menu' : v['mtype'];
    var evt = isUndefined(v['evt']) ? 'mouseover' : v['evt'];
    var pos = isUndefined(v['pos']) ? '43' : v['pos'];
    var layer = isUndefined(v['layer']) ? 1 : v['layer'];
    var duration = isUndefined(v['duration']) ? 2 : v['duration'];
    var timeout = isUndefined(v['timeout']) ? 250 : v['timeout'];
    var maxh = isUndefined(v['maxh']) ? 600 : v['maxh'];
    var cache = isUndefined(v['cache']) ? 1 : v['cache'];
    var drag = isUndefined(v['drag']) ? '' : v['drag'];
    var dragobj = drag && $(drag) ? $(drag) : menuObj;
    var fade = isUndefined(v['fade']) ? 0 : v['fade'];
    var cover = isUndefined(v['cover']) ? 0 : v['cover'];
    var zindex = isUndefined(v['zindex']) ? JSMENU['zIndex']['menu'] : v['zindex'];
    var winhandlekey = isUndefined(v['win']) ? '' : v['win'];
    zindex = cover ? zindex + 200 : zindex;
    if (typeof JSMENU['active'][layer] == 'undefined') {
        JSMENU['active'][layer] = [];
    }

    if (evt == 'click' && in_array(menuid, JSMENU['active'][layer]) && mtype != 'win') {
        hideMenu(menuid, mtype);
        return;
    }
    if (mtype == 'menu') {
        hideMenu(layer, mtype);
    }

    if (ctrlObj) {
        if (!ctrlObj.initialized) {
            ctrlObj.initialized = true;
            ctrlObj.unselectable = true;

            ctrlObj.outfunc = typeof ctrlObj.onmouseout == 'function' ? ctrlObj.onmouseout : null;
            ctrlObj.onmouseout = function () {
                if (this.outfunc) this.outfunc();
                if (duration < 3 && !JSMENU['timer'][menuid]) JSMENU['timer'][menuid] = setTimeout('hideMenu(\'' + menuid + '\', \'' + mtype + '\')', timeout);
            };

            ctrlObj.overfunc = typeof ctrlObj.onmouseover == 'function' ? ctrlObj.onmouseover : null;
            ctrlObj.onmouseover = function (e) {
                doane(e);
                if (this.overfunc) this.overfunc();
                if (evt == 'click') {
                    clearTimeout(JSMENU['timer'][menuid]);
                    JSMENU['timer'][menuid] = null;
                } else {
                    for (var i in JSMENU['timer']) {
                        if (JSMENU['timer'][i]) {
                            clearTimeout(JSMENU['timer'][i]);
                            JSMENU['timer'][i] = null;
                        }
                    }
                }
            };
        }
    }

    var dragMenu = function (menuObj, e, op) {
        e = e ? e : window.event;
        if (op == 1) {
            if (in_array(BROWSER.ie ? e.srcElement.tagName : e.target.tagName, ['TEXTAREA', 'INPUT', 'BUTTON', 'SELECT'])) {
                return;
            }
            JSMENU['drag'] = [e.clientX, e.clientY];
            JSMENU['drag'][2] = parseInt(menuObj.style.left);
            JSMENU['drag'][3] = parseInt(menuObj.style.top);
            document.onmousemove = function (e) { try { dragMenu(menuObj, e, 2); } catch (err) { } };
            document.onmouseup = function (e) { try { dragMenu(menuObj, e, 3); } catch (err) { } };
            doane(e);
        } else if (op == 2 && JSMENU['drag'][0]) {
            var menudragnow = [e.clientX, e.clientY];
            menuObj.style.left = (JSMENU['drag'][2] + menudragnow[0] - JSMENU['drag'][0]) + 'px';
            menuObj.style.top = (JSMENU['drag'][3] + menudragnow[1] - JSMENU['drag'][1]) + 'px';
            doane(e);
        } else if (op == 3) {
            JSMENU['drag'] = [];
            document.onmousemove = null;
            document.onmouseup = null;
        }
    };

    if (!menuObj.initialized) {
        menuObj.initialized = true;
        menuObj.ctrlkey = ctrlid;
        menuObj.mtype = mtype;
        menuObj.layer = layer;
        menuObj.cover = cover;
        if (ctrlObj && ctrlObj.getAttribute('fwin')) { menuObj.scrolly = true; }
        menuObj.style.position = 'absolute';
        menuObj.style.zIndex = zindex + layer;
        menuObj.onclick = function (e) {
            if (!e || BROWSER.ie) {
                window.event.cancelBubble = true;
                return window.event;
            } else {
                e.stopPropagation();
                return e;
            }
        };
        if (duration < 3) {
            if (duration > 1) {
                menuObj.onmouseover = function () {
                    clearTimeout(JSMENU['timer'][menuid]);
                    JSMENU['timer'][menuid] = null;
                };
            }
            if (duration != 1) {
                menuObj.onmouseout = function () {
                    JSMENU['timer'][menuid] = setTimeout('hideMenu(\'' + menuid + '\', \'' + mtype + '\')', timeout);
                };
            }
        }
        if (cover) {
            var coverObj = document.createElement('div');
            coverObj.id = menuid + '_cover';
            coverObj.style.position = 'absolute';
            coverObj.style.zIndex = menuObj.style.zIndex - 1;
            coverObj.style.left = coverObj.style.top = '0px';
            coverObj.style.width = '100%';
            coverObj.style.height = document.body.offsetHeight + 'px';
            coverObj.style.backgroundColor = '#000';
            coverObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)';
            coverObj.style.opacity = 0.5;
            $('append_parent').appendChild(coverObj);
            _attachEvent(window, 'load', function () {
                coverObj.style.height = document.body.offsetHeight + 'px';
            }, document);
        }
    }
    if (drag) {
        dragobj.style.cursor = 'move';
        dragobj.onmousedown = function (event) { try { dragMenu(menuObj, event, 1); } catch (e) { } };
    }
    menuObj.style.display = '';
    if (cover) $(menuid + '_cover').style.display = '';
    if (fade) {
        var O = 0;
        var fadeIn = function (O) {
            if (O == 100) {
                clearTimeout(fadeInTimer);
                return;
            }
            menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
            menuObj.style.opacity = O / 100;
            O += 10;
            var fadeInTimer = setTimeout(function () {
                fadeIn(O);
            }, 50);
        };
        fadeIn(O);
        menuObj.fade = true;
    } else {
        menuObj.fade = false;
    }
    if (pos != '*') {
        setMenuPosition(showid, menuid, pos);
    }
    if (BROWSER.ie && BROWSER.ie < 7 && winhandlekey && $('fwin_' + winhandlekey)) {
        $(menuid).style.left = (parseInt($(menuid).style.left) - parseInt($('fwin_' + winhandlekey).style.left)) + 'px';
        $(menuid).style.top = (parseInt($(menuid).style.top) - parseInt($('fwin_' + winhandlekey).style.top)) + 'px';
    }
    if (maxh && menuObj.scrollHeight > maxh) {
        menuObj.style.height = maxh + 'px';
        if (BROWSER.opera) {
            menuObj.style.overflow = 'auto';
        } else {
            menuObj.style.overflowY = 'auto';
        }
    }

    if (!duration) {
        setTimeout('hideMenu(\'' + menuid + '\', \'' + mtype + '\')', timeout);
    }

    if (!in_array(menuid, JSMENU['active'][layer])) JSMENU['active'][layer].push(menuid);
    menuObj.cache = cache;
    if (layer > JSMENU['layer']) {
        JSMENU['layer'] = layer;
    }
}

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(hide, timeout);
}

function hide() {
    if (ddmenuitem) { ddmenuitem.hide(); }
}

function Show(id, currentObj) {
    mcancelclosetime();
    if (ddmenuitem) { ddmenuitem.hide(); }
    ddmenuitem = $("#" + id);
    ddmenuitem.show();
}

function SearchStock() {
    if ($("#headkeyword").val().isEmpty() || $("#headkeyword").val() == "请输入股票代码") {
        Dialog.Alert("请输入股票代码!");
        $("#headkeyword").focus();
    }
    if (!$("#headkeyword").val().isNumber()) {
        Dialog.Alert("请输入正确的股票代码!");
        $("#headkeyword").focus();
        return false;
    }
    if ($("#headkeyword").val().length != 6) {
        Dialog.Alert("请输入正确的股票代码!");
        $("#headkeyword").focus();
        return false;
    }
    window.open("http://www.538538.com/Stock---" + $("#headkeyword").val() + ".html", "_blank");
}

function StockCoinTopUp(rate, button) {
    var coin = $("#tbTopUpStockCoin").val();
    if (coin.isEmpty()) { Dialog.Alert("请输入充值股数!"); $("#tbTopUpStockCoin").focus(); return; }
    if (!coin.isNumber()) { Dialog.Alert("请输入整型股数!"); $("#tbTopUpStockCoin").focus(); return; }
    if (coin % rate != 0) { Dialog.Alert("充值股数必须是" + rate + "的整数倍!"); $("#tbTopUpStockCoin").focus(); return }
    AjaxRequest.Post("btnSubmitStockCoinTopUp", "userInfomationPanel", function (content) {
        var tips = content['Tip'].split("|");
        $("#CurrentUserCoinSpan").text("金币:" + tips[1]);
        if (content['Status'] == 'Success') {
            Dialog.Success(tips[0]);
            window.parent.stockCoinTopUpDialog.close();
        }
        else if (content['Status'] == 'Fail') {
            Dialog.Fail(tips[0]);
        }
        else {
            Dialog.Alert(tips[0]);
        }

    });
}

function UsersGradeGoup(button) {
    $(button).attr("disabled", true);
    AjaxRequest.Get("/dialog/UsersGradeGoup.aspx?action=stockCoin", "userInfomationPanel", function (content) {
        $(button).attr("disabled", false);
        var tips = content['Tip'].split("|");
        $("#CurrentUserCoinSpan").text("金币:" + tips[1]);
        Dialog.Alert(tips[0]);
        window.parent.UsersGradeGoupDialog.close();
    });
}

function ShowStockCompleteDetail(id, title) {
    title = title + '本次完整操作明细';
    Msg.CompleteOperate(id, title);
}

function ShowUserStockCompleteDetail(id, title) {
    title = title + '本次完整操作明细';
    Msg.CompleteOperate(id, title);
}

function showShowSubScriptionSet() {
    Msg.showSubscriptionSet();
    return false;
}

function EditInvestmentType() {

    AjaxRequest.Post("btnSubmitInvestmentType", function (content) {
        if (content['Status'] == 'Success') {
            Dialog.Success(content['Tip']);
            window.parent.InvestmentStyleDialog.close();
        }
        else if (content['Status'] == 'Alert') {
            Dialog.Alert(content['Tip']);
        }
        else {
            Dialog.Fail(content['Tip']);
        }
    });
}

function showInvestmentStyleDialog() {
    Msg.InvestmentStyle();
}

$(function () {

    $("#showSubscriptionSet").click(function () {
        Msg.showSubscriptionSet();
        return false;
    });
    $("#showStockCoinTopUp").click(function () {
        Msg.stockCoinTopUp();
        return false;
    });
    $("#showUsersGradeGoup").click(function () {
        Msg.UsersGradeGoup();
        return false;
    });

    $('#showUserBugBack').click(function () {
        Msg.UserBugBackSubmit(); //用户意见反馈        
        return false;
    });
});

//意见反馈对话框
var uploadIndex = 0;
function addUpLoadImg() {
    uploadIndex++;
    if (uploadIndex <= 5) {
        if ($('#uploadImgBlock_' + uploadIndex)) {
            $('#uploadImgBlock_' + uploadIndex).show();
        }
    }
    else {
        Dialog.Alert("最多只能添加5个附件!");
    }

    if (uploadIndex >= 1) {
        $('#removeUpLoadPanel').show();
    }

    if (uploadIndex == 5) {
        $('#addUpLoadPanel').hide();
    }
    else {
        $('#addUpLoadPanel').show();
    }
}

function deleteUpLoadImg() {

    if (uploadIndex <= 5 && uploadIndex >= 1) {
        if ($('#uploadImgBlock_' + uploadIndex)) {
            $('#uploadImgBlock_' + uploadIndex).hide();
        }
    }
    uploadIndex--;
    if (uploadIndex >= 1) {
        $('#removeUpLoadPanel').show();
    }
    else {
        $('#removeUpLoadPanel').hide();
    }

    if (uploadIndex == 5) {
        $('#addUpLoadPanel').hide();
    }
    else {
        $('#addUpLoadPanel').show();
    }

}

function vaildInputLenght() {
    var inputContents = $('#txtContents').val();
    var limitLength = 500;
    $('#iputTip').html('(当前还可输入:' + inputContents.length + '/' + limitLength + '个字符)');
    if (inputContents.length > limitLength) {
        $('#txtContents').val(inputContents.substring(0, limitLength - 1));
    }
}

function submitUserBugFeedBack() {
    var title = $('#txtTitle').val();
    var questionType = $('#questionType').val();
    var contents = $('#txtContents').val();

    if (title == '' || title.length >= 120) {
        Dialog.Alert("反馈标题必须控制在120字内!");
        $("#txtTitle").focus();
        return;
    }

    if (contents == '' || contents.length >= 500) {
        Dialog.Alert("反馈内容必须控制在500字以内!");
        $("#txtContents").focus();
        return;
    }

    Submit("submitUserBugButton");




    //    AjaxRequest.Post("submitUserBugButton", function (content) {
    //        
    //        if (content['Status'] == 'Success') {
    //            Dialog.Success(content['Tip']);
    //            window.parent.UserBugBackDialog.close();
    //        }
    //        else {
    //            Dialog.Fail(content['Tip']);
    //        }
    //    });
}

function submitFirmOperation() {
    if ($("#file1").val().isEmpty()) {
        Dialog.Alert("请先选择要上传的文件！");
        return false;
    }
    Submit("submitFirmOperationButton");
}

function ShowHelp(obj, num) {
    var ss = "";
    switch (num) {
        case 1:
            ss = "总资产 = 股票市值 + 可用金额 + 冻结金额；默认值为100000";
            break;
        case 2:
            ss = "首页登录模拟炒股，系统默认送出的股币，默认值为100000";
            break;
        case 3:
            ss = "股票市值 = 所有持仓股票的市值；单只股票的股票市值 = 买入价格 × 买入数量";
            break;
        case 4:
            ss = "仓位 = 股票市值 / 总资产";
            break;
        case 5:
            ss = "可用于进行买入股票的金额";
            break;
        case 6:
            ss = "总收益率 = （总金额 - 原始资金）/ 原始资金";
            break;
        case 7:
            ss = "本周收益率 = （本周总资产 - 上周总资产 - 本周充值金额）/ （上周总资产 + 本周充值金额）";
            break;
        case 8:
            ss = "本月收益率 = （本月总资产 - 上月总资产 - 本月充值金额）/ （上月总资产 + 本月充值金额）";
            break;
        case 9:
            ss = "市值 = 成本价 × 总股数";
            break;
        case 10:
            ss = "总股数：当前股票所持有的股票数量";
            break;
        case 11:
            ss = "可用股数 = 总股数 - 今日买入的股数 - 委托卖出的股数";
            break;
        case 12:
            ss = "成本价：多笔买入的股票平均成本；单笔股票成本价 = 买入价格 × 买入数量 + 总税费 / 买入数量";
            break;
        case 13:
            ss = "浮动盈亏 = （最新价 - 成本价）× 买入数量";
            break;
        case 14:
            ss = "浮动盈亏比 = 浮动盈亏 /（成本价 × 买入数量）";
            break;
        case 15:
            ss = "今日涨跌幅：当前价格相对于昨日收盘价的跌幅比例";
            break;
        case 16:
            ss = "今日盈亏 = 今日总资产 - 昨日总资产 - 今日充值资金";
            break;
        case 17:
            ss = "本周盈亏 = 本周总资产 - 上周总资产 - 本周充值资金";
            break;
        case 18:
            ss = "本月收益 = 本月总资产 - 上月总资产 - 本月充值资金";
            break;
        case 19:
            ss = "总盈亏 = 总资产 - 原始资金";
            break;
        case 20:
            ss = "冻结资金：委托买入股票是冻结的资金；单笔委托的冻结资金 = 委托买入价格 × 委托买入数量 + 总税费";
            break;
        case 21:
            ss = "操作股数：该只股票从第一次买入到全部卖出总共买入的数量";
            break;
        case 23:
            ss = "实现盈亏 = （卖出均价 - 成本价）× 操作股数";
            break;
        case 24:
            ss = "盈亏比例 = 浮动盈亏 /（成本价 × 操作股数）";
            break;
        case 25:
            ss = "卖出均价：多次卖出的平均价格";
            break;
        case 26:
            ss = "印花税：买入时不收取；印花税 = 卖出价格 × 卖出数量 × 0.001";
            break;
        case 27:
            ss = "佣金 = 买入/卖出价格 × 买入/卖出数量 × 0.001";
            break;
        case 28:
            ss = "过户费 = 买入/卖出价格 × 买入/卖出数量 × 0.001";
            break;
        case 29:
            ss = "冻结资金 = 买入价格 × 买入数量 + 佣金 + 过户费";
            break;
        case 30:
            ss = "总金额 = 买入/卖出价格 × 买入/卖出数量 + 佣金 + 过户费 + 印花税";
            break;
        case 31:
            ss = "总税费 = 佣金 + 过户费 + 印花税";
            break;
        default:
            break;
    }

    $(obj).attr("title", ss);
}

function ReplyUserBug(ID) {
    Msg.ReplyUserBug(ID);
    return false;
}

function ApplyMoneyBox() {
    Msg.ApplyMoneyBox();
    return false;
}

function SendMessageBox(userRecomID, gotoUserID) {
    Msg.SendMessageBox(userRecomID, gotoUserID);
    return false;
}


function submitReplyButtonClick() {
    var contents = $('#txtContents').val();

    if (contents == '' || contents.length >= 500) {
        Dialog.Alert("反馈内容必须控制在500字以内!");
        $("#txtContents").focus();
        return;
    }
    AjaxRequest.Post("submitReplyButton", function (content) {
        if (content['Status'] == 'Success') {
            Dialog.Success(content['Tip'], function () { window.parent.location.href = '/UserBugBack.aspx'; });
        }
        else {
            Dialog.Fail(content['Tip']);
        }
    });
}

function LocationTo(userID) {
    if (userID <= 0) {
        location.href = 'http://bbs.laoqianzhuang.com/member.php?mod=logging&action=login&referer=http%3A//s.laoqianzhuang.com/Account.aspx';
    }
    else {
        location.href = 'http://s.laoqianzhuang.com/Account.aspx';
    }
}

function ShowSetUserNameAndPWDBox(id) {
    Msg.SetUserNameAndPWD(id);
    return false;
}

function submitButtonClick() {
    if ($("#BondUserName").val() == '') {
        Dialog.Alert("请输入证券用户名!");
        $("#BondUserName").focus();
        return;
    }
    if ($("#BondPassWord").val() == '') {
        Dialog.Alert("请输入证券密码!");
        $("#BondPassWord").focus();
        return;
    }
    AjaxRequest.Post("submitButton", function (content) {
        if (content['Status'] == 'Success') {
            Dialog.Success(content['Tip'], function () {
                window.parent.location.href = "/ApplyMoneyList.aspx";
            });
        }
        else {
            Dialog.Fail(content['Tip']);
        }
    });
}

function submitVieFirm() {
    if ($("#txtUserName").val() == '') {
        Dialog.Alert("请输入用户名!");
        $("#BondUserName").focus();
        return;
    }
    if ($("#txtDays").val() == '') {
        Dialog.Alert("请输入有效期!");
        $("#BondPassWord").focus();
        return;
    }
    AjaxRequest.Post("submitViewFirmButton", function (content) {
        if (content['Status'] == 'Success') {
            Dialog.Success(content['Tip'], function () {
                window.parent.location.href = "/ViewFirmList.aspx";
            });
        }
        else {
            Dialog.Fail(content['Tip']);
        }
    });
}

function ShowUploadImageBox() {
    Msg.UploadImage();
    return false;
}

function UploadImgClick() {
    //alert($("#ke-iframe", parent.document.body).contents().find(".ke-content").html());
    //return;
    var imgurl = $("#url").val();
    if (imgurl == "") {
        Dialog.Alert("请选择要上传的文件!");
        return false;
    }
    var lastindex = imgurl.lastIndexOf('.');
    if (lastindex < 0) {
        Dialog.Alert("请选择正确的上传文件!");
        return false;
    }

    var suffix = imgurl.substring(lastindex + 1);

    if (suffix != "jpg" && suffix != "gif" && suffix != "bmp" && suffix != "png") {
        Dialog.Alert("请选择后缀为JPG、JPEG、GIF、BMP、PNG的文件!");
        return false;
    }


    Submit("btUploadImg");

//    AjaxRequest.Post("btUploadImg", function (content) {
//        if (content['Status'] == 'Success') {
//            var content = $("#content1").text() + "<img src='" + content["Tip"] + "' />";
//            $("#content1").text(content);
//        }
//        else {
//            Dialog.Fail(content['Tip']);
//        }
//    });
}
