#!/bin/sh
# $Id: newscientist,v 1.3 2000/08/06 23:15:13 proff Exp $
# elvis: newscientist	-- Search New Scientist magazine (http://www.newscientist.com)
. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_newscientist_results $SURFRAW_results
def   SURFRAW_newscientist_sort    Date
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search New Scientist magazine archives (http://www.newscientist.com)
Local options:
  -results=NUM                  Number of search results returned
                                Default: $SURFRAW_newscientist_results
                                Environment: SURFRAW_newscientist_results
  -sort=Date | Rank             Sort results by Date or Rank
                                Default: $SURFRAW_newscientist_sort
                                Environment: SURFRAW_newscientist_sort
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-results=*)	setopt	SURFRAW_newscientist_results	$optarg	;;
	-sort=Date | -sort=Rank)	setopt	SURFRAW_newscientist_sort	$optarg	;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
if test -z "$w3_args"; then
    w3_browse_url http://www.newscientist.com/
else
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "http://www.newscientist.com/search/wholesiteresults.jsp?qu=${escaped_args}&&mh=${SURFRAW_newscientist_results}&st=s&so=${SURFRAW_newscientist_sort}%5Bd%5D"
fi
