
var tipTimer;
function locateObject(n, d) {
    var p, x;
    if (!d) d = document;
    if ((p = n.indexOf('?')) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    return x = d.getElementById(n);
}
function ShowADPreview(ADContent) {
    showTooltip('dHTMLADPreview', ADContent, '#ffffff', '#000000', '#000000', '6000');
}
function showTooltip(object, tipContent, backcolor, bordercolor, textcolor, displaytime) {

    if (self.pageYOffset || self.pageXOffset) {
        posy = self.pageYOffset;
        posx = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft) {
        posy = document.documentElement.scrollTop;
        posx = document.documentElement.scrollLeft;
    } else if (document.body) {
        posy = document.body.scrollTop;
        posx = document.body.scrollLeft;
    }
    window.clearTimeout(tipTimer)
    var evt = getEvent();
    var _top;
    if (document.all) {
        locateObject(object).innerHTML = '<table style="border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: ' + backcolor + '" border="0" cellspacing="0" cellpadding="0"><tr><td nowrap><font style="font-family:宋体; font-size: 9pt; color: ' + textcolor + '">' + unescape(tipContent) + '</font></td></tr></table> '
        if ((document.body.scrollTop + posy + evt.clientY + 10 + locateObject(object).childNodes[0].clientHeight) > (getViewPortHeight() + document.body.scrollTop + posy)) {
            locateObject(object).style.top = (getViewPortHeight() + document.body.scrollTop + posy) - locateObject(object).childNodes[0].clientHeight - 5 + "px";
        } else {
            locateObject(object).style.top = document.body.scrollTop + posy + evt.clientY + 10 + "px";
        }
        if ((evt.clientX + locateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft)) {
            locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - locateObject(object).clientWidth - 10;
        } else {
            locateObject(object).style.left = document.body.scrollLeft + evt.clientX + 5;
        }
        locateObject(object).style.visibility = 'visible';
        tipTimer = window.setTimeout("hideTooltip('" + object + "')", displaytime);
        return true;
    } else if (document.layers) {
        locateObject(object).document.write('<table width="10" border="0" cellspacing="1" cellpadding="1"><tr bgcolor="' + bordercolor + '"><td><table width="10" border="0" cellspacing="0" cellpadding="0"><tr bgcolor="' + backcolor + '"><td nowrap><font style="font-family:宋体; font-size: 9pt; color: ' + textcolor + '">' + unescape(tipContent) + '</font></td></tr></table></td></tr></table>')
        locateObject(object).document.close();
        locateObject(object).top = evt.clientY + posy + 20 + "px";
        if ((evt.clientX + locateObject(object).clip.width) > (window.pageXOffset + window.innerWidth)) {
            locateObject(object).left = window.innerWidth - locateObject(object).clip.width - 5;
        } else {
            locateObject(object).left = evt.clientX;
        }
        locateObject(object).visibility = 'show';
        tipTimer = window.setTimeout("hideTooltip('" + object + "')", displaytime);
        return true;
    } else {
        if ((evt.pageY + 5 + locateObject(object).childNodes[0].clientHeight) > (getViewPortHeight() + posy)) {
            locateObject(object).style.top = (getViewPortHeight() + posy) - locateObject(object).childNodes[0].clientHeight + "px";
        } else {
            locateObject(object).style.top = document.body.scrollTop + posy + evt.clientY + 5 + "px";
        }
        locateObject(object).innerHTML = '<table width="100" height="100" style="border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: ' + backcolor + '" border="0" cellspacing="0" cellpadding="0"><tr><td nowrap><font style="font-family:宋体; font-size: 9pt; color: ' + textcolor + '">' + unescape(tipContent) + '</font></td></tr></table> '
        if ((evt.clientX + locateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft)) {
            locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - locateObject(object).clientWidth - 10;
        } else {
            locateObject(object).style.left = document.body.scrollLeft + evt.clientX + 10 + "px";
        }
        locateObject(object).style.visibility = 'visible';
        tipTimer = window.setTimeout("hideTooltip('" + object + "')", displaytime);
        return true;
    }
}

function getEvent() //同时兼容ie和ff的写法
{
    if (document.all) return window.event;
    func = getEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0) {
            if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
                return arg0;
            }
        }
        func = func.caller;
    }
    return null;
}

function getViewPortHeight() {
    var height = 0;

    if (window.innerHeight) {
        height = window.innerHeight - 18;
    }
    else if ((document.documentElement) && (document.documentElement.clientHeight)) {
        height = document.documentElement.clientHeight;
    }

    return height;
}

function hideTooltip(object) {
    if (document.all) {
        locateObject(object).style.visibility = 'hidden';
        locateObject(object).style.left = 1;
        locateObject(object).style.top = 1;
        return false;
    } else {
        if (document.layers) {
            locateObject(object).visibility = 'hide';
            locateObject(object).left = 1;
            locateObject(object).top = 1;
            return false;
        } else {
            locateObject(object).style.visibility = 'hidden';
            locateObject(object).style.left = 1;
            locateObject(object).style.top = 1;
            return false;
        }
    }
} 