﻿// JavaScript Document
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") {
            if (img.className.toLowerCase() != "photowall") {
                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 main_Body() {
    if (window.ActiveXObject) {
        window.attachEvent("onload", correctPNG);
    }
    var mainDiv = document.getElementById("main_Body");
    if (mainDiv) {
        var aa = mainDiv.getElementsByTagName("div");
        if (aa.length > 1) {
            aa[0].style.height = aa[2].offsetHeight + "px";
            aa[1].style.height = aa[2].offsetHeight + "px";
        }
    }
}

function menu(i) {
    //menu(4);
    i--;
    var menuBar = document.getElementById("menu");
    if (menuBar) {
        var m = menuBar.getElementsByTagName("li");
        var a = menuBar.getElementsByTagName("a");
        for (var k = 0; k < m.length; k++) {
            if (k == i) {
                m[k].className = "bgnone";
                a[k].className = "div";
            } else {
                m[k].className = "";
                a[k].className = "";
            }
        }
    }
}

function ResizeImage(ImgD, w, h) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= w / h) {
            if (image.width > w) {
                ImgD.width = w;
                ImgD.height = (image.height * w) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            //ImgD.alt=image.width+"×"+image.height;
        }
        else {
            if (image.height > h) {
                ImgD.height = h;
                ImgD.width = (image.width * h) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            //ImgD.alt=image.width+"×"+image.height;
        }
    }
    ImgD.style.display = "inline";
}

function addToFavorite(username, ftype, contentid, contentguid) {
    if (username) {
        if (confirm("是否将该内容添加到收藏夹？")) {
            $.post("/BaseAppCode/UHFavorite.ashx", { action: "add", ftype: ftype, contentid: contentid, contentguid: contentguid }, function(data) {
                alert(data);
                if (data == "1") {
                    alert("该内容已经添加到您的收藏夹");
                } else if (data == "0") {
                    alert("添加内容失败，请稍候重试");
                } else {
                    alert("您还没有登录系统，请先登录");
                }
            });
        }
    } else {
        alert("请先登录");
    }
}
