﻿var isIE = /msie/.test(navigator.userAgent.toLowerCase()); 
//弹出层
function openLayer(id,title,url,popname,LayerWidth,LayerHeight)
{	
	//创建一个div元素
   var popupDiv;
	if(document.getElementById(popname) != null)
	{
		document.getElementById(popname).style.display = "";
		popupDiv=document.getElementById(popname);
	}
	else
	{
		popupDiv = document.createElement("div");
	}
 
 
 //给这个元素设置属性与样式
 popupDiv.setAttribute("id",popname)
 //popupDiv.style.border = "1px solid #ccc";
 popupDiv.style.width = LayerWidth+"px";
// popupDiv.style.height = LayerHeight+"px";
 popupDiv.style.background = "#fff";
 popupDiv.style.zIndex = 99;
 popupDiv.style.position = "absolute";
 
 
 //让弹出层在页面中垂直左右居中
 var arrayPageSize = getPageSize();
 var arrayPageScroll = getPageScroll();
 //alert(arrayPageScroll);
 //alert(arrayPageSize); 

  
	popupDiv.style.top = (30+arrayPageScroll[1] + ((arrayPageSize[3] - 35 - LayerHeight) / 2) + 'px') ;
	popupDiv.style.left = (((arrayPageSize[0] - 20 - LayerWidth) / 2) + 'px');
  
 //收工插入到目标元素之后
 var mybody = document.getElementById(id);
 insertAfter(popupDiv,mybody);
 
	  var bodyBack;
	  //创建背景层
	  if(document.getElementById("bodybg")!=null)
	  {
   		  document.getElementById("bodybg").style.display = "";
		  bodyBack=document.getElementById("bodybg");
	  }
	  else
	  {
		  bodyBack = document.createElement("div");
	  }
   bodyBack.setAttribute("id","bodybg")
   bodyBack.style.width = "100%";
   bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
   bodyBack.style.zIndex = 98;
   bodyBack.style.position = "absolute";
   bodyBack.style.top = 0;
   bodyBack.style.left = 0;
   
   bodyBack.style.filter = "alpha(opacity=20)";
   bodyBack.style.opacity = 0.2;
   bodyBack.style.background = "#000";
	insertAfter(bodyBack,mybody);
  
 //弹出层内容
 popupDiv.innerHTML = addrHTML(title,url,LayerWidth,LayerHeight);
 document.getElementById('mr').src = url;
}
//弹出层内容
function addrHTML(title,url,LayerWidth,LayerHeight) 
{
	
 //文字
 
 var CLOSE = '<span style="cursor:pointer;" onclick="javascript:closeLayer();">[关闭]</span>';
 

 var htmlDiv = '';
 htmlDiv += '<div style="width:'+LayerWidth+'px;height:'+LayerHeight+'px;font-size:12px;background:#fff;border:solid #163bbb;border-width:0px 2px 2px 2px;">';
 
 //头部
 htmlDiv += '<div style="width:100%;background:#163bbb; FILTER:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#1331b2, EndColorStr=#091038);height:28px;color:#fff;cursor:move;" onmousedown=mousedown(arguments[0])>';
 htmlDiv += '<span style="line-height:28px;padding-left:2px;float:left;">';
 htmlDiv += title;
 htmlDiv += '</span>';
 htmlDiv += '<span style="float:right;padding-right:2px;line-height:28px;">';
 htmlDiv += CLOSE;
 htmlDiv += '</span>';
 htmlDiv += '</div>';
 //END头部
 var width1=Number(LayerWidth)-4;
 var height1=Number(LayerHeight)-30;
 //内容部分
 htmlDiv += '<div id="container" style="width:'+LayerWidth+'px;height:100%;border:0;"><iframe id = "mr" frameborder="0" width="'+width1+'px" height="'+height1+'px" src="'+url+'"></iframe></div>';
 htmlDiv += '<div style="border:0;clear:both; height:0px; overflow:hidden;" ></div>';
 //END内容部分
 htmlDiv += '</div>';
 
 return htmlDiv;
}
//关闭弹出层
function closeLayer()
{
     if(document.getElementById("popupAddr") != null)
     {
        document.getElementById("popupAddr").style.display = "none";
     }
     if(document.getElementById("bodybg") != null)
     {
        document.getElementById("bodybg").style.display = "none";
     }
     if(document.getElementById("bodybg_iframe") != null)
     {
        document.getElementById("bodybg_iframe").style.display = "none";
     } 
 return false;
}

