﻿
/// 弹出框
///
///
var isIe=(document.all)?true:false;   
function EditBox(strPageName,strTitle,w,h)
{
  DelEditBox();
  var msgw,msgh
  msgw=w;//提示窗口的宽度
  msgh=h;//提示窗口的高度
  
  	var ie=document.all && !window.opera
	var dom=document.getElementById
	iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	objEdit=(dom)? document.getElementById("msgObj") : document.all.msgObj
	var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
	var sWidth=(ie)? iebody.clientWidth : window.innerWidth
	sHeight=(ie)? iebody.clientHeight: window.innerHeight
  
  //隐藏所有Select控制
  var selectObj=document.getElementsByTagName("select");
  for (i=0;i<selectObj.length;i++)
  {
      selectObj[i].style.visibility="hidden";
  }
  
document.body.scroll="no";
 var back=document.createElement("div");  
 back.id="back";  
 var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+sWidth+"px;height:"+sHeight+"px;";  
 styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";  
 back.style.cssText=styleStr;  
 document.body.appendChild(back);  
 showBackground(back,50);


  var msgObj=document.createElement("div")//创建一个div对象（提示框层）
  //定义div属性，即相当于
  //<div id="msgDiv" align="center" style="background-color:white; border:1px solid #336699; position:absolute; left:50%; top:50%; font:12px/1.6em Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left:-225px; margin-top:npx; width:400px; height:100px; text-align:center; line-height:25px; z-index:100001;"></div>
  toph=scroll_top+sHeight/2-h/2;
  if(toph<0){toph=0;document.body.scroll="auto";}
  msgObj.setAttribute("id","msgDiv");
  msgObj.setAttribute("align","center");
  msgObj.style.position = "absolute";
  msgObj.style.left=document.body.offsetWidth/2-w/2+"px"
  msgObj.style.top=toph+"px"
  msgObj.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
  msgObj.style.width = msgw;
  msgObj.style.height =msgh +"px";
  msgObj.style.textAlign = "center";
  msgObj.style.zIndex = "10001";
  msgObj.innerHTML= '<div style="width: 100%; background: #666666; margin: 5px auto; text-align: left">' +
				'<div style="width: 100%; height: ' + msgh + 
				'px; padding: 1px; background: #FFFFFF; border: 1px solid #7597B8; position: relative; left: -6px; top: -3px">' +
				'<div onmouseover="drag(msgDiv)" style="text-indent:10px;cursor: move; position: relative; left: 0px; top: 0px; width: 100%; height: 25px; margin-bottom: 0px;BORDER-RIGHT: #7b9ebd 0px solid;BORDER-TOP: #7b9ebd 0px solid;FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde); BORDER-LEFT: #7b9ebd 0px solid;COLOR: black;BORDER-BOTTOM: #7b9ebd 0px solid;">'+
				'<div style="margin-top:5px;font-size:14px;font-weight:bold;color:#000066;">'+strTitle+'</div></div>' +
				'<a onclick="DelEditBox()"><div style="cursor:hand;;font-size:14px;font-weight:bold;;position: absolute; right: 10px; top: 5px" title="关闭">关闭</div></a>' +
				'<div id="pmwinmask" style="margin-top: 30px; position: absolute; width: 100%; height: 100%; display: none"></div><iframe id="pmframe" name="pmframe" src="'+strPageName+'" style="width:' + msgw + 'px;height:'+(msgh-30)+'px" allowTransparency="true" frameborder="0"></iframe></div></div>';
    
  document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj
  
  }
  
  
  function DelEditBox(){//删除
  //显示所有select
      var selectObj=document.getElementsByTagName("select");
      for (i=0;i<selectObj.length;i++)
      {
          selectObj[i].style.visibility="visible";
      }
      var aa=document.getElementById("back");
      var bb=document.getElementById("msgDiv");
      if(aa!=null&&bb!=null){
      aa.parentNode.removeChild(aa);  
      bb.parentNode.removeChild(bb);}
      document.body.scroll="auto";
    }
    
//背影渐暗参数OBJ对象，endint速度
function showBackground(obj,endInt)  
{  
    if(isIe)  
 {  
 obj.filters.alpha.opacity+=2;  
 if(obj.filters.alpha.opacity<endInt)  
 {  
 setTimeout(function(){showBackground(obj,endInt)},2);  
 }  
 }else{  
 var al=parseFloat(obj.style.opacity);al+=0.01;  
 obj.style.opacity=al;  
 if(al<(endInt/100))  
 {setTimeout(function(){showBackground(obj,endInt)},2);}  
 }  
}


function drag(o,s)  
{  
    if (typeof o == "string") o = document.getElementById(o);  
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;  
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;  
    o.orig_index = o.style.zIndex;  
          
    o.onmousedown = function(a)  
    {  
        this.style.cursor = "move";  
        this.style.zIndex = 10000;  
        var d=document;  
        if(!a)a=window.event;  
        var x = a.clientX+d.body.scrollLeft-o.offsetLeft;  
        var y = a.clientY+d.body.scrollTop-o.offsetTop;  
        //author: www.longbill.cn  
        d.ondragstart = "return false;"  
        d.onselectstart = "return false;"  
        d.onselect = "document.selection.empty();"  
                  
        if(o.setCapture)  
            o.setCapture();  
        else if(window.captureEvents)  
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);  

        d.onmousemove = function(a)  
        {  
            if(!a)a=window.event;  
            o.style.left = a.clientX+document.body.scrollLeft-x;  
            o.style.top = a.clientY+document.body.scrollTop-y;  
            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;  
            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;  
        }  

        d.onmouseup = function()  
        {  
            if(o.releaseCapture)  
                o.releaseCapture();  
            else if(window.captureEvents)  
                window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);  
            d.onmousemove = null;  
            d.onmouseup = null;  
            d.ondragstart = null;  
            d.onselectstart = null;  
            d.onselect = null;  
            o.style.cursor = "normal";  
            o.style.zIndex = o.orig_index;  
        }  
    }  
      
    if (s)  
    {  
        var orig_scroll = window.onscroll?window.onscroll:function (){};  
        window.onscroll = function ()  
        {  
            orig_scroll();  
            o.style.left = o.orig_x + document.body.scrollLeft;  
            o.style.top = o.orig_y + document.body.scrollTop;  
        }  
    }  
}