﻿  function $import(jsUrl)
  { 
    var head   = document.getElementsByTagName('head');
    var script = document.createElement('script');
  
    script.src      = jsUrl;
    script.language = "javascript";
    script.type     = "text/javascript";

    head[0].appendChild(script);
  }

  //$import("common.js");
  $import("rscctl.js");

  var docEle = function()
  {
     return document.getElementById(arguments[0]) || false;
  }
  
  function removeDocEle(id, m)
  {
     document.body.removeChild(docEle(id));
     document.body.removeChild(docEle(m));
     
     return false;
  }

  function funOpenDownDiv(rscID, rscName, rscUrl, rscWidth, rscHeight)
  {
     var _id   = "newImageDiv";
     var _mask = "newMask";
     
     var scrollLeft   = getScrollLeft();
     var scrollTop    = getScrollTop();
     var scrollWidth  = getScrollWidth();
     var scrollHeight = getScrollHeight();
     var clientWidth  = getClientWidth();
     var clientHeight = getClientHeight();
     
     var imgWidth     = rscWidth;
     var imgHeight    = rscHeight;
     
     //验证宽度
     if (imgWidth > 800)
     {
       imgWidth       = 800;
       imgHeight      = Math.round(800 / rscWidth * imgHeight);
     }
     
     //验证高度
     if (imgHeight > 500)
     {
       
       imgWidth       = Math.round(500 / imgHeight * imgWidth); 
       imgHeight      = 500;
     }
     
     var addHeight    = 30;
     var divWidth     = imgWidth < 150 ? 150 : imgWidth + 10;
     var divHeight    = imgHeight + addHeight;
     var divTop       = scrollTop + (clientHeight - divHeight) / 2;
     var divLeft      = scrollLeft + (clientWidth - divWidth) / 2;
     
     divTop  = divTop < 0 ? 0 : divTop;
     divLeft = divLeft < 0 ? 0 : divLeft;

     if (docEle(_id))
     {
       document.removeChild(docEle(_id));
     }
     
     if (docEle(_mask))
     {
       document.removeChild(docEle(_mask));
     }
     
     // mask图层
     var newMask              = document.createElement("div");
     newMask.id               = _mask;
     newMask.style.position   = "absolute";
     newMask.style.zIndex     = "1";
     newMask.style.width      = scrollWidth + "px";
     newMask.style.height     = scrollHeight + "px";
     newMask.style.top        = "0px";
     newMask.style.left       = "0px";
     //newMask.style.background = "#000";
     newMask.style.background = "url(/Images/bgmask.png)";
     newMask.style.filter     = "alpha(opacity=40)";   //支持IE
     newMask.style.opacity    = "0.40";                //支持FF

     document.body.appendChild(newMask);

     
     // 新激活图层
     var newDiv              = document.createElement("div");
     newDiv.id               = _id;
     newDiv.style.position   = "absolute";
     newDiv.style.zIndex     = "9999";
     newDiv.style.width      = divWidth + "px";
     newDiv.style.height     = divHeight + "px";
     newDiv.style.top        = divTop + "px"; 
     newDiv.style.left       = divLeft + "px"; // 屏幕居中     
     newDiv.style.background = "#EFEFEF";
     newDiv.style.border     = "1px solid #860001";
     newDiv.style.padding    = "3px";
     newDiv.innerHTML        = "<table align=\"center\" border=\"0px\" width=\"" + divWidth + "px\" height=\"" + divHeight + "px\"><tr><td align=\"center\" valign=\"middle\" height=\"" + imgHeight + "px\"><img alt=\"" + rscName + "\" src=\"" + rscUrl + "\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" /></td></tr><tr><td height=\"" + addHeight + "px\" align=\"center\" valign=\"middle\"><a href=\"#\" onclick=\"return funRscDown2('" + rscID + "');\">[ 下 载 ]</a> | <a href=\"#\" onclick=\"return removeDocEle('" + _id + "','" + _mask + "');\">[ 关 闭 ]</a></td></tr></table>";
     
     document.body.appendChild(newDiv);
     
     //点击计数     
     funAddClickNum(rscID);
          
     return false;
  }
