/**********************************************************************
 *
 * $Id: childwindow.js,v 1.1 2007/10/18 07:22:57 sanoju Exp $
 *
 * JavaScript for displaying child window.
 * 
 * Copyright (C) 2006  Junya Sano
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 **********************************************************************/

// Reference
// http://www.beasys.co.jp/dev2dev/pub/a/2005/4/portal_menus..html

// Trick to prevent MS Windows controls from being rendered above child window.

//Creates a new shim
function createShim() {
//  alert('<iframe scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none"></iframe>'); 
  var shim = document.createElement('iframe'); 
  shim.id = 'shim';
  shim.setAttribute("scrolling", "no");
  shim.setAttribute("frameborder", 0);
  shim.setAttribute("style", "position:absolute; display:none");

  window.document.body.appendChild(shim);

  return shim;
}

//Opens a shim for a div, creating one if no shim exists
function openShim(div) {
  var shim = document.getElementById('shim');
  if (shim == null) {
    shim = createShim();
  }

  shim.style.width = div.style.width;
  shim.style.height = div.style.height;
  shim.style.top = div.style.top;
  shim.style.left = div.style.left;
  shim.style.padding = div.style.padding;
  shim.style.zIndex = div.style.zIndex - 1;
  shim.style.position = "absolute";
  shim.style.display = "block";
}

//Closes the shim
function closeShim() {
  var shim = document.getElementById('shim');
  if (shim != null) {
    shim.style.display = "none";
  }
}

function showChildWindow(left, top, width, height, html) {
//alert("html = " + html + ", left = " + left + ", top = " + top +
//      ", width = " + width + ", height = " + height);
  closeChildWindow();
  var div = childWindow("childwindow", left, top, width, height);

  html = '<div style="float: right; cursor: pointer; font-size: 70%;" ' +
         ' onclick="closeChildWindow();">' +
         '  <img src="images/close.gif">' +
         '  <a href="javascript:closeChildWindow();">' +
         '    閉じる' +
         '  </a>' +
         '</div><br>' +
         '<p style="padding: 5px">' + html + '</p>';
  div.innerHTML = html;
}

function closeChildWindow() {
//alert("closeChildWindow()");
  var doc   = document                           ; // documentオブジェクト
  var body  = doc.body                           ;

  var div = getRawObject("childWindowDiv");
  if (div != null) {
    body.removeChild(div);
  }
}

//=====================================================================
//  SYSTEM      :  DragableFloat DIV
//  PROGRAM     : ドラッグできて、スクロール時には画面の固定位置で停止するDIV
//  FILE NAME   :  jsgt_dragfloat.js
//  CALL FROM   :  HTML
//  AUTHER      :  Toshirou Takahashi http://jsgt.org/mt/01/
//  SUPPORT URL :  http://jsgt.org/mt/archives/01/000419.html
//  CREATE      :  2005.7.8
//  UPDATE      :  2005.11.20 v08 セレクトができなくなるのでdocument.onmousemoveのreturn falseをコメントアウト
//  UPDATE      :  2005.9.26 v07 floatEnabled boundEnabled setBounds chkBounds追加
//  UPDATE      :  2005.9.22 v06 getTOP getLEFT getMouseX getMouseYをdivのプロパティ化
//  UPDATE      :  2005.8.12 v05ドラッグ時にieで発生するselectをonselectstartでキャンセル
//  UPDATE      :  2005.8.10 v04ドラッグ時にiframe上でイベントを拾えないのを多少修正しました
//  UPDATE      :  2005.8.8  dbg_echo()追加
//  UPDATE      :  2005.8.8  bodyタグが無い時用ダミーbody出力を追加　
//  UPDATE      :  2005.7.8 DOCTYPE 標準モードに対応
//                   参考 http://otd8.jbbs.livedoor.jp/877597/bbs_tree?base=9322&range=1
//
//
// このソースは改変も商用利用も自由ですが、
// その自由を護るために著作権は放棄しません。
//---------------------------------------------------------------------
// 高橋登史朗 (Toshirou Takahashi http://jsgt.org/mt/01/) 2005.7.8

////
// child window
//
function childWindow(id,x,y,w,h)
{
//alert("childWindow start");
    
    ////
    // DIV生成
    // @param  id             DIVのID名
    //
    this.mkDiv = function (id) 
    {
//alert("mkDiv start");
//        var canvas = document[ 'CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
        var doc   = document                           ; // documentオブジェクト
        var body  = doc.body                           ;
        var elem  = doc.createElement("DIV")           ; //DIV要素を生成
        var div   = body.appendChild(elem);
            div.setAttribute("id",id)                   ;
            div.style.position = "absolute"           ;
            div.style.left     = x + "px"             ;
            div.style.top      = y + "px"             ;
            div.style.width    = w + "px"             ;
            div.style.height   = h + "px"             ;
// added by sanoju
            div.style.zIndex   = 200                 ;
            div.style.backgroundColor = "#ffffff"     ;
            div.style.border = "3px solid #336666"    ;
            div.style.overflow = "auto"               ;
//            div.style.margin = "10px"                 ;
            div.style.padding = "5px 2em 5px 2em"                 ;
//alert("zIndex = " + div.style.zIndex);
// end added by sanoju
            div.innerHTML      = ""                   ;
            div.onmouseout     = function (e){ 
            }
            div.onselectstart  = function (e){ return false }
            div.onmouseover    = function (e){ return false }
            div.onmousedown    = function (e)
            {
            }

//        childWindowId[div.id] = div.id;//windowへ登録
//alert("childWindowId.length = " + childWindowId.length);
          div.id = "childWindowDiv";
//        div.index++;
        return div;
    }

    //マウス移動時の動作
    document.onmousemove  = function (e)
    {
    }
    
    //マウスアップ時の動作
    document.onmouseup  = function (e)
    {
        return false
    }

  return this.mkDiv(id) ;
		
}
