

function groupCountProcess()
{
	if(!$('label#group-count-1 select').is('select'))
		return true;
	var selectFirst = $('label#group-count-1 select').get(0);
//	$('label#group-count-2 span.tmp').append('<span class="access">'+selectFirst.options[selectFirst.selectedIndex].value+'</span>');

	if(!selectFirst.selectedIndex)
	 	selectFirst.selectedIndex = 0;
	if(!selectFirst.options[selectFirst.selectedIndex]  || !selectFirst.options[selectFirst.selectedIndex].value)
		return false;
		
	var idProduct = $('input#AddToCart').get(0).value;
	if(!idProduct)
		return false;
		
	$('label#group-count-2').show();
	$('label#group-count-2 select').remove();
	$('label#group-count-2 span.tmp').empty();
	$('label#group-count-2 span.tmp').append('proszę czekać...');
	$('label#group-count-2 span.tmp').load("index.php?getECProductCheckAJAX",
		{
			idProduct: idProduct,
			group1 : selectFirst.options[selectFirst.selectedIndex].value
		},
		function()
		{
		}
	);
	
	
}

function initGroupCountAjax()
{
	
	$('label#group-count-1 select').change( function() { groupCountProcess(); });
	$('label#group-count-2 select').before('<span class="tmp"></span>');
	$('label#group-count-2').hide();
	groupCountProcess();
}


function initializeGroupCount()
{
	// check if first group exists
	if($('label#group-count-1').get(0))
	{
		// ...and check if the second is present
		if($('label#group-count-2').get(0))
		{	
			initGroupCountAjax();
		}
	}
}

$(document).ready(initializeGroupCount);

