// JScript 文件
  
var iDiffX = 0;
var iDiffY = 0;
function handleMouseMove() {
    var content = document.getElementById(_ContentPanelId)
    if(content.style.display!="none"){
        content.style.display="none";
    }
    var oEvent = EventUtil.getEvent();
    _popDiv.style.left = oEvent.clientX - iDiffX;
    _popDiv.style.top = oEvent.clientY - iDiffY;
}      
function handleMouseDown() {
    var oEvent = EventUtil.getEvent();
    iDiffX = oEvent.clientX - _popDiv.offsetLeft;
    iDiffY = oEvent.clientY - _popDiv.offsetTop;
    EventUtil.addEventHandler(document.body, "mousemove", handleMouseMove);
    EventUtil.addEventHandler(document.body, "mouseup", handleMouseUp);
    
}
function handleMouseUp() {
    EventUtil.removeEventHandler(document.body, "mousemove", handleMouseMove);
    EventUtil.removeEventHandler(document.body, "mouseup", handleMouseUp);
    document.getElementById(_ContentPanelId).style.display="block";
}
var _popDiv= null;
var _ContentPanelId ='_ContentPanel';
function  ShowPopupPanel(w,h,url){
    if(_popDiv!=null&&_popDiv.style.display=="block"){
        var iframe = document.getElementById('_popC_Panel');
     
        
        iframe.style.display="none";
        _popDiv.style.height=h+"px";
        _popDiv.style.width=w+"px";
        iframe.style.width=w+"px";
        iframe.style.height=(h-25)+"px";
         iframe.src=openPanel(url);
       iframe.style.display="block";
        return;
    }
    if(_popDiv==null){
        _popDiv = document.createElement("div"); 
        _popDiv.className="pop"; 
       _popDiv.onmousedown = handleMouseDown;
        _popDiv.style.border="whitesmoke 20px solid";
        _popDiv.style.height=h+"px";
        _popDiv.style.width=w+"px";
        _popDiv.style.position = "absolute";
        _popDiv.style.backgroundColor="#fff";
        _popDiv.style.display ="block";
        setContentLocation(w,h);
        var contentY = h/3;
        var contentX = w/2-100;
        document.body.appendChild(_popDiv);  
        _popDiv.innerHTML=
        "<input id='_popClose' type='button'  style='background-color:whitesmoke;float:right;border:none;' value='关闭' onclick='hidePop();'/> <div id="+
        _ContentPanelId+" style='margin-top:20px' ><iframe id='_popC_Panel'  width='"+w+"px' height='"+(h-25)+
        "px'></iframe></div>";
        iframe = document.getElementById('_popC_Panel');
        iframe.src=openPanel(url);
        return;
   }
   if(_popDiv!=null&&_popDiv.style.display=="none"){
   
        iframe = document.getElementById('_popC_Panel');
        _popDiv.style.height=h+"px";
        _popDiv.style.width=w+"px";
        iframe.style.width=w+"px";
        iframe.style.height=(h-25)+"px";
        setContentLocation(w,h);
        iframe.src=openPanel(url);
        _popDiv.style.display ="block"; 
        
        
        

       return;
   }
}   
    
function openPanel(url){
     var randomnumber=Math.floor(Math.random()*100000)
     if(url.indexOf('?')!=-1){
         return url+"&Random="+randomnumber;
     }
     return url+"?Random="+randomnumber;
    
}
function setContentLocation(w,h){
    var maskHeight = document.documentElement.clientHeight
    var maskWidth = document.documentElement.clientWidth 

    var dialogTop =  (maskHeight/3) - (h/3-30)+(document.documentElement.scrollTop || document.body.scrollTop);
    var dialogLeft = (maskWidth/2) - (w/2)+(document.documentElement.scrollLeft || document.body.scrollLeft);
    _popDiv.style.top = dialogTop + "px";
    _popDiv.style.left = dialogLeft + "px";
}

function hidePop(){
    _popDiv.style.display ="none";
}

var EventUtil = new Object;
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};
        
EventUtil.removeEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else { 
        oTarget["on" + sEventType] = null;
    }
};

EventUtil.formatEvent = function (oEvent) {

    if (typeof oEvent.charCode == "undefined") {
        oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
        oEvent.isChar = (oEvent.charCode > 0);
    }
    
    if (oEvent.srcElement && !oEvent.target) {
        oEvent.eventPhase = 2;
        oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
        oEvent.pageY = oEvent.clientY + document.body.scrollTop;
        
        if (!oEvent.preventDefault) {
                oEvent.preventDefault = function () {
                    this.returnValue = false;
                };
        }
        if (oEvent.type == "mouseout") {
            oEvent.relatedTarget = oEvent.toElement;
        } else if (oEvent.type == "mouseover") {
            oEvent.relatedTarget = oEvent.fromElement;
        }

        if (!oEvent.stopPropagation) {
                oEvent.stopPropagation = function () {
                    this.cancelBubble = true;
                };
        }
        oEvent.target = oEvent.srcElement;
        oEvent.time = (new Date).getTime();
    }
    return oEvent;
};

EventUtil.getEvent = function() {
    if (window.event) {
        return this.formatEvent(window.event);
    } else {
        return EventUtil.getEvent.caller.arguments[0];
    }
};
