// JavaScript Document£ºpopupdiv.js
// function:    alert div tips
// date:        2008/3/31

var yScroll,popupDiv;

function addLoadEvent(func){
    var oldonload = window.onload;
    if(typeof window.onload != 'function'){
    window.onload = func;
    }else{
    window.onload = function(){
    oldonload();
    func();
    }
    }
}

function $id(){
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++){
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    } 
        return elements;
}

function _getbodySize(){
    if (window.innerHeight && window.scrollMaxY) {    
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
    }
    return yScroll;
}

function popupTips(obj){
    if(!$id(obj)){return false;}
    if (!document.createElement) return false;
         popupDiv = $id(obj);
        popupDiv.className = "popupdiv";
        popupDiv.style.marginLeft = "-" + popupDiv.clientWidth/2 + "px";
        popupBg = document.createElement("div");
        popupBg.setAttribute("id","popupbg");
        pHeight = popupDiv.clientHeight;
        sHeight = screen.height;
        bHeight = yScroll;
    if(pHeight>bHeight){
        popupDiv.style.top = "0";
        popupBg.style.height = pHeight+240+"px";
        popupDiv.style.marginTop = "120px";
    }else{
        if(bHeight>sHeight){
            popupBg.style.height = bHeight+"px";
        }else{
            popupBg.style.height = sHeight+"px";
        }
        popupDiv.style.marginTop = "-" + pHeight/2 + "px";
    }
    
    document.body.appendChild(popupBg);

    placeholder = document.createElement("iframe");
    placeholder.setAttribute("id","divshim");
    placeholder.setAttribute("src","javascript:void(0);");
    placeholder.setAttribute("scrolling","no");
    placeholder.setAttribute("frameborder","0");
    placeholder.setAttribute("allowtransparency","true");
    insertAfter(placeholder,popupBg);
    placeholder.className = "popupifra";
    placeholder.style.height = popupBg.style.height;
    placeholder.style.width = popupBg.style.width;
}

function insertAfter(newElement,targetElement) {
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
} else {
    parent.insertBefore(newElement,targetElement.nextSibling);
}
}

function closeDiv(obj){
    popupBg.className = "hidden";
    placeholder.className="hidden";
    $id(obj).className = "hidden";
}

addLoadEvent(_getbodySize);


