$(document).ready(function(){
	
	if($('input[name="idFirma"]').val() == '')
	{
		$('input[name="idFirma"]').removeAttr('checked');
		$('#montazni_firma_ne').attr('checked', 'checked');
	}
	else
	{
		$('input[name="idFirma"]').removeAttr('checked');
		$('#montazni_firma_ano').attr('checked', 'checked');	
	}
	
	$('#montazni_firma_ano').click(function(){
		$.get('katalog_mont_firem_pokladna_mapa.php', function(data){
			$("#nacti_mapu_montaze_obsah").html(data);

			$("#montazni_firma_dialog").dialog({
				resizable: false,
				title: txt_katalog_montaznich_firem,
				width: 650,
				height: 800,
				show: "scale{percent: 150}",
				hide: "scale{percent: 0}",
				beforeClose: function(){
					if($('#montazni_firma_ano').val() == '')
						$('#montazni_firma_ne').attr('checked', 'checked');
				}
			});
		});
	});	
	
	if($('.idBranch').val() == '')
	{
		$('.showBranches').removeAttr('checked');
	}

	$('.showBranches').click(function(){
		if($(this).hasClass('branchTrue'))
		{
			$.get('katalog_mont_firem_pokladna_mapa.php', {prodejce: 1}, function(data){
			$("#nacti_mapu_montaze_obsah").html(data);

			$("#montazni_firma_dialog").dialog({
				resizable: false,
				title: txt_katalog_prodejcu,
				width: 650,
				height: 800,
				show: "scale{percent: 150}",
				hide: "scale{percent: 0}",
				beforeClose: function(){
					if($('.idBranch').val() == '')
						$('.showBranches').removeAttr('checked');
				}
			});
			});
		}				
	});

	$('.pla_dor').submit(function(){
		if($('.showBranches:checked').hasClass('branchTrue') && ($('.idBranch').val() == '' || $('.idBranch').val() == undefined))
		{
			alert(txt_vyberte_prodejce);
			return false;
		}
		else if(!$('.showBranches:checked').hasClass('branchTrue'))
		{
			$('.idBranch').val('');
		}
		return true;
	});
});
