function rsTextSelection()
{
  if ( document.getSelection ) // older Mozilla versions
    var selectedString = document.getSelection();
  else if ( document.all ) // MSIE 4+
    var selectedString = document.selection.createRange().text;
  else if ( window.getSelection ) // recent Mozilla versions
    var selectedString = window.getSelection ( );

  document.forms [ 'rs_form' ].elements [ 'selectedtext' ].value = selectedString;

  if ( document.forms [ 'rs_form' ].elements [ 'url' ] )
  {
    if ( !document.forms [ 'rs_form' ].elements [ 'url' ].value )
    {
      if ( window.location.href )
        document.forms [ 'rs_form' ].elements [ 'url' ].value = window.location.href;
      else if ( document.location.href )
        document.forms [ 'rs_form' ].elements [ 'url' ].value = document.location.href;
    }
  }
}

function copyselected()
{
  setTimeout ( "rsTextSelection ()", 50 );
  return true;
}

function openAndRead ()
{
  if ( window.open ( '', 'rs', 'width=380,height=180,toolbar=0' ) )
    document.forms [ 'rs_form' ].submit();

  return false;
}

document.onmouseup = copyselected;
document.onkeyup = copyselected;