/*
   Highlighting for elements related to an active anchor tag
*/
function highlight () {
  if ( oElement ) oElement.className = '';
  if ( ! window.location ) return;
  var sAnchor = window.location.hash;
  if ( ! sAnchor ) return;
  if ( ! sAnchor.slice ) return;
  var sAnchorLessHash = sAnchor.slice ( 1 );
  if ( ! window.document || ! window.document.getElementById ) return;
  oElement = document.getElementById ( 'highlight_' + sAnchorLessHash );
  if ( ! oElement ) return;
  oElement.className = 'highlighted';
}
var oElement = null;
window.onload = highlight;
/*
   Text-size switching
*/
var nMaxTextSize = 3;
var nMinTextSize = -3;
var nTextSize = parseInt ( getCookie ( 'textsize' ) );
if ( nTextSize ) {
  var sFileSuffix = ( nTextSize > 0 ? 'plus' : 'minus' ) + Math.abs ( nTextSize );
  dw ( '<style type="text/css">' );
  dw ( '@import "' + sRoot + '/css/textsize' + sFileSuffix + '.css";' );
  dw ( '</style>' );
}
function changeTextSize ( nPlusMinus ) {
  var nTextSize = parseInt ( getCookie ( 'textsize' ) );
  if ( ! nTextSize ) nTextSize = 0;
  nTextSize += nPlusMinus;
  if ( nTextSize <= nMaxTextSize && nTextSize >= nMinTextSize ) {
    setOneYearCookie ( 'textsize', nTextSize.toString () );
    location.reload ();
  }
}
function setOneYearCookie ( sName, sValue ) {
  var dDate = new Date ();
  dDate.setTime ( dDate.getTime () + 365 * 24 * 60 * 60 * 1000 );
  document.cookie = sName + '=' + escape ( sValue ) + '; expires=' + dDate.toGMTString () + '; path=/';
}
function getCookie ( sName ) {
  var sSearch = sName + '=';
  if ( document.cookie.length > 0 ) {
    iOffset = document.cookie.indexOf ( sSearch );
    if ( iOffset != -1 ) {
      iOffset += sSearch.length;
      iEnd = document.cookie.indexOf ( ';', iOffset );
      if ( iEnd == -1 ) iEnd = document.cookie.length;
      return unescape ( document.cookie.substring ( iOffset, iEnd ) );
    }
  }
  return null;
}
/*
  Floaters
*/
function show ( objname, pointobjname ) {
  var x = getObj ( objname );
  var objleft = getObj ( pointobjname );
  var newX = findPosX ( objleft );
  if ( getWindowWidth () - newX < 350 + 12 + 10 ) {
    if ( objleft.offsetWidth ) newX += objleft.offsetWidth;
    newX -= 350 + 12;
  }
  var newY = findPosY ( objleft );
  if ( objleft.offsetHeight ) newY += objleft.offsetHeight - 1;
  x.style.top = newY + 'px';
  x.style.left = newX + 'px';
  if ( typeof ( x.style.filter ) == 'string' ) x.style.filter = 'progid:DXImageTransform.Microsoft.Fade(duration=0.33)';
  if ( navigator.userAgent.indexOf ( 'Mac' ) == -1 && x.filters && x.filters['DXImageTransform.Microsoft.Fade'] ) x.filters['DXImageTransform.Microsoft.Fade'].apply ();
  x.style.visibility = 'visible';
  if ( navigator.userAgent.indexOf ( 'Mac' ) == -1 && x.filters && x.filters['DXImageTransform.Microsoft.Fade'] ) x.filters['DXImageTransform.Microsoft.Fade'].play ();
}
function hide ( objname ) {
  var x = getObj ( objname );
  if ( navigator.userAgent.indexOf ( 'Mac' ) == -1 && x.filters && x.filters['DXImageTransform.Microsoft.Fade'] ) x.filters['DXImageTransform.Microsoft.Fade'].apply ();
  x.style.visibility = 'hidden';
  if ( navigator.userAgent.indexOf ( 'Mac' ) == -1 && x.filters && x.filters['DXImageTransform.Microsoft.Fade'] ) x.filters['DXImageTransform.Microsoft.Fade'].play ();
}
function findPosX ( obj ) {
  var curleft = 0;
  if ( obj.offsetParent ) {
    while ( obj.offsetParent ) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  } else if ( obj.x ) {
    curleft += obj.x;
  }
  return curleft;
}
function findPosY ( obj ) {
  var curtop = 0;
  if ( obj.offsetParent ) {
    while ( obj.offsetParent ) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  } else if ( obj.y ) {
    curtop += obj.y;
  }
  return curtop;
}
function getObj ( objname ) {
  if ( document.getElementById ) {
    return document.getElementById ( objname );
  } else if ( document.all ) {
    return document.all[objname];
  }
}
function getWindowWidth () {
  if (self.innerWidth) return self.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
  else if (document.body) return document.body.clientWidth;
}
/*
  Email address cloaking
*/
function writeEmail () {
  var sEmail = '';
  for ( var i = 0; i < arguments.length; i ++ ) {
    if ( i < arguments.length - 1 ) sEmail += arguments[i];
    else sEmail = arguments[i] + '@' + sEmail;
  }
  dw ( '<a href="mailto:' + sEmail + '">' + sEmail + '</a>' );
}
function dw ( s ) {
  document.writeln ( s );
}
/*
  Open small window
*/
function popup(element) {
  open(element.href, '_blank', 'width=400,height=600,menubar=no,resizable=yes,scrollbars=yes,location=no,status=no,toolbar=no');
  return false;
}
