/* ******
 * Name:        common.js
 * Description: javascript code for position and menu handling
 * Version:     1.2
 * Date:        Mon Feb 23 10:29:24 FLEST 2009
 * Changes:     1.2 - corrected scollbar positioning to work with IE6
 *              1.1 - support of multiple languages; deleted some unused code;
 *                    corrected bug in scrollbar positioning
 * Author:      Johan Forsbäck, Stefan Fronzek, SYKE
 */

// opens a new window with a help document
function helpWindow (id,lang) {
	if(!lang)
		window.open("help.php?id=" +id, "helpWindow", 
			"width=400px, height=400px, scrollbars, resizable") ;	
	else
		window.open("help.php?id=" +id + "&lang="+lang, "helpWindow", 
			"width=400px, height=400px, scrollbars, resizable") ;	
}


/* preserve scrollbar position by storing in a cookie
 * code modified from http://www.webreference.com/js/tips/991203.html
 */
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function saveScroll() {
  //if (!scroll) return;
  var now = new Date();
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	var xy=getScrollXY();
  var x = xy[0];
  var y = xy[1];
  setCookie("xy", x + "_" + y, now);
}

function loadScroll() {
  //if (!scroll) return;
  var xy = getCookie("xy");
  if (!xy) return;
  var ar = xy.split("_");
  if (ar.length == 2) window.scrollTo(parseInt(ar[0]), parseInt(ar[1]));
}

// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


/*!!!! deleted functions that are unused:
!* TJK toggle menu: saveMenu() loadMenu()
!* Static menu script by maximus: makeStatic() menu3()
!*/
