function openLayer(divname){
     //alert("openLayer");
     //创建一个div元素做上面显示的层
// JavaScript Documentfunction openLayer(navi){
     //alert("openLayer");
     //创建一个div元素做上面显示的层
     var popupDiv=createPopupDiv(divname);
     //创建背景层，就是遮罩层，半透明，以使页面失效
     var bodyBack=createBackgroundDiv();
     
     //收工插入到目标元素之后，body下面
     var mybody = document.getElementById("flow");
     insertAfter(popupDiv,mybody);//控制层的顺序
     insertAfter(bodyBack,mybody);
     //弹出层内容
     // if()
}

function createPopupDiv(divname){
	var popupDiv = document.getElementById(divname);
   // var popupDiv = document.createElement("div");
     //给这个元素设置属性与样式
	// alert(parseInt(popupDiv.style.height));
     //popupDiv.setAttribute("id","maskdiv")
     popupDiv.style.display="block";
     popupDiv.style.border = "1px solid #ccc";
     popupDiv.style.width = popupDiv.style.width;
     popupDiv.style.height = popupDiv.style.height;
     popupDiv.style.background = "#FFF";
     popupDiv.style.zIndex =2;
     popupDiv.style.position = "absolute";
 	 //popupDiv.style.filter = "alpha(opacity=80)";
     //popupDiv.style.opacity = 0.8;

     //让弹出层在页面中垂直左右居中
     var arrayPageSize = getPageSize();
     var arrayPageScroll = getPageScroll();
     //alert(arrayPageScroll);
     //alert(arrayPageSize);
	 //alert(arrayPageScroll[1]+"+(("+arrayPageSize[3]+" +100- "+popupDiv.style.height+")/2)="+(arrayPageScroll[1] + (arrayPageSize[3] + 100 - parseInt(popupDiv.style.height)) / 2));
     popupDiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - parseInt(popupDiv.style.height)) / 2) + 'px') ;
     popupDiv.style.left = (((arrayPageSize[0] - 20 - parseInt(popupDiv.style.width)) / 2) + 'px');
     return popupDiv;
    }
function createBackgroundDiv(){
     var bodyBack = document.createElement("div");
     bodyBack.setAttribute("id","bodybg")
     bodyBack.style.width = "100%";
     bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
     bodyBack.style.zIndex = 1;
     bodyBack.style.position = "absolute";
     bodyBack.style.top = 0;
     bodyBack.style.left = 0;

     bodyBack.style.filter = "alpha(opacity=50)";
     bodyBack.style.opacity = 0.5;
     bodyBack.style.background = "#000";
     //bodyBack.style.background = "#ccc";
     return bodyBack;
}   
   

//元素插入另一个元素之后
function insertAfter(newElement, targetElement){
      var parent = targetElement.parentNode;
      if(parent.lastChild == targetElement){
         parent.appendChild(newElement);
      }else{
         parent.insertBefore(newElement, targetElement.nextSibling);
    }
}
//获取滚动条的高度
function getPageScroll(){
    var yScroll;
    if (self.pageYOffset) {
    yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
}
    arrayPageScroll = new Array('',yScroll)
    return arrayPageScroll;
}
//获取页面实际大小
function getPageSize(){
  
    var xScroll, yScroll;
  
    if (window.innerHeight && window.scrollMaxY) {  
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
  
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }  
  
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){  
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
//关闭弹出层
function closeLayer(divname){//----------------------need edit！
     document.getElementById(divname).style.display = "none";
     document.getElementById("bodybg").style.display = "none";
     return false;
}
//拖动函数
function mousedown(e){
    var obj = document.getElementById("popupAddr");
    var e = window.event ? window.event : e;

    obj.startX = e.clientX - obj.offsetLeft;
    obj.startY = e.clientY - obj.offsetTop;


    document.onmousemove = mousemove;
    var temp = document.attachEvent ? document.attachEvent("onmouseup",mouseup) : document.addEventListener("mouseup",mouseup,"");
}
function mousemove(e){
    var obj = document.getElementById("popupAddr");
    var e = window.event ? window.event : e;

    with(obj.style){
    left = (e.clientX - obj.startX)<10 ? 10 : (e.clientX - obj.startX) + "px";
    top = (e.clientY - obj.startY)<10?10:(e.clientY - obj.startY) + "px";
}
}
function mouseup(e){
    var e = window.event ? window.event : e;
    var obj = document.getElementById("popupAddr");
    var currentX=e.clientX - obj.startX;
    var currentY=e.clientY - obj.startY;
    //让弹出层在页面中垂直左右居中
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
    //alert(arrayPageScroll);
    //alert(arrayPageSize);

    //popupDiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 400) / 2) + 'px') ;
    //popupDiv.style.left = (((arrayPageSize[0] - 20 - 600) / 2) + 'px');
    //alert(arrayPageSize[1]);
    var maxX=arrayPageSize[0]-600-24;
    var maxY=arrayPageScroll[1] +((arrayPageSize[3] - 400));

    if(currentX>maxX){
    obj.style.left=maxX-10 + "px";
    }
    if(currentY>maxY){
    obj.style.top=maxY-10 + "px";
    }
    document.onmousemove = "";
    var temp = document.detachEvent ? document.detachEvent("onmouseup",mouseup) : document.addEventListener("mouseup",mouseup,"");
    }
