jQuery (document).ready(function(){

	$(".collapse").hide();
	$("a.more").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	$("a.more").click(function(){
		$(this).next(".collapse").slideToggle("slow");
	});


	$(".raktaron").click(function(){
		var termekid = $(this).parent().find("input[name='termekid']").val();
		var darab = $(this).parent().find(".darab").val();
		$.post("components/webshop/kosarba.php", {termekid: termekid, darab: darab}, function(data){
			$('#dialog-message')
			.html(data)
			.dialog({
				autoOpen: false,
			    modal: true,
			    buttons: {
			      'Ok': function() {
			        $(this).dialog('close');
			      }
			    }
			})
			.dialog('open');
			return false;
		});
	});
	$(".nincsraktaron").click(function(){
		var termekid = $(this).parent().find("input[name='termekid']").val();
		var darab = $(this).parent().find(".darab").val();
		if(!/^[1-9]\d*$/.test(darab)){
			$('#dialog-message')
			.html('Neudali ste množstvo')
			.dialog({
				autoOpen: false,
			    modal: true,
			    buttons: {
			      'Naspäť': function() {
			        $(this).dialog('close');
			      }
			    }
			})
			.dialog('open');
		}
		else {
			$('#dialog-order')
			.html('Výrobok sa práve nenachádza v sklade. Objednáte si ho aj napriek tomu?')
			.dialog({
				autoOpen: false,
			    modal: true,
			    buttons: {
			      'Naspäť': function() {
			        $(this).dialog('close');
			      },
				  'Ok': function() {
			        $.post("components/webshop/kosarba.php", {termekid: termekid, darab: darab}, function(data){});
					$(this).dialog('close');
			      }
			    }
			})
			.dialog('open');
		}
		return false;
	});
});

function mennyiseg(elemid, elojel){
    $.post("components/rendeles/tartalom.php", {termekid: elemid, irany: elojel},
    function(data){
        if (data.length>0){$(".kosar").html(data);}
    })
};
