
function getKeyCode(e) {
   var keycode = 0;
   if (!e)
      e = window.event;
   if (e) {
      if (e.keyCode)
         keycode = e.keyCode;
      else if (e.which)
         keycode = e.which;
   }
   return keycode;
}

function submitFormOnEnter(myfield, e, fnSubmit){
   if (getKeyCode(e) == 13) {
      if (fnSubmit)
         fnSubmit();
      else
         myfield.form.submit();
      return false;
   } else return true;
}

function focusElementIdOnEnter(id,e){
   if (getKeyCode(e) == 13) {
      var el = document.getElementById(id);
      if (el)
         el.focus();
      return false;
   } else return true;
}

function trackclick(url, name) {
    if(document.images){
        (new Image()).src="/clicktracker.jsp?name=" + name;
    }
    return true;
}

// track click ticket
function tct(id, num, action) {
    if(document.images){
       (new Image()).src="/ticket.jspax?id=" + id + "&num=" + num + "&action=" + action;
    }
    return true;
}


function buttonRollIn(button, bgcolor) {
   button.style.background = bgcolor;
   button.style.cursor = "pointer";
}

function buttonRollOut(button, bgcolor) {
   button.style.background = bgcolor;
   button.style.cursor = "auto";
}

function openWindowPos(x, y, width, height, url, wnd, wndname, reload, scrollbars, resizable, fullscreen) {
   if (!fullscreen)
      fullscreen = "no";
   if (x < 0)
      x = 0;
   if (y < 0)
      y = 0;
   var properties = "toolbar=0,location=0,status=0,menubar=0,fullscreen=" + fullscreen + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y;

   if (wnd && !wnd.closed && wnd.location) {
      if (reload)
         wnd.location.href = url;
   } else {
      wnd = window.open(url, wndname, properties);
   }
   if (wnd.focus) {
      wnd.focus();
   }
   return wnd;
}


function openWindow(width, height, url, wnd, wndname, reload, scrollbars, resizable, fullscreen) {
   var x = (screen.width - width) / 2;
   var y = (screen.height - height) / 2;
   return openWindowPos(x, y, width, height, url ,wnd, wndname, reload, scrollbars, resizable, fullscreen)
}


function openWindowAt(xInner, yInner, siteCenteredWidth, width, height, url, wnd, wndname, reload, scrollbars, resizable) {
   var winSize = getWindowSize();
   var sx = 0;
   var sy = 0;
   if (window.screenX)
      sx = window.screenX;
   if (window.screenY)
      sy = window.screenY;
   if (window.screenLeft)
      sx = window.screenLeft;
   if (window.screenTop)
      sy = window.screenTop;

   var x = sx + xInner;
   if (winSize[0] > siteCenteredWidth)
      x = sx + xInner + (winSize[0] - siteCenteredWidth) / 2;
   if (x + width > screen.width)
      x = screen.width - width - 20;
   /*var y = sy + yInner;
   if (y + height > screen.height)
      y = screen.height - height - 20;*/
   var y = (screen.height - height) / 2;
   return openWindowPos(x, y, width, height, url ,wnd, wndname, reload, scrollbars, resizable)
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth, myHeight);
}

function setMinimumWindowSize(cxMin, cyMin) {
   var size = getWindowSize();
   if (parseInt(navigator.appVersion)>3) {
      if (navigator.appName=="Netscape") {
         if (size[0] < cxMin)
            window.innerWidth = cxMin;
         if (size[1] < cyMin)
            window.innerHeight = cyMin;
      } else {
         if (size[0] < cxMin - 16 && size[1] < cyMin) {
            window.resizeBy(cxMin - size[0] - 16, cyMin - size[1]);
         } else if (size[0] < cxMin - 16) {
            window.resizeBy(cxMin - size[0] - 16, 0);
         } else if (size[1] < cyMin) {
            window.resizeBy(0, cyMin - size[1]);
         }
      }
   }
}

function setWindowSize(cx, cy) {
   var size = getWindowSize();
   if (parseInt(navigator.appVersion)>3) {
      if (navigator.appName=="Netscape") {
         window.innerWidth = cx;
         window.innerHeight = cy;
      } else {
         if (size[0] != cx - 16 || size[1] != cy) {
            window.resizeBy(cx - size[0] - 16, cy - size[1]);
         }
      }
   }
}

function setWindowHeight(cy) {
   var size = getWindowSize();
   if (parseInt(navigator.appVersion)>3) {
      if (navigator.appName=="Netscape") {
         window.innerHeight = cy;
      } else {
         if (size[1] != cy) {
            window.resizeBy(0, cy - size[1]);
         }
      }
   }
}

function getPageHeight() {
   return document.documentElement.scrollHeight || document.body.scrollHeight;
}

function getPageWidth() {
   return document.documentElement.scrollWidth;
}



function getPageScrollTop(){
	var yScrolltop;
	var xScrollleft;
	if (self.pageYOffset || self.pageXOffset) {
		yScrolltop = self.pageYOffset;
		xScrollleft = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
		xScrollleft = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
		xScrollleft = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScrollleft,yScrolltop)
	return arrayPageScroll;
}

function scrollToElement(theElement, wndElement, wndHeight) {
  var selectedPosX = 0;
  var selectedPosY = 0;
  var y = wndElement.document.documentElement.scrollTop || wndElement.document.body.scrollTop;
  if (wndElement.pageYOffset)
     y = wndElement.pageYOffset;

  var elHeight = theElement.offsetHeight;
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
  if (selectedPosY != 0) {
     if (selectedPosY < y) {
        wndElement.scrollTo(selectedPosX,selectedPosY - (elHeight + 12));
     } else if (selectedPosY > y + wndHeight - (elHeight + 12)) {
        wndElement.scrollTo(selectedPosX,selectedPosY - (wndHeight - (elHeight + 12)));
     }
  }
}

function scrollToWindowElement(el) {
   scrollToElement(el, window, getWindowSize()[1]);
}


function redirTo(url) { window.location=url; }

function trimLeft(s) {
   var whitespaces = " \t\n\r";
   for(n = 0; n < s.length; n++) { if (whitespaces.indexOf(s.charAt(n)) == -1) return (n > 0) ? s.substring(n, s.length) : s; }
   return("");
}

function trimRight(s){
   var whitespaces = " \t\n\r";
   for(n = s.length - 1; n  > -1; n=n-1) { if (whitespaces.indexOf(s.charAt(n)) == -1) return (n < (s.length - 1)) ? s.substring(0, n+1) : s; }
   return("");
}

function trim(s) {return ((s == null) ? "" : trimRight(trimLeft(s))); }

// Variable number of arguments
function setElementsByIdsVisible() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.style.visibility = 'visible';
   }
}
function setElementsByIdsHidden() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.style.visibility = 'hidden';
   }
}
function toggleVisibilityOfElementsByIds() {
   var fVisibleNow = false;
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el) {
         if (el.style.visibility == 'visible') {
            el.style.visibility = 'hidden';
         } else {
            el.style.visibility = 'visible';
            fVisibleNow = true;
         }
      }
   }
   return fVisibleNow;
}
function resetElementsByIdsDisplay() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.style.display = "";
   }
}
function setElementsByIdsDisplayInline() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.style.display = 'inline';
   }
}
function setElementsByIdsDisplayBlock() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.style.display = 'block';
   }
}
function setElementsByIdsDisplayNone() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.style.display = 'none';
   }
}
function setElementsByIdsEmpty() {
   for (var i = 0; i < arguments.length; i++) {
      var el = document.getElementById(arguments[i]);
      if (el)
         el.innerHTML = "";
   }
}
//

function getElementAbsoluteOffsetTop(theElement) {
  var y = 0;

  while (theElement) {
    y += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
  return y;
}

function getElementAbsoluteOffset(theElement) {
  var x = 0, y = 0;

  while (theElement) {
    x += theElement.offsetLeft;
    y += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
  return new Array(x, y);
}


function getElementsByClassName(className, tag, elm){
   var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
   var tag = tag || "*";
   var elm = elm || document;
   var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
   var returnElements = [];
   var current;
   var length = elements.length;
   for(var i=0; i<length; i++) {
      current = elements[i];
      if(testClass.test(current.className)){
         returnElements.push(current);
      }
   }
   return returnElements;
}

function disabledTextSelOnMouseDown(e) {
   var srcElement=e ? e.target : event.srcElement;
   if (srcElement.type) {
      if (srcElement.type == 'textarea' || srcElement.type == 'text' || srcElement.type == 'password') {
         return true;
      }
   }
   return false;
}
function disableTextSelection() {
   if ((browser.ie4up || browser.opera6up) && !browser.safari) {
      document.onselectstart = disabledTextSelOnMouseDown; //new Function ("return false");
   } else if (browser.ns6up && !browser.safari) {
      document.onmousedown = disabledTextSelOnMouseDown;  //new Function ("return false");
      document.onclick = new Function ("return true");
   }
}

function detectBrowser() {
   // Get the Navigator properties
   this.useragent = navigator.userAgent;
   this.appname = navigator.appName;
   this.appversion = navigator.appVersion;

   // Get the user agent string and convert all characters to lowercase to simplify testing

   var loc_usragt = navigator.userAgent.toLowerCase();

   // Get the browser major and minor version id's

   this.major_version = parseInt(navigator.appVersion);
   this.minor_version = parseFloat(navigator.appVersion);

   // Set up browser values
   //
   // ns = Netscape Navigator

   // Opera and WebTV spoof Navigator so have to eliminate them via specific search for the browser
   // names in the user agent.

   this.ns  = ((loc_usragt.indexOf("mozilla")!= -1) &&
               (loc_usragt.indexOf("spoofer") == -1) &&
               (loc_usragt.indexOf("compatible") == -1) &&
               (loc_usragt.indexOf("opera") == -1) &&
               (loc_usragt.indexOf("webtv") == -1) &&
               (loc_usragt.indexOf("safari") == -1) &&
               (loc_usragt.indexOf("hotjava") == -1));

   this.ns2 = (this.ns &&
              (this.major_version == 2));

   this.ns3 = (this.ns &&
              (this.major_version == 3));

   this.ns4 = (this.ns &&
              (this.major_version == 4));

   // Although Netscape 6/7 should have major versions of 6/7 they actually report a major version
   // of 5

   this.ns6 = (this.ns &&
               this.major_version == 5 &&
               loc_usragt.indexOf("netscape 7") == -1 &&
               loc_usragt.indexOf("netscape/7") == -1);

   this.ns7 = (this.ns &&
               this.major_version == 5 &&
              (loc_usragt.indexOf("netscape 7") != -1 ||
               loc_usragt.indexOf("netscape/7") != -1));

   this.ns4up = (this.ns &&
                (this.major_version >= 4));

   this.ns6up = (this.ns &&
                (this.major_version >= 5));

   this.ns7up = (this.ns &&
                 this.major_version == 5 &&
                (loc_usragt.indexOf("netscape 7") != -1 ||
                 loc_usragt.indexOf("netscape/7") != -1));

   this.nsonly =  (this.ns &&
                 ((loc_usragt.indexOf(";nav") != -1) ||
                  (loc_usragt.indexOf("; nav") != -1)));

   this.gecko = (loc_usragt.indexOf("gecko") != -1 &&
                 loc_usragt.indexOf("safari") != -1);

   // ie = Internet Explorer

   this.ie      = ((loc_usragt.indexOf("msie") != -1) &&
                   (loc_usragt.indexOf("opera") == -1));

   this.ie3     = (this.ie &&
                  (this.major_version < 4));

   // Although Internet Explorer 4, 5, 5.5 and 6 should have a major versions of 4, 5, 5 and 6
   // respectively they all report a major version of 4 so need to search the user agent string for
   // specific names for each of them.

   this.ie4     = (this.ie &&
                  (this.major_version == 4) &&
                  (loc_usragt.indexOf("msie 4")!=-1));

   this.ie5     = (this.ie &&
                  (this.major_version == 4) &&
                  (loc_usragt.indexOf("msie 5.0")!=-1));

   this.ie5_5   = (this.ie &&
                  (this.major_version == 4) &&
                  (loc_usragt.indexOf("msie 5.5") !=-1));

   this.ie6     = (this.ie &&
                  (this.major_version == 4) &&
                  (loc_usragt.indexOf("msie 6.")!=-1) );

   this.ie4up   = (this.ie  &&
                  (this.major_version >= 4));

   this.ie5up   = (this.ie  &&
                  !this.ie3 &&
                  !this.ie4);

   this.ie5_5up = (this.ie &&
                  !this.ie3 &&
                  !this.ie4 &&
                  !this.ie5);

   this.ie6up   = (this.ie  &&
                  !this.ie3 &&
                  !this.ie4 &&
                  !this.ie5 &&
                  !this.ie5_5);

   // opera = Opera

   this.opera =  (loc_usragt.indexOf("opera") != -1);

   this.opera2 = (loc_usragt.indexOf("opera 2") != -1 ||
                  loc_usragt.indexOf("opera/2") != -1);

   this.opera3 = (loc_usragt.indexOf("opera 3") != -1 ||
                  loc_usragt.indexOf("opera/3") != -1);

   this.opera4 = (loc_usragt.indexOf("opera 4") != -1 ||
                  loc_usragt.indexOf("opera/4") != -1);

   this.opera5 = (loc_usragt.indexOf("opera 5") != -1 ||
                  loc_usragt.indexOf("opera/5") != -1);

   this.opera6 = (loc_usragt.indexOf("opera 6") != -1 ||
                  loc_usragt.indexOf("opera/6") != -1);

   this.opera7 = (loc_usragt.indexOf("opera 7") != -1 ||
                  loc_usragt.indexOf("opera/7") != -1);

   this.opera5up = (this.opera &&
                   !this.opera2 &&
                   !this.opera3 &&
                   !this.opera4);

   this.opera6up = (this.opera &&
                   !this.opera2 &&
                   !this.opera3 &&
                   !this.opera4 &&
                   !this.opera5);

   this.opera7up = (this.opera &&
                   !this.opera2 &&
                   !this.opera3 &&
                   !this.opera4 &&
                   !this.opera5 &&
                   !this.opera6);
   // safari = Safari

   this.safari = (loc_usragt.indexOf("safari") != - 1);

   // ff mac
   this.ffmac = (loc_usragt.indexOf("firefox") != -1 &&
                 loc_usragt.indexOf("macintosh") != -1);
}


var browser = new detectBrowser();


var articlewnd = '';
function openArticle(key, altWndName) {
   var wndName = "articlewnd";
   if (altWndName)
      wndName = altWndName;
   articlewnd = openWindowAt(500, 50, 1000, 568, 680, "/" + "artiklar/" + key + ".html?popup", articlewnd, wndName, true, "1", "1");
}




