/**
 * Eredetileg kisérleti modul volt.
 * Jelenleg, a legegyszerűbb modul, kizárólag szöveges (formázott HTML) információk mejelenítésére.
 */
function TSimpleText(widget, content, editor) {
	this.widget = widget;
	this.refresh(content);

	if(widget.webxEditor) {
		var edd = [ "table",
			[ "tr",
				[ "td", "Stílus:" ],
				[ "td", { element: null } ]
			]
		];

		Sarissa.clearChildNodes(widget.webxEditor);
		widget.webxEditor.appendChild(webxJsonML(edd));
		webxCreateLookEditor(edd[1][2][1].element);
	}
}

TSimpleText.prototype.refresh = function(content) {
	if(content == null) content = '<div style="color: red; font-weight: bold; text-align: center; font-size: 110%; padding: 2px;">Hiba betöltés közben!</div>';
	else if(!this.widget.webxWidget.full) content = '<div style="text-align: justify; padding: 2px;">' + content + '</div>';

	this.widget.webxPane.innerHTML = content;
}

/**
 * RSS Feed
 */
function TFeed(widget, content, editor) {
	this.widget = widget;
	var _this = this;

	// Editor
	var inpRSS = [ "input", { type: "text", "class": "txt", element: null } ];
	var btnRSS = [ "input", { type: "button", "class": "btn", value: "OK", element: null } ];
	var inpTitle = [ "input", { type: "text", "class": "txt", element: null } ];
	var btnTitle = [ "input", { type: "button", "class": "btn", value: "OK", element: null } ];
	var inpItemCnt = [ "select", { element: null, webxManager: this } ];
	var lookMngr = [ "td", { colSpan: 2, element: null } ];

	var ed = [ "table", { "class": "wx_edit" },
		[ "tr",
			[ "td", "Cím:" ],
			[ "td", { style: "width: 100%;" }, inpTitle ],
			[ "td", btnTitle ]
		],
		[ "tr",
			[ "td", "RSS:" ],
			[ "td", inpRSS ],
			[ "td", btnRSS ]
		],
		[ "tr",
			[ "td", /* { style: "white-space: nowrap;" } ,*/ "Elemek száma:" ],
			[ "td", { colSpan: 2 }, inpItemCnt ]
		],
		[ "tr", 
			[ "td", "Stílus" ],
			lookMngr
		]
	];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(ed));
	this.itemCountSelect = inpItemCnt[1].element;
	this.itemCountSelect.onchange = function() {
		widget.webxWidget.itemCount = new Number(this.value);
		widget.webxManager._refresh();
	}

	if(!widget.webxWidget.itemCount) {
		widget.webxWidget.itemCount = 10;
		this.itemCountSelectCnt = 0;
	}

	this.titleInput = inpTitle[1].element;
	btnTitle[1].element.onclick = function() {
		_this.widget.webxWidget.title = _this.titleInput.value;
		_this.widget.webxDirty = true;
		webx.updateTitle(_this.widget);
	}

	this.rssInput = inpRSS[1].element;
	btnRSS[1].element.onclick = function() {
		var r = webx.urls.rss2json + escape(_this.rssInput.value);
		if(_this.widget.webxWidget.content.ref != r) {
			_this.widget.webxWidget.content.ref = r;
			_this.widget.webxWidget.title = "";
			webx.loadWidget(_this.widget);
		}
	}

	webxCreateLookEditor(lookMngr[1].element);

	delete inpRSS;
	delete btnRSS;
	delete inpTitle;
	delete btnTitle;
	delete inpItemCnt;
	delete lookMngr;
	delete ed;

	this.refresh(content);
}

TFeed.prototype.refresh = function(content) {
	if(content == null) {
		Sarissa.clearChildNodes(this.widget.webxPane);
		this.widget.webxPane.innerHTML = "Hiba betöltés közben!";
		return;
	}

	wxlog.log("refresh: " + content);
	this.content = content;
	this._refresh();
}

TFeed.prototype._refresh = function() {
	var _this = this;
	var wd = this.widget.webxWidget;

	if(this.itemCountSelectCnt != this.content.items.length) {
		if(wd.itemCount > this.content.items.length) wd.itemCount = this.content.items.length;

		// Item count select
		Sarissa.clearChildNodes(this.itemCountSelect);
		for(var i = 0; i < this.content.items.length; i++) {
			var attrs = { value: i };
			if(i == wd.itemCount) attrs.selected = "selected";
			var opt = [ "option", attrs, i ];
			this.itemCountSelect.appendChild(webxJsonML(opt));
		}
		this.itemCountSelectCnt = this.content.items.length;
	}

	if(wd.title == "") webx.setTitle(this.widget, this.content.title, this.content.link);
	if(this.content.icon) webx.setIcon(this.widget, this.content.icon);

	Sarissa.clearChildNodes(this.widget.webxPane);

	var ul = document.createElement("UL");
	ul.className = "rss";

	// Items
	var tips = new Array();
	wxlog.dir(this.content);
	for(var i = 0; i < wd.itemCount; i++) {
		var item = this.content.items[i];
		var li = document.createElement("LI");

		var a = document.createElement("A");
		a.href = item.link;
		a.target = "_blank";
//		a.href = "javascript:nop()";

		if(item.description) {
			var tip = Sarissa.stripTags(item.description).trim().replace(/\s+/g, ' ');
			if(tip.length != 0) {
				if(tip.length > 300) tip = tip.substring(0, tip.indexOf(' ', 295)) + "...";
				tips[tips.length] = { element: li, tip: tip };
			}

			a.webxFloat = {
				icon: wd.icon,
				title: wd.title + " - " + item.title,
				type: "TFeedOne",
				content: { type: "empty" },
				params: { fastClose: true },
				rssURL: item.link
			};
			a.webxDirect = false;
			if(item.contentx) a.webxFloat.rss = item.contentx;
			else a.webxFloat.rss = item.description;
			a.onclick = function() {
				if(this.webxDirect) return true;

				var w = webx.createWidget(this.webxFloat, true);
				var pos = GetBounds(_this.widget);
				with(w.style) {
					left = pos.x + "px";
					top = pos.y + "px";
				}
				return false;
			}

			var ad = document.createElement("A");
			ad.className = "";
			ad.href = "";
			function over(btn) { btn.parentNode.webxDirect = true; }
			function out(btn) { btn.parentNode.webxDirect = false; }
			var img = new WebxButton(null, null, null, null, "%img%/webx/rssnyil.gif", null, null, null, over, out);
			a.appendChild(img.create());
		}

		a.appendChild(document.createTextNode(item.title));
		li.appendChild(a);
		ul.appendChild(li);
	}

	this.widget.webxPane.appendChild(ul);
	if(tips.length != 0) {
		new TipManager(tips);
	}
}

TFeed.prototype.editorVisible = function(v) {
	if(v) {
		this.titleInput.value = this.widget.webxWidget.title;

		var u = this.widget.webxWidget.content.ref;
		var p = webx.urls.rss2json;
		if(u.indexOf(p) == 0) {
			u = u.substr(p.length);
		}
		this.rssInput.value = unescape(u);
	}
}

/* egy feed lebegő ablaka. */
function TFeedOne(widget, content, editor) {
	var html = '<div style="text-align: justify; padding: 2px;">' + widget.webxWidget.rss + '<div style="height: 12px; line-height: 12px; padding: 3px;"><a style="float: right; display: block; color: red; font-weight: bold;" target="_blank" href="' + widget.webxWidget.rssURL + '">link &gt;&gt;</a></div></div>';
	widget.webxPane.innerHTML = html;
}

/**
 * Konzol.
 */
function TConsole(widget, content, editor) {
	var d = widget.webxPane;
	Sarissa.clearChildNodes(d);
	d.appendChild(webx.console);
}

/**
 * WebJegyzet
 *
 * A widget descriptor ''WebJegyzet'' nevű property-jében tárolódik az adat.
 */
function TWebJegyzet(widget, content, editor) {
	this.widget = widget;

	var d = widget.webxPane;
	var _this = this; // ezt a beágyazott funkciók fogják használni.
	Sarissa.clearChildNodes(d);

	// Editor
	var inpEdTitle = [ "input", { type: "text", "class": "txt", style: "width: 100%", maxLength: "60", element: null } ];
	var btnEdOK = [ "input", { type: "button", "class": "btn", value: "Elment", element: null, onclick: btnEdOkClick } ];
	//var btnEdCancel = [ "input", { type: "button", value: "Mégsem", element: null } ];
	var tdEdStyle = [ "td", { element: null, colSpan: "2" } ];

	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr",
				[ "td", "Cím:" ],
				[ "td", inpEdTitle ],
				[ "td", btnEdOK ]
			],
			[ "tr", [ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	this.Edit_btnEdOk = btnEdOK[1].element;
	//this.Edit_btnEdCancel = btnEdCancel[1].element;
	this.Edit_inpEdTitle = inpEdTitle[1].element;
	_this.Edit_inpEdTitle.value = _this.widget.webxWidget.title;

	function btnEdOkClick() {
		webx.setTitle(_this.widget, _this.Edit_inpEdTitle.value);
	}

	// content panel
	var content =
	[ "DIV",
		[ "DIV", { "class": "WebJegyzet", innerHTML: TWebJegyzet_escape(widget.webxWidget.WebJegyzet), element: null, onclick: StartEdit } ], // view
		[ "DIV", { align: "center", "class": "WebJegyzet_edit", element: null }, // editdiv
			[ "DIV",
				[ "TEXTAREA", { element: null, onchange: txtContentEditChange, onkeyup: txtContentEditChange, value: widget.webxWidget.WebJegyzet } ] // edit
			],
			[ "INPUT", { type: "button", value: "Elment", onclick: btnContentOkClick } ],
			[ "INPUT", { type: "button", value: "Mégsem", onclick: btnContentCancelClick } ]
		]
	];

	//DONE: editdiv reload utan rossz a merete (3 sor vagy mennyi, ahelyett, hogy content-nek megfelelo lenne)
	var e = webxJsonML(content);
	this.view = content[1][1].element;
	this.editdiv = content[2][1].element;
	this.editdiv.style.display = "none";
	this.edit = content[2][2][1][1].element;

	d.appendChild(this.view);
	d.appendChild(this.editdiv);

	function StartEdit() {
		_this.edit.style.height = ((_this.view.offsetHeight < 40 ? 40 : _this.view.offsetHeight) - 5) + "px"; // set editor height
		_this.view.style.display = "none";
		_this.editdiv.style.display = "";
		_this.edit.focus(0);
	}

	function txtContentEditChange() {
		with(_this.edit) {
			if(offsetHeight != scrollHeight) {
				style.height = scrollHeight + "px";
			}
		}
	}

	function btnContentOkClick() {
		var v = _this.edit.value;
		_this.widget.webxWidget.WebJegyzet = v;
		_this.view.innerHTML = TWebJegyzet_escape(v);
		_this.view.style.display = "";
		_this.editdiv.style.display = "none";
		webx.saveWidget(_this.widget, true);
	}

	function btnContentCancelClick() {
		_this.edit.value = _this.widget.webxWidget.WebJegyzet;
		_this.view.innerHTML = TWebJegyzet_escape(_this.edit.value);
		_this.view.style.display = "";
		_this.editdiv.style.display = "none";
		//webx.saveWidget(_this.widget, true); // XXX: nem kell really?
	}
}

function TWebJegyzet_escape(sHtml) {
	return Sarissa.escape(sHtml).replace(/\n/g, '<br/>') + '<br/>';
}

TWebJegyzet.prototype.editorVisible = function(vis) {
	if (vis) {
		this.Edit_inpEdTitle.value = this.widget.webxWidget.title;
	}
}

/**
 * Bookmarks
 */
/*
DONE: A "Cimkéim (tagek)" feliratú sorra kattintva tűnjön el a taglista és helyette a jobb oldali dropdown-ból lehessen kiválasztani a
szűrés feltételét. Újabb kattintás, vissza az egészet.
DONE: bug1: IE alatt meg nem mukodik a select-es, opera alatt picit bugzik: ha ugy valasztasz, hogy lenyitod a selectet, majd foleviszed valahova az egeret, majd lenyomod az egergombot, athuzod az egeret (lenyomott egergombbal!) egy masik itemre, es ott engeded fol az egergombot; akkor az olyan, mintha mi sem tortent volna -- ffox jol kezeli ezt is... -.-
DONE: valami masik property kell, talan megoldja
DONE: bug2: ha billentyuzettel valasztunk (fel-le gomb), az egyik bongeszo alatt sem csinal semmit
DONE: bug3: ffox + (?) lenyit, egergomb le az egyik felett, egeret lehuzni a listarol lefele (egergomb nyomvatartasa mellett), majd egergomb felenged -> utolso elem lesz kivalasztva, kozben semmi event nem erkezett
DONE: bug4: operanal ha select lista tartalmat frissitjuk js-bol, akkor a regi elemek ottmaradnak(?!) - csak nem tudom, miert javult meg, Currencynel meg mindig rossz
*/
function TBookmarks(widget, content, editor) {
	this.widget = widget;

	var _this = this; // ezt a beágyazott funkciók fogják használni.
	//var d = widget.webxPane;
	//Sarissa.clearChildNodes(d);

	// editor
	var tdEdStyle = [ "td", { element: null } ];
	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr", [ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	// content panel
	var inpCoTitle = [ "input", { "class": "txt", type: "text", element: null } ];
	var inpCoURL = [ "input", { "class": "txt", type: "text", element: null } ];
	var inpCoTags = [ "input", { "class": "txt", type: "text", element: null } ];
	var btnCoSaveBookmark = [ "input", { "class": "btn", type: "button", value: "Hozzáad", onclick: btnCoSaveBookmarkClick, xBookmarkId: -1, element: null } ];
	var btnCoCancelBookmark = [ "input", { "class": "btn", type: "button", value: "Mégsem", onclick: btnCoCancelBookmarkClick, element: null } ];
	var divInvalidURL = [ "div", { style: "display: none; color: red; font-weight: bold; padding: 2px 0px 0px 2px;", element: null }, "Kérlek írj be egy URL-t" ];
	var inpCoComment = [ "textarea", { style: "width: 100%;", element: null } ];
	var btnBookmarkOpener = [ "webx:button", { "webx:ref": "comOpenClose", element: null } ];
	this.Content_tagSelectorDiv = {};
	this.Content_tagSelectorSelect = {};
	this.Content_btntagSelector = {};
	this.Content_selectTags = {};

	var content =
		[ "div",
			[ "div", { "class": "Bookmarks_new", onclick: btnShowAddBookmark, element: null },
				btnBookmarkOpener,
				"Új könyvjelző hozzáadása"
			],
			[ "table", { "class": "wx_form", style: "display: none;", element: null },
				[ "tr", [ "td", { "class": "tit" }, "Cím" ], [ "td", inpCoTitle ] ],
				[ "tr", [ "td", { "class": "tit" }, "Link" ], [ "td", inpCoURL, divInvalidURL ] ],
				[ "tr", [ "td", { "class": "tit" }, "Megjegyzés" ], [ "td", inpCoComment ] ],
				[ "tr", [ "td", { "class": "tit" }, "Címkék" ], [ "td", inpCoTags, [ "div", { style: "color: #808080; padding: 2px 0px 3px 2px;" }, "Több cimke esetén vesszővel válaszd el őket" ] ] ],
				[ "tr", [ "td", { colSpan: 2, style: "text-align: center;" }, btnCoSaveBookmark, btnCoCancelBookmark ] ]
			],
			[ "div", { element: null },
				[ "div", { "class": "wx_form Bookmarks_tagshd" },
					[ "span", { style: "display: none;", element: this.Content_tagSelectorSelect },
						[ "select", { style: "display: block;", onchange: btnShowOnlyForTagStub, onkeyup: btnShowOnlyForTagStub, element: this.Content_selectTags }, [ "option", { style: "font-weight: bold;" }, "cimkézetlen" ], [ "option", { style: "font-weight: bold;" }, "összes" ] ]
					],
					[ "div", { style: "display: block;", onclick: btnTagStyleToSelect, element: this.Content_tagSelectorDiv },
						[ "webx:button", { "webx:ref": "comOpenClose", element: this.Content_btntagSelector } ],
						"Cimkéim (tagek)"
					]
				],
				[ "div", { element: null, "class": "Bookmarks_tags" } ],
				[ "div", { element: null } ]
/*				[ "div", [ "span", { style: "cursor: pointer", onclick: btnShowAddBookmark }, "Új könyvjelző" ] ] */
			]
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content));
//	Sarissa.moveChildNodes(webxJsonML(content), widget.webxPane);
	this.Content_btntagSelector.element.webxSelect(false);

	this.Content_tabAddBookmark = content[2][1].element;
	this.Content_btnBookmarkOpener = btnBookmarkOpener[1].element;
	this.Content_btnBookmarkOpener.webxSelect(true);
	this.Content_inpCoTitle = inpCoTitle[1].element;
	this.Content_inpCoURL = inpCoURL[1].element;
	this.Content_inpCoTags = inpCoTags[1].element;
	this.Content_inpCoComment = inpCoComment[1].element;
	this.Content_btnCoSaveBookmark = btnCoSaveBookmark[1].element;
	this.Content_btnCoCancelBookmark = btnCoCancelBookmark[1].element;
	this.Content_divInvalidURL = divInvalidURL[1].element;

	this.Content_tabBookmarkList = content[3][1].element;
	this.Content_divTags = content[3][3][1].element;
	this.Content_divBookmarks = content[3][4][1].element;
	this.Content_divTags.innerHTML = "&nbsp;";
	this.Content_divNewBookmarks = content[1][1].element;
//	this.Content_divBookmarks.innerHTML = "&nbsp;";
	this.showntag = "összes";
	this.selectTagsChanged = true;

	this.fulltaglist = [];
	// betoltes utan hajtodik vegre
	BookmarkShow();

	function btnTagStyleToSelect() {
		_this.Content_tagSelectorSelect.element.style.display = "";
		_this.Content_divTags.element.style.display = "none";
		_this.Content_btntagSelector.element.webxSelect(true);
		_this.Content_tagSelectorDiv.element.onclick = btnTagStyleToDiv;
		BookmarkShow();
	}

	function btnTagStyleToDiv() {
		_this.Content_tagSelectorSelect.element.style.display = "none";
		_this.Content_divTags.element.style.display = "";
		_this.Content_btntagSelector.element.webxSelect(false);
		_this.Content_tagSelectorDiv.element.onclick = btnTagStyleToSelect;
	}

	function btnShowAddBookmark() {
		_this.Content_btnCoSaveBookmark.xBookmarkId = -1;
		_this.Content_tabAddBookmark.style.display = "";
		_this.Content_tabBookmarkList.style.display = "none";
		_this.Content_btnBookmarkOpener.webxSelect(false);
		_this.Content_divNewBookmarks.onclick = btnCoCancelBookmarkClick;
	}

	function Clear_tabAddBookmark_Props() {
		_this.Content_inpCoTitle.value = "";
		_this.Content_inpCoURL.value = "";
		_this.Content_inpCoTags.value = "";
		_this.Content_divInvalidURL.style.display = "none";
	}

	function btnCoCancelBookmarkClick() {
		_this.Content_divNewBookmarks.onclick = btnShowAddBookmark;
		_this.Content_tabAddBookmark.style.display = "none";
		_this.Content_tabBookmarkList.style.display = "";
		_this.Content_btnBookmarkOpener.webxSelect(true);
		Clear_tabAddBookmark_Props();
	}

	function btnCoSaveBookmarkClick() {
		if (_this.Content_inpCoURL.value.trim() == "") {
			_this.Content_divInvalidURL.style.display = "";
		} else {
			_this.selectTagsChanged = true;
			_this.Content_divNewBookmarks.onclick = btnShowAddBookmark;
			BookmarkAdd(_this.Content_btnCoSaveBookmark.xBookmarkId, _this.Content_inpCoTitle.value.trim(), _this.Content_inpCoURL.value.trim(), _this.Content_inpCoComment.value.trim(), _this.Content_inpCoTags.value.trim());
			BookmarkShow();
			_this.Content_tabAddBookmark.style.display = "none";
			_this.Content_tabBookmarkList.style.display = "";
			_this.Content_btnBookmarkOpener.webxSelect(true);
			Clear_tabAddBookmark_Props();
		}
	}

	function CheckBookmarkTagsvsTaglist(taglist, vs) {
		if (vs == "összes") {
			return 1;
		}
		if (vs == "címkézetlen") {
			if (taglist.length == 0) {
				return 1;
			} else {
				return 0;
			}
		}
		if (taglist.indexOf(vs) != -1) {
			return 1;
		} else {
			return 0;
		}
	}

	function BookmarkShow() {
		var list = _this.widget.webxWidget.Bookmarks;
		var showntag = _this.showntag;
		// bookmark lista
		var divBookmarks = [ "table", { "class": "Bookmarks_table" } ];
		var tips = new Array();
		var shownitems = 0;
		for (var i = 0; i < list.length; i++) {
			if (CheckBookmarkTagsvsTaglist(list[i].taglist, showntag) != 0) {
				shownitems++;
				var divtmp = [ "div" ];
				for (var j = 0; j < list[i].taglist.length; j++) {
					divtmp[j * 2 + 1] = [ "span", { onclick: btnShowOnlyforTag, xTag: list[i].taglist[j] }, list[i].taglist[j] ];
					if (j != 0) {
						divtmp[j * 2] = " | ";
					}
				}

				var tip;
				if(list[i].comment && list[i].comment.trim() != "") {
					tip = { tip: list[i].comment };
					tips[tips.length] = tip;
				} else {
					tip = null;
				}

				divBookmarks[divBookmarks.length] =
					[ "tr", { "class": (divBookmarks.length % 2 == 0 ? "" : "Bookmarks_i1") },
						[ "td",
							[ "a", { href:list[i].url, target: "_blank", element: tip }, (list[i].title == "" ? list[i].url : list[i].title) ],
							divtmp
						],
						[ "td", { "class": "ctrl" },
							[ "webx:button", { "webx:ref": "comEdit", onclick: btnEditBookmark, xBookmarkId: i } ],
							" ",
							[ "webx:button", { "webx:ref": "comDelete", style: "padding-top: 2px;", onclick: btnDelBookmark, xBookmarkId: i } ]
						]
/*						[ "div",
							[ "table", { style: "width: 100%" },
								[ "tr",
									[ "td", { style: "width: 90%" }, [ "div", { style: "overflow: hidden; white-space: nowrap" }, [ "a", { href:list[i].url, target: "_blank"  }, (list[i].title == "" ? list[i].url : list[i].title) ] ] ],
									[ "td", { style: "width: 10%" },
										[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entryedit.png"), style: "cursor: pointer", onclick: btnEditBookmark, xBookmarkId: i } ],
										[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entrydelete.png"), style: "cursor: pointer", onclick: btnDelBookmark, xBookmarkId: i } ]
									]
								]
							]
						], */
					];
			}
		}
		if ((list.length > 0) && (shownitems == 0)) {
			_this.showntag = "összes";
			BookmarkShow();
			return(0);
		}
		var tb = webxJsonML(divBookmarks);
		_this.Content_divBookmarks.parentNode.replaceChild(tb, _this.Content_divBookmarks);
		_this.Content_divBookmarks = tb;

		if(tips.length > 0) {
			// Így kell tootipet csinázni (by győző)
			new TipManager(tips);
		}

/*		Sarissa.clearChildNodes(_this.Content_divBookmarks);
		_this.Content_divBookmarks.appendChild(webxJsonML(divBookmarks)); */

		// tag lista
		var divTags = [ "div" ];
		var selectTags = [ "select" ];
		//[ "select", { style: "display: block;", element: this.Content_selectTags }, [ "option", { style: "font-weight: bold;" }, "cimkézetlen" ], [ "option", { style: "font-weight: bold;" }, "összes" ], [ "option", "macilaci" ], [ "option", "lorem" ] ]
		var fulltaglist = [ "címkézetlen" ];
		var fulltagvals = [ 0 ];
		for (var i = 0; i < list.length; i++) {
			var tmpinnertaglist = list[i].taglist;
			if (tmpinnertaglist.length == 0) {
				fulltagvals[0]++;
			}
			for (var j = 0; j < tmpinnertaglist.length; j++) {
				var iof = fulltaglist.indexOf(tmpinnertaglist[j])
				if (iof != -1)	{
					fulltagvals[iof]++;
				} else {
					fulltagvals[fulltaglist.length] = 1;
					fulltaglist[fulltaglist.length] = tmpinnertaglist[j];
				}
			}
		}
		fulltagvals[fulltaglist.length] = list.length;
		fulltaglist[fulltaglist.length] = "összes";

		var tmpselectedIndex = fulltaglist.length;
		for (var i = 0; i < fulltaglist.length; i++) {
			divTags[divTags.length] = [ "span", { "class": (fulltaglist[i] == showntag ? "sel": ""), onclick: btnShowOnlyforTag, xTag: fulltaglist[i] },
				fulltaglist[i],
				[ "b", " (" + fulltagvals[i] + ")" ]
			];
			if (i < fulltaglist.length - 1) {
				divTags[divTags.length] = " | ";
			}
			selectTags[selectTags.length] = [ "option", { /*onclick: btnShowOnlyforTag, */xTag: fulltaglist[i] },
				fulltaglist[i],
				" (" + fulltagvals[i] + ")"
			];
			if (fulltaglist[i] == showntag) {
				tmpselectedIndex = i;
			}
		}
		Sarissa.moveChildNodes(webxJsonML(divTags), _this.Content_divTags);
		if (_this.selectTagsChanged) {
			Sarissa.moveChildNodes(webxJsonML(selectTags), _this.Content_selectTags.element);
			_this.selectTagsChanged = false;
		}
		wxlog.log('bookmarks show1: ' + _this.Content_selectTags.element.selectedIndex + ' ### ' + tmpselectedIndex);
		_this.Content_selectTags.element.selectedIndex = tmpselectedIndex;
/*		Sarissa.clearChildNodes(_this.Content_divTags);
		_this.Content_divTags.appendChild(webxJsonML(divTags)); */
		_this.fulltaglist = fulltaglist;
	}

	function BookmarkAdd(BookmarkId, title, url, comment, tags) {
		var list = _this.widget.webxWidget.Bookmarks;
		var taglist = tags.trim().replace(/\s+,/g, ',').replace(/,\s+/g, ',').replace(/,+/g, ',').replace(/^,+/, '').replace(/,+$/, '').trim().split(',');
		if ((taglist.length == 1) && (taglist[0] == '')) {
			taglist = [];
		}
		for (var i = 0; i < taglist.length; i++ ) {
			taglist[i] = taglist[i].trim();
		}
		if (BookmarkId == -1 ) {
			var ll = list.length;
		} else {
			ll = BookmarkId;
		}
		list[ll] = { "title":title, "url":url, "taglist":taglist, "comment":comment };
		webx.saveWidget(_this.widget, true);
	}

	function btnEditBookmark() {
		var BookmarkId = this.xBookmarkId;
		var list = _this.widget.webxWidget.Bookmarks;
		_this.Content_inpCoTitle.value = list[BookmarkId].title;
		_this.Content_inpCoURL.value = list[BookmarkId].url;
		_this.Content_inpCoComment.value = list[BookmarkId].comment ? list[BookmarkId].comment : "";
		_this.Content_inpCoTags.value = list[BookmarkId].taglist.toString();
		_this.Content_divInvalidURL.style.display = "none";
		_this.Content_btnCoSaveBookmark.xBookmarkId = BookmarkId;
		_this.Content_tabAddBookmark.style.display = "";
		_this.Content_tabBookmarkList.style.display = "none";
	}

	function btnDelBookmark() {
		var BookmarkId = this.xBookmarkId;
		var list = _this.widget.webxWidget.Bookmarks;
		if (!window.confirm("Biztos hogy törölni akarod?")) {
			return;
		}
		list.splice(BookmarkId, 1);
		webx.saveWidget(_this.widget, true);
		_this.selectTagsChanged = true;
		BookmarkShow();
	}

	/*function SO(obj) {
		var r = '';
		for(var i in obj) {
			var s = '' + obj[i];
			s = s.substring(0, 30)
			r = r + i + ':' + s + ',';
		}
		return r;
	}*/

	function btnShowOnlyforTag() {
		var Tag = this.xTag;
		_this.showntag = Tag;
		BookmarkShow();
	}

	function btnShowOnlyForTagStub() {
		var id = _this.Content_selectTags.element.selectedIndex;
		_this.showntag = _this.fulltaglist[id];
		BookmarkShow();
	}
}

/**
 * Calculator
 */
function TCalculator(widget, content, editor) {
	this.widget = widget;

	var _this = this; // beágyazott funkciók fogják használni

	// editor
	var tdEdStyle = [ "td", { element: null } ];
	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr",	[ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	// content
	var inpCoValue = [ "input", { "class": "txt", type: "text", "style":"width: 100%;", value: "1+1", element: null, onkeyup: Calculate, onproperychange: Calculate } ];
	var outCoValue = [ "input", { "class": "txt", type: "text", "style":"width: 100%;", "readOnly": true, value: "", element: null } ];

	var content =
		[ "div",
			[ "table", { "class": "wx_form", "style":"width: 100%;" },
				[ "tr", [ "td", { "colSpan":"2" }, inpCoValue ] ],
				[ "tr", [ "td", { "style":"width: 30%" }, "Eredmény:" ], [ "td", { "style":"width: 70%" }, outCoValue ] ]
//				[ "tr", [ "td", inpCoValue ] ],
//				[ "tr", [ "td", "Eredmény:", outCoValue ] ]
			]
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content));

	this.Content_inpCoValue = inpCoValue[1].element;
	this.Content_outCoValue = outCoValue[1].element;

	Calculate();

	function Calculate() {
		try {
			if (/[^0-9 +*\/^=|\\&%><()xa-fA-F.-]/.test(_this.Content_inpCoValue.value)) {
				_this.Content_outCoValue.value = "hibás képlet";
			} else {
				_this.Content_outCoValue.value = eval(_this.Content_inpCoValue.value);
			}
		} catch(e) {
			_this.Content_outCoValue.value = "hibás képlet";
		}
	}
}

/**
 * Currency
 */
//TODO: idonkent ujrakerni a penznemek ertekeit
//TODO: bug: operaban ha select lista tartalmat frissitjuk js-bol, akkor van par ures sor a vegen
function TCurrency(widget, content, editor) {
	this.widget = widget;

	var _this = this; // beágyazott funkciók fogják használni

	// editor
	var tdEdStyle = [ "td", { element: null } ];
	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr",	[ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	// content
	var inpCoValue = [ "input", { "class": "txt", type: "text", value: "1", element: null, onkeyup: CalculateCurrency, onproperychange: CalculateCurrency } ];
	var inpCoFromCurrency= [ "select", { element: null, onchange: CalculateCurrency, onkeyup: CalculateCurrency } ];
	var inpCoToCurrency= [ "select", { element: null, onchange: CalculateCurrency, onkeyup: CalculateCurrency } ];
	var outCoValue = [ "input", { "class": "txt", type: "text", "readOnly": true, value: "", element: null } ];
	var divResult = [ "div", { type: "div", "style": "display: none; color: red;", element: null }, "Hiba a szerverrel történő kommunikáció közben" ];

	var content =
		[ "div",
			divResult,
			[ "table", { "class": "wx_form" },
				[ "tr", [ "td", "Összeg:" ], [ "td", inpCoValue ] ],
				[ "tr", [ "td", "Miről:" ], [ "td", inpCoFromCurrency ] ],
				[ "tr", [ "td", "Mire:" ], [ "td", inpCoToCurrency ] ],
				[ "tr", [ "td", "Eredmény:" ], [ "td", outCoValue ] ]
			]
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content));

	this.Content_inpCoValue = inpCoValue[1].element;
	this.Content_inpCoFromCurrency = inpCoFromCurrency[1].element;
	this.Content_inpCoToCurrency = inpCoToCurrency[1].element;
	this.Content_outCoValue = outCoValue[1].element;
	this.Content_divResult = divResult[1].element;

	this.currencylist = [ 1 ];
	Init();
	CalculateCurrency();

	function CalculateCurrency() {
		if ((_this.Content_inpCoFromCurrency.selectedIndex < 0) || (_this.Content_inpCoToCurrency.selectedIndex < 0)) {
			_this.Content_outCoValue.value = _this.Content_inpCoValue.value;
		} else {
			_this.Content_outCoValue.value =
				_this.Content_inpCoValue.value *
				(_this.currencylist[_this.Content_inpCoFromCurrency.selectedIndex].value /
				_this.currencylist[_this.Content_inpCoToCurrency.selectedIndex].value);
		}
	}

	function MakeCurrencyLists() {
		wxlog.dir(_this.currencylist);
		wxlog.dir(_this.newcurrencylist);
		wxlog.log("currency1: " + _this.currencylist.length + "   " + _this.newcurrencylist.length);
		if (_this.newcurrencylist.length != 0) {
			_this.currencylist = _this.newcurrencylist;
		}
		var selectCurFrom = [ "select" ];
		var selectCurTo = [ "select" ];
		for(var i = 0; i < _this.currencylist.length; i++) {
		//for(var i = 0; i < 1; i++) {
			selectCurFrom[selectCurFrom.length] = [ "option", { onclick: CalculateCurrency, xTag: i }, _this.currencylist[i].currency];
			selectCurTo[selectCurTo.length] = [ "option", { onclick: CalculateCurrency, xTag: i }, _this.currencylist[i].currency];
		}
		// hopefully, the number and the order of the currencies will not change(!)
		wxlog.log("currency2: " + selectCurFrom.length + "   " + selectCurTo.length);
		siFrom = _this.Content_inpCoFromCurrency.element.selectedIndex;
		siTo = _this.Content_inpCoToCurrency.element.selectedIndex;
		siFrom = (siFrom < 0 ? 0 : siFrom);
		siTo = (siTo < 0 ? 0 : siTo);
		siFrom = (siFrom >= _this.currencylist.length ? _this.currencylist.length - 1 : siFrom);
		siTo = (siTo >= _this.currencylist.length ? _this.currencylist.length - 1: siTo);
		wxlog.log("currency3: " + siFrom + "   " + siTo);
		Sarissa.moveChildNodes(webxJsonML(selectCurFrom), _this.Content_inpCoFromCurrency);
		Sarissa.moveChildNodes(webxJsonML(selectCurTo), _this.Content_inpCoToCurrency);
		_this.Content_inpCoFromCurrency.element.selectedIndex = siFrom;
		_this.Content_inpCoToCurrency.element.selectedIndex = siTo;
		CalculateCurrency();
	}

	function Init() {
		try {
			_this.Content_divResult.style.display = "none";
			var sr = new XMLHttpRequest();
			wxlog.log("TCurrency POSTURL: " + webx.urlConsolidator(_this.widget.webxWidget.POSTURL));
			sr.open("POST", webx.urlConsolidator(_this.widget.webxWidget.POSTURL), true);
			sr.setRequestHeader("Content-type", "application/json;charset=utf-8");
			sr.onreadystatechange = function() {
				if (sr.readyState == 4) {
					var responseText = sr.responseText;
					if (sr.status == 0) { // forced response - local testing
						responseText = '[{currency:"HUF",value:"1.0"},{currency:"EUR",value:"248.0328212871"},{currency:"JPY",value:"1.5763254242"},{currency:"GBP",value:"365.4095728239"},{currency:"USD",value:"185.8791663710"}]'; // @ 2007/03/27 [19:21:05] Tuesday
					}
					if (sr.status == 200 || sr.status == 0) { // 200: OK; 0: local
						wxlog.log("TCurrency: readyState == 4 and status == 200");
						eval("_this.newcurrencylist=" + responseText);
						MakeCurrencyLists();
					} else {
						_this.Content_divResult.style.display = "";
						wxlog.log("TCurrency: error: sr.status = " + sr.status);
						wxlog.dir(responseText);
					}
				}
			}
			sr.send();
		} catch(e) {
			wxlog.dir(e);
			wxlog.log("TCurrency: error: " + e);
			_this.Content_divResult.style.display = "";
		}
	}

}

/**
 * QuickLinkBox
 */

function TQuickLinkBox(widget, content, editor) {
	this.widget = widget;

	var _this = this; // ezt a beágyazott funkciók fogják használni.

	// Editor
	var inpEdTitle = [ "input", { type: "text", "class": "txt", style: "width: 100%", maxLength: "60", element: null } ];
	var btnEdOK = [ "input", { type: "button", "class": "btn", value: "Elment", element: null, onclick: btnEdOkClick } ];
	var tdEdStyle = [ "td", { element: null, colSpan: "2" } ];

	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr",
				[ "td", "Cím:" ],
				[ "td", inpEdTitle ],
				[ "td", btnEdOK ]
			],
			[ "tr",	[ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	this.Edit_btnEdOk = btnEdOK[1].element;
	this.Edit_inpEdTitle = inpEdTitle[1].element;
	_this.Edit_inpEdTitle.value = _this.widget.webxWidget.title;

	function btnEdOkClick() {
		webx.setTitle(_this.widget, _this.Edit_inpEdTitle.value);
	}

	// content panel
	var content1 =
		[ "div", { element: null } ];
	var content2 =
		[ "a", { "class": "QuickLinkBox_new", onclick: btnAddURL },
			[ "webx:button", { "webx:ref": "comRedcross" } ],
			"Új link felvétele"
		];
//		[ "div", [ "span", { style: "cursor: pointer", onclick: btnAddURL }, "Új link felvétele" ] ]

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content1));
	widget.webxPane.appendChild(webxJsonML(content2));

	this.Content_divQuickLinkBox = content1[1].element;
	this.QuickLinkItems = [];
	this.Editing = -1;
	this.Content_divEdit = [];

	// betoltes utan hajtodik vegre
	QuickLinkBoxShow();

	function btnAddURL() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.QuickLinkBox;
		var tmp = list.length;
		list[tmp] = { "title":"", "URL":"", "hilite":"0" };
		QuickLinkBoxShow();
		_this.Editing = tmp;
		EditURL(tmp);
		webx.saveWidget(_this.widget, true);
	}

	function btnEditOK() {
		EditDone();
		webx.saveWidget(_this.widget, true);
	}

	function EditDone() {
		Id = _this.Editing;
		if (Id < 0) {
			return;
		}
		var list = _this.widget.webxWidget.QuickLinkBox;
		list[Id].title = _this.Content_editInpTitle.value;
		list[Id].URL = _this.Content_editInpURL.value;
		list[Id].hilite = (_this.Content_editInpHiLite.checked == true ? 1 : 0);
		_this.Editing = -1;
		QuickLinkBoxShow();
	}

	function btnEditURL() {
		EditDone();
		var Id = this.xId;
		EditURL(Id);
	}

	function EditURL(Id) {
		var list = _this.widget.webxWidget.QuickLinkBox;
		_this.Editing = Id;
		var divEdit = _this.QuickLinkItems[Id][1].element;
		var editInpTitle = [ "input", { element: null, "class": "txt", type: "text", value: list[Id].title } ];
		var editInpURL = [ "input", { element: null, "class": "txt", type: "text", value: list[Id].URL } ];
		var editInpHiLite = [ "input", { element: null, type: "checkbox", checked: (list[Id].hilite == 1 ? true : false) } ];
		//FIXME: design-ot
		var jsonEdit =
			[ "div", { element: null },
				[ "table", { style: "width: 100%", "class": "wx_form" },
					[ "tr",
						[ "td", { style: "width: 10%" }, "Név" ],
						[ "td", { style: "width: 70%" }, editInpTitle ],
						[ "td", { style: "width: 20%; vertical-align: middle; white-space: nowrap;" },
							[ "webx:button", { "webx:ref": "comDelete", style: "float: right; padding: 2px 0px 2px 2px;", onclick: btnDelURL, xId: Id } ],
							[ "webx:button", { "webx:ref": "comEdit", style: "float: right; padding: 2px 2px 2px 8px;", onclick: btnEditOK, xId: Id } ],
							[ "div", { style: "float: left" }, editInpHiLite ],
							"Kiemelt"
/*							[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entryedit.png"), style: "cursor: pointer", onclick: btnEditOK, xId: Id } ],
							[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entrydelete.png"), style: "cursor: pointer", onclick: btnDelURL, xId: Id } ] */
						]
					],
					[ "tr",
						[ "td", { style: "width: 10%" }, "URL" ],
						[ "td", { style: "width: 70%" }, editInpURL ],
						[ "td", { style: "width: 20%" }, [ "input", { type: "button", "class": "btn", value: "Módosít", onclick: btnEditOK, xId: Id } ] ]
					]
				]
			];
		Sarissa.clearChildNodes(divEdit);
		divEdit.appendChild(webxJsonML(jsonEdit));
		_this.Content_editInpTitle = editInpTitle[1].element;
		_this.Content_editInpURL = editInpURL[1].element;
		_this.Content_editInpHiLite = editInpHiLite[1].element;
		_this.Content_editInpTitle.focus(0);
	}

	function btnDelURL() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.QuickLinkBox;
		if (!window.confirm("Biztos hogy törölni akarod?")) {
			return;
		}
		list.splice(Id, 1);
		QuickLinkBoxShow();
		webx.saveWidget(_this.widget, true);
	}

	function xchg(list, Id1, Id2) {
		tmp = list[Id1];
		list[Id1] = list[Id2];
		list[Id2] = tmp;
	}

	function btnGoUp() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.QuickLinkBox;
		if (Id <= 0) {
			return;
		}
		xchg(list, Id, Id - 1);
		QuickLinkBoxShow();
	}

	function btnGoDown() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.QuickLinkBox;
		if (Id >= list.length - 1) {
			return;
		}
		xchg(list, Id, Id + 1);
		QuickLinkBoxShow();
	}

	function QuickLinkBoxShow() {
		var list = _this.widget.webxWidget.QuickLinkBox;
		var tmp = [];
		_this.QuickLinkItems = [];
		Sarissa.clearChildNodes(_this.Content_divQuickLinkBox);
		for (var i = 0; i < list.length; i++) {
			_this.QuickLinkItems[i] =
				[ "div", { element: null },
					[ "table", { "class": "QuickLinkBox" },
						[ "tr",
							[ "td", { "class": "col1" },
								[ "a", { "class": (list[i].hilite == 1 ? "hil" : ""), href:list[i].URL, target: "_blank" }, (list[i].title == "" ? list[i].URL : list[i].title) ]
							],
							[ "td", { "class": "col2" },
								[ "webx:button", { "webx:ref": "comGoUp", onclick: btnGoUp, xId: i } ],
								[ "webx:button", { "webx:ref": "comGoDown", onclick: btnGoDown, xId: i } ],
								[ "webx:button", { "webx:ref": "comEdit", onclick: btnEditURL, xId: i } ],
								[ "webx:button", { "webx:ref": "comDelete", onclick: btnDelURL, xId: i } ]
/*								[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entryup.png"), style: "cursor: pointer", onclick: btnGoUp, xId: i } ],
								[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entrydown.png"), style: "cursor: pointer", onclick: btnGoDown, xId: i } ],
								[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entryedit.png"), style: "cursor: pointer", onclick: btnEditURL, xId: i } ],
								[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entrydelete.png"), style: "cursor: pointer", onclick: btnDelURL, xId: i } ] */
							]
						]
					]
				];
		_this.Content_divQuickLinkBox.appendChild(webxJsonML(_this.QuickLinkItems[i]));
		}

		if (list.length == 0) {
			_this.Content_divQuickLinkBox.innerHTML = "&nbsp;";
		}
	}
}

TQuickLinkBox.prototype.editorVisible = function(vis) {
	if (vis) {
		this.Edit_inpEdTitle.value = this.widget.webxWidget.title;
	}
}

/**
 * SimpleToDoList
 */

function TSimpleToDoList(widget, content, editor) {
	this.widget = widget;

	var _this = this; // ezt a beágyazott funkciók fogják használni.

	// editor
	var inpEdTitle = [ "input", { type: "text", "class": "txt", style: "width: 100%", maxLength: "60", element: null } ];
	var btnEdOK = [ "input", { type: "button", "class": "btn", value: "Elment", element: null, onclick: btnEdOkClick } ];
	var tdEdStyle = [ "td", { element: null, colSpan: "2" } ];

	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr",
				[ "td", "Cím:" ],
				[ "td", inpEdTitle ],
				[ "td", btnEdOK ]
			],
			[ "tr", [ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	this.Edit_btnEdOk = btnEdOK[1].element;
	this.Edit_inpEdTitle = inpEdTitle[1].element;
	_this.Edit_inpEdTitle.value = _this.widget.webxWidget.title;

	function btnEdOkClick() {
		webx.setTitle(_this.widget, _this.Edit_inpEdTitle.value);
	}

	// content panel
	var content1 =
		[ "form", { element: null, onsubmit: function() { btnEditOK(); return false; } } ];
	var content2 =
		[ "a", { "class": "SimpleToDo_new", onclick: btnAddToDo },
			[ "webx:button", { "webx:ref": "comRedcross" } ],
			"Új Teendő felvétele"
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content1));
	widget.webxPane.appendChild(webxJsonML(content2));

	this.Content_divSimpleToDoList = content1[1].element;
	this.ToDoItems = [];
	this.Editing = -1;
	this.Content_divEdit = [];

	// betoltes utan hajtodik vegre
	SimpleToDoListShow();

	function btnAddToDo() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.ToDoList;
		var tmp = list.length;
		list[tmp] = { "item":"", "done":"0" };
		//list[tmp].done = 0;
		SimpleToDoListShow();
		_this.Editing = tmp;
		EditToDo(tmp);
		webx.saveWidget(_this.widget, true);
	}

	function btnEditOK() {
		EditDone();
		webx.saveWidget(_this.widget, true);
	}

	function EditDone() {
		Id = _this.Editing;
		if (Id < 0) {
			return;
		}
		var list = _this.widget.webxWidget.ToDoList;
		list[Id].item = _this.Content_divEdit.value;
		_this.Editing = -1;
		SimpleToDoListShow();
	}

	function btnChangeDone() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.ToDoList;
		list[Id].done = 1 - list[Id].done;
		SimpleToDoListShow();
		webx.saveWidget(_this.widget, true);
	}

	function btnEditToDo() {
		EditDone();
		var Id = this.xId;
		EditToDo(Id);
	}

	function EditToDo(Id) {
		var list = _this.widget.webxWidget.ToDoList;
		_this.Editing = Id;
		var divEdit = _this.ToDoItems[Id][1].element;
		var jsonEdit =
			[
				[ "input", { element: null, "class": "txt", style: "float: left;", type: "text", value: list[Id].item } ],
				[ "div", { onclick: btnEditOK, xId: Id }, "OK" ]
			]
		Sarissa.clearChildNodes(divEdit);
		//divEdit.type = "text";
		divEdit.appendChild(webxJsonML(jsonEdit[0]));
		divEdit.appendChild(webxJsonML(jsonEdit[1]));
		_this.Content_divEdit = jsonEdit[0][1].element;
		_this.Content_divEdit.focus(0);
	}

	function btnDelToDo() {
		EditDone();
		var Id = this.xId;
		var list = _this.widget.webxWidget.ToDoList;
		if (!window.confirm("Biztos hogy törölni akarod?")) {
			return;
		}
		list.splice(Id, 1);
		SimpleToDoListShow();
		webx.saveWidget(_this.widget, true);
	}

	function SimpleToDoListShow() {
		var list = _this.widget.webxWidget.ToDoList;
		var tmp = [ "table", { "class": "wx_form SimpleToDo" } ];
		//var divSimpleToDoList = [ "div" ];
		_this.ToDoItems = [];
		Sarissa.clearChildNodes(_this.Content_divSimpleToDoList);
		for (var i = 0; i < list.length; i++) {
			//_this.ToDoItems[i] = [ "div", { element: null }, [ "span", { style: (list[i].done == 1 ? "text-decoration: line-through" : "") }, list[i].item ] ];
			_this.ToDoItems[i] = 
				[ "td", { "class": "col2", element: null },
					[ "span", { onclick: btnEditToDo, xId: i, "class": (list[i].done == 1 ? "todox" : "todo") }, list[i].item ]
				];

			tmp[tmp.length] =
				[ "tr",
					[ "td", { "class": "col1" }, [ "input", { onclick: btnChangeDone, type: "checkbox", xId: i, checked: (list[i].done == 1 ? true : false) } ] ],
					_this.ToDoItems[i],
					[ "td", { "class": "col3" },
						[ "webx:button", { "webx:ref": "comEdit", onclick: btnEditToDo, xId: i } ],
						[ "webx:button", { "webx:ref": "comDelete", onclick: btnDelToDo, xId: i } ]
					]
				];

/*			_this.ToDoItems[i] = [ "span", { element: null, onclick: btnEditToDo, xId: i, style: "cursor: pointer;" + (list[i].done == 1 ? "text-decoration: line-through" : "") }, list[i].item ];
			tmp[i] =
				[ "div",
					[ "table", { style: "width: 100%" },
						[ "tr",
							[ "td", { style: "width: 90%" }, [ "div", { style: "overflow: hidden; white-space: nowrap;" }, [ "input", { onclick: btnChangeDone, type: "checkbox", xId: i, checked: (list[i].done == 1 ? true : false) } ], _this.ToDoItems[i] ] ],
							[ "td", { style: "width: 10%" },
								[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entryedit.png"), style: "cursor: pointer", onclick: btnEditToDo, xId: i } ],
								[ "img", { "src": webx.urlConsolidator("%img%/webx/quicklink-entrydelete.png"), style: "cursor: pointer", onclick: btnDelToDo, xId: i } ]
							]
						]
					]
				];
		_this.Content_divSimpleToDoList.appendChild(webxJsonML(tmp[i]));
*/
		}
		//var divSimpleToDoList = [ "div", _ToDoItems ];

		if (list.length == 0) {
			_this.Content_divSimpleToDoList.innerHTML = "&nbsp;";
		} else {
			Sarissa.clearChildNodes(_this.Content_divSimpleToDoList);
			_this.Content_divSimpleToDoList.appendChild(webxJsonML(tmp));
		}
	}
}

TSimpleToDoList.prototype.editorVisible = function(vis) {
	if (vis) {
		this.Edit_inpEdTitle.value = this.widget.webxWidget.title;
	}
}

/**
 * TellAFriend
 */
function TTellAFriend(widget, content, editor) {
	this.widget = widget;

	var d = widget.webxPane;
	var _this = this; // ezt a beágyazott funkciók fogják használni.
	Sarissa.clearChildNodes(d);

	var inpCoYourName = [ "input", { "class": "txt", style: "width: 95%", type: "text", element: null } ];
	var inpCoToName = [ "input", { "class": "txt", style: "width: 95%", type: "text", element: null } ];
	var txtCoMessage = [ "textarea", { "class": "TellAFriend_Message", element: null, rows: 10 } ];
	// TODO: readonly-t nem veszi figyelembe! es anelkul ez egy spambox (bar ha post-ban atmegy a szoveg, ugyis az lesz)
	var btnCoOK = [ "input", { "class": "btn", type: "button", value: "Elküld", element: null, onclick: TTellAFriend_btnCoOKClick } ];
	//var btnCoCancel = [ "input", { type: "button", value: "Mégsem", element: null } ];
	var divResult = [ "div", { type: "div", element: null } ];

	var content =
		[ "table", { "class": "wx_form" },
			[ "tr", [ "td", "Ajánld barátodnak is a C6-ot!" ] ],
			[ "tr", [ "td", divResult ] ],
			[ "tr", [ "td", "A te neved:" ] ],
			[ "tr", [ "td", inpCoYourName ] ],
			[ "tr", [ "td", "Az értesíteni kívánt személy e-mail címe (pontosvesszővel elválasztva több címet is megadhatsz):" ] ],
			[ "tr", [ "td", inpCoToName ] ],
			[ "tr", [ "td", "Az üzeneted szövege:" ] ],
			[ "tr",	[ "td", txtCoMessage ] ],
			[ "tr", [ "td", { "style": "text-align: center;" }, btnCoOK ] ]
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content));

	this.Content_inpCoYourName = inpCoYourName[1].element;
	this.Content_inpCoToName = inpCoToName[1].element;
	this.Content_txtCoMessage = txtCoMessage[1].element;
	this.Content_btnCoOK = btnCoOK[1].element;
	//this.Content_btnCoCancel = btnCoCancel[1].element;
	this.Content_divResult = divResult[1].element;

	this.Content_txtCoMessage.value = "Szia!\nTaláltam egy jó oldalt, nézd meg te is, szerintem érdemes!\nwww.webextreme.hu\nEzen az oldalon személyre szabhatod a nyitólapodat! RSS olvasókkal nem maradsz le a legfrissebb hírekről, ezenkívül további hasznos folyamatosan bővülő alkalmazásokkal találkozhatsz, mint pl. jegyzettömb, irányítószám kereső stb. Ha van kedved nézd meg te is! És ez az oldal csak egy része az egésznek! A www.c6.hu oldalon online rádió, érdekes cikkek, és chat is vár!";
	//this.Content_txtCoMessage.rows = 10;

	//this.Content_btnCoOK.onclick = TTellAFriend_btnCoOKClick;
	//this.Content_btnCoCancel.onclick = function() { }

	// TODO: A szükséges mezők kitöltése után a az elküld gombra kattintva a rendszerünk küld egy levelet a megadott címre, az ablakban pedig megjelenik, hogy "A leveledet elküldtük! Írj be új címet, ha másnak is szeretnél szólni!"
}

function TTellAFriend_btnCoOKClick() {
	var _this = webx.searchWidget(this).webxManager;

	try {
		TTellAFriend_makedivResult(_this, ["div", "Küldöm..."]);
		var sr = new XMLHttpRequest();
		sr.open("POST", webx.urlConsolidator(_this.widget.webxWidget.POSTURL), true);
		sr.setRequestHeader("Content-type", "application/json;charset=utf-8");
		sr.onreadystatechange = function() { 
			if (sr.readyState == 4) {
				if(sr.status == 200 || sr.status == 0 /* local */) {
					wxlog.log("TellAFriend: readyState == 4 and status == 200");
					TTellAFriend_FillResults(_this, sr.responseText);
				} else {
					TTellAFriend_makedivResult(_this, ["div", { style: "color: red;" }, "Hiba a szerverrel történő kommunikáció közben"]);
				}
			}
		}

		var d = {
			yourname: _this.Content_inpCoYourName.value,
			toname: _this.Content_inpCoToName.value,
			message: _this.Content_txtCoMessage.value
		};
		var post = d.toJSONString();
		wxlog.log("TellAFriend: send post: " + post);
		sr.send(post);
	} catch(e) {
		wxlog.dir(e);
		wxlog.log("TellAFriend: send error: " + e);
		TTellAFriend_makedivResult(_this, ["div", { style: "color: red;" }, "Hiba a szerverrel történő kommunikáció közben"]);
	}
}

function TTellAFriend_FillResults(_this, Resultset) {
	// TODO:Resultset -> content
	var content =
		[ "div", "Üzeneted elküldtük" ];

	TTellAFriend_makedivResult(_this, content);
}

function TTellAFriend_makedivResult(_this, content) {
	var dR = _this.Content_divResult;
	Sarissa.clearChildNodes(dR);
	dR.appendChild(webxJsonML(content));
}

function TTellAFriend_escape(sHtml) {
	return Sarissa.escape(sHtml).replace(/\n/g, '<br/>');
}

/**
 * VATCalc
 */
function TVATCalc(widget, content, editor) {
	this.widget = widget;

	var _this = this; // beágyazott funkciók fogják használni

	// editor
	var tdEdStyle = [ "td", { element: null } ];
	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr",	[ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	// content
	var inpCoValue = [ "input", { "class": "txt", type: "text", value: "1", element: null, onkeyup: CalculateVAT, onproperychange: CalculateVAT } ];
	var inpCoVAT= [ "input", { "class": "txt", type: "text", value: "20", element: null, onkeyup: CalculateVAT, onproperychange: CalculateVAT } ];
	var outCoPlus = [ "input", { "class": "txt", type: "text", "readOnly": true, value: "", element: null } ];
	var outCoMinus = [ "input", { "class": "txt", type: "text", "readOnly": true, value: "", element: null } ];

	var content =
		[ "div",
			[ "table", { "class": "wx_form" },
				[ "tr", [ "td", "Összeg:" ], [ "td", inpCoValue ] ],
				[ "tr", [ "td", "ÁFA %:" ], [ "td", inpCoVAT ] ],
				[ "tr", [ "td", outCoPlus ], [ "td", outCoMinus ] ]
			]
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content));

	this.Content_inpCoValue = inpCoValue[1].element;
	this.Content_inpCoVAT = inpCoVAT[1].element;
	this.Content_outCoPlus = outCoPlus[1].element;
	this.Content_outCoMinus = outCoMinus[1].element;

	CalculateVAT();

	function CalculateVAT() {
		try {
			_this.Content_outCoPlus.value = Math.round(_this.Content_inpCoValue.value * (100 + new Number(_this.Content_inpCoVAT.value))) / 100;
			_this.Content_outCoMinus.value = Math.round(_this.Content_inpCoValue.value / (1 + (new Number(_this.Content_inpCoVAT.value) / 100)) * 100) / 100;
		} catch(e) {
			_this.Content_outCoPlus.value = "?";
			_this.Content_outCoMinus.value = "?";
		}
	}
}

/**
 * WebSearch
 */
function TWebSearch(widget, content, editor) {
	this.widget = widget;

	var _this = this;

	// editor
	var tdEdStyle = [ "td", { element: null } ];
	var editor =
		[ "table", { "class": "wx_edit" },
			[ "tr", [ "td", "Stílus:" ], tdEdStyle ]
		];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	// content panel
	this.Engines =
		[
			[ "Google", "http://www.google.com/search?hl=en&q=$QUERYSTRING$&btnG=Google+Search" ],
			[ "Yahoo", "http://search.yahoo.com/search?p=$QUERYSTRING$&u=http%3A%2F%2Fsearch.yahoo.com%2Fsearch%3Ffr%3Dyfp-t%26p%3D&fr=yfp&toggle=1&cop=mss&ei=UTF-8" ],
			[ "Wikipedia", "http://en.wikipedia.org/wiki/Special:Search?search=$QUERYSTRING$&go=Go" ]
		]
	this.content1 =
	[ "div",
		[ "table",
			[ "tr" ]
		]
	];
	var spanEngineName = [ "span", { element: null }, this.Engines[0][0] ];
	var inpSearch = [ "input", { "class": "txt", type: "text", element: null } ];
	var btnSearch = [ "input", { "class": "btn", type: "button", value: "Search", onclick: btnDoSearch, element: null } ];
	var content2 =
	[ "div",
		[ "table",
			[ "tr",
				[ "td", spanEngineName ],
				[ "td", inpSearch ],
				[ "td", btnSearch ]
			]
		]
	];

	Sarissa.clearChildNodes(widget.webxPane);
	this.EngineInfo = [];
	var tmp;
	for (var i = 0; i < this.Engines.length; i++) {
		tmp = {};
		this.EngineInfo[i] = tmp;
		this.content1[1][1][i+1] = [ "td", { element: tmp, style: "cursor: pointer", onclick: ChangeEngine, xId: i }, this.Engines[i][0] ];
	}
	widget.webxPane.appendChild(webxJsonML(this.content1));
	widget.webxPane.appendChild(webxJsonML(content2));

	this.Content_spanEngineName = spanEngineName[1].element;
	this.Content_inpSearch = inpSearch[1].element;
	this.Content_btnSearch = btnSearch[1].element;
	this.CurrentEngine = 0;
	//var xId = 0;
	//var Id = 0;
	//ChangeEngine(); // es ez miert nem jo? ha igy hivom, mi a this-e a funkcionak? hogy tudok atadni egy xId-t inicializalasra neki?
	_this.EngineInfo[this.CurrentEngine].element.style.backgroundColor = "red"; // TODO

	function btnDoSearch() {
		var url = _this.Engines[_this.CurrentEngine][1];
		url = url.replace('$QUERYSTRING$', encodeURIComponent(_this.Content_inpSearch.value));
		wxlog.log('search url: ' + url);
		window.open(url);
	}

	function ChangeEngine() {
		var Id = this.xId;
		wxlog.log('ChangeEngine: ' + Id);
		_this.EngineInfo[_this.CurrentEngine].element.style.backgroundColor = "transparent";
		_this.EngineInfo[Id].element.style.backgroundColor = "red";
		_this.Content_spanEngineName.innerHTML = _this.Engines[Id][0]; //hack
		_this.CurrentEngine = Id;
	}

}

/**
 * huZIP
 */
function ThuZIP(widget, content, editor) {
	this.widget = widget;

	var _this = this; // ezt a beágyazott funkciók fogják használni.

	// editor
	var tdEdStyle = [ "td", { element: null } ];
	var editor =
	[ "table", { "class": "wx_edit" },
		[ "tr",	[ "td", "Stílus:" ], tdEdStyle ]
	];

	Sarissa.clearChildNodes(widget.webxEditor);
	widget.webxEditor.appendChild(webxJsonML(editor));
	webxCreateLookEditor(tdEdStyle[1].element);

	// content
	var inpCoCity = [ "input", { "class": "txt", type: "text", element: null } ];
	var inpCoStreet= [ "input", { "class": "txt", type: "text", element: null } ];
	var btnCoSearch = [ "input", { "class": "btn", type: "button", value: "Keresés", element: null, onclick: btnCoSearchClick } ];
	var divResult = [ "div", { type: "div", element: null } ];

	var content =
		[ "div",
			[ "table", { "class": "wx_form" },
				[ "tr", [ "td", "Település:" ], [ "td", inpCoCity ] ],
				[ "tr", [ "td", "Közterület:" ], [ "td", inpCoStreet ] ],
				[ "tr", [ "td" ], [ "td", btnCoSearch ] ]
			],
			[ "div", divResult ]
		];

	Sarissa.clearChildNodes(widget.webxPane);
	widget.webxPane.appendChild(webxJsonML(content));

	this.Content_inpCoCity = inpCoCity[1].element;
	this.Content_inpCoStreet = inpCoStreet[1].element;
	this.Content_btnCoSearch = btnCoSearch[1].element;
	this.Content_divResult = divResult[1].element;

	//this.Content_btnCoSearch.onclick = btnCoSearchClick;

	function btnCoSearchClick() {
		//var _this = webx.searchWidget(this).webxManager;

		try {
			makedivResult(["div", "Keresem..."]);
			var sr = new XMLHttpRequest();
			sr.open("POST", webx.urlConsolidator(_this.widget.webxWidget.POSTURL), true);
			sr.setRequestHeader("Content-type", "application/json;charset=utf-8");
			sr.onreadystatechange = function() { 
				if (sr.readyState == 4) {
					if(sr.status == 200 || sr.status == 0 /* local */) {
						wxlog.log("huZIP: readyState == 4 and status == 200");
						FillResults(sr.responseText);
					} else {
						makedivResult(["div", { style: "color: red;" }, "Hiba a szerverrel történő kommunikáció közben"]);
					}
				}
			}

			var d = {
				city: _this.Content_inpCoCity.value,
				street: _this.Content_inpCoStreet.value
			};
			var post = d.toJSONString();
			wxlog.log("huZIP: search post: " + post);
			sr.send(post);
		} catch(e) {
			wxlog.dir(e);
			wxlog.log("huZIP: search error: " + e);
			makedivResult(["div", { style: "color: red;" }, "Hiba a szerverrel történő kommunikáció közben"]);
		}
	}

	function FillResults(Resultset) {
		eval("var tmp=" + Resultset);
		if (tmp.length == 0) {
			var content =
				[ "div", "Nincs találat" ];
		}	else {
			var content =
				[ "table",
					[ "tr", [ "th", "Ir. sz." ], [ "th", "Város" ], [ "th", "Utca" ] ]
				];
			for(var i = 0; i < tmp.length; i++) {
				//content[i + 2] = new Array();
				content[i + 2] = [ "tr" , [ "td", tmp[i].ZIP ], [ "td", tmp[i].city ], [ "td", tmp[i].street ] ];
			}
		}

		makedivResult(content);
	}

	function makedivResult(content) {
		var dR = _this.Content_divResult;
		Sarissa.clearChildNodes(dR);
		dR.appendChild(webxJsonML(content));
	}

}


