	function PostOffer(postId, item, need_from) {
		this.postId = postId;
		this.containerDiv = null;
		this.default_email = "e-mail cím...";
		this.default_name = "neved...";
		this.item = item;

		var pos = new Array(0, 0);
		if (item != null)
			pos = findPos(item);

		this.createContainer(pos[0]-245, pos[1]+20);
		
		if (need_from) {
			this.switchLayout("emailToAndFrom");
		} else {
			this.switchLayout("emailTo");
		}

		// var obj = this;
		// addEvent(window.document, "click", function () { obj.cancelOffer(); });
	}

	PostOffer.prototype.createContainer = function (x, y) {
		var div = window.document.createElement("DIV");
		div.className = "postOffer";
		div.style.position = "absolute";
		div.style.left = x+"px";
		div.style.top = y+"px";
		div.onclick = stopBubbling;
		window.document.body.appendChild(div);
		// alert(this.item.parentNode);
		// this.item.appendChild(div);
		this.containerDiv = div;
	}
	PostOffer.prototype.switchLayout = function (layout, param) {
		this.containerDiv.innerHTML = "";
		switch (layout) {
			case "emailTo": return this.createEmailToLayout();
			case "emailToAndFrom": return this.createEmailToAndFromLayout();
			case "sending": return this.createSendingLayout();
			case "sent": return this.createSentLayout(param);
		}
	}
	PostOffer.prototype.createEmailToLayout = function () {
		var form, toLabel, toInput, submit, title;
		var obj = this;

		title = window.document.createElement("H2");
		title.innerHTML = "Küldd el másnak!";

		form = window.document.createElement("FORM");
		form.className = "to";
		form.onsubmit = function () { obj.sendOffer(toInput.value); return false; };

		toLabel = window.document.createElement("DIV");
		toLabel.className = "label";
		toLabel.innerHTML = "E-mail cím: ";

		toInput = window.document.createElement("INPUT");
		toInput.type = "text";
		toInput.className = "text email";
		toInput.focus();
		
		submit = window.document.createElement("INPUT");
		submit.type="submit";
		submit.className = "submit";
		submit.value = "Küld";

		// form.appendChild(toLabel);
		form.appendChild(toInput);
		form.appendChild(submit);

		initFieldDefValueByItem(toInput, this.default_email);

		this.containerDiv.appendChild(title);
		this.containerDiv.appendChild(form);

		// toInput.focus();
	}
	PostOffer.prototype.createEmailToAndFromLayout = function () {
		var form, fromLabel, fromInput, toLabel, toInput, submit, cancel, nameLabel, nameInput;
		var obj = this;

		title = window.document.createElement("H2");
		title.innerHTML = "Küldd el másnak!";

		form = window.document.createElement("FORM");
		form.className = "to_and_from";
		form.onsubmit = function () { obj.sendOffer(toInput.value, fromInput.value); return false; };

		fromLabel = window.document.createElement("DIV");
		fromLabel.className = "label";
		fromLabel.innerHTML = "Kitől: ";

		fromInput = window.document.createElement("INPUT");
		fromInput.type = "text";
		fromInput.className = "text";
		
		toLabel = window.document.createElement("DIV");
		toLabel.className = "label";
		toLabel.innerHTML = "Kinek:";

		toInput = window.document.createElement("INPUT");
		toInput.type = "text";
		toInput.className = "text";

		submit = window.document.createElement("INPUT");
		submit.type="submit";
		submit.className = "submit";
		// submit.src = "images/b_go.gif";
		submit.value = "Küld";

		form.appendChild(fromLabel);
		form.appendChild(fromInput);
		form.appendChild(toLabel);
		form.appendChild(toInput);
		form.appendChild(submit);

		initFieldDefValueByItem(toInput, this.default_email);
		initFieldDefValueByItem(fromInput, this.default_name);

		this.containerDiv.appendChild(title);
		this.containerDiv.appendChild(form);

		// fromInput.focus();
	}
	PostOffer.prototype.createSendingLayout = function () {
		var div;

		div = window.document.createElement("DIV");
		div.className = "sending";
		div.innerHTML = "Küldjük a leveled...";

		this.containerDiv.appendChild(div);
	}
	PostOffer.prototype.createSentLayout = function (message) {
		// alert(message);
		var div, ok;
		var obj = this;

		div = window.document.createElement("DIV");
		div.className = "sent";
		div.innerHTML = message;

		/*
		ok = window.document.createElement("INPUT");
		ok.type="button";
		ok.value = " Bezár ";
		ok.onclick = function () { obj.removeContainerDiv(); }
		*/

		this.containerDiv.appendChild(div);
		// this.containerDiv.appendChild(ok);

		// ok.focus();

		// window.document.body.removeChild(this.containerDiv);
	}
	PostOffer.prototype.handleSendingResponse = function (response) {
		this.switchLayout("sent", response);
	}
	PostOffer.prototype.sendOffer = function (to, from) {
		if (to=="") return false;
		if (from=="") return false;
		if (to==this.default_email) return false;
		
		this.switchLayout("sending");

		var req;
		var obj = this;
		var url;
		
		url = "index.php?load=ajax_post_offer&id="+this.postId+"&to="+to;
		if (from!=null) url+="&from="+from;

		req = new MyHttpRequest();
		req.setProcessorFunc(function (response) { obj.handleSendingResponse(response); });
		req.sendRequest(url);
	}
	PostOffer.prototype.cancelOffer = function () {
		this.removeContainerDiv();
	}
	PostOffer.prototype.removeContainerDiv = function () {
		window.document.body.removeChild(this.containerDiv);
		// if (this.item) this.item.removeChild(this.containerDiv);
	}

	var _postOffer = null;
	function showPostOffer(id, item, need_from) {
		cancelPostOffer();
		_postOffer = new PostOffer(id, item, need_from);
		return false;
	}
	function cancelPostOffer() {
		if (_postOffer!=null) _postOffer.cancelOffer();
		_postOffer = null;
	}
	addEvent(window.document, "click", cancelPostOffer);
