var docEle = function() 
{
    return document.getElementById(arguments[0]) || false;
}

function MessageBox(titel,width,height,text)
{
		var html = '<div style="width:'+width+'px; color:#5e7baa;">'+
		'<div style="width:100%; height:25px; line-height:25px; background:url(../Images/box_bj.gif);">'+
			'<div style="background:url(../Images/box_left.gif); width:2px; height:25px;float:left;"></div>'+
			'<div style=" font-weight:bold; float:left; height:100%;cursor: hand;">&nbsp;'+titel+'</div>'+
			'<div style="background:url(../Images/box_right.gif); width:2px; height:25px;float:right;"></div>'+
			'<div style="float:right; width:20px; text-align:center; margin-top:5px;"><a href="javascript:void(0);" onclick="Close();" ><img src="../Images/box_close.gif" border="0" /></a></div>'+
		'</div>'+
		'<div>'+
			'<div style="height:'+height+'px; width:1px; background:#a7b8cf; float:left;"></div>'+
			'<div style="height:'+(height-10)+'px;width:'+(width-2)+'px; background:#d3dfed; float:left; border-bottom:1px #a7b8cf solid; text-align:center; padding-top:10px;color:#370000;line-height:20px;">'+text+'<br /><br /><input type="button" onclick="Close();" value="  OK  " /></div>'+
			'<div style="height:'+height+'px; width:1px; background:#a7b8cf; float:left;"></div>'+
		'</div></div>'
	openNewDiv(width,height,html);
}

function MessageBoxWeb(titel,width,height,url)
{
		var html = '<div style="width:'+width+'px; color:#5e7baa;">'+
		'<div style="width:100%; height:25px; line-height:25px; background:url(../Images/box_bj.gif);">'+
			'<div style="background:url(../Images/box_left.gif); width:2px; height:25px;float:left;"></div>'+
			'<div style=" font-weight:bold; float:left; height:100%;cursor: hand;">&nbsp;'+titel+'</div>'+
			'<div style="background:url(../Images/box_right.gif); width:2px; height:25px;float:right;"></div>'+
			'<div style="float:right; width:20px; text-align:center; margin-top:5px;"><a href="javascript:void(0);" onclick="Close();" ><img src="../Images/box_close.gif" border="0" /></a></div>'+
		'</div>'+
		'<div>'+
			'<div style="height:'+height+'px; width:1px; background:#a7b8cf; float:left;"></div>'+
			'<div style="height:'+height+'px;width:'+(width-2)+'px; background:#d3dfed; float:left; border-bottom:1px #a7b8cf solid; text-align:center;color:#370000;"><iframe src="'+url+'" style="width:100%; height:100%;" frameborder="no" border="0" framespacing="0"></iframe></div>'+
			'<div style="height:'+height+'px; width:1px; background:#a7b8cf; float:left;"></div>'+
		'</div></div>'
	openNewDiv(width,height,html);
}

function openNewDiv(iwidth,iheight,html) 
{
    var w = window.screen.availWidth;
    var h =window.screen.availHeight;
    //alert(w+'  '+h);
    
    var m = "mask";
    if (docEle("mydiv")) document.body.removeChild(docEle("mydiv"));
    if (docEle(m)) document.body.removeChild(docEle(m));
    
    //mask遮罩层
    //document.body.scroll="no"; 滚动条
    var newMask = document.createElement("div");
    newMask.id = m;

    newMask.style.position = "absolute";
    newMask.style.zIndex = "1";
    _scrollWidth = 2000;
    _scrollHeight = 2000;
    newMask.style.width = _scrollWidth + "px";
    newMask.style.height = _scrollHeight + "px";
    newMask.style.top = "0px";
    newMask.style.left = "0px";
    newMask.style.background = "#CEE6FF";
    newMask.style.filter = "alpha(opacity=40)";
    newMask.style.opacity = "0.40";
    document.body.appendChild(newMask);
    
    //新弹出层
    var newDiv = document.createElement("div");
    newDiv.id = "mydiv";
    newDiv.style.position = "absolute";
    
    newDiv.style.zIndex = "9999";
    newDivWidth = iwidth;
    newDivHeight = iheight;
    newDiv.style.width = iwidth + "px";
    newDiv.style.height = iheight + "px";
   	newDiv.style.top = (h-window.screenTop-iheight)/2-25+ "px";
    newDiv.style.left = (w-iwidth)/2 + "px";
    newDiv.style.padding = "0px";
	newDiv.style.font =	"13px/20px \"Verdana\",\"Arial\",\"宋体\"";
    newDiv.innerHTML = html; 
    document.body.appendChild(newDiv);
    
    //弹出层滚动居中

    function newDivCenter()
    {
        newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
        newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
    }
    if(document.all)
    {
        window.attachEvent("onscroll",newDivCenter);
    }
    else
    {
        window.addEventListener('scroll',newDivCenter,false);
    }
	Move_obj('mydiv');
    setwindow();
}
function Closes()
{
        //window.location.href = window.location.href;
        document.body.removeChild(docEle("mydiv"));
        document.body.removeChild(docEle("mask"));
        setwindow();
        //document.URL=location.href;
}

function Close()
{
        document.body.removeChild(docEle("mydiv"));
        document.body.removeChild(docEle("mask"));
        setwindow();
}
var htmlbody = document.documentElement;
var newdivs = false;
function setwindow(){
	if (newdivs){
		newdivs = false;
		htmlbody.style.overflow = "auto";
	}else{
		newdivs = true;
		htmlbody.style.overflow = "hidden";
	}
}

var drag_=false
var D=new Function('obj','return document.getElementById(obj);')
var oevent=new Function('e','if (!e) e = window.event;return e')
function Move_obj(obj){
 var x,y;
 D(obj).onmousedown=function(e){
  drag_=true;
  with(this){
   style.position="absolute";var temp1=offsetLeft;var temp2=offsetTop;
   x=oevent(e).clientX;y=oevent(e).clientY;
   document.onmousemove=function(e){
    if(!drag_)return false;
    with(this){
     style.left=temp1+oevent(e).clientX-x+"px";
     style.top=temp2+oevent(e).clientY-y+"px";
    }
   }
  }
  document.onmouseup=new Function("drag_=false");
 }
}
