﻿$(document).ready(function () {
    var url = window.location.toString();
    var obj = url.match(/\/(\w+?)(.html|-)/);
    if (obj) {
        var id = obj[1];

        if (id == "fundsanalysis" || id == "tradeanalysis" || id == "tradestatistics") {
            $("#FundsAnalysis").addClass("on");
        }
        else if (id == "stocktodaydatadetail" || id == "now" || id == "nowdetail") {
            $("#StockTodayDataList").addClass("on");
        }
        else if (id == "stockhistorydatadaysdetail" || id == "stockhistorydetail" || id == "history" || id == "historydaysdetail") {
            $("#StockHistoryDataList").addClass("on");
        }
        else {
            $("#" + id).addClass("on");
        }
    }
    else {
        $("#default").addClass("on");
    }
});

var user = {};

user.Login = function () {
    var name = document.getElementById("txtName").value;
    var ps = document.getElementById("txtPs").value;

    if (name.length < 1 || ps.length < 1) {
        alert("用户名或密码不能为空");
        return;
    }

    document.getElementById("loginForm").submit();

}

function changeTab(cart, boxId) {
    if (cart == 0) {

        $("#a" + boxId + "0").removeClass("a2").addClass("a1");
        $("#a" + boxId + "1").removeClass("a1").addClass("a2");
        $("#" + boxId + "0").show();
        $("#" + boxId + "1").hide();
    }
    else {

        $("#a" + boxId + "0").removeClass("a1").addClass("a2");
        $("#a" + boxId + "1").removeClass("a2").addClass("a1");
        $("#" + boxId + "0").hide();
        $("#" + boxId + "1").show();
    }
}

var isff = document.all ? false : true;
// onkeydown(event,buttonid) 
function EnterFocus() {
    var key = isff ? arguments[0].keyCode : event.keyCode;
    if (key == 13)
        AClick(arguments[1]);
}

// a:<a>id (ff compatibly <a> click())
function AClick(a) {
    a = document.getElementById(a);
    if (!isff) {
        a.click();
    }
    else if (document.createEvent) { //FOR DOM2
        var ev = document.createEvent('MouseEvents');
        ev.initEvent('click', false, true);
        a.dispatchEvent(ev);
    }
}

function suggesttopviewindex(tid) {
    var StockID = $("#" + tid).val();
    window.suggestStock_top = new Suggest(tid, StockID, ["http://src.lqz.cn/stocklist_A.js"], ["stocka_suggest"], StockSuggestConfiguration, null, [200, 800, 2, "solid", "#EEE", "#FFF", 3, 3, 0.2, "#000", "#444", "#F1F5FC", false]);
}

$(function () {
    if (suggesttopviewindex) {
        suggesttopviewindex('LqzStockCode');
    }
});

$(document).ready(function () {
    $("#btnStockNameEnter").click(function () {
        var gugeSel = $("#gugeSel").val();
        var stockId = StockIdCheck($("#LqzStockCode").val());
        if (stockId == null || stockId.length == 0) return;
        switch (gugeSel) {
            case "1":
                location.href = "now-1---1-" + stockId + "-1.html";
                break;
            case "2":
                location.href = "historydaysdetail-1-" + stockId + ".html";
                break;
            case "3":
                location.href = "tradeanalysis-" + stockId + ".html";
                break;
            case "4":
                location.href = "tradestatistics-" + stockId + ".html";
                break;
            default:
                break;
        }
    });
});

String.format = function () {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function StockIdCheck(stockId) {
    if (stockId == null || stockId.length < 3)
        return '';
    var substr = stockId.substring(0, 2).toLowerCase();
    var shstr = '19,50,51,52,60';
    if (shstr.indexOf(substr) > -1)
        stockId = 'SH' + stockId;
    else if (substr != 'sz' && substr != 'sh' && '03'.indexOf(stockId.substring(0, 1)) > -1)
        stockId = 'SZ' + stockId;
    return stockId;
}
