local path = getpref(TYPE_STRING, "kmeleon.general.settingsDir")



function test(hwnd)
	local title,url=GetDocInfo(hwnd)
	url2=GetGlobalVar(TYPE_STRING, "URL")
	alert(title)
	alert(url)
	alert(url2)
end

function reply(hwnd)
	local title,url=GetDocInfo(hwnd)
	position=string.find(url,"t=")
	if (position) then
			a="http://bbs.et8.net/bbs/newreply.php?do=newreply&noquote=1"
			b=string.sub(url,position)
			a=a .. "&" .. b
			NavigateTo(a, OPEN, hwnd)
	end
end

function languageSelect(hwnd)
	path=getpref(TYPE_STRING,"kmeleon.general.profileDir")
	index,lang=choose("请选择使用的语言?","语言选择","Chinese(默认)","English");
	if (lang=="English") then
		setpref(TYPE_BOOL,"kmeleon.language.English",true)
		pluginmsg("utils", "rename", path.."language.cfg", path.."_language.cfg");
	else
		setpref(TYPE_BOOL,"kmeleon.language.English",false)
		pluginmsg("utils", "rename", path.."_language.cfg", path.."language.cfg");
	end	
end

function skinSelect(hwnd)
	index,skin=choose("Which skin do you want to use","skin selection","Safari","Silverbird","Camrod","Escape the Net","Tango");
	if (index==1) then
		setpref(TYPE_STRING,"kmeleon.general.skinsCurrent","Safari\\");
	end
	if (index==2) then
		setpref(TYPE_STRING,"kmeleon.general.skinsCurrent","Silverbird\\");
	end	
	if (index==3) then
		setpref(TYPE_STRING,"kmeleon.general.skinsCurrent","Camrod\\");
	end	
	if (index==4) then
		setpref(TYPE_STRING,"kmeleon.general.skinsCurrent","Escape the Net\\");
	end	
	if (index==5) then
		setpref(TYPE_STRING,"kmeleon.general.skinsCurrent","Tango\\");
	end	
end


function checkupdates()
	opennew("http://kmeleon.blogspot.com")
end


function URL(hwnd)
	local old, new
	old = km.getclipboard()
	km.id("ID_EDIT_COPY")
	new = km.getclipboard()
	NavigateTo(new,OPEN_BACKGROUNDTAB)
	km.setclipboard(old)
end
	
function feelinglucky()
	local lucky="http://www.google.com/search?btnI=I%27m+Feeling+Lucky&q=";
	local searchkey=km.GetWindowVar(Window_UrlBar);
	local url=lucky..searchkey;
	NavigateTo(url,OPEN_NORMAL);
end

function bookmarkall(hwnd)
	local pref = "kmeleon.plugins.bookmarks.askforFolder"
	local expect = false
	local now = getpref(TYPE_BOOL, pref)
	if now ~= nil then
		now = true
	end
	if now ~= expect then
		setpref(TYPE_BOOL, pref, expect)
	end

        local title, url = GetDocInfo(hwnd)
        local url_saved=url
	plugin("bookmarks","add")
        id("ID_TAB_NEXT")
        title,url=GetDocInfo(hwnd)
        while (url~=url_saved) do
	    plugin("bookmarks","add")
            id("ID_TAB_NEXT")
            title,url=GetDocInfo(hwnd)
        end

	if now ~= expect then
		setpref(TYPE_BOOL, pref, now)
	end
end

function runmacro(hwnd)
	local command=prompt("Please input the id or luamacro name:","Run macro","")
	if(command) then
		if (string.find(command,"ID_")) then
			km.id(command)
		else
			plugin("luamacro",command)
		end
	end
end

function fullscreen_config(hwnd)
	plugin("fullscreen","Config")
end

function profilebackup(hwnd)
	local toolpath=BROWSERPATH.."Tools";
	local kmpath=BROWSERPATH.."k-meleon.exe";
	local profilepath=GetFolder(ProfileFolder)
	local destpath=BROWSERPATH.."profilebackup";
	local command=toolpath.."\\profilebackup.exe \""..profilepath.."\" \""..destpath.."\" \""..kmpath.." "..toolpath.."\\backed.htm\" \""..kmpath.." "..toolpath.."\\restored.htm\"";
	--alert(command);
	exec(command);	
end	

function maximize(hwnd)
	id("ID_TOGGLE_TITLE");
	id("ID_MAXIMIZE_WINDOW");
	id("ID_TOGGLE_TITLE");
end

function setdefault(hwnd)
	local defaultexe=BROWSERPATH.."SetDefault.exe";
	exec(defaultexe);
end

function test1(hwnd)
	inJS("refresh.js")	
end


