function $e(id){return document.getElementById(id);}
function c(tagName){ return document.createElement(tagName); }
function addEvent(o,et,f){if(o.attachEvent){o.attachEvent("on"+et,f);}else if(o.addEventListener){o.addEventListener(et,f,false);}}
function removeEvent(o,et,f){if(o.detachEvent){o.detachEvent("on"+et,f);}else if(o.removeEventListener){o.removeEventListener(et,f,false);}}
function addClass(elem, strClass){	if(elem.nodeType!==1 || !strClass){ return false }elem.className = (elem.className) ? elem.className + " " + strClass : strClass; }
function removeClass(elem, strClass){	if(elem.nodeType!==1 || !strClass){ return false }var reg = new RegExp("\\s\*"+strClass+"|"+strClass+"\\s\*","g");elem.className = elem.className.replace(reg, ""); }
function console_log(l){ if(/Firefox/i.test(navigator.userAgent)){ console.log(l); } }
var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
var isIE7 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 7);
if(isIE6){ document.execCommand("BackgroundImageCache", false, true); }
String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); }
function Ajax(O) {
    var O = O || {},
    httpUrl = O.url || "",
    data = O.data || "",
    dataType = O.dataType || "text",
    method = O.method == "post" ? "POST": "GET",
    charset = O.charset || "gb2312",
    succeed = typeof(O.succeed) == "function" ? O.succeed: function() {},
    error = typeof(O.error) == "function" ? O.error: function() {};
    function getXmlHttp() {
        var xmlHttp;
        if (window.ActiveXObject) {
            var httplist = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
            for (var i = httplist.length - 1; i >= 0; i--) {
                try {
                    xmlHttp = new ActiveXObject(httplist[i]);
                    return xmlHttp
                } catch(ex) {}
            }
        } else if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest()
        }
        return xmlHttp
    }
    function R() {
        var ajx = getXmlHttp();
        var rcontent = '';
        if (!httpUrl) {
            console_log("url 不能为空!");
            return false
        }
        httpUrl += httpUrl.indexOf("?")==-1 ? "?": "&";
        httpUrl += "httprnd=" + Math.random().toString().substr(2);
        dataEncode();
        if (method == "GET" && data) {
            httpUrl += "&" + data;
            data = ""
        }
        ajx.onreadystatechange = function() {
            if (ajx.readyState == 4) {
                if (ajx.status == 200) {
                    rcontent = (dataType == "text") ? ajx.responseText: ajx.responseXML;
                    succeed(rcontent)
                } else {
                    error(ajx.status)
                }
            }
        };
        ajx.open(method, httpUrl, true);
        if (method.toLowerCase() == "post") {
            ajx.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        }
        ajx.send(data)
    }
    function _get(url, oData, suc, err) {
        httpUrl = url || httpUrl;
        data = oData || data;
        succeed = typeof(suc) == "function" ? suc: succeed;
        error = typeof(err) == "function" ? err: error;
        method = "GET";
        R()
    }
    function _post(url, oData, suc, err) {
        httpUrl = url || httpUrl;
        data = oData || data;
        succeed = typeof(suc) == "function" ? suc: succeed;
        error = typeof(err) == "function" ? err: error;
        method = "POST";
        R()
    }
    function _postf(f, suc, err) {
        if (!f) {
            console_log("对象不存在!");
            return false
        }
        if (f.nodeName.toLowerCase() != "form" || f.action == "" || f.method == "") {
            console_log("对象不是表单，或表单参数不全。form:" + f.nodeName.toLowerCase() + " action:" + f.action + "method:" + f.method);
            return false
        }
        httpUrl = f.action;
        method = f.method;
        data = "";
        for (var i = 0; i < f.length; i++) {
            if (f[i].name.trim() == "" || ((f[i].type.toLowerCase() == "checkbox" || f[i].type.toLowerCase() == "radio") && !f[i].checked)) {
                continue
            }
            data += "&" + f[i].name.trim() + "=" + f[i].value
        }
        if (data != "") {
            data = data.substr(1)
        }
        succeed = typeof(suc) == "function" ? suc: succeed;
        error = typeof(err) == "function" ? err: error;
        R()
    }
    function dataEncode() {
        if (!data) {
            return false
        }
        var items = data.split("&");
        var _item,
        newDate = "";
        for (var i = 0; i < items.length; i++) {
            _item = items[i].split("=");
            if (charset == "gb2312") {
                newDate += "&" + escape(_item[0]) + "=" + escape(_item[1])
            } else if (charset == "utf-8") {
                newDate += "&" + encodeURIComponent(_item[0]) + "=" + encodeURIComponent(_item[1])
            }
        }
        data = newDate.substr(1)
    }
    return {
        get: _get,
        post: _post,
        postf: _postf
    }
}
function LoadJs(url) {
    var loaded = false,
	loading = false,
	sTime;
    function _load(func) {
        if (!loaded && !isLoading()) {
            loading = true;
			sTime = new Date();
            var dJs = document.createElement("script");
            dJs.type = "text/javascript";
            dJs.src = url;
			document.getElementsByTagName("head")[0].appendChild(dJs);
        }
		if(isIE){
			dJs.onreadystatechange = function(){
				if(dJs.readyState=="loaded"||dJs.readyState=="complete"){ loaded = true;loading = false; func() }
			}
		}else{
			dJs.onload = function(){
				loaded = true; loading = false; func();

			}
		}
    }
    function isLoad() {
        return loaded
    }
    function isLoading() {
		var eTime = new Date();
		if((loading&&(eTime-sTime)>1000)||loaded){
			loading = false;
		}
        return loading
    }
    return {
        load: _load,
        isLoad: isLoad,
        isLoading: isLoading
    }
}
