/* 
  Algo: a dekstop environment look-a-like in your web browser
  Copyright (C) 2009  Niels Serup
  
	This file is part of Algo.

	Algo 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 3 of the License, or
	(at your option) any later version.

	Algo 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 Algo.  If not, see <http://www.gnu.org/licenses/>.
*/

/* This script page must be included by all pages.
   Without it, clicking on a window will not focus it.
   See the function below */
document.onmousedown = get_focus

function get_focus() {
  parent.scr.change_focus(getwnd().num)
}

/* Get the value of the id. There are always two ids and two values.
   The first one covers the title, while the second one is a unique number. */
function getget(id) {
  var txt, len, ab
  txt = window.location.search.substring(1).split('&')
  len = txt.length
  for (var i = 0; i < len; i++) {
    ab = txt[i].split('=')
    if (ab[0] == id) return ab[1]
  }
}

// Get the window, so to say.
function getwnd() {
  var onum = getget('num') * 1
  var num = -1
  for (var i = 0; i < parent.scr.len; i++) {
    if (parent.wnds[i].onum == onum) {
      num = i
      break
    }
  }
  if (num > -1)
    return parent.wnds[num]
}

function minimize() {
  getwnd().minimize()
}

function maximize() {
  getwnd().maximize()
}

function close() {
  getwnd().close()
}

function setwindow(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
  parent.scr.setwindow(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
}

function settitle(title) {
  getwnd().settitle(title)
}

function getwh() {
  if (self.innerHeight) {
    h=self.innerHeight
    w=self.innerWidth
  }
  else if (document.documentElement && document.documentElement.clientHeight) {
    h=document.documentElement.clientHeight
    w=document.documentElement.clientWidth
  }
  else if (document.body) {
    h=document.body.clientHeight
    w=document.body.clientWidth
  }
}