require "compat"

local animation="image.animation_mode";
local colors="browser.display.use_document_colors"
local cookies="network.cookie.cookieBehavior"
local images="permissions.default.image"
local java="security.enable_java"
local jscript="javascript.enabled"
local popups="dom.disable_open_during_load"
local referer="network.http.sendRefererHeader"

function AniToggle()
	local tip
	togglepref(TYPE_STRING,animation,"normal","none")
	local pref=getpref(TYPE_STRING,animation)
	if pref=="none" then
		SetCheck("luamacro(AniToggle)",true)
		tip="BLOCKED"
	elseif pref=="normal" then
		SetCheck("luamacro(AniToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Animation "..tip)
end

function CToggle()
	local tip
	togglepref(TYPE_BOOL,colors)
	local pref=getpref(TYPE_BOOL,colors)
	if pref==false then
		SetCheck("luamacro(CToggle)",true)
		tip="BLOCKED"
	elseif pref==true then
		SetCheck("luamacro(CToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Page Colors "..tip)
end

function CKToggle()
	local tip
	togglepref(TYPE_INT,cookies,2,0)
	local pref=getpref(TYPE_INT,cookies)
	if pref==2 then
		SetCheck("luamacro(CKToggle)",true)
		tip="BLOCKED"
	elseif pref==0 then
		SetCheck("luamacro(CKToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Cookies "..tip)
end	

function ImgToggle()
	local tip
	togglepref(TYPE_INT,images,2,0)
	local pref=getpref(TYPE_INT,images)
	if pref==2 then
		SetCheck("luamacro(ImgToggle)",true)
		tip="BLOCKED"
	elseif pref==0 then
		SetCheck("luamacro(ImgToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Images "..tip)
end	

function JToggle()
	local tip
	togglepref(TYPE_BOOL,java)
	local pref=getpref(TYPE_BOOL,java)
	if pref==false then
		SetCheck("luamacro(JToggle)",true)
		tip="BLOCKED"
	elseif pref==true then
		SetCheck("luamacro(JToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Java "..tip)
end	

function JSToggle()
	local tip
	togglepref(TYPE_BOOL,jscript)
	local pref=getpref(TYPE_BOOL,jscript)
	if pref==false then
		SetCheck("luamacro(JSToggle)",true)
		tip="BLOCKED"
	elseif pref==true then
		SetCheck("luamacro(JSToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("JavaScript "..tip)
end

function PBToggle()
	local tip
	togglepref(TYPE_BOOL,popups)
	local pref=getpref(TYPE_BOOL,popups)
	if pref==true then
		SetCheck("luamacro(PBToggle)",true)
		tip="BLOCKED"
	elseif pref==false then
		SetCheck("luamacro(PBToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Popups "..tip)
end

function RefToggle()
	local tip
	togglepref(TYPE_INT,referer,2,0)
	local pref=getpref(TYPE_INT,referer)
	if pref==0 then
		SetCheck("luamacro(RefToggle)",true)
		tip="BLOCKED"
	elseif pref==2 then
		SetCheck("luamacro(RefToggle)",false)
		tip="ALLOWED"
	end
	SetStatusBarText("Referer "..tip)
end	

function ClearAll()
	plugin(privacy,ClearCache)
	plugin(privacy,ClearCookies)
	plugin(privacy,ClearHistory) 
	plugin(privacy,ClearMRU)
	plugin(privacy,ClearSignon)
end
