﻿var divFlyBar = null;

//定义要显示页面的层
document.write("<div id='open_div' onMouseDown='catchFlyBar()' onMouseUp='releaseFlyBar()' style='position:absolute;display:none;border:#808080 1px ridge;background-color:white;overflow:none;z-index:8001'></div>");
//定义覆盖层
document.write("<div id='fill_div' style='position:absolute;display:none;left:0px;top:0px;background-color:#656565;filter:alpha(opacity:30);border:0px;z-index:8000;'></div>");
	
//以模式窗口的形式打开新页面,pageUrl代表页面path,width代表页面宽度,height代表页面的高
function OpenModelWindow(pageUrl,width,height,pageTitle)
{

    //禁用所有下拉列表
    var selects = document.getElementsByTagName("select");
    for(var i =0;i<selects.length;i++)
    {
        selects[i].style.display = 'none';
    }
    
    //
    var clientW = document.documentElement.offsetWidth;
    var clientH = document.documentElement.offsetHeight;

    document.getElementById("fill_div").style.display = 'block';
    document.getElementById("fill_div").style.width = clientW + 'px';
    document.getElementById("fill_div").style.height = document.body.scrollHeight + 'px'; 
    
    if(width > clientW)
		width = clientW - 50;
	if(height > clientH)
		height= clientH - 50;
	
	var left =(clientW - width) / 2;
    var top = (clientH/2 - height) / 2;

    document.getElementById("open_div").style.display = 'block';
    document.getElementById("open_div").style.left = left;
	document.getElementById("open_div").style.top = top;
	document.getElementById("open_div").style.width = width;
	document.getElementById("open_div").style.height = 0; 
	divFlyBar=document.getElementById("open_div");
	
	//定义窗体头
	var title="";
	title+="<table id='tab_" + document.getElementById("open_div").id + "' background='/page_user/img/pageTitle.bmp' width='" + width + "px' height='22px' border='0px' cellspacing='0px' cellpadding='0px'>";
	title+="<tr>";
	title+="<td style='font-size:9pt;padding-left:5px;'>" + pageTitle + "</td>";
	title+="<td height='16px' width='42px' style='padding-right:3px'><img src='/page_user/img/close.bmp' width='42px' onmouseover=\"this.src='/page_user/img/close_over.bmp'\" onmouseout=\"this.src='/page_user/img/close.bmp'\" onclick='myClose()'></td>";
	title+="</tr>";
	title+="</table>"

	document.getElementById("open_div").innerHTML="<table border=0 cellspacing=0 cellpadding=0 width=100% height=100%>";
	document.getElementById("open_div").innerHTML+="<tr><td height='22px' width='100%'>";
	document.getElementById("open_div").innerHTML+=title;
	document.getElementById("open_div").innerHTML+="</td></tr>";
	document.getElementById("open_div").innerHTML+="<tr><td width='100%' valign='top'>";
	document.getElementById("open_div").innerHTML+="<iframe id='myFrame' src='about:blank' height='" + height + "px' width='" + width + "px' frameborder='0px' marginwidth='0px' marginheight='0px'></iframe>";
	document.getElementById("open_div").innerHTML+="</td></tr>";
	document.getElementById("open_div").innerHTML+="</table>";
	
	if(pageUrl.indexOf("?") == -1)
		pageUrl += "?tmp=" + Math.random();
	else
		pageUrl += "&tmp=" + Math.random();
		
	document.getElementById("myFrame").src=pageUrl;
}

//关闭窗体
function myClose()
{
    //启用所有select
    var selects = document.getElementsByTagName("select");
    for(var i =0;i<selects.length;i++)
    {
        selects[i].style.display = '';
//        selects[i].disabled = false;
//        selects[i].style.backgroundColor = '#FFFFFF';
    }
    
    document.getElementById("myFrame").src="about:blank";
	document.getElementById("open_div").style.display = "none";
	document.getElementById("fill_div").style.display = "none";
}

// bigin fly bar
var bIsCatchFlyBar = false;
var dragClickX = 0;
var dragClickY = 0;
	
function HideFlyBar(){
    divFlyBar.style.display = "hidden";
    myFlyBarRestorButton.style.display = '';
}

function catchFlyBar(e){
    bIsCatchFlyBar = true;
    var x=event.x+document.body.scrollLeft;
    var y=event.y+document.body.scrollTop;
    dragClickX=x-divFlyBar.style.pixelLeft;
    dragClickY=y-divFlyBar.style.pixelTop;
    divFlyBar.setCapture();
    document.onmousemove = moveFlyBar;
}
	
function releaseFlyBar(e){
    bIsCatchFlyBar = false;

    if(parseInt(divFlyBar.style.top) < 20)
    {
	    divFlyBar.style.top= 0 + "px";
    }
    if(parseInt(divFlyBar.style.top) > (parseInt(document.body.offsetHeight)-10))
    {
	    divFlyBar.style.top= parseInt(document.body.offsetHeight)-parseInt(20) + "px";
    }
    if(parseInt(divFlyBar.style.left) <= ((parseInt(divFlyBar.offsetWidth)*-1)+10))
    {
	    divFlyBar.style.left = (20 - parseInt(divFlyBar.offsetWidth))  + "px";
    }
    if(parseInt(divFlyBar.style.left) >= (parseInt(document.body.offsetWidth)-10))
    {
	    divFlyBar.style.left= parseInt(document.body.offsetWidth)-parseInt(20) + "px";
    }

    divFlyBar.releaseCapture();
    document.onmousemove = null;
}

function moveFlyBar(e){
    if(bIsCatchFlyBar){
        divFlyBar.style.left = (event.x+document.body.scrollLeft - dragClickX) + "px";
        divFlyBar.style.top = (event.y+document.body.scrollTop - dragClickY) + "px";
    }
}
	
function myload_flybar(){
    divFlyBar.style.top = document.body.scrollTop + "px";
    divFlyBar.style.left = (document.body.offsetWidth - divFlyBar.clientWidth - 30 + document.body.scrollLeft) + "px";
}

