function imgzoom(o) {
    if (event.ctrlKey) {
        var zoom = parseInt(o.style.zoom, 10) || 100;
        zoom -= event.wheelDelta / 12;
        if (zoom > 0) {
            o.style.zoom = zoom + '%';
        }
        return false;
    } else {
        return true;
    }
}


var msgwidth = 0;
function thumbImg(obj, method) {
    if (!obj) {
        return;
    }
    obj.onload = null;
    file = obj.src;
    zw = obj.offsetWidth;
    zh = obj.offsetHeight;
    if (!zw) {
        if (!obj.id) {
            obj.id = 'img_' + Math.random();
        }
        setTimeout("thumbImg(document.getElementById('" + obj.id + "'), " + method + ")", 100);
        return;
    }
    zr = zw / zh;
    method = !method ? 0 : 1;
    if (method) {
        fixw = obj.getAttribute('_width');
        fixh = obj.getAttribute('_height');
        if (zw > fixw) {
            zw = fixw;
            zh = zw / zr;
        }
        if (zh > fixh) {
            zh = fixh;
            zw = zh * zr;
        }
    } else {
        fixw = 600; //!contentwidth || contentwidth < 100 ? 600 : contentwidth;
        if (zw > fixw) {
            zw = fixw;
            zh = zw / zr;
            obj.style.cursor = 'pointer';
            if (!obj.onclick) {
                obj.onclick = function() {
                    zoom(obj, obj.src);
                }
            }
        }
    }
    obj.width = zw;
    obj.height = zh;
}


function attachimg(obj, action) {
    if (action == 'load') {
        if (is_ie && is_ie < 7) {
            var objinfo = fetchOffset(obj);
            msgwidth = document.body.clientWidth - objinfo['left'] - 20;
        } else {
            if (!msgwidth) {
                var re = /postcontent|msgborder/i;
                var testobj = obj;
                while ((testobj = testobj.parentNode) != null) {
                    var matches = re.exec(testobj.className);
                    if (matches != null) {
                        msgwidth = testobj.clientWidth - 20;
                        break;
                    }
                };
                if (msgwidth < 1) {
                    msgwidth = window.screen.width;
                }
            }
        };
        if (obj.width > msgwidth) {
            obj.resized = true;
            obj.width = msgwidth;
            obj.style.cursor = 'pointer';
        } else if (obj.width <= 610) {
            obj.onclick = null;
        }
    } else if (action == 'mouseover') {
        if (obj.resized)
            obj.style.cursor = 'pointer';
    }
}
function extendAttachimg(obj, action, maxwidth) {
    if (action == 'load') {
        if ((obj.width == 0) || (obj.width > maxwidth)) {
            obj.resized = true;
            obj.width = maxwidth;
            obj.style.cursor = 'pointer';
        } else if (obj.width < maxwidth) {
            obj.onclick = null;
        }
    } else if (action == 'mouseover') {
        if (obj.resized)
            obj.style.cursor = 'pointer';
    }
}
function attachimginfo(obj, infoobj, show, event) {
    objinfo = fetchOffset(obj);
    if (show) {
        document.getElementById(infoobj).style.left = objinfo['left'] + 'px';
        document.getElementById(infoobj).style.top = obj.offsetHeight < 40 ? (objinfo['top'] + obj.offsetHeight) + 'px' : objinfo['top'] + 'px';
        document.getElementById(infoobj).style.display = '';
    } else {
        if (is_ie) {
            document.getElementById(infoobj).style.display = 'none';
            return;
        } else {
            var mousex = document.body.scrollLeft + event.clientX;
            var mousey = document.documentElement.scrollTop + event.clientY;
            if (mousex < objinfo['left'] || mousex > objinfo['left'] + objinfo['width'] || mousey < objinfo['top'] || mousey > objinfo['top'] + objinfo['height']) {
                document.getElementById(infoobj).style.display = 'none';
            }
        }
    }
}

var zoomobj = Array();
var zoomadjust; var zoomstatus = 1;
function zoom(obj, zimg) {
    if (!zoomstatus) {
        window.open(zimg, '', '');
        return;
    }
    if (!zimg) {
        zimg = obj.src;
    }

    if (!document.getElementById('zoomimglayer_bg')) {

        div = document.createElement('div'); div.id = 'zoomimglayer_bg';
        div.style.position = 'absolute';
        div.style.left = div.style.top = '0px';
        div.style.width = '100%';
        div.style.height = document.body.scrollHeight + 'px';
        div.style.backgroundColor = '#000';
        div.style.display = 'none';
        div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=80,finishOpacity=100,style=0)';
        div.style.opacity = 0.8;
        document.getElementById('append_parent').appendChild(div);
        div = document.createElement('div'); div.id = 'zoomimglayer';
        div.style.position = 'absolute';
        div.className = 'popupmenu_popup';
        div.style.padding = 0;
        document.getElementById('append_parent').appendChild(div);
    }

    zoomobj['srcinfo'] = fetchOffset(obj);
    zoomobj['srcobj'] = obj;
    zoomobj['zimg'] = zimg;
    document.getElementById('zoomimglayer').style.display = '';
    document.getElementById('zoomimglayer').style.left = zoomobj['srcinfo']['left'] + 'px';
    document.getElementById('zoomimglayer').style.top = zoomobj['srcinfo']['top'] + 'px';
    document.getElementById('zoomimglayer').style.width = zoomobj['srcobj'].width + 'px';
    document.getElementById('zoomimglayer').style.height = zoomobj['srcobj'].height + 'px';
    document.getElementById('zoomimglayer').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=40,finishOpacity=100,style=0)';
    document.getElementById('zoomimglayer').style.opacity = 0.4;
    document.getElementById('zoomimglayer').style.zIndex = 999;
    document.getElementById('zoomimglayer').innerHTML = '<table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle"><img src="images/common/loading.gif"></td></tr></table><div style="position:absolute;top:-100000px;visibility:hidden"><img onload="zoomimgresize(this)" src="' + zoomobj['zimg'] + '"></div>';
}
var zoomdragstart = new Array();
var zoomclick = 0;
function zoomdrag(e, op) {
    if (op == 1) {
        zoomclick = 1;
        zoomdragstart = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
        zoomdragstart[2] = parseInt(document.getElementById('zoomimglayer').style.left);
        zoomdragstart[3] = parseInt(document.getElementById('zoomimglayer').style.top);
        doane(e);
    } else if (op == 2 && zoomdragstart[0]) {
        zoomclick = 0;
        var zoomdragnow = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
        document.getElementById('zoomimglayer').style.left = (zoomdragstart[2] + zoomdragnow[0] - zoomdragstart[0]) + 'px';
        document.getElementById('zoomimglayer').style.top = (zoomdragstart[3] + zoomdragnow[1] - zoomdragstart[1]) + 'px';
        doane(e);
    } else if (op == 3) {
        if (zoomclick) zoomclose();
        zoomdragstart = [];
        doane(e);
    }
}
function zoomimgresize(obj) {
    zoomobj['zimginfo'] = [obj.width, obj.height];
    var r = obj.width / obj.height;
    var w = document.body.clientWidth * 0.95;
    w = obj.width > w ? w : obj.width;
    var h = w / r;
    var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
    if (h > clientHeight) {
        h = clientHeight;
        w = h * r;
    }
    var l = (document.body.clientWidth - w) / 2;
    var t = h < clientHeight ? (clientHeight - h) / 2 : 0;
    t += +scrollTop;
    zoomobj['x'] = (l - zoomobj['srcinfo']['left']) / 5;
    zoomobj['y'] = (t - zoomobj['srcinfo']['top']) / 5;
    zoomobj['w'] = (w - zoomobj['srcobj'].width) / 5;
    zoomobj['h'] = (h - zoomobj['srcobj'].height) / 5;
    document.getElementById('zoomimglayer').style.filter = '';
    document.getElementById('zoomimglayer').innerHTML = '';
    setTimeout('zoomST(1)', 5);
}

function zoomST(c) {
    if (document.getElementById('zoomimglayer').style.display == '') {
        document.getElementById('zoomimglayer').style.left = (parseInt(document.getElementById('zoomimglayer').style.left) + zoomobj['x']) + 'px';
        document.getElementById('zoomimglayer').style.top = (parseInt(document.getElementById('zoomimglayer').style.top) + zoomobj['y']) + 'px';
        document.getElementById('zoomimglayer').style.width = (parseInt(document.getElementById('zoomimglayer').style.width) + zoomobj['w']) + 'px';
        document.getElementById('zoomimglayer').style.height = (parseInt(document.getElementById('zoomimglayer').style.height) + zoomobj['h']) + 'px';
        var opacity = c * 20;
        document.getElementById('zoomimglayer').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ',finishOpacity=100,style=0)';
        document.getElementById('zoomimglayer').style.opacity = opacity / 100;
        c++;
        if (c <= 5) {
            setTimeout('zoomST(' + c + ')', 5);
        } else {
            zoomadjust = 1;
            document.getElementById('zoomimglayer').style.filter = '';
            document.getElementById('zoomimglayer_bg').style.display = '';
            document.getElementById('zoomimglayer').innerHTML = '<table cellspacing="0" cellpadding="2"><tr><td style="text-align: right">鼠标滚轮缩放图片 <a href="' + zoomobj['zimg'] + '" target="_blank"><img src="images/common/newwindow.gif" border="0" style="vertical-align: middle" title="在新窗口打开" /></a> <a href="###" onclick="zoomimgadjust(event, 1)"><img src="images/common/resize.gif" border="0" style="vertical-align: middle" title="实际大小" /></a> <a href="###" onclick="zoomclose()"><img style="vertical-align: middle" src="images/common/close.gif" title="关闭" /></a>&nbsp;</td></tr><tr><td align="center" id="zoomimgbox"><img id="zoomimg" style="cursor: move; margin: 5px;" src="' + zoomobj['zimg'] + '" width="' + document.getElementById('zoomimglayer').style.width + '" height="' + document.getElementById('zoomimglayer').style.height + '"></td></tr></table>';
            document.getElementById('zoomimglayer').style.overflow = 'visible';
            document.getElementById('zoomimglayer').style.width = document.getElementById('zoomimglayer').style.height = 'auto';
            if (is_ie) {
                document.getElementById('zoomimglayer').onmousewheel = zoomimgadjust;
            } else {
                document.getElementById('zoomimglayer').addEventListener("DOMMouseScroll", zoomimgadjust, false);
            }
            document.getElementById('zoomimgbox').onmousedown = function(event) { try { zoomdrag(event, 1); } catch (e) { } };
            document.getElementById('zoomimgbox').onmousemove = function(event) { try { zoomdrag(event, 2); } catch (e) { } };
            document.getElementById('zoomimgbox').onmouseup = function(event) { try { zoomdrag(event, 3); } catch (e) { } };
        }
    }
}

function zoomimgadjust(e, a) {
    if (!a) {
        if (!e) e = window.event;
        if (e.altKey || e.shiftKey || e.ctrlKey) return;
        var l = parseInt(document.getElementById('zoomimglayer').style.left);
        var t = parseInt(document.getElementById('zoomimglayer').style.top);
        if (e.wheelDelta <= 0 || e.detail > 0) {
            if (document.getElementById('zoomimg').width <= 200 || document.getElementById('zoomimg').height <= 200) {
                doane(e); return;
            }
            document.getElementById('zoomimg').width -= zoomobj['zimginfo'][0] / 10;
            document.getElementById('zoomimg').height -= zoomobj['zimginfo'][1] / 10;
            l += zoomobj['zimginfo'][0] / 20;
            t += zoomobj['zimginfo'][1] / 20;
        } else {
            if (document.getElementById('zoomimg').width >= zoomobj['zimginfo'][0]) {
                zoomimgadjust(e, 1); return;
            }
            document.getElementById('zoomimg').width += zoomobj['zimginfo'][0] / 10;
            document.getElementById('zoomimg').height += zoomobj['zimginfo'][1] / 10;
            l -= zoomobj['zimginfo'][0] / 20;
            t -= zoomobj['zimginfo'][1] / 20;
        }
    } else {
        var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
        var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        document.getElementById('zoomimg').width = zoomobj['zimginfo'][0]; document.getElementById('zoomimg').height = zoomobj['zimginfo'][1];
        var l = (document.body.clientWidth - document.getElementById('zoomimg').clientWidth) / 2; l = l > 0 ? l : 0;
        var t = (clientHeight - document.getElementById('zoomimg').clientHeight) / 2 + scrollTop; t = t > 0 ? t : 0;
    }
    document.getElementById('zoomimglayer').style.left = l + 'px';
    document.getElementById('zoomimglayer').style.top = t + 'px';
    document.getElementById('zoomimglayer_bg').style.height = t + document.getElementById('zoomimglayer').clientHeight > document.getElementById('zoomimglayer_bg').clientHeight ? (t + document.getElementById('zoomimglayer').clientHeight) + 'px' : document.getElementById('zoomimglayer_bg').style.height;
    doane(e);
}
function zoomclose() {
    document.getElementById('zoomimglayer').innerHTML = '';
    document.getElementById('zoomimglayer').style.display = 'none';
    document.getElementById('zoomimglayer_bg').style.display = 'none';
}

function setIdentify(identify) {
    identify.style.left = ((document.body.clientWidth - document.getElementById('container').clientWidth) / 2 + document.getElementById('container').clientWidth - 400) + 'px';
    identify.style.top = identify.offsetTop + 25 + 'px';
}

var tags = new Array();
if (typeof (closedtags) == 'undefined') {
    var closedtags;
}
if (typeof (colorfultags) == 'undefined') {
    var colorfultags;
}




function BOX_show(e, aid) {       //显示
    if (document.getElementById(e) == null) { return; }
    BOX_layout(e);
    window.onresize = function() { BOX_layout(e); } //改变窗体重新调整位置
    window.onscroll = function() { BOX_layout(e); } //滚动窗体重新调整位置

    if (e == 'attachpaymentlog') {
        loadattachpaymentlog(aid);
    } else if (e == 'buyattach') {
        loadbuyattach(aid);
    }

}

function BOX_remove(e) {       //移除
    window.onscroll = null;
    window.onresize = null;
    document.getElementById('BOX_overlay').style.display = "none";
    document.getElementById(e).style.display = "none";
}



function BOX_layout(e) {       //调整位置
    var a = document.getElementById(e);
    if (document.getElementById('BOX_overlay') == null) { //判断是否新建遮掩层
        var overlay = document.createElement("div");
        overlay.setAttribute('id', 'BOX_overlay');
        overlay.onclick = function() { BOX_remove(e); };
        a.parentNode.appendChild(overlay);
    }
    //取客户端左上坐标，宽，高
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var clientWidth = document.documentElement.clientWidth;

    var clientHeight = document.documentElement.clientHeight;

    var bo = document.getElementById('BOX_overlay');
    bo.style.left = scrollLeft + 'px';
    bo.style.top = scrollTop + 'px';
    bo.style.width = clientWidth + 'px';
    bo.style.height = clientHeight + 'px';
    bo.style.display = "";
    //Popup窗口定位
    a.style.position = 'absolute';
    a.style.zIndex = 101;
    a.style.display = "";
    a.style.left = scrollLeft + ((clientWidth - a.offsetWidth) / 2) + 'px';
    a.style.top = scrollTop + ((clientHeight - a.offsetHeight) / 2) + 'px';

}
