﻿// JScript 文件
var docEle = function() {
	return document.getElementById(arguments[0]) || false;
}
function openNewDiv(url,_width,_height,_title) {
    //取得窗口及页面大小
    var sz = GetPageSize();
    var sl = GetPageScroll();
    //alert(sz.WinW+","+sz.WinH);
    var _pageHeight= sz.WinH; //页面高度
    var _id = "div_dialog";
	var m = "mask";
	var yy = "div_dialog_yy";
	if (docEle(_id)) document.removeChild(docEle(_id));
	if (docEle(m)) document.removeChild(docEle(m));
	var newDiv = document.createElement("div");
	newDiv.id = _id;
	//newDiv.style.position = "fixed";
	newDiv.style.position = "absolute";
	newDiv.style.zIndex = "9999";
	newDiv.style.width = _width + "px";
	newDiv.style.height = _height + "px";
	newDiv.style.top =sl.Y + (_pageHeight - _height) /2 + "px";
	newDiv.style.left =sl.X + (parseInt(sz.WinW)-_width) / 2 + "px";
	newDiv.style.background = "#EFEFEF";
	newDiv.style.border = "1px solid #585858";
	newDiv.style.padding = "0px";
	newDiv.innerHTML = "<iframe id ='frmNewDialog'  src='"+url+"'frameborder='0'"+
	" width='"+ _width +"' height='"+(_height-30)+"'></iframe>";
	document.body.appendChild(newDiv);
	
	//创始阴影层div
	var newYY =  document.createElement("div");
	newYY .id = yy;
	//newYY .style.position = "fixed";
	newYY .style.position = "absolute";
	newYY .style.zIndex = "9998";
	newYY .style.width = _width + "px";
	newYY .style.height = _height + "px";
	newYY .style.top = sl.Y +((_pageHeight - _height) /2) + 6 + "px";
	newYY .style.left =sl.X +(((parseInt(sz.WinW)-_width) / 2)+6) + "px";
	newYY .style.background = "#7E7E7E";
	newYY .style.border = "0px";
	newYY .style.padding = "0px";
	newYY .style.filter = "alpha(opacity=80)";
	newYY .style.opacity = "0.8";
	document.body.appendChild(newYY);
	//创建底层div
	var newMask = document.createElement("div");
	newMask.id = m;
	//newMask.style.position = "fixed";
	newMask.style.position = "absolute";
	newMask.style.zIndex = "9997";
	newMask.style.width = sz.PageW;
	newMask.style.height = sz.PageH;
	newMask.style.top = 0;
	newMask.style.left = 0;
	newMask.style.background = "#000";
	newMask.style.filter = "alpha(opacity=60)";
	newMask.style.opacity = "0.60";
	//document.body.style.overflow="hidden";
	document.body.appendChild(newMask);
	var newA = document.createElement("div");
	newA.style.cursor= "pointer";
	newA.innerHTML = "<div style='padding:0px;line-height:30px;height:30px;background:#9C9C9C;'><span id = 'div_dialog_title'  style ='float:left;font-size:12px; font-weight:bold; color:#FFFFFF;text-indent:10px;'>"+
	_title
	+"</span><span id = 'span_dialog_close' style='color:#000000;font-size:12px;TEXT-DECORATION:none;float:right;padding-right:5px;cursor:pointer'><img src='/images/common/dlg_close.gif'style='padding:6px' border=0 /></span></div>";
	//newDiv.appendChild(newA);
	newDiv.insertBefore(newA,docEle('frmNewDialog'));
	docEle("span_dialog_close").onclick = function() {
		document.body.removeChild(docEle(_id));
		document.body.removeChild(docEle(m));
		document.body.removeChild(docEle(yy));
	    //document.body.style.overflow="auto";
		return false;
	}
}
//移动窗口
function MoveDialog(){
    var _id = "div_dialog";
	var yy = "div_dialog_yy";
	var newDiv= docEle(_id);
	var newYY= docEle(yy);
	if(!newDiv)return;
	var _pageHeight= document.documentElement.clientHeight; //页面高度
    newDiv.style.top =(_pageHeight - newDiv.clientHeight) /2 + "px";
	newDiv.style.left =(parseInt(document.body.scrollWidth)-newDiv.clientWidth) / 2 + "px";
	newYY .style.top = ((_pageHeight - newYY.clientHeight) /2) + 6 + "px";
	newYY .style.left =(((parseInt(document.body.scrollWidth)-newYY.clientWidth) / 2)+6) + "px";
}

//关闭对话框
function CloseDialog(){
    var _id = "div_dialog";
	var m = "mask";
    var yy = "div_dialog_yy";
	document.body.removeChild(docEle(_id));
	document.body.removeChild(docEle(m));
	document.body.removeChild(docEle(yy));
	//document.body.style.overflow="auto";
	return false;
}

function InitDialog(){
    document.body.onresize="MoveDialog();";
}

//取得页面大小。
function GetPageSize() {
  var scrW, scrH;
  if(window.innerHeight && window.scrollMaxY) {
    // Mozilla
    scrW = window.innerWidth + window.scrollMaxX;
    scrH = window.innerHeight + window.scrollMaxY;
  } else if(document.body.scrollHeight > document.body.offsetHeight){
    // all but IE Mac
    scrW = document.body.scrollWidth;
    scrH = document.body.scrollHeight;
  } else if(document.body) { // IE Mac
    scrW = document.body.offsetWidth;
    scrH = document.body.offsetHeight;
  }
  
  var winW, winH;
  if(window.innerHeight) { // all except IE
    winW = window.innerWidth;
    winH = window.innerHeight;
  } else if (document.documentElement 
    && document.documentElement.clientHeight) {
    // IE 6 Strict Mode
    winW = document.documentElement.clientWidth; 
    winH = document.documentElement.clientHeight;
  } else if (document.body) { // other
    winW = document.body.clientWidth;
    winH = document.body.clientHeight;
  }
  
  // for small pages with total size less then the viewport
  var pageW = (scrW<winW) ? winW : scrW;
  var pageH = (scrH<winH) ? winH : scrH;
  
  return {PageW:pageW, PageH:pageH, WinW:winW, WinH:winH};
}

function GetPageScroll() {
  var x, y;
  if(window.pageYOffset) {
    // all except IE
    y = window.pageYOffset;
    x = window.pageXOffset;
  } else if(document.documentElement 
    && document.documentElement.scrollTop) {
    // IE 6 Strict
    y = document.documentElement.scrollTop;
    x = document.documentElement.scrollLeft;
  } else if(document.body) {
    // all other IE
    y = document.body.scrollTop;
    x = document.body.scrollLeft; 
  }
  return {X:x, Y:y};
}
