
function getQueryParameter( par ) {
  var query = window.top.location.search.substring(1);
  if ( !query ) return null;

  var begin = query.indexOf ( par + '=' );
  if ( begin < 0 ) return null;
  begin += par.length + 1;

  var end = query.indexOf( '&' , begin );
  if ( end < 0 ) end = query.length;

  return unescape( query.substring ( begin, end ) );
}

function markQueryParameter( par, bgColor ) {
  if ( !par ) par = 'mark';
  if ( !bgColor ) bgColor = '#F4F49E';

  var show = getQueryParameter( par );
  if ( !show ) return;

  var div = document.getElementById( show );
  if ( !div ) return;

  div.style.backgroundColor = bgColor;

//  div.scrollIntoView();
  if ( ! InView( div, 20 ) ) ScrollIntoView( div, true, 20 );
}

function InView(element,margin) {
  if(!margin) margin=0;
  var Top=GetTop(element), ScrollTop=GetScrollTop();
  return !(Top<ScrollTop+margin||
    Top>ScrollTop+GetWindowHeight()-element.offsetHeight-margin);
}

function ScrollIntoView(element,bAlignTop,margin) {
  if(!margin) margin=0;
  var posY=GetTop(element);
  if(bAlignTop) posY-=margin;
  else posY+=element.offsetHeight+margin-GetWindowHeight();
  window.scrollTo(0, posY);
}

function GetWindowHeight() {
  return window.innerHeight||
    document.documentElement&&document.documentElement.clientHeight||
    document.body.clientHeight||0;
}

function GetScrollTop() {
  return window.pageYOffset||
    document.documentElement&&document.documentElement.scrollTop||
    document.body.scrollTop||0;
}

function GetTop(element) {
  var pos=0;
  do pos+=element.offsetTop
  while(element=element.offsetParent);
  return pos;
}

//
// Popup
//

var _popup = null;
var _reset = null;

function getPopup( index ) {
	return document.getElementById( 'popup' + index );
}

function enter( index ) {
	if ( _reset ) {
		clearTimeout( _reset );
		_reset = null;
	}
	var popup = getPopup( index );
	if ( popup != _popup ) {
		if ( _popup != null ) {
			closePopup();
		}
		_popup = popup;
		assignPosition( _popup );
		_popup.style.display = 'block';
	}
}

function leave( index ) {
	if ( _reset ) {
		clearTimeout( _reset );
		_reset = null;
	}
	_reset = setTimeout( 'closePopup()', 250 );
}

function closePopup() {
	_reset = null;
	if ( _popup != null ) {
		_popup.style.display = 'none';
		_popup = null;
	}
}

var cX = 0;
var cY = 0;

function updateCursorPosition(e) {
	cX = e.pageX;
	cY = e.pageY;
}

function updateCursorPositionDocAll(e) {
	cX = event.clientX;
	cY = event.clientY;
}

if ( document.all ) {
	document.onmousemove = updateCursorPositionDocAll;
} else {
	document.onmousemove = updateCursorPosition;
}

function assignPosition(d) {
	d.style.left = ( cX + 0 ) + "px";
	d.style.top = ( cY + 0 ) + "px";
}
