/* ========================================================================
   << Library for cross browser >>

   JavaScript Library for Netscape Navigator 4.0+
                       and Internet Explorer 4.0+

   Author : Shinichi Hagiwara
   Type   : library - free software
   History:
   1.0   : 10/18/1998 original
   1.1   : 08/15/2000 remake for my book
   1.2   : 05/20/2001 add the functions getLeftFromEvent,getTopFromEvent
   1.3   : 05/27/2001 update the functions getLeftFromEvent,getTopFromEvent

   Copyright(C) 1998 - 2001 ShinSoft. All rights reserved.
________________________________________________________________________ */

/* =====================================================================
 * 以下の変数はブラウザの識別及び関数の互換をとるためのものです。
 * もし、このファイルを外部ソース( SCRIPT タグ内の src属性 )で使用する
 * 場合は、以下の変数を HTML 本体の SCRIPT タグ内に移動して使用してください。
 * ( 外部ソース内で直接定義した変数値は NN4 では実行されない場合があります )
________________________________________________________________________ */
// variables
// version of library
LCB_version = 1.3;
// _mac : true = macintosh, false = other os
_mac=navigator.userAgent.indexOf('Mac')!=-1;
// _dom : kind of DOM. : IE4 = 1, IE5 = 2, NN4 = 3, others = 0
_dom = document.all?(document.getElementById?2:1):(document.layers?3:0);
_createLayerNo = 0;                    // レイア生成番号
/* ======================================================================
 *このスクリプトを外部ソースとして使用する場合は以下の関数を有効にして
 * 使用する最初に onLoad イベントでこの関数を呼び出して初期化して下さい */
function initCrossBrowserLib(){
  _mac=navigator.userAgent.indexOf('Mac')!=-1;
  _dom = document.all?(document.getElementById?2:1):(document.layers?3:0);
  _createLayerNo = 0;                    // レイア生成番号
}
/* _____________________________________________________________________ */
function getWindowWidth (){
  if(_dom==1 || _dom==2) return document.body.clientWidth;
  if(_dom==3)            return window.innerWidth;
  return 0;
}

function getWindowHeight(){
  if(_dom==1 || _dom==2) return document.body.clientHeight;
  if(_dom==3)            return window.innerHeight;
  return 0;
}

function getWinXOffset(){
  if(_dom==1 || _dom==2) return document.body.scrollLeft;
  if(_dom==3)            return window.pageXOffset;
  return 0;
}

function getWinYOffset(){
  if(_dom==1 || _dom==2) return document.body.scrollTop;
  if(_dom==3)            return window.pageYOffset;
  return 0;
}

function getDivFromName(nm){
  if(_dom==1 || _dom==2) return document.all(nm);
  if(_dom==3){
    var s='';
    for(var i=1; i<arguments.length; i++) s+='document.layers.'+arguments[i]+'.';
    return eval(s+'document.layers.'+nm);
  }
  return null;
}

function getDivName(div){
  if(_dom==1 || _dom==2) return div.id;
  if(_dom==3)            return div.name;
  return '';
}

function createLayer(left,top,width,height,parentLayer){
  var s='';
  if(arguments.length>5){
    for(var i=5; i<arguments.length; i++) s+=arguments[i];
  }
  if(_dom==1 || _dom==2){
    var adj=_mac?' ':'';
    var bd, divName = '_js_layer_'+_createLayerNo;
    _createLayerNo++;
    var ha=(height>0)?(';height:'+height):'';
    if(arguments.length>4 && parentLayer)
         bd = parentLayer;
    else bd = document.body;
    bd.insertAdjacentHTML('BeforeEnd',
      '<div id="'+divName+
      '" style="position:absolute;left:'+left+';top:'+top+
      ';width:'+width+ha+';visibility:hidden;">'+s+'<\/div>'+adj);
    return document.all(divName);
  }
  if(_dom==3){
    var div;
    if(arguments.length>4 && parentLayer) div = new Layer(width,parentLayer);
    else                                  div = new Layer(width);
    if(height>0) div.resizeTo(width,height);
    div.moveTo(left,top);
    if(s!=''){
      div.document.open('text/html','replace');
      div.document.write(s);
      div.document.close();
    }
    return div;
  }
  return null;
}

function createExLayer(url,left,top,width,height,parentLayer){
  if(_dom==1 || _dom==2){
    var adj=_mac?' ':'';
    var bd, divName = '_js_layer_'+_createLayerNo;
    _createLayerNo++;
    var ha=(height>0)?(';height:'+height):'';
    if(arguments.length>5 && parentLayer)
         bd = parentLayer;
    else bd = document.body;
    bd.insertAdjacentHTML('BeforeEnd',
      '<div id="'+divName+
      '" style="position:absolute;left:'+left+';top:'+top+
      ';width:'+width+ha+';visibility:hidden;">'+
      '<iframe src="'+url+'" name="'+divName+'_if" '+
      'width='+width+' height='+height+
      'marginwidth=0 marginheight=0 '+
      'scrolling="no" frameborder="no">'+
      '<\/iframe>'+
      '<\/div>'+adj);
    return document.all(divName);
  }
  if(_dom==3){
    var div;
    if(parentLayer) div = new Layer(width,parentLayer);
    else            div = new Layer(width);
    if(height>0) div.resizeTo(width,height);
    div.moveTo(left,top);
    div.load(url,width);
    return div;
  }
  return null;
}

function getDivImage(div,imgName){
  if(_dom==1 || _dom==2) return document.images(imgName);
  if(_dom==3)            return div.document.images[imgName];
  return null;
}

function initDivPos(div){
  if(_dom==1 || _dom==2){
    div.style.pixelLeft = div.offsetLeft;
    div.style.pixelTop  = div.offsetTop;
  }
}

function getDivLeft(div){
  if(_dom==1) return div.style.pixelLeft;
  if(_dom==2) return div.offsetLeft;
  if(_dom==3) return div.left;
  return 0;
}

function getDivTop(div){
  if(_dom==1) return div.style.pixelTop;
  if(_dom==2) return div.offsetTop;
  if(_dom==3) return div.top;
  return 0;
}

function moveDivTo(div,left,top){
  if(_dom==1 || _dom==2){
    div.style.pixelLeft = left;
    div.style.pixelTop  = top;
    return;
  }
  if(_dom==3){
    div.moveTo(left,top);
    return;
  }
}

function moveDivBy(div,left,top){
  if(_dom==1){
    div.style.pixelLeft+=left;
    div.style.pixelTop +=top;
    return;
  }
  if(_dom==2){
    div.style.pixelLeft=div.offsetLeft+left;
    div.style.pixelTop =div.offsetTop +top;
    return;
  }
  if(_dom==3){
    div.moveBy(left,top);
    return;
  }
}

function scrollExlHItTo(exdiv,x){
  if(_dom==1 || _dom==2){
    frames(exdiv.id+'_if').scrollTo(x,frames(exdiv.id+'_if').document.body.scrollTop);
  }
  if(_dom==3){
    var dx=x-exdiv.clip.left, ch=exdiv.clip.width;
    exdiv.left-=dx;
    exdiv.clip.left=x; exdiv.clip.width=ch;
  }
}

function scrollExlVItTo(exdiv,y){
  if(_dom==1 || _dom==2){
    frames(exdiv.id+'_if').scrollTo(frames(exdiv.id+'_if').document.body.scrollLeft,y);
  }
  if(_dom==3){
    var dy=y-exdiv.clip.top, ch=exdiv.clip.height;
    exdiv.top-=dy;
    exdiv.clip.top=y; exdiv.clip.height=ch;
  }
}

function initDivSize(div){
  if(_dom==1 || _dom==2){
    div.style.pixelWidth  = div.offsetWidth;
    div.style.pixelHeight = div.offsetHeight;
  }
}

function getDivWidth (div){
  if(_dom==1) return div.style.pixelWidth;
  if(_dom==2) return div.offsetWidth;
  if(_dom==3) return div.clip.width;
  return 0;
}

function getDivHeight(div){
  if(_dom==1) return div.style.pixelHeight;
  if(_dom==2) return div.offsetHeight;
  if(_dom==3) return div.clip.height;
  return 0;
}

function resizeDivTo(div,width,height){
  if(_dom==1 || _dom==2){
    div.style.pixelWidth  = width;
    div.style.pixelHeight = height;
    return;
  }
  if(_dom==3){
    div.resizeTo(width,height);
    return;
  }
}

function resizeDivBy(div,width,height){
  if(_dom==1){
    div.style.pixelWidth +=width;
    div.style.pixelHeight+=height;
    return;
  }
  if(_dom==2){
    div.style.pixelWidth =div.offsetWidth +width;
    div.style.pixelHeight=div.offsetHeight+height;
    return;
  }
  if(_dom==3){
    div.resizeBy(width,height);
    return;
  }
}

function getExlWidth (exdiv){
  if(_dom==1 || _dom==2)
    return _mac?frames(exdiv.id+'_if').document.body.offsetWidth
               :frames(exdiv.id+'_if').document.body.scrollWidth;
  if(_dom==3)
    return exdiv.document.width;
  return 0;
}

function getExlHeight(exdiv){
  if(_dom==1 || _dom==2)
    return _mac?frames(exdiv.id+'_if').document.body.offsetHeight
               :frames(exdiv.id+'_if').document.body.scrollHeight;
  if(_dom==3)
    return exdiv.document.height;
  return 0;
}

function setDivVisibility(div,visible){
  if(_dom==1 || _dom==2) div.style.visibility=(visible)?'inherit':'hidden';
  if(_dom==3)            div.visibility = (visible)?'inherit':'hide';
}

function setDivClip(div,top,right,bottom,left){
  if(_dom==1 || _dom==2)
    div.style.clip = 'rect('+top+' '+right+' '+bottom+' '+left+')';
  if(_dom==3){
    div.clip.top    = top;   div.clip.right = right;
    div.clip.bottom = bottom;div.clip.left  = left;
  }
}

function writeDivHTML(div,op,cl){
  if(_dom==1 || _dom==2){
    var s='';
    for(var i=3; i<arguments.length; i++) s+=arguments[i];
    if(op) div.innerHTML = '';
    if(_mac) div.innerHTML +=s;
    else     div.insertAdjacentHTML('BeforeEnd',s);
  }
  if(_dom==3){
    var s='';
    if(op) div.document.open('text/html','replace');
    for(var i=3; i<arguments.length; i++) s+=arguments[i];
    div.document.write(s);
    if(cl) div.document.close();
  }
}

function setDivBackgroundColor(div,color){
  if(_dom==1 || _dom==2) div.style.backgroundColor=(color==null)?'':color;
  if(_dom==3)            div.bgColor=color;
}

function setDivBackgroundImage(div,url){
  if(_dom==1 || _dom==2) div.style.backgroundImage = 'url('+url+')';
  if(_dom==3)            div.background.src=url;
}

function setDivZIndex(div,order){
  if(_dom==1 || _dom==2) div.style.zIndex=order;
  if(_dom==3)            div.zIndex=order;
}

function changeExlURL(exdiv,url){
  if(_dom==1 || _dom==2) frames(exdiv.id+'_if').location.replace(url);
  if(_dom==3)            exdiv.load(url,exdiv.clip.width);
}
function getLeftFromEvent(e){
  if(_dom==2||_dom==1) return document.body.scrollLeft+window.event.clientX;
  if(_dom==3)          return e.pageX;
  return 0;
}
function getTopFromEvent(e){
  if(_dom==2||_dom==1) return document.body.scrollTop+window.event.clientY;
  if(_dom==3)          return e.pageY;
  return 0;
}
