
var popWinW = 0;
var popWinH = 0;
var browserW = 0;
var browserH = 0;
var moveLimitX = 0;
var moveLimitY = 0;

var popWinDrag = 0;
var popWinMove = 0;
window.document.onmousemove = mouseMove;
window.document.onmousedown = mouseDown;
window.document.onmouseup   = mouseUp;
window.document.ondragstart = mouseStop;
function mouseUp() {
	popWinMove = 0;
}
function mouseDown() {
	if (popWinDrag) {
		clickleft = window.event.x - parseInt(document.getElementById("popWin").style.left);
		clicktop  = window.event.y - parseInt(document.getElementById("popWin").style.top);
		popWinMove = 1;
	}
}
function mouseMove() {
	if (popWinMove) {
        movex = window.event.x - clickleft;
        if (movex<0) {
            movex = 0;
        }
        if (movex>moveLimitX) {
            movex = moveLimitX;
        }
        movey = window.event.y - clicktop;
        if (movey<0) {
            movey = 0;
        }
        if (movey>moveLimitY) {
            movey = moveLimitY;
        }
		document.getElementById("popWin").style.left = movex;
		document.getElementById("popWin").style.top  = movey;
	}
}
function mouseStop() {
	window.event.returnValue = false;
}
function loadPopWin(lock) {
    if (!(lock)) {
        lock = "";
    }
    document.writeln('<div id="popWin" style="position:absolute;left:0px;top:0px;z-index:100;display:none;" ondragstart="return false" onselectstart="return false">');
    document.writeln('<table border="0" cellpadding="0" cellspacing="0">');
    document.writeln('<tr>');
    document.writeln('<td colspan="3">');
    document.writeln('<table width="100%" border="0" cellpadding="0" cellspacing="0">');
    document.writeln('<tr>');
    document.writeln('<td><img src="../../mid/popwindow/win_11.gif" width="23" height="31"></td>');
    if (lock=="") {
        document.writeln('<td width="100%" background="../../mid/popwindow/win_21.gif" style="cursor:move" onmouseover="popWinDrag=1; popWinMove=0;" onmouseout="popWinDrag=0"><img style="width:1px;height:1px;"></td>');
    } else {
        document.writeln('<td width="100%" background="../../mid/popwindow/win_21.gif"><img style="width:1px;height:1px;"></td>');
    }
    document.writeln('<td><img src="../../mid/popwindow/win_31.gif" width="54" height="31" onmouseover="this.src=\'../../mid/popwindow/win_31_.gif\'" onmouseout="this.src=\'../../mid/popwindow/win_31.gif\'" onclick="hidePopWin()"></td>');
    document.writeln('</tr>');
    document.writeln('</table>');
    document.writeln('</td>');
    document.writeln('</tr>');
    document.writeln('<tr>');
    document.writeln('<td background="../../mid/popwindow/win_12.gif"><img style="width:1px;height:1px;"></td>');
    document.writeln('<td bgcolor="#FFFFFF"><iframe id="popFrame" name="popFrame" src="about:blank" frameborder="0" width="100" height="100" scrolling="no"></iframe></td>');
    document.writeln('<td background="../../mid/popwindow/win_32.gif"><img style="width:1px;height:1px;"></td>');
    document.writeln('</tr>');
    document.writeln('<tr>');
    document.writeln('<td><img src="../../mid/popwindow/win_13.gif" width="3" height="3"></td>');
    document.writeln('<td background="../../mid/popwindow/win_23.gif"><img style="width:1px;height:1px;"></td>');
    document.writeln('<td><img src="../../mid/popwindow/win_33.gif" width="3" height="3"></td>');
    document.writeln('</tr>');
    document.writeln('</table>');
    document.writeln('</div>');
}
function showPopWin(url,w,h,p) {
    var timestamp = new Date();
    if (url.indexOf("?")<0) {
        url = url + "?v_pop_dmy=" + timestamp.getTime();
    } else {
        url = url + "&v_pop_dmy=" + timestamp.getTime();
    }
    document.getElementById("popFrame").src = url;
    frameW = parseInt(w);
    frameH = parseInt(h);
    browserW = parseInt(document.body.clientWidth);
    browserH = parseInt(document.body.clientHeight);
    if ((frameW+6)>browserW) {
        frameW = browserW - 6;
    }
    if ((frameH+34)>browserH) {
        frameH = browserH - 34;
    }
    popWinW = frameW + 6;
    popWinH = frameH + 34;
    moveLimitX = browserW - popWinW;
    moveLimitY = browserH - popWinH;
    document.getElementById("popFrame").style.width  = frameW;
    document.getElementById("popFrame").style.height = frameH;
    if (p=="T" || p=="t") {
        document.getElementById("popWin").style.left = 0;
        document.getElementById("popWin").style.top  = 0;
    } else {
        pw = (browserW - popWinW) / 2;
        if (pw<0) {
            pw = 0;
        }
        ph = (browserH - popWinH) / 2 - 100;
        if (ph<0) {
            ph = 0;
        }
        document.getElementById("popWin").style.left = pw;
        document.getElementById("popWin").style.top  = ph;
    }
    document.getElementById("popWin").style.display = "block";
}
function hidePopWin() {
    document.getElementById("popFrame").src = "about:blank";
    document.getElementById("popWin").style.display = "none";
}
