var __dhtml_popup_html = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" id=\"$id$\" style=\"z-index:20000;display:block;position:absolute;left:$left$px;top:$top$px;\"><col width=\"6\" /><col /><col width=\"6\" /><tr><td><img src=\"/popup/left_left_top.png\" /></td><td><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><col width=\"6\" /><col /><col width=\"6\" /><tr><td><img src=\"/popup/left_top.png\" /></td><td style=\"background-image: url(/popup/top.png);\"><div style=\"cursor:default;height:33px;color:white;font-weight:bold;font-size:10pt;\" onselectstart=\"return false;\" ondragstart=\"return false;\" id=\"mover_$id$\">$title$</div></td><td><img src=\"/popup/right_top.png\" style=\"cursor:pointer;\" onclick=\"closePopup('$id$','$name$');\" /></td></tr></table></td><td><img src=\"/popup/right_right_top.png\" /></td></tr><tr><td style=\"background-image:url(/popup/left.png);\"></td><td bgcolor=\"white\"><iframe id=\"$name$\" name=\"$name$\" src=\"$url$\" frameborder=\"0\" scrolling=\"$scrolling$\" style=\"width:$width$px;height:$height$px;\"></iframe></td><td style=\"background-image:url(/popup/right.png);\"></td></tr><tr><td><img src=\"/popup/left_left_bottom.png\" /></td><td><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><col width=\"6\" /><col /><col width=\"6\" /><tr><td><img src=\"/popup/left_bottom.png\" /></td><td style=\"background-image: url(/popup/bottom.png);\">&nbsp;</td><td><img src=\"/popup/right_bottom.png\" /></td></tr></table></td><td><img src=\"/popup/right_right_bottom.png\" /></td></tr></table>";
var __dhtml_popup_temp = new Object();
__dhtml_popup_temp.current = null;
function openPopup(url, width, height, left, top, name, scrolling) {
  scrolling = scrolling || "no";
  var id = "dpopup" + new Date().getTime();
  var frameName = name || ("ifr_" + id);
  var popup = window.open(url, frameName, "width=" + width + "px,height=" + height + "px,left=" + left + "px,top=" + top + "px,scrollbars=" + scrolling);
  if(popup)
    return popup;
  var moverId = "mover_" + id;
  var title = "&nbsp;";
  var tblSrc = __dhtml_popup_html.replace(
    /\$(.+?)\$/g,
    function(all, word) {
      switch(word) {
        case "id":
          return id;
        case "title":
          return title;
        case "width":
          return width;
        case "height":
          return height;
        case "left":
          return left;
        case "top":
          return top;
        case "url":
          return url;
        case "name":
          return frameName;
        case "scrolling":
          return scrolling;
        default:
          return word;
      }
    }
  );

  document.write(tblSrc);
  return createDHTMLPopup(id, moverId, frameName);
}
function createDHTMLPopup(id, moverId, frameName) {
  var obj = new Object();
  obj.isMove = false;
  obj.id = id;
  obj.mouseX = 0;
  obj.mouseY = 0;
  obj.tbl = document.getElementById(id);
  obj.mover = document.getElementById(moverId);
  obj.frame = document.getElementById(frameName);
  obj.onmousedown = function(e){
    obj.focus();
    obj.frame.style.visibility = "hidden";
    var e = (window.event || e);
    obj.mouseX = (window.event ? e.clientX : e.pageX);
    obj.mouseY = (window.event ? e.clientY : e.pageY);
    obj.isMove = true;
  }
  obj.onmousemove = function(e){
    if(false == obj.isMove)
      return;
    var e = (window.event || e);
    var newX = (window.event ? e.clientX : e.pageX);
    var newY = (window.event ? e.clientY : e.pageY);
    var incrX = newX - obj.mouseX;
    var incrY = newY - obj.mouseY;
    obj.mouseX = newX;
    obj.mouseY = newY;
    obj.tbl.style.left = Number(obj.tbl.style.left.replace("px", "")) + incrX;
    obj.tbl.style.top = Number(obj.tbl.style.top.replace("px", "")) + incrY;
  }
  obj.onmouseup = function(e){
    obj.frame.style.visibility = "visible";
    obj.isMove = false;
  }
  obj.close = function(){
    closePopup(obj.id, frameName);
  }
  obj.moveTo = function(x, y) {
    obj.tbl.style.left = x + "px";
    obj.tbl.style.top = y + "px";
  }
  obj.focus = function() {
    if(__dhtml_popup_temp.current != null) {
      __dhtml_popup_temp.current.tbl.style.zIndex = 100;
    }
    obj.tbl.style.zIndex = 101;
    __dhtml_popup_temp.current = obj;
  }
  obj.resizeTo = function(width, height) {
    obj.tbl.style.width = width + "px";
    obj.tbl.style.height = height + "px";
  }
  if(document.attachEvent) {
    document.attachEvent("onmousemove", obj.onmousemove);
    obj.mover.attachEvent("onmouseup", obj.onmouseup);
    obj.mover.attachEvent("onmousedown", obj.onmousedown);
  } else if(document.addEventListener) {
    document.addEventListener("mousemove", obj.onmousemove, false);
    obj.mover.addEventListener("mousedown", obj.onmousedown, false);
    obj.mover.addEventListener("mouseup", obj.onmouseup, false);
  }
  window.frames[frameName].opener = window;
  if(window.frames[frameName].contentWindow) {
    window.frames[frameName].contentWindow.close = obj.close;
    window.frames[frameName].contentWindow.resizeTo = obj.resizeTo;
    window.frames[frameName].contentWindow.moveTo = obj.moveTo;
  } else {
    window.frames[frameName].close = obj.close;
    window.frames[frameName].resizeTo = obj.resizeTo;
    window.frames[frameName].moveTo = obj.moveTo;
  }
  return obj;
}
function closePopup(id, frameName) {
  document.getElementById(frameName).src = "about:blank";
  try {
    document.body.removeChild(document.getElementById(id));
  } catch(e) {
    document.getElementById(id).style.display = "none";
  }
}