<?xml version="1.0"?>
<?xul-overlay href="chrome://kmprefs/content/kmprefs/ovrl-urlbar.xul"?>
<!DOCTYPE overlay SYSTEM "chrome://kmprefs/locale/kmprefs/ovrl-history.dtd">
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
	<script type="application/x-javascript">
<![CDATA[
// Import the module to FormHistory
Components.utils.import("resource://gre/modules/FormHistory.jsm");
var kHistory = {
	name : "history",
	pref : "kmeleon.plugins.history.load",
	init : function () {
		if (kPlugin.absent(this.name))
			document.getElementById(this.pref).setAttribute("hidden", true);
		else
			initCheckbox(this.pref);
	}
};
var History = {
	prefs : Components.classes["@mozilla.org/preferences-service;1"]
					.getService(Components.interfaces.nsIPrefService)
					.getBranch("kmeleon.MRU.URL"),
	_srvc : null,
	init : function () {
		kHistory.init();
		URLBarHeight.init();
		//	this._srvc = Components.classes["@mozilla.org/browser/global-history;2"]
		//			.getService(Components.interfaces.nsIBrowserHistory);
		this._srvc = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService);
		var _elem,
		_pref;
		//	_pref = "browser.history_expire_days",
		//	_elem = document.getElementById("toggleHistory");
		//	_elem.checked = (pref.getIntPref(_pref));
		//	initTextbox(_pref,false);
		//	document.getElementById(_pref).disabled = !_elem.checked;
		_pref = "places.history.enabled";
		initCheckbox(_pref);
		
		_pref = "kmeleon.MRU.maxURLs";
		_elem = document.getElementById("mru");
		_elem.checked = (pref.getIntPref(_pref));
		initTextbox(_pref, false);
		document.getElementById(_pref).disabled = !_elem.checked;
		
		_pref = "kmeleon.MRU.behavior";
		initRadiogroup(_pref);
		document.getElementById(_pref).disabled = !_elem.checked;
		
		// Added for Form History options:
		this.initFormBtn();
		_pref = "browser.formfill.enable";
		initCheckbox(_pref);
		_pref = "browser.formfill.expire_days";
		initTextbox(_pref, false);
		_pref = "browser.formfill.bucketSize";
		initTextbox(_pref, false);
		_pref = "browser.formfill.saveHttpsForms";
		initCheckbox(_pref);
	// End of added for Form History options.
		//	document.getElementById("clearHistory").disabled = !this._srvc.count;
		document.getElementById("clearHistory").disabled = !this._srvc.hasHistoryEntries;
		document.getElementById("btnURLBarHistory").disabled = this.prefs.getChildList("", {}).length == 0;
	},
	clear : function () {
		this._srvc.removeAllPages();
	},
	// Added for Form History options:
	initFormBtn: function () {
		var count = 0;
		var done = false;
		FormHistory.count({}, {
			handleResult: function (result) {
				count = result;
			},
			handleError: function (error) {
				throw error;
			},
			handleCompletion: function (reason) {
				done = true;
			}
		});
		var timer = Components.classes['@mozilla.org/timer;1'].createInstance(Components.interfaces.nsITimer);
		timer.initWithCallback(function () {
			done = true;
		}, 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
		var thread = Components.classes['@mozilla.org/thread-manager;1'].getService().mainThread;
		while (!done) {
			thread.processNextEvent(true);
		}
		document.getElementById('btnFormHistory').disabled = count == 0;
	},
	clearForms : function () {
		FormHistory.update({op: "remove"});
	},
	// End of added for Form History options.
	clearURLBar : function () {
		for (var a = 0, b = this.prefs.getChildList("", {}); a < b.length; a++)
			this.prefs.clearUserPref(b[a]);
	},
	toggle : function (elem) {
		if (elem.checked)
			restoreDefault(elem.nextSibling.id);
		else
			pref.setIntPref(elem.nextSibling.id, 0);
		this.init();
		elem.nextSibling.focus();
	}
};
//addEventListener("load",History.init,true);
]]>
	</script>
	<vbox id="history">
		<groupbox>
			<caption>
				<label>&history.global.label;</label>
			</caption>
			<separator class="thin"/>
			<hbox align="center">
				<checkbox id="places.history.enabled" label="&history.global.remember;" oncommand="toggleCheckbox(this.id)"/>
<!-- 	Disabled starting from the k-meleon gecko v.25.0
				<checkbox oncommand="History.toggle(this)" id="toggleHistory" label="&history.global.keepBefore;"/>
				<textbox id="browser.history_expire_days" size="4" class="uri-element" oninput="setIntPref(this.id,this.value)"/>
				<label value="&history.global.keepAfter;"/>
-->
				<spacer flex="1"/>
				<button oncommand="History.clear();this.disabled=true" id="clearHistory" label="&clear;"/>
			</hbox>
			<separator class="thin"/>
			<checkbox oncommand="toggleCheckbox(this.id)" id="kmeleon.plugins.history.load" label="&history.plugin;"/>
			<separator class="thin"/>
		</groupbox>
		<separator class="thin"/>
		<groupbox>
			<caption>
				<label>&history.urlbar.label;</label>
			</caption>
			<hbox align="center">
				<checkbox oncommand="History.toggle(this)" id="mru" label="&history.urlbar.keepBefore;"/>
				<textbox id="kmeleon.MRU.maxURLs" size="4" class="uri-element" oninput="setIntPref(this.id,this.value)"/>
				<label value="&history.urlbar.keepAfter;"/>
				<spacer flex="1"/>
				<button oncommand="History.clearURLBar();this.disabled=true" id="btnURLBarHistory" label="&clear;"/>
			</hbox>
			<separator class="thin"/>
			<hbox id="urlbarheight"/>
			<separator class="thin"/>
			<description>&history.urlbar.descr;</description>
			<radiogroup id="kmeleon.MRU.behavior" oncommand="toggleRadiogroup(this.id)">
				<radio value="0" label="&history.urlbar.everything;"/>
				<radio value="1" label="&history.urlbar.domains;"/>
				<radio value="2" label="&history.urlbar.typed;"/>
				<radio value="3" label="&history.urlbar.nothing;"/>
			</radiogroup>
			<separator class="thin"/>
		</groupbox>
<!-- Added for Form History options -->
		<separator class="thin"/>
		<groupbox>
			<caption>
				<label>&history.formfill.label;</label>
			</caption>
			<hbox align="center">
				<checkbox id="browser.formfill.enable" label="&history.formfill.enable;" oncommand="toggleCheckbox(this.id)"/>
				<spacer flex="1"/>
				<button oncommand="History.clearForms();this.disabled=true" id="btnFormHistory" label="&clear;"/>
			</hbox>
			<separator class="thin"/>
			<hbox align="center">
				<label value="&history.formfill.keepBefore;"/>
				<textbox id="browser.formfill.expire_days" size="4" class="uri-element" oninput="setIntPref(this.id,this.value)"/>
				<label value="&history.formfill.keepAfter;"/>
			</hbox>
			<separator class="thin"/>
			<hbox id="formfillheight" align="center">
				<label value="&history.formfill.height;"/>
				<textbox id="browser.formfill.bucketSize" size="2" class="uri-element" oninput="setIntPref(this.id,this.value)"/>
				<label value="&history.formfill.lines;"/>
			</hbox>
			<separator class="thin"/>
			<hbox align="center">
				<checkbox id="browser.formfill.saveHttpsForms" label="&history.formfill.saveHttps;" oncommand="toggleCheckbox(this.id)"/>
			</hbox>
			<separator class="thin"/>
		</groupbox>
<!-- End of added for Form History options -->
	</vbox>
</overlay>