/*
  main.js
  include file for brautinfo.at website
  Author: TheGismo
  Copyright (c)2007 by OmanBros.com. All rights reserved.

  Contents:
	function anOption
	function valueSort
	function MoveSelected
	function DoOpenExtWin
*/

/*-----------------------------------------------------------*\
| Defining an associative array with a custom sort() function |
\*-----------------------------------------------------------*/
function anOption(key,value,anElement) { // actually an object
  this.key = key;
  this.value = value;
  this.anElement = anElement;
}

function valueSort (a,b) { // the custom sort function
var SortBy = 'value';
  if(a[SortBy] > b[SortBy]){return 1;}
  if(a[SortBy] < b[SortBy]){return -1;}
  return 0;
}

/* -------------------------------------------------------------------
  function MoveSelected

  Move one ore more items from one multiple select list to
  another.
*/
function MoveSelected(sourceid,destid) {
var srcList = document.getElementById(sourceid);	// those available for selection
var destList = document.getElementById(destid);		// those already selected
var optList = new Array();
  if (srcList && destList) {
    optElement = srcList.getElementsByTagName("option");
    // fetch selected items from source
    for (var i=srcList.length-1;i>-1;i--)
      if (srcList[i].selected) {
        optList.push(new anOption(srcList[i].value,srcList[i].text,optElement[i]));
        srcList.options[i] = null;
      }
    optElement = destList.getElementsByTagName("option");
    // additionally fetch all items from destination
    for (var i=destList.length-1;i>-1;i--) {
      optList.push(new anOption(destList[i].value,destList[i].text,optElement[i]));
      destList.options[i] = null;
    }
    optList.sort(valueSort);
    // sort the pot and put them back to destination
    for (var i=0;i<optList.length;i++) {
      destList.options.add(optList[i].anElement,i);
      destList.options[i].selected = 0;
    }
  }
  optList = null;
}

/* -------------------------------------------------------------------
  function DoOpenExtWin

  Opens a popup window in the center of the screen in w x h resolution
  and inserts a document from an url.
  w represents the first parameter (width)
  h represents the second parameter (height)
  n represents the third parameter (name of the window)
  s represents the fourth parameter (scrollbar+resizeable yes/no)
*/
function DoOpenExtWin(anurl) {
var ns4=(navigator.appName=="Netscape"&&parseInt(navigator.appVersion)==4)
var w=500,h=500,s='no'
var n="brautinfo_ExternalWindow",args=DoOpenExtWin.arguments,argslen=args.length
  if (argslen > 1) {w = args[1]}
  if (argslen > 2) {h = args[2]}
  if (argslen > 3) {n = args[3]}
  if (argslen > 4) {s = args[4]}
  // we check that coordinates are in screen boundaries
  if (w > screen.width) w=screen.width
  if (h > screen.height) h=screen.height
  t=(screen.height-h)/2
  if (t < 0) {h=screen.height; t=0}
  l=(screen.width-w)/2
  if (l < 0) {w=screen.width; l=0}
  newwin=window.open(
    anurl,
    n,
    'height='+h+',width='+w+','+
    'toolbar=no,'+
    'location=no,'+
    'directories=no,'+
    'status=no,'+
    'menubar=no,'+
    'scrollbars='+s+','+
    'resizable='+s+','+
    'copyhistory=no,'+
    'top='+t+',left='+l
  )
  newwin.focus()
}
