﻿//一些基本的功能函数
var $ = function(o) { return document.getElementById(o); };
var $T = function() {
    if (arguments.length == 2) {
        var o = arguments[0];
        if (typeof (o) == "string") o = $(o);
        return o.getElementsByTagName(arguments[1]);
    }
    else
        return document.getElementsByTagName(arguments[0]);
}
var $C = function(o) { return document.createElement(o); }

var $H = {
    To: function(Address) {
        window.location.href = Address;
    },
    ATo: function(Address, Message) {
        alert(Message);
        window.location.href = Address;
    },
    Back: function() {
        window.history.back();
    },
    Top: function(Address) {
        window.top.location.href = Address;
    }
}

//基本的样式控制
var $S = function(Obj) {
    var o = Obj.style;
    if (typeof (Obj) == "string")
        o = $(Obj).style;
    else if (typeof (Obj) == "object")
        o = Obj.style;

    return {
        Show: function() {
            o.display = "";
        },
        Hide: function() {
            o.display = "none";
        },
        Height: function(_h) {
            o.height = _h + "px";
        },
        Width: function(_w) {
            o.width = _w + "px";
        },
        Top: function(_t) {
            o.top = _t + "px";
        },
        Left: function(_l) {
            o.left = _l + "px";
        }
    }
}

String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};

var IsIE = function() {
    return window.navigator.appName == "Microsoft Internet Explorer";
};

var AddEvent = function(Obj, _Evt, _handle) {
    if (IsIE())
        Obj.attachEvent("on" + _Evt, _handle);
    else
        Obj.addEventListener(_Evt, _handle);

};

//搜索控制
var SearchControl = function() {
    var Text = $("SearchText");
    var SearchStart = function() {
        if (Text.value.Trim() == "") return;
        window.location.href = "/News/Default.aspx?Title=" + escape(Text.value.Trim());
    };

    AddEvent($("SearchButton"), "click", SearchStart);
};

var LoadInit = function() {
    document.body.oncontextmenu = function() { return false; };
    document.body.onselectstart = function() { return false; };
};


AddEvent(window, "load", SearchControl);
AddEvent(window, "load", LoadInit);

// 简单的显示开关控制
var ShowContent = function(id) {
    var Obj = $("Content" + id);
    if (Obj.className.indexOf(" Hide") != -1)
        Obj.className = Obj.className.replace(" Hide", "");
    else if (Obj.className == "Hide")
        Obj.className = "";
    else if (Obj.className == "")
        Obj.className = "Hide";
    else
        Obj.className += " Hide";
};

