--[[
Very very tiny search script

But this can pass non-ascii charactors to Google.

luamacro(GoogleSearch)
]]


local function encode(url)
	return string.gsub(url, "([^a-zA-Z0-9_%.%-])", function (s)
		if s == " " then
			return "+"
		else
			return string.format("%%%02X", string.byte(s))
		end
	end)
end


function GoogleSearch()
	local engine, word
	engine = "http://www.google.com/search?q="
	word = prompt("Search", "Google")
	if word and word ~= "" then
		word = EncodeUTF8(word)
		word = encode(word)
--		alert(engine .. word,
--		      "Google", ICON_INFO)
		if getpref(km.TYPE_BOOL, "kmeleon.plugins.layers.load") then
			pluginmsg("layers", "OpenURL", engine .. word)
		else
			NavigateTo(engine .. word, km.OPEN_NEW)
		end
	end
end
