// JavaScript Document
// 获取ID方法
function $(id) {
    return document.getElementById(id);
}
//处理图片居中
function resizePhoto(obj, wid, heig) {
    var virtualImageObj = document.createElement("img");
    virtualImageObj.src = obj.src;
    if (wid < virtualImageObj.width || heig < virtualImageObj.height) {
        if (virtualImageObj.width / virtualImageObj.height > wid / heig) {
            w = wid;
            h = (virtualImageObj.height / virtualImageObj.width) * wid;
            obj.style.marginTop = (heig - h) / 2 + "px";
        }
        else {
            h = heig;
            w = (virtualImageObj.width / virtualImageObj.height) * heig;
            obj.style.marginLeft = (wid - w) / 2 + "px";
        }
        obj.height = h;
        obj.width = w;
    }
    else {
        obj.style.marginTop = (heig - virtualImageObj.height) / 2 + "px";
        obj.style.marginLeft = (wid - virtualImageObj.width) / 2 + "px";
    }
}
function correctPNG() {
    for (var i = 0; i < document.images.length; i++) {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i - 1
        }
    }
}

function showTips(baseName, tipsName, contName) {
    baseID = $(baseName);
    tipsID = $(tipsName);
    contID = $(contName);
    if (showTips.timer) clearTimeout(showTips.timer);
    hideCur();
    tipsID.style.display = "block";
    showTips.cur = tipsID;
    if (!tipsID.isCreate) {
        tipsID.isCreate = true;
        //divID.timer = 0;
        tipsID.onmouseover = function() {
            if (showTips.timer) clearTimeout(showTips.timer);
            hideCur();
            tipsID.style.display = "block";
        };

        function hide() {
            showTips.timer = setTimeout(function() { tipsID.style.display = "none"; }, 500);
        }

        tipsID.onmouseout = hide;
        baseID.onmouseout = hide;
    }
    function hideCur() {
        showTips.cur && (showTips.cur.style.display = "none");
    }
    if (contID.offsetWidth > 80 && contID.offsetWidth < 200) {
        tipsID.style.width = contID.offsetWidth + 25 + "px";
    }
    else if (contID.offsetWidth >= 200) {
        tipsID.style.width = 220 + "px";
    }
    else {
        tipsID.style.width = 100 + "px";
    }
}



//添加cookie
function addCookie(objName, objValue, objMinutes) {
    var str = objName + "=" + escape(objValue);
    if (objMinutes > 0) {   //为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objMinutes * 60 * 1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}
//获取指定名称的cookie的值 
function getCookie(objName) {
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
    return "";
}
//删除指定名称的cookie
function delCookie(name) {
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
}


var PreTitleBlock = "Title_Default";
var PreContentBlock = "Content_Default";
function SwitchBlock(Name) {
    var TitleBlock = "Title_" + Name;
    var ContentBlock = "Content_" + Name;
    document.getElementById(PreTitleBlock).className = "";
    document.getElementById(PreContentBlock).style.display = "none";
    document.getElementById(TitleBlock).className = "title-on";
    document.getElementById(ContentBlock).style.display = "";
    PreTitleBlock = TitleBlock;
    PreContentBlock = ContentBlock;
}