var noteWin;

function openOpener( href )
{
  if (!window.opener.closed) { window.opener.location.href = href; }
  else                       { window.open( href ); }
}

function note(id){
  if (noteWin){
    noteWin.close();
  }

  noteWin = document.open("/favorite/show_note.pl?OBJECT_ID="+id,"NoteWindow",
      "location=0,directories=0,menubar=0,scrollbars=1,status=0,toolbar=0,width=250,height=250,resizable=1");

}

function inAlpha(arg){
  document.images[arg].style.filter="alpha(opacity=70)";
  document.images[arg].style.KHTMLOpacity = .7;
  document.images[arg].style.MozOpacity  = .7;
  document.images[arg].style.opacity  = .7;
}

function outAlphaGray(arg){
  document.images[arg].style.filter="alpha(opacity=100)gray()";
  document.images[arg].style.KHTMLOpacity = 1;
  document.images[arg].style.MozOpacity  = 1;
  document.images[arg].style.opacity  = 1;
}

function inAlphaGray(arg){
  document.images[arg].style.filter="alpha(opacity=70)gray()";
  document.images[arg].style.KHTMLOpacity = .7;
  document.images[arg].style.MozOpacity  = .7;
  document.images[arg].style.opacity  = .7;
}

function outAlpha(arg){
  document.images[arg].style.filter="alpha(opacity=100)";
  document.images[arg].style.KHTMLOpacity = 1;
  document.images[arg].style.MozOpacity  = 1;
  document.images[arg].style.opacity  = 1;
}


function popupDetailWin(topParent )
{
  var altText;

  if ( topParent )
  {
    altText = topParent.getAttribute( 'alt' );

    if (!( altText && altText != null && altText != '') ) {
      altText = popupDetailWinFindAlt( topParent );
    }

    if ( altText && altText != null && altText != '' )
    {
      popupCreate(altText );
    }

  }
}

function popupDetailWinFindAlt( parent )
{
  var children;
  var altValue;
  var i;

  if ( parent )
  {

    children = parent.childNodes;
    for ( i = 0; i < children.length; i++ )
    {
      if ( children[i].getAttribute )
      {
        altValue = children[i].getAttribute('alt');
        if ( altValue && altValue != null && altValue != '' )
        {
          return( altValue );
        }
        else
        {
          return( popupDetailWinFindAlt( children[i] ) );
        }
      }
    }
  }
  else
  {
    return null;
  }
}

function popupCreate( altText )
{
  var tmpDiv;

  if ( window.popupCurrentText && ( String(window.popupCurrentText) != String(altText) ) )
  {
    document.onmousemove = null;
    document.body.removeChild( window.popupDiv );
    window.popupDiv = null;
    window.popupCurrentText = null;
  }

  if (window.popupTimeout)
  {
    clearTimeout( window.popupTimeout );
    window.popupTimeout = null;
  }

  if ( !window.popupDiv )
  {

    if ( document.getElementById('ID_GRAPH_O') )
    {
      document.getElementById('ID_GRAPH_O').style.visibility='hidden';
    }
    if ( document.getElementById('ID_GRAPH_E') )
    {
      document.getElementById('ID_GRAPH_E').style.visibility='hidden';
    }

    window.popupCurrentText = altText;
    var divBlock = document.createElement( 'div' );
    var spanColor = document.createElement( 'span' );
    var txtAlt   = document.createTextNode( altText );
    spanColor.setAttribute( 'alt', String(txtAlt) );
    spanColor.appendChild( txtAlt );
    divBlock.appendChild( spanColor );
    divBlock.className = 'popup_hover';
    document.body.appendChild( divBlock );

    divBlock.style.width = (divBlock.childNodes[0].offsetWidth + 10) + 'px';
    window.popupDiv = divBlock;

    window.lastX = 0;
    window.lastY = 0;

    document.onmousemove = function( e )
    {
      if ( document.all ) { document.body.style.cursor= 'hand'; }
      else { document.body.style.cursor= 'pointer'; }

      if ( document.all ) { e = window.event; }
      if ( String(window.popupDiv.style.visibility) != String( 'visible' ))
      {
        window.popupDiv.style.top= (e.clientY - 20 + document.body.scrollTop) + 'px';
        window.popupDiv.style.left= (e.clientX + 20 + document.body.scrollLeft) + 'px';
        window.popupDiv.style.visibility = 'visible';
        window.lastX=e.clientX + 20 + document.body.scrollLeft;
        window.lastY=e.clientY - 20 + document.body.scrollTop;
      }
      else
      {
        var difX = e.clientX - window.lastX + document.body.scrollLeft + 20;
        var difY = e.clientY - window.lastY + document.body.scrollTop - 20;

        var newX = parseInt( window.popupDiv.style.left ) + difX;
        var newY = parseInt( window.popupDiv.style.top ) + difY;

        window.popupDiv.style.left=newX+'px';
        window.popupDiv.style.top=newY+'px';

        window.lastX = newX;
        window.lastY = newY;
      }
    }
  }
}

function popupRelease(){
  if ( window.popupTimeout )
  {
    clearTimeout( window.popupTimeout );
    window.popupTimeout = null;
  }

  window.popupTimeout = window.setTimeout("popupTimeOutRelease()", 200 );
}

function popupTimeOutRelease()
{
  if ( window.popupDiv )
  {
    document.onmousemove = null;
    document.body.removeChild( window.popupDiv );
    window.popupDiv= null;
    window.popupCurrentText = null;
    document.body.style.cursor= 'auto' ;
    if ( document.getElementById('ID_GRAPH_O') )
    {
      document.getElementById('ID_GRAPH_O').style.visibility='visible';
    }
    if ( document.getElementById('ID_GRAPH_E') )
    {
      document.getElementById('ID_GRAPH_E').style.visibility='visible';
    }

  }
}
