﻿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 ModeWindow(AddControl,width,height,left,top,title, canCloseWin){
    this.AddControl = AddControl;
    this.width = (width == undefined) ? 400 : width;
    this.height = (height == undefined) ? 300 : height;
    this.left = (left == undefined) ? 300 : left;
    this.top = (top == undefined) ? 180 : top;
    this.title = (title == undefined)? "" : title;
    this.form1 = document.getElementById("form1");
    this.canCloseWin = canCloseWin;

    if(document.getElementById("form1_ShowWin_iframe") == null)
    {
        this.form1_ShowWin_iframe = document.createElement("iframe");
        this.form1_ShowWin_iframe.id = "form1_ShowWin_iframe";
        this.form1_ShowWin_iframe.className = "form1_ShowWin_iframe";
    }
    else
    {
       this.form1_ShowWin_iframe=document.getElementById("form1_ShowWin_iframe");
    }
    if(document.getElementById("form1_ShowWin_div") == null)
    {
        this.form1_ShowWin_div = document.createElement("div");
        this.form1_ShowWin_div.id = "form1_ShowWin_div";
        this.form1_ShowWin_div.className = "form1_ShowWin_div";
        this.form1_ShowWin_div.style.height = this.height + "px";
        this.form1_ShowWin_div.style.width = this.width + "px";
        this.form1_ShowWin_div.style.top = this.top + "px";
        this.form1_ShowWin_div.style.left = this.left + "px";
    }
    else
    {
        this.form1_ShowWin_div = document.getElementById("form1_ShowWin_div");
        this.form1_ShowWin_div.style.display = "";
        this.form1_ShowWin_div.style.height = this.height + "px";
        this.form1_ShowWin_div.style.width = this.width + "px";
        this.form1_ShowWin_div.style.top = this.top + "px";
        this.form1_ShowWin_div.style.left = this.left + "px";
    }
    if(document.getElementById("form1_ShowWin_table") == null)
    {
        this.form1_ShowWin_table = document.createElement("table");
        this.form1_ShowWin_table.id = "form1_ShowWin_table";
        this.form1_ShowWin_table.className = "form1_ShowWin_table";
        var form1_ShowWin_Rows = this.form1_ShowWin_table.rows;
        var form1_ShowWin_newRow = this.form1_ShowWin_table.insertRow(0);
        var form1_ShowWin_Cells = form1_ShowWin_newRow.cells;
        var form1_ShowWin_newCell = form1_ShowWin_Rows[form1_ShowWin_newRow.rowIndex].insertCell(0);
        form1_ShowWin_newCell.align = "left";
        form1_ShowWin_newCell.valign = "top";
        form1_ShowWin_newCell.height ="20px";
        form1_ShowWin_newCell.width = "95%";
        form1_ShowWin_newCell.innerHTML = "<span id='form1_ShowWin_title' style='font-size:10pt; color:#FFFFFF; font-weight:bold'>"+this.title+"</span>";
        var form1_ShowWin_newCell = form1_ShowWin_Rows[form1_ShowWin_newRow.rowIndex].insertCell(1);
        form1_ShowWin_newCell.align = "right";
        form1_ShowWin_newCell.valign = "top";
        form1_ShowWin_newCell.height = "20px";
        form1_ShowWin_newCell.width = "5%";
        form1_ShowWin_newCell.innerHTML = "<span style='font-size:12pt; color:#FFFFFF;cursor: pointer;' onmouseover=\"javascript:this.style.backgroundColor='#5F69E4'\" onmouseout=\"javascript:this.style.backgroundColor='#C1D8F4'\" title='关闭' onclick='return form1_ShowWin_funWinClose(\""+this.AddControl.id+"\", \"" + this.canCloseWin + "\")'>X</span>";

        this.form1_ShowWin_div.appendChild(this.form1_ShowWin_table);
    }
    else
    {
       this.form1_ShowWin_table = document.getElementById("form1_ShowWin_table");
    }
    this.form1.appendChild(this.form1_ShowWin_iframe);
    this.form1.appendChild(this.form1_ShowWin_div);
    if(this.AddControl != null)
       if(this.AddControl.parentElement != this.form1_ShowWin_div)
          this.form1_ShowWin_div.appendChild(this.AddControl);
 }

 ModeWindow.prototype.show = function() {
     var h = getPageSize()[1];//screen.availHeight; 
     var w = getPageSize()[0];//screen.availWidth;
     if (document.all) {
         var style = ".form1_ShowWin_iframe {position:absolute; z-index:1001; height:" + h + "px; width:" + w + "px; top:0; left:0; background-Color:#000000; filter:Alpha(Opacity=80); }";
         style += ".form1_ShowWin_div {position:absolute; z-index:1009; background-color:#ECF1F3; padding-right: 2px; padding-left: 2px; padding-top: 2px;font-size: 12px; color: black;filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5);}";
         style += ".form1_ShowWin_table { background-color:#73A6FF; height:20px; width:100%;filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr=#81A9E8, EndColorStr=#C3DAF5); }";
         var style1 = document.createElement("style");
         style1.type = 'text/css';
         style1.styleSheet.cssText = style;
         document.getElementsByTagName('HEAD').item(0).appendChild(style1);
     } else {
         var style = document.createElement('style');
         style.type = 'text/css';
         style.innerHTML = ".form1_ShowWin_iframe {position:absolute; z-index:1001;height:" + h + "px; width:" + w + "px; top:0; left:0; background-color:#000000; opacity:0.8;}";
         style.innerHTML += ".form1_ShowWin_div {position:absolute; z-index:1009; background-color:#ecf1f3;	padding-right: 2px; padding-left: 2px; padding-top: 2px;font-size: 12px; color: black; opacity:0.8}";
         style.innerHTML += ".form1_ShowWin_table { background-color:#73A6FF; height:20px; width:100%; opacity:0.6; }";
         document.getElementsByTagName('HEAD').item(0).appendChild(style);
     }
     this.form1_ShowWin_iframe.style.display = "block";
     this.form1_ShowWin_div.style.display = "block";
     this.AddControl.style.display = "block";
     document.getElementById("form1_ShowWin_iframe").style.display = "";
     document.getElementById("form1_ShowWin_div").style.display = "";
 }

 ModeWindow.prototype.close = function () {
    this.form1_ShowWin_iframe.style.display = "none";
    this.form1_ShowWin_div.style.display = "none";
    do{
        if(this.form1_ShowWin_div.firstChild == this.AddControl)
        {
          this.form1_ShowWin_div.firstChild.style.display = "none";
          this.form1.appendChild(this.form1_ShowWin_div.firstChild);
        } else {
          this.form1_ShowWin_div.removeChild(this.form1_ShowWin_div.firstChild);
        }
     }while(this.form1_ShowWin_div.childNodes.length>0)
}

function form1_ShowWin_funWinClose(ChildNodeID, canCloseWin) {
    if (canCloseWin) {
        if(canCloseWin == "true")
            window.close();
  }
  document.getElementById("form1_ShowWin_iframe").style.display = "none";
  document.getElementById("form1_ShowWin_div").style.display = "none";
  do{
      if(document.getElementById("form1_ShowWin_div").firstChild.id == ChildNodeID)
      {
         document.getElementById("form1_ShowWin_div").firstChild.style.display = "none";
         document.getElementById("form1").appendChild(document.getElementById("form1_ShowWin_div").firstChild);
      } else {
         document.getElementById("form1_ShowWin_div").removeChild(document.getElementById("form1_ShowWin_div").firstChild);
      }
  } while (document.getElementById("form1_ShowWin_div").childNodes.length > 0)
  
}
