﻿var $ = function(o) { return typeof (o) == 'string' ? document.getElementById(o) : o; }
var $E = function(e) { tempObj = e.target ? e.target : event.srcElement; return tempObj; }

var addEvent = function(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    } else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    } else {
        elm['on' + evType] = fn;
    }
}
var delEvent = function(elm, evType, fn, useCapture) {
    if (elm.removeEventListener) {
        elm.removeEventListener(evType, fn, useCapture);
        return true;
    } else if (elm.detachEvent) {
        var r = elm.detachEvent('on' + evType, fn);
        return r;
    } else {
        elm['on' + evType] = null;
        return;
    }
}

//登录时处理
function clickLoginSelect(){
	if($("loginFldselectop").style.display == "block"){
		LoginSelectClose();
	}else{
		$("loginFldselectop").style.display = "block";
		addEvent(document.body,"mousedown",LoginSelectClickOther);
	}
};
function LoginSelectClickOther(e){
	thisObj = e.target?e.target:event.srcElement;
	do{
		if(thisObj.id == "loginFldselect" || thisObj == $("user_pass")) return;
		if(thisObj.tagName == "BODY"){LoginSelectClose();return;};
		thisObj = thisObj.parentNode;
	}while(thisObj.parentNode);
};
function LoginSelectClose(){
	$("loginFldselectop").style.display = "none";
	delEvent(document.body,"mousedown",LoginSelectClickOther);
};
function LoginSelect(title) {
    var titleName;
    switch (title) {
        case "passport":
            titleName = "通行证";
            $("select1").value = "通行证";
            document.showLogin.action = "http://passport.eastmoney.com/BLogin.EmUser";
            $("user_username").name = "loginuname";
            $("user_pass").name = "loginpass";
            break;
        case "cfbg":
            titleName = "财富报告";
            $("select1").value = "机构内参";
            document.showLogin.action = "http://product.eastmoney.com/shouye_dengru.aspx?action=yes";
            $("user_username").name = "user_username";
            $("user_pass").name = "user_pass";
            break;
        case "cfrk":
            titleName = "财富日刊";
            $("select1").value = "财富日刊";
            document.showLogin.action = "http://product.eastmoney.com/login.aspx";
            $("user_username").name = "user_username";
            $("user_pass").name = "user_pass";
            break;
        case "hxnc":
            titleName = "核心内参";
            $("select1").value = "核心内参";
            document.showLogin.action = "http://www.caopanmima.com/hxnc/default.aspx";
            $("user_username").name = "u";
            $("user_pass").name = "p";
            break;
        case "09q2bg":
            titleName = "09三季度报告";
            $("select1").value = "baogao2";
            document.showLogin.action = "http://caifumima.eastmoney.com/tzbgc/default.aspx";
            $("user_username").name = "u";
            $("user_pass").name = "p";
            break;
        default:
            document.showLogin.action = "http://passport.eastmoney.com/BLogin.EmUser";
            $("user_username").name = "loginuname";
            $("user_pass").name = "loginpass";
            break;
    };
    $("loginFldselectdis").innerHTML = titleName;
    LoginSelectClose();
}
function checkLoginForm(o) {
    var user_username = o["user_username"].value;
    var user_pass = o["user_pass"].value;
    if (user_username == "" || user_pass == "") {
        return false;
    }
    return true;
}

function so_search(bb) {
    var s1 = bb;
    var s = escape(s1);
    if (s1 == "请输入关键字" || s1 == "") {
        window.open("http://so.eastmoney.com/");
        return false;
    } else {
        window.open("http://so.eastmoney.com/index.aspx?Page=1&t=body&q=" + s);
        return false;
    }
}

function quotesearch(code) {

    stockcode_current = code;
    if (stockcode_current == "请输入代码或简称" || stockcode_current == "") stockcode_current = "600900";
    var re = /[0-9]{6}/;
    var re2 = /[0-9]{1,}/;
    var re3 = /[^0-9]{1,}/;
    bool1 = code.match(re);
    bool2 = code.match(re2);
    bool3 = code.match(re3);

    if (bool1 != null && stockcode_current.length == 6) {
        window.open("http://quote.eastmoney.com/" + stockcode_current + ".html");
    }
    else {
        if (bool2 != null && bool3 == null && stockcode_current.length < 3 || stockcode_current.length == 3 && stockcode_current == "600" || stockcode_current.length == 3 && stockcode_current == "000") { alert("符合条件的股票代码过多，请重新输入关键字！"); return false; }
        if (bool2 == null && bool3 != null && stockcode_current.length < 2) { alert("模糊查询时关键字至少2位！"); return false; }
        window.open("http://quote.eastmoney.com/quote.asp?stockcode=" + stockcode_current);
    }
    return (false);
}

function q_search(bb) {
    var s1 = bb;
    var s = escape(s1);
    if (s1 == "输代码、名称或拼音" || s1 == "") {
        window.open("http://q.eastmoney.com/");
        return false;
    } else {
        window.open("http://q.eastmoney.com/q.aspx?StockCode=" + s);
        return false;
    }
}

function info_search(bb) {
    var s1 = bb;
    var s = escape(s1);
    if (s1 == "输代码、名称或拼音" || s1 == "") {
        window.open("http://so.eastmoney.com/");
        return false;
    } else {
        window.open("http://so.eastmoney.com/Search.aspx?Page=1&q=" + s + "&t=body");
        return false;
    }
}

function gb_search(code) {
    var re = /[0-9]{6}/;
    bool1 = code.match(re);

    if (bool1 != null)
    { window.open('http://guba.eastmoney.com/' + code + ',guba.html'); }
    else
    { window.open('http://guba.eastmoney.com'); }
}

var Cookies = {
    Get: function(sName) {
        var cookies = document.cookie;
        if (cookies == null || cookies == "undefined") {
            return null;
        }
        var aCookie = cookies.split("; ");
        var value = null;
        for (var i = 0; i < aCookie.length; i++) {
            var aCrumb = aCookie[i].split("=");
            if (sName == aCrumb[0]) {
                value = aCrumb[1];
                break;
            }
        }
        if (value == null || value == "undefined" || value.length == 0) return null;
        return decodeURIComponent(value);
    },
    Delete: function(sName) {
        var date = new Date();
        document.cookie = sName + "=;path=/;domain=eastmoney.com;expires=" + date.toGMTString();
    }
};
var User = {
    init: function(a, b) {
        var _name = Cookies.Get("dcuser_name");
        var _nick = Cookies.Get("dcuser_mingchen");
        if (_name == null || _nick == null) {
            $(a).style.display = "block";
            $(b).style.display = "none";
        } else {
            $(a).style.display = "none";
            $(b).style.display = "block";
            $(b).innerHTML = '欢迎&nbsp;&nbsp;&nbsp;&nbsp;<strong>' + _nick + '</strong>&nbsp;&nbsp;<a href="http://passport.eastmoney.com/UserCenter.EmUser" target="blank">用户中心</a>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"User.exit(\'' + a + '\',\'' + b + '\')\" target=\"_top\">退出</a>';
        }
    },
    exit: function(a, b) {
        Cookies.Delete("dcuser_name");
        Cookies.Delete("dcuser_mingchen");
        $(a).style.display = "block";
        $(b).style.display = "none";
    }
};



// 加入收藏
function AddFavor() {
    try {
        window.external.addFavorite(window.location.href, window.document.title);
    } catch (e) {
        try {
            window.sidebar.addPanel(window.document.title, window.location, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}  
