document.write('<div style="z-index: 3000;" style="hidden" class="jqmWindow jqmID1" id="dialog"></div>');

window.onload = function() {
	$('#dialog').jqm();

	$('.ajaxForm').submit(function () {
		ajaxPostUpdate (this.id, this.action + (this.action.indexOf("?") == -1 ? "?" : "&") + "ajax=true", "dialog", false);
		return false;
	});

	$('.delBtn').click(function () {
		return confirm("Valóban törli a tételt?\nA törlés nem visszavonható!") ? true : false;
	});

	$('.accentuatedBtn').click(function() {
		ajaxGetUpdate("dialog", this.href, false);
		return false;
	});

	$(".menu_category").click(function() {
		var lines = this.parentNode.getElementsByTagName("li");
		for (a in lines) {

			if (a >= 0 && lines[a].className.indexOf("menu_category") == -1) {
				if (lines[a].className.indexOf("hidden") == -1) {
					lines[a].className = lines[a].className + " hidden";
				} else {
					lines[a].className = lines[a].className.replace(" hidden", "");
				}
			}
		}
	});

	$(".secretBtn").click(function() {
		var input = this.getElementsByTagName("input");
		var image = this.getElementsByTagName("img");

		if ((input.length > 0) && (image.length > 0)) {
			input[0].value = (input[0].value) == 0 ? 1 : 0;

			image[0].src = (input[0].value) == 0 ? "/images/structure/public.gif" : "/images/structure/secret.gif";
			image[0].alt = (input[0].value) == 0 ? "nyilvános adat" : "titkos adat";
			image[0].title = (input[0].value) == 0 ? "nyilvános adat" : "titkos adat";
		}

		return false;
	});

	$("#postalcode").keyup(function() {
		var postalCodeValue = parseInt(this.value, 10);

		if (postalCodeValue == this.value && this.value.length == 4) {
			var myAjax = $.ajax({
				type: "GET",
				url: "/regisztracio/get_settlement?code=" + postalCodeValue,
				success: function(msg) {
					$("#settlement").attr("value", msg);
				}
			 });
		} else if (this.value.length == 0) {
			$("#settlement").attr("value", "");
		}
	});

	$(".sendURLBtn").click(function() {
		ajaxGetUpdate("dialog", this.href, false);
		return false;
	});

	$('a.lightbox').lightBox();
}
