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

function cssPreloadImages() {
	var i, j, img;
	for (i=0; i<document.styleSheets.length; i++) {
		var pos = document.styleSheets[i].href.lastIndexOf("/");
		var cssDir = (pos != -1) ? document.styleSheets[i].href.substring(0, pos + 1) : "";
		var rules = document.styleSheets[i].cssRules ? document.styleSheets[i].cssRules : document.styleSheets[i].rules;
		for (j=0; j<rules.length; j++) {
			var style = rules[j].style;
			if (style && style.backgroundImage.toLowerCase().substr(0,4) == "url(") {
				var filename = style.backgroundImage.substring(4, style.backgroundImage.length - 1);
				if (filename.indexOf("http://") != 0 && filename.indexOf("/") != 0)
					filename = cssDir + filename;
				var img = new Image();
				img.src = filename;
			}
		}
	}
}

if (window.attachEvent) {
	window.attachEvent("onload", cssPreloadImages);
} else {
	window.addEventListener("load", cssPreloadImages, false);
}

window.onload = function() {
	$('#dialog').jqm();
	$('#soapModal').jqm();
	
	$("div#menucol li").each(function(i, li) {
		if (!$(this).hasClass("active")) {
				$("ul", this).css({'display': 'none'});
			}	
	});
	$("a").each(function(i, a) {
		$(this).click(function(){
			this.blur(); // most browsers
			this.hideFocus = false; // ie
		});
	});
	
	$('.delBtn').click(function () {
		return confirm("Valóban törli a tételt?\nA törlés nem visszavonható!") ? true : false;
	});

	$("div#menucol li.level1").each(function(i, li) {
		$("a:first", this).click(function(){

			/*$("div#menucol li.level1 ul").css({'display': 'none'});*/
			$(this).next().slideToggle("fast");
			this.blur(); // most browsers
			this.hideFocus = false; // ie
		});
	});
	
	$("#registrationBtn").click(function() {
		ajaxGetUpdate("soapModal", "/regisztracio", false);
		return false;
	});
	
	$("#modificationBtn").click(function() {
		ajaxGetUpdate("soapModal", "/adatmodositas", false);
		return false;
	});
	
	$("#legalDeclarationBtn").click(function() {
		ajaxGetUpdate("soapModal", "/jogi-nyilatkozat", false);
		return false;
	});
	
	$("#sendNewPasswordBtn").click(function() {
		$("#dialog").html($("#sendNewPasswordModal").html());
		$("#dialog").jqmShow();
		
		$("#sendNewPasswordForm").submit(function () {
			ajaxPostUpdate (this.id, this.action + (this.action.indexOf("?") == -1 ? "?" : "&") + "ajax=true", "sendNewPasswordDiv", false);
			return false;
		});
		
		return false;
	});

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

	validate();
}
function validate() {
	$('div.content #menucol').css({'overflow-x':'hidden'});
}
