#!/bin/sh
# Launch a default browser
# License : GNU GPL
# (c) Eko M. Budi, 2004
# (c) Vector Linux, 2004

# Change this to reorder
if [ -z "$BROWSER_LIST" ]; then
  BROWSER_LIST="seamonkey firefox opera galeon epiphany mozilla konqueror firebird dillo"
fi

case "$1" in 
  "-h"|"--help")
  echo browser
  echo Usage: browser [URL]
  echo Launching any browser to access the URL
  exit 0
  ;;
esac

if [ "$BROWSER" ]; then
   PROG=`which $BROWSER 2> /dev/null`
   echo Browser=$PROG
fi

if [ -z "$PROG" ]; then
   for TRY in $BROWSER_LIST  ; do
      PROG=`which "$TRY" 2> /dev/null`
      if [ $? = 0 ]; then
         echo Browser=$PROG
	 break;
      fi         
   done
fi


if [ -z "$1" ]; then
   PAGE="file:///usr/doc/VLHelpCenter/index.html"
else
   PAGE="$1"
fi

if [ ! -z "$PROG" ]; then
  case `basename "$PROG"` in
    seamonkey|*firefox|*firebird|*galeon|*mozilla|*konqueror)
       echo "Opening remotely ..."
       $PROG -remote openURL\("$1",new-window\) && exit
       echo "Opening directly ..."
       exec $PROG "$PAGE"
       ;;
    opera)
       echo "Opening remotely ..."
       $PROG -remote openURL\("$1",new-window\) && exit
       echo "Opening directly ..."
       exec $PROG "$PAGE"
       ;;
    *) 
       echo "Opening directly ..."
       exec $PROG "$PAGE"
       ;;
  esac
fi

message "ERROR" "Could not launch: " "$PROG_LIST" 
exit 1

