require "dialog"

local width = 360
local height = 80
local ffont="Arial"
local fpoint=10

local folder=GetFolder(ProfileFolder)

local fname=folder.."\\lastpass.ini"

local function lastpass_read()
	io.input(fname)
	local g={}
	local i=1
	for line in io.lines() do
		g[i]=line
		i=i+1
	end
	return g
end

function lastpass_login(hwnd)
local g=lastpass_read()
open(g[1])
end

function lastpass_fill(hwnd)
local g=lastpass_read()
open(g[2])
end

function lastpass_form(hwnd)
local g=lastpass_read()
open(g[3])
end



local d = create_dialog({
	width = width,
	height = height,
	caption = "LastPass Bookmarklets",
	style = w32dlg.DS_CENTER,
	font = ffont, point = fpoint,

	{type = "static",x = 25,y = 7,width = 120, height = 10, id = "IDSTATIC", caption = "LastPass Login! bookmarklet"},
	{type = "static",x = 25,y = 20,width = 120, height = 10, id = "IDSTATIC", caption = "LastPass Fill! bookmraklet"},
	{type = "static",x = 25,y = 33,width = 120, height = 10, id = "IDSTATIC", caption = "LastPass Fill Form bookmarket"},
	{type = "edit", style = w32dlg.WS_BORDER+w32dlg.ES_AUTOHSCROLL, x = 130, y = 5, width = 200, height = 10, id = "IDLPLOGIN", caption = ""},
	{type = "edit", style = w32dlg.WS_BORDER+w32dlg.ES_AUTOHSCROLL, x = 130, y = 18, width = 200, height = 10, id = "IDLPFILL", caption = ""},
	{type = "edit", style = w32dlg.WS_BORDER+w32dlg.ES_AUTOHSCROLL, x = 130, y = 31, width = 200, height = 10, id = "IDLPFORM", caption = ""},
	{type="button",style=w32dlg.BS_DEFPUSHBUTTON,x=5,y=50,width=40,height=12,id="IDOK",caption="Done"},   	
})

local function lastpass_write(g)
	io.output(fname)
	for i, l in ipairs(g) do 
		io.write(g[i], "\n") 
	end	
	io.close()
end

function lastpass_config(hwnd)
	local g=lastpass_read()
	r,rr=d("LastPass Bookmarklets",{
		IDLPLOGIN=g[1],
		IDLPFILL=g[2],
		IDLPFORM=g[3],
	})
	g[1]=rr.IDLPLOGIN
	g[2]=rr.IDLPFILL
	g[3]=rr.IDLPFORM
	lastpass_write(g)
end
