#!/bin/sh
# $Id$
# elvis: ixquick		-- Search the web using ixquick [HTTPS] (www.ixquick.com)
. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_ixquick_search 'do/metasearch.pl'
def   SURFRAW_ixquick_lang "$SURFRAW_lang"
defyn SURFRAW_ixquick_ssl   yes
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search the web using Ixquick metasearch [HTTPS] (www.ixquick.com)
Local options:
  -nossl                        Don't use https
                                Environment: SURFRAW_ixquick_ssl
  -search=                      Specialized search on topic
          web		|       web
          pics		|       images
                                Environment: SURFRAW_ixquick_search

  -lang=                      	Language interface of ixquick
	english
	dansk
	deutsch
	espanol
	francais
	italiano
	nederlands
	norsk
	polski
	portugues
	suomi
	svenska
	turkce
	jiantizhongwen
	nihongo
	fantizhengwen
	hangul
                                Default: english
                                Environment: SURFRAW_ixquick_lang, SURFRAW_lang
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
    -no*)       setoptyn SURFRAW_ixquick_ssl    no      ;;
    -search=*)  setopt   SURFRAW_ixquick_search	$optarg ;;
    -lang=*)  setopt   SURFRAW_ixquick_lang	$optarg ;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"

if ifyes SURFRAW_ixquick_ssl
then
    proto="https"
else
    proto="http"
fi

# w3_args now contains a list of arguments
if test -z "$w3_args"; then
    w3_browse_url "${proto}://www.ixquick.com/"
else
    case "$SURFRAW_ixquick_lang" in
	en|english)           SURFRAW_ixquick_lang="english"        ;;
	dk|dansk)             SURFRAW_ixquick_lang="dansk"          ;;
	de|deutsch)           SURFRAW_ixquick_lang="deutsch"        ;;
	es|espanol)           SURFRAW_ixquick_lang="espanol"        ;;
	fr|francais)          SURFRAW_ixquick_lang="francais"       ;;
	it|italiano)          SURFRAW_ixquick_lang="italiano"       ;;
	nl|nederlands)        SURFRAW_ixquick_lang="nederlands"     ;;
	no|nb|nn|norsk)       SURFRAW_ixquick_lang="norsk"          ;;
	pl|polski)            SURFRAW_ixquick_lang="polski"         ;;
	pt|portugues)         SURFRAW_ixquick_lang="portugues"      ;;
	fi|suomi)             SURFRAW_ixquick_lang="suomi"          ;;
	sv|svenska)           SURFRAW_ixquick_lang="svenska"        ;;
	tr|turkce)            SURFRAW_ixquick_lang="turkce"         ;;
	cn|zh|jiantizhongwen) SURFRAW_ixquick_lang="jiantizhongwen" ;;
	ja|jp|nihongo)        SURFRAW_ixquick_lang="nihongo"        ;;
	zt|fantizhengwen)     SURFRAW_ixquick_lang="fantizhengwen"  ;;
	ko|kr|kp|hangul)      SURFRAW_ixquick_lang="hangul"         ;;
	*)                    SURFRAW_ixquick_lang="english"        ;;
    esac
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "${proto}://www.ixquick.com/do/metasearch.pl?cat=${SURFRAW_ixquick_search}&cmd=process_search&language=${SURFRAW_ixquick_lang}&query=${escaped_args}"
fi
