// JavaScript Library - WINDOW object
// VERSION: 1.0.1
// REQUIREMENTS: jslib.js
var _CENTER					=1
var _UPPER_LEFT				=2
var _UPPER_RIGHT			=3
var _LOWER_LEFT				=4
var _LOWER_RIGHT			=5

var __window_width 			= -1
var __window_height 		= -1
var __window_inner_height 	= -1
var __window_inner_width 	= -1

function _createWindow(url,name,w,h,attribs)
{    
  var menubar=0;
  var toolbar=0;
  var locationbar=0;
  var personalbar=0;
  var statusbar=0;
  var scrollbars=0;
  var resizable=0;  
  if(typeof(w)=="undefined") var w=0;
  if(typeof(h)=="undefined") var h=0;  
  if(typeof(attribs)=="undefined") var attribs="";
  else if(attribs.match("all")||attribs.match("every")) {
    menubar=1;
    toolbar=1;
    locationbar=1;
    personalbar=1;
    statusbar=1;
    scrollbars=1;
    resizable=1; 
  } else {
    if(attribs.match("menu")) menubar=1;
    if(attribs.match("tool")) toolbar=1;
    if(attribs.match("loc")) locationbar=1;
    if(attribs.match("pers")) personalbar=1;
    if(attribs.match("stat")) statusbar=1;
    if(attribs.match("scroll")) scrollbars=1;
    if(attribs.match("resiz")) resizable=1;
  }    
  attribs="";
  if(w>0) attribs+="width="+w;
  if(h>0) {
    if(attribs!="") attribs+=",";
    attribs+="height="+h;
  }
  if(attribs!="") attribs+=",";
  attribs+="menubar="+menubar+",toolbar="+toolbar+",location="+locationbar;
  attribs+=",personalbar="+personalbar+",status="+statusbar+",scrollbars="+scrollbars;
  attribs+=",resizable="+resizable;  
  return window.open(url,name,attribs);
}   

function _setStatusMsg(msg)
{ 
	window.status=msg;
} 
  
function _closeWindow(focusopener)
{
  if(typeof(focusopener)=="undefined") var focusopener=false;
  if(focusopener&&window.opener) window.opener.focus();
  window.close();   
}

function _determineWindowSize(win,fakeIE)
{
  if(typeof(win)=="undefined") var win = window
  if(typeof(fakeIE)=="undefined") var fakeIE = true
  
  if(win.outerWidth){ 
  
    __window_width			= win.outerWidth
    __window_height			= win.outerHeight
    __window_inner_width	= win.innerWidth
    __window_inner_height	= win.innerHeight
    
  }else if(win.document.body.offsetWidth){ 
  
    if(fakeIE) {
      __window_width		= win.document.body.offsetWidth+8
      __window_height		= win.document.body.offsetHeight+140
      __window_inner_width	= win.document.body.offsetWidth
      __window_inner_height	= win.document.body.offsetHeight
    } else {
      var resize_w	= 800
      var resize_h	= 600
      var offset_w	= win.document.body.offsetWidth
      var offset_h	= win.document.body.offsetHeight
      
      window.resizeTo(resize_w,resize_h);
      
      var diff_w	= win.document.body.offsetWidth-offset_w;
      var diff_h	= win.document.body.offsetHeight-offset_h;
      var w			= resize_w-diff_w;
      var h			= resize_h-diff_h;
      
      window.resizeTo(w,h);
      
      __window_width=w;
      __window_height=h;
    }
    
  } else {
    __window_width			= -1
    __window_height			= -1
    __window_inner_width	= -1
    __window_inner_height	= -1   
  }
  
  var array	= new Array();
  
  array[0]	= __window_width;
  array[1]	= __window_height;
  array[2]	= __window_inner_width;
  array[3]	= __window_inner_height;
  
  return array; 
}

function _getWindowWidth()
{
	return __window_width;
}

function _getWindowHeight()
{
	return __window_height;
}

function _getWindowPosX(win)
{
  if(typeof(win)=="undefined") var win=window;
  if(window.screenX) return win.screenX;
  else if(window.screenLeft) return win.screenLeft;    
}

function _getWindowPosY(win)
{
  if(typeof(win)=="undefined") var win=window;
  if(window.screenY) return win.screenY;
  else if(window.screenTop) return win.screenTop;    
}

function _moveWindowTo(x,y,win)
{
  if(typeof(win)=="undefined") var win=window;
  win.moveTo(x,y);      
}

function _moveWindowBy(x,y,win)
{
  if(typeof(win)=="undefined") var win=window;
  win.moveBy(x,y)  
}

function _positionWindow(pos,win,fakeIE)
{
  if(typeof(win)=="undefined") { var win=window; }
  if(typeof(fakeIE)=="undefined") { var fakeIE=true; }
  var sw=screen.width;
  var sh=screen.height;
  var array=_determineWindowSize(win,fakeIE);
  var ww=array[0];
  var wh=array[1]; 
  if(ww>0&&wh>0) {
    var left=0;
    var top=0;
    if(pos==_UPPER_LEFT) {
      left=(sw-ww)*0.1;
      top=(sh-wh)*0.2;
    } else if(pos==_UPPER_RIGHT) {
      left=(sw-ww)*0.9;
      top=(sh-wh)*0.2;
    } else if(pos==_LOWER_LEFT) {
      left=(sw-ww)*0.1;
      top=(sh-wh)*0.9;
    } else if(pos==_LOWER_RIGHT) {
      left=(sw-ww)*0.9;
      top=(sh-wh)*0.9; 
    } else {
      left=(sw-ww)/2;
      top=(sh-wh)/2;  
    }
    if(left>0&&top>0) { win.moveTo(left,top); }
    return true;
  }
  return false;
} 
// EOF