function centerWindow()
{	// centers window on screen

	// for MSIE use different width/height properties
	// to make this work, function must be called from body tag with onload(), not earlier in the document
	if		(navigator.userAgent.indexOf('MSIE') != -1)
			{
				var width  = document.body.offsetWidth;
				var height = document.body.offsetHeight;
			}
	else	{
				var width  = window.outerWidth;
				var height = window.outerHeight;
			}

	// center window
	self.moveTo(screen.availWidth/2 - width/2, screen.height/2 - height/2);
}

function changeRowColor(theRow, newColor)
{ /* Sets the cell background color in browse mode
  *  @param   object   the table row
  *  @param   integer  the row number
  *  @param   string   the new cell background color
  *  @return  boolean  whether pointer is set or not
  */

    // This array is used to remember mark status of rows in browse mode
    var marked_row = new Array;

    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the row -> exits
    if (newColor == '' || typeof(theRow.style) == 'undefined')
       { return false;
       }

    // 2. Gets the current row and exits if the browser can't get it
    if      (typeof(document.getElementsByTagName) != 'undefined')
            { theCells = theRow.getElementsByTagName('td');
            }
    else if (typeof(theRow.cells) != 'undefined')
            { theCells = theRow.cells;
            }
    else    { return false;
            }

    // 3. DOM detect
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return valid values with "getAttribute"
    if   (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined')
         { domDetect = true;
         }
    // 3.2 ... with other browsers
    else { domDetect = false;
         }

    // 4. Sets the new color...
    if (newColor)
       { var c = null;
         // 4.1 ... with DOM compatible browsers except Opera
         if   (domDetect)
              { for (c = 0; c < rowCellsCnt; c++)
                    { theCells[c].setAttribute('bgcolor', newColor, 0);
                    }
              }
         // 4.2 ... with other browsers
         else { for (c = 0; c < rowCellsCnt; c++)
                    { theCells[c].style.backgroundColor = newColor;
                    }
              }
       }

    return true;
}

function confirmLink(theWarning)
{ var is_confirmed = confirm(theWarning);
  return is_confirmed;
}

function confirmButton(theWarning)
{ var is_confirmed = confirm(theWarning);
  return is_confirmed;
}

function openPrintMenu()
{	// opens browser's print menu

	// only on non-Macs (causes error on Mac)
	if	(navigator.userAgent.indexOf('Mac') == -1)
		{
			window.print();
		}
} 

function openPrintVersion(filename) // popup HTML
{
  // Mac popup is always 20px bigger than specified
  if	(navigator.userAgent.indexOf('Mac') != -1)
		{ window.open(filename, 'popup', "width=680,height=480,scrollbars=yes,menubar=yes");
		}
  else	{ window.open(filename, 'popup', "width=700,height=500,scrollbars=yes,menubar=yes");
		}
}

function openWindow(target, view, mode)
{ var filename = target + "&view=" + view + "&mode=" + mode;
  window.open(filename, view, "width=510,height=400,scrollbars=yes");
}

function preloadImages(mode)
{ // define general images (preload always)
  var generalImages = new Array('/buergel/img/logout-h.gif',
                                '/buergel/img/trash-h.gif');

  // define array with images to preload depending on mode
  if      (mode == 'cms')
          { // set root directory
            var root = '/buergel/cms/img/';

            var myImages = new Array('menu01-h.gif',
                                     'menu02-h.gif',
                                     'menu03-h.gif',
                                     'menu04-h.gif',
                                     'menu05-h.gif',
                                     'submenu01-h.gif',
                                     'submenu02-h.gif',
                                     'submenu03-h.gif',
                                     'submenu04-h.gif',
                                     'submenu05-h.gif',
                                     'submenu06-h.gif');
          }

  // init target array
  var preImages = new Array();
  var genImages = new Array();

  // preload general images
  for (i = 0; i < generalImages.length; i++)
      { genImages[i]     = new Image();
		genImages[i].src = generalImages[i];
	  }

  // preload mode images
  for (i = 0; i < myImages.length; i++)
      { preImages[i]     = new Image();
		preImages[i].src = root + myImages[i];
	  }
}

function processLoginForm()
{ document.forms[0].password.value = MD5(document.forms[0].password.value);
  document.forms[0].submit();
}

function processURL(target)
{ window.location.href = target;
  return true;
}

function setStatusText(text)
{ status = text;
}

function submitSearchForm(action, idName, id)
{
	// append params to form action, submit
	var formAction				= document.forms[0].action;
	formAction					= formAction.replace('#results', '');	// replace anchor
	document.forms[0].action	= formAction + '?' + action + '&' + idName + '=' + id;
	document.forms[0].submit();
}

function swapImage(imgName, imgSource)
{ document.images[imgName].src = imgSource;
}

function switchVisibility(obj, status)
{ if      (status == "on")
          { document.all[obj].style.display = "block";
          }
  else if (status == "off")
          { document.all[obj].style.display = "none";
          }
  else if (status == "switch")
          { if   (document.all[obj].style.display == "none")
                 { document.all[obj].style.display = "block";
                 }
            else { document.all[obj].style.display = "none";
                 }
          }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
