﻿if (!window.attachEvent) { function GetEvent() { var _caller = GetEvent.caller; while (_caller) { if (_caller.arguments.length == 0) { _caller = _caller.caller; continue; } var obj = _caller.arguments[0]; if (obj.constructor == Event || obj.constructor == MouseEvent || obj.constructor == KeyboardEvent) return obj; _caller = _caller.caller; } return null; } Window.prototype.__defineGetter__("event", GetEvent); Event.prototype.__defineSetter__("returnValue", function(v) { if (!v) this.preventDefault(); return v; }); Event.prototype.__defineGetter__("srcElement", function() { return this.target; }); Event.prototype.__defineGetter__("x", function() { return this.layerX; }); Event.prototype.__defineGetter__("y", function() { return this.layerY; }); Event.prototype.__defineSetter__("cancelBubble", function(value) { if (value) this.stopPropagation(); }); Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent = HTMLElement.prototype.attachEvent = function(eventName, eventFunction) { this.addEventListener(eventName.replace(/on/, ""), eventFunction, true); }; Window.prototype.detachEvent = HTMLDocument.prototype.detachEvent = HTMLElement.prototype.detachEvent = function(eventName, eventFunction) { this.removeEventListener(eventName.replace(/on/, ""), eventFunction, true); }; Window.prototype.fireEvent = HTMLDocument.prototype.fireEvent = HTMLElement.prototype.fireEvent = function(eventName) { var e, et; eventName = eventName.toLowerCase(); if (eventName.indexOf("click") != -1 || eventName.indexOf("mouse") != -1) et = "MouseEvents"; else if (eventName.indexOf("key") != -1) et = "KeyboardEvents"; else et = "Events"; e = document.createEvent(et); e.initEvent(eventName.replace(/on/, ""), true, true); this.dispatchEvent(e); }; HTMLDocument.prototype.__defineGetter__("innerText", function() { return this.textContent; }); HTMLDocument.prototype.__defineSetter__("innerText", function(t) { this.textContent = t; }); HTMLElement.prototype.__defineGetter__("innerText", function() { return this.textContent; }); HTMLElement.prototype.__defineSetter__("innerText", function(t) { this.textContent = t; }); HTMLElement.prototype.removeNode = function(bRemoveChildren) { this.parentNode.removeChild(this); if (!bRemoveChildren) { for (var i = 0; i < this.childNodes.length; i++) this.parentNode.appendChild(this.childNodes[i]); } }; }

var id_Str2 = "";

//获取指定id的对象
function $(id) { return document.getElementById(id); }
//获取指定的服务器对象
function $$(id) {
    var l = document.forms[0].elements;
    for (var i = 0; i < l.length; i++)
        if (l[i].id.match("_" + id + "$"))
        return l[i];
}
//获取指定id的第一个子对象
function $sub(id) { return $(id).children[0]; }

//String类的扩展函数．功能：清除字符串两端的空格．
String.prototype.trim = function() {
    var returnString = this;
    for (; returnString.charCodeAt(0) == 0x20; returnString = returnString.substr(1));
    for (; returnString.charCodeAt(returnString.length - 1) == 0x20; returnString = returnString.substr(0, returnString.length - 1));
    return returnString;
}

//格式化字符串
String.prototype.format = function(params) {
    var str = this;
    for (var i = 0; i < arguments.length; i++)
        str = str.replace("{" + i + "}", arguments[i].toString());

    return str;

}

//缩放图片
function zoomImg(img, maxWidth, maxHeight, isAlignMiddle) {
    var actualImg = new Image();
    actualImg.attachEvent("onload", function() {
        var finalHeight, finalWidth, actualWidth, actualHeight;
        actualWidth = actualImg.width;
        actualHeight = actualImg.height;

        if (maxWidth > actualWidth && maxHeight > actualHeight) {
            finalHeight = actualHeight;
            finalWidth = actualWidth;
        }
        else if (maxWidth / maxHeight > actualWidth / actualHeight) {
            finalHeight = maxHeight;
            finalWidth = Math.round(maxHeight * actualWidth / actualHeight);
        }
        else if (maxWidth / maxHeight < actualWidth / actualHeight) {
            finalHeight = Math.round(maxWidth * actualHeight / actualWidth);
            finalWidth = maxWidth;
        }
        else {
            finalHeight = maxHeight;
            finalWidth = maxWidth;
        }

        if (isAlignMiddle) {
            img.style.position = "absolute";
            img.style.top = (maxHeight - finalHeight) / 2 + "px";
            img.style.left = (maxWidth - finalWidth) / 2 + "px";
        }

        img.style.width = img.width = finalWidth + "px";
        img.style.height = img.height = finalHeight + "px";
        delete actualImg;
        actualImg = null;

    }
                 );
    actualImg.src = img.src;

}

//判断当前浏览器是否是IE
var isIE = navigator.appName == "Microsoft Internet Explorer" ? true : false;
var isIE6 = navigator.userAgent.indexOf("MSIE 6.0") > 0;
var isIE7 = navigator.userAgent.indexOf("MSIE 7.0") > 0;



//获取当前页面地址中search部分包含的参数值
function getQueryValue(key, win) {
    key = key.toLowerCase();
    var href = (win ? win : window).location.search.toLowerCase();
    var arr = href.match("[?,&]" + key + "=([^&]*)&?");
    if (arr != null)
        return arr[1];
    return null;
}



//获取指定对象的坐标
function getElementPos(e) {
    var elemX = 0;
    var elemY = 0;
    do {
        elemX += e.offsetLeft;
        elemY += e.offsetTop;
    } while (e = e.offsetParent)

    return { x: elemX, y: elemY };
}


function enterToButton(bt) {
    var b = typeof (bt) == "string" ? $(bt) : bt;
    if (event.keyCode == 13) {
        b.click();
        return false;
    }
}



//显示页面的遮盖层
function showPageCover(flag) {
    $("coverDiv").style.display = flag ? "block" : "none";
}

//显示全屏半透明遮盖
function showFullPageCover(isDisplay) {
    var obj = document.body.pageCover;

    if (obj == undefined) {
        document.body.pageCover = obj = document.createElement("div");
        obj.className = "pageCover";
        document.body.appendChild(obj);
    }

    if (isDisplay == true) {

        var h = document.documentElement.scrollHeight;
        var w = document.documentElement.scrollWidth;

        obj.style.display = "block";
        obj.style.height = h + "px";
        obj.style.width = w + "px";
    }
    else
        obj.style.display = "none";
}


function hoverTableRow(table, color) {
    var tb = typeof (table) == "string" ? $(table) : table;
    tb.hoverTableRow_Current = null;
    var rows = tb.rows;
    for (var i = 0; i < rows.length; i++) {
        var row = rows[i];

        if (row.hoverTableRow_None == "1")
            continue;
        row.oldColor = row.style.backgroundColor;

        row.onmouseover = function() { this.style.backgroundColor = color; }
        row.onmouseout = function() { this.style.backgroundColor = this.oldColor; }
    }

}

function scrollList(e, width, p, fun) {
    e.scrollLeft += p * width / 100;

    if ((width < 0 && e.scrollLeft == 0) || (width > 0 && (e.scrollLeft + parseInt(e.style.width)) == e.scrollWidth)) {
        if (fun)
            fun(width > 0 ? 1 : -1);
        return;
    }

    if (Math.abs(width) <= 1) {
        e.scrollLeft += width;

        if (fun) {
            if ((width < 0 && e.scrollLeft == 0) || (width > 0 && (e.scrollLeft + parseInt(e.style.width)) == e.scrollWidth))
                fun(width > 0 ? 1 : -1);
            else
                fun(0);
        }
        return;
    }

    setTimeout(function() { scrollList(e, (1 - p / 100) * width, p, fun); }, 80);
}


//收藏
function favoritePro(proname) {
    window.external.addFavorite(window.location.href, proname);
}

//去除字符串中的空格
String.prototype._trim = function() {
    return this.replace(/ */g, "");
}


//显示或取消指定对象上的遮盖层
function showPlaceCover(place, flag/*---true为显示；false为不显示---*/) {
    var place1 = typeof (place) == "string" ? $(place) : place;
    if (!place1.cover) {
        place1.cover = document.createElement("div");
        document.body.appendChild(place1.cover);
        place1.cover.className = "coverDiv";
        var p = getElementPos(place1);
        var h = place1.scrollHeight;
        var w = place1.scrollWidth;
        place1.cover.style.height = h + "px";
        place1.cover.style.width = w + "px";
        place1.cover.style.left = p.x + "px";
        place1.cover.style.top = p.y + "px";
        place1.cover.style.zIndex = place1.style.zIndex + 1;
    }

    place1.cover.style.display = flag ? "block" : "none";
}


function SetCookie(name, value) {
    var date = new Date();
    date = new Date(date.valueOf() + (60 * 60 * 24 * 1000 * 30));
    DelCookie(name);
    var str = "";
    var vs = value.split("&");
    for (var i = 0; i < vs.length; i++) {
        var s = vs[i].split("=");
        str += "&";
        if (s.length > 0)
            str += escape(s[0]) + "=" + escape(vs[i].substr(s[0].length + 1));
        else
            str += escape(vs[i]);
    }

    if (str == "")
        str = escape(value);
    else
        str = str.substr(1);

    document.cookie = name + "=" + str + "; expires=" + date.toGMTString() + "; path=/";

}


function GetCookie(name) {
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (name == aCrumb[0])
            return unescape(aCookie[i].substr(name.length + 1));
    }
    return null;
}


function DelCookie(name) {

    var date = new Date();
    date = new Date(date.valueOf() - 22333);
    document.cookie = name + "=; expires=" + date.toGMTString();
}


// function selectCity(code, name) {
//     SetCookie("CurrentCity", "Code=" + code + "&Name=" + name);
//     location = location.href.replace("#", "");
// }

function adminSelectLanguage(flag) {
    SetCookie("CurrentLanguage", "IsChinese=" + flag.toString());
    //window.location = location.href.replace("#", "");
    alert("版本切换成功!");
    window.location.href = '/admin/Welcome.aspx';
}

function selectLanguage(code) {
    SetCookie("CurrentLanguage", "IsChinese=" + code.toString());

    var url = document.URL;
    if (!code && url.indexOf("/en/") < 0) {
        var tmpUPage = url.split("/");
        var thisUPage = tmpUPage[tmpUPage.length - 1];
        var tmp = thisUPage.split(".");
        var page = tmp[0];
        var reg = /^[1-9]\d*$/;
        if (reg.test(page)) {
            thisUPage = tmpUPage[tmpUPage.length - 2];
            page = thisUPage;

        }
        window.location = location.href.replace("#", "").replace("/" + page, "/en/" + page);
    }
    else if (code && url.indexOf("/en/") > 0) {
        window.location = location.href.replace("#", "").replace("/en/", "/");
    }
}



function showPageLoading(isDisplay, msg) {

    var obj = document.body.pageCover_loading;
    if (obj == undefined) {
        document.body.pageCover_loading = obj = document.createElement("div");
        obj.className = "pageCover_loading";
        obj.innerHTML = "<h2>加载中</h2>";
        document.body.appendChild(obj);
    }

    showFullPageCover(isDisplay);

    if (isDisplay == true) {

        obj.style.top = (document.documentElement.clientHeight - obj.clientHeight) / 2 + document.documentElement.scrollTop + "px";
        obj.style.left = (document.documentElement.clientWidth - obj.clientWidth) / 2 + document.documentElement.scrollLeft + "px";
        if (msg)
            obj.firstChild.innerHTML = msg;
        obj.style.display = "block";
    }
    else
        obj.style.display = "none";
}
// 

// //获取当前服务器控件的在网页中的对象
// function $server(id) {
//     return $(id_Str2 + id);
// }
// //设置服务器控件在网页中的ID前缀如：全局变量id_Str2 = ctl00_city_Select_原始id
// function setServerIdStr(objThis, id) {
//     var reg = eval("/" + id + "/g");      // 创建正则表达式模式。
//     id_Str2 = objThis.id.replace(reg, ""); 
// }
