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>');

var is_ie = navigator.appName == 'Microsoft Internet Explorer';

function clearVote()
{
	$(".vote").each(function() {
		this.src = "/images/flower_gray.png";
	});
}

function showVote(vote)
{
	$(".vote").each(function() {
		if (this.alt <= vote) {
			this.src = "/images/flower_red.png";
		} else {
			this.src = "/images/flower_gray.png";
		}
	});
}

$("#body").ready(function () {
	$('#dialog').jqm();
	$('#soapModal').jqm();
	
	$("#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;
	});

	$("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
		});
	});

	$("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
			if (!is_ie) {
				this.style.outline = null; // mozilla
			}
		});
	});

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

	$(".delBtn").click(function() {
		if (confirm("Valóban törli a kijelölt tételt?\n A törlés nem visszavonható!")) {
			return true;
		} else {
			return false;
		}
		this.blur(); // most browsers
		this.hideFocus = false; // ie
		this.style.outline = null; // mozilla
	});
	
	$(".vote").mouseover(function() {
		showVote(this.alt);
	});
	
	$(".vote").mouseout(function() {
		clearVote();
	});
	
	validate();
});
function validate() {
	$('div.content #menucol').css({'overflow-x':'hidden'});
}
