#!/bin/sh

case " $FMDEBUG " in
*' url '*)
	echo "Hello from $0""
""FMBROWSER is $FMBROWSER""
""args are $@""
" >&2
	set -x
	;;
esac

case $# in
1)
	url=$1
	;;
*)
	echo "Usage: $0 url" >&2
	exit 1
	;;
esac

browser=${FMBROWSER-netscape}
r=`type $browser 2>/dev/null`
case "$? $r" in
'0 '*$browser*$browser*)
	;;
*)
	echo "Cannot find browser '$browser' in $PATH" >&2
	exit 1
	;;
esac

case $browser in
*[Nn]etscape*)
	# XXX -h test for symbolic links portable to all UNIXes?
	if [ -h $HOME/.netscape/lock ]; then
		# XXX this new-window business doesn't seem to work, although
		# -remote is fine (contacts a running netscape)
		#
		# The -raise option tells netscape not to raise a randomly
		# chosen pre-existing window. This option seems to make
		# the new-window argument more likely to be honored.
		#
		#
		# The best way to do this, which works only with versions 4.?
		# and presumably future versions of netscape is:
		# $browser -noraise -remote "new($url)" > /dev/null 2>&1
		#
		# Version 3.01 of netscape ignores the $url argument to new().
		# You might think you could remote "new()" and follow with "openURL($url)",
		# but there are two problems. First, version 4.? is very unhappy
		# to encounter a "new()" with no argument. Second, "openURL($url)"
		# causes netscape to try to open the url in a random window, not
		# necessarily the one just created by new. In fact, version 4.?
		# of netscape can get so confused it will try to open the url in
		# a mail window, which leads nowhere.
		#
		# One could determine the version of netscape via "$browser -version";
		# however, this reveals the version only of the client. The netscape
		# which will receive the "-remote" request may be a different version.
		# 
		# 6/22/98 -- Carl
		# 
		$browser -noraise -remote "openURL($url, new-window)"
		if [ $? -eq 0 ]; then
			exit 0
		fi
	fi
	$browser "$url" &
	exit $?
	;;
*)
	$browser "$url" &
	exit $?
	;;
esac
