var mouse_is_inside = false;
// @ skrytie multiselect boxu po kliknuti kdekolvek na body, okrem divu sameho
$(document).ready(function() {
$("#multiSelectLocalityBox").live({
mouseenter:
function() {
mouse_is_inside=true;
},
mouseleave:
function() {
mouse_is_inside=false;
}
}
);
$("body").mouseup(function(){
if(! mouse_is_inside) $('#multiSelectLocalityBox').slideUp();
});
});
function checkedRgcA($item) {
$item.parent().find('input[type="checkbox"]').attr("checked", "checked");
}
function checkedDsrA($item) {
$item.attr("checked", "checked");
$item.parent().parent().parent().find('.destinationCheckbox').attr("checked", "checked");
}
function selectSubDestination($subDestination) {
$destination = $subDestination.parent().parent().parent().find('.destinationCheckbox');
$rgcA = $destination.val();
$checkboxes = $destination.parent().find('input[type="checkbox"]');
$count = 0;
$checkboxes.each(function(index) {
if (!$(this).attr('checked')) $count = $count + 1;
});
$input = $('input.topDestinantionsBox[value="' + $rgcA + '"]');
if ($count==0) {
$input.attr('checked', true);
} else {
$input.attr('checked', false);
}
$subDestinations = $subDestination.parent().parent().find('input[type="checkbox"]');
$noneSelected = true;
$subDestinations.each(function(index) {
if ($(this).attr('checked')) $noneSelected = false;
});
}
function uncheck_multiselect_locality() {
$('#multiSelectLocalityBox input:checked').attr("checked", false);
calculate_count();
}
function calculate_count() {
$subDestinations = $("input.subDestinationCheckbox:checked").length;
$destinations = $('input[name="rgcA[]"]:checked').length;
$destinationsDir = $('input[name="mainRgcA[]"]:checked').length;
$allDestinations = $destinations + $destinationsDir;
$count = $destinations + $subDestinations;
// ak nie je vybrana ziadna polozka
if ($count>0) {
$('#multiSelectLocalityBoxFilter').html('Zrušiť voľbu');
} else $('#multiSelectLocalityBoxFilter').html('');
if ($count==0) {
$('#destination_drop').html('Všetky destinácie');
} else if ($destinationsDir==1 && $destinations==0) {
$('#destination_drop').html($('input[name="mainRgcA[]"]:checked').attr('title') + ' (' + $count + ')');
} else if ($destinations==1 && $count==1) {
$('#destination_drop').html($('input[name="rgcA[]"]:checked').attr('title'));
} else if ($allDestinations>1 && $allDestinations<5) {
var $title = '';
$('input[name="rgcA[]"]:checked').each(function(index) {
if ($title!='') $title = $title + '; ';
$title = $title + $(this).attr('title');
});
$('input[name="mainRgcA[]"]:checked').each(function(index) {
if ($title!='') $title = $title + '; ';
$title = $title + $(this).attr('title');
});
$('#destination_drop').html($title + ' (' + $count + ')');
} else {
$('#destination_drop').html('Destinácie (' + $count + ')');
}
$('input[name="mainRgcA[]"]:checked').each(function(index) {
$li = $(this).parent();
$unchecked = $li.find('ul input[name="dsrA[]"]').not(':checked');
$checked = $li.find('ul input[name="dsrA[]"]:checked');
if ($checked.length==0) {
$(this).attr("checked", false);
}
if ($unchecked.length==0) {
$li.removeClass('notAllSelected');
} else {
$li.addClass('notAllSelected');
}
});
/*
$('input[name="mainRgcA[]"]:checked').each(function(index) {
$(this).find('input[type="checkbox"]')
if ($(this).find('input[type="checkbox"]')
}
*/
}
//$("a.offsite").live("click", function(){ alert("Goodbye!"); });
function loadMultiSelect() {
$('ul#example').collapsibleCheckboxTree({
checkParents : true, // When checking a box, all parents are checked (Default: true)
checkChildren : true, // When checking a box, all children are checked (Default: false)
uncheckChildren : true, // When unchecking a box, all children are unchecked (Default: true)
initialState : 'default' // Options - 'expand' (fully expanded), 'collapse' (fully collapsed) or default
});
}
function InicializateMultiSelect() {
$('#destination_drop').live("click", function() {
$box = $('#multiSelectLocalityBox');
if ($box.is(':visible')) {
$box.slideUp();
} else {
$box.slideDown();
}
});
$('#multiSelectLocalityBox').live("click", function() {
mouse_is_inside=true;
}, function() {
//mouse_is_inside=false;
});
$('input[name="dsrA[]"]').live("click", function() {
selectSubDestination($(this));
calculate_count()
});
$('input[name="rgcA[]"]').live("click", function() {
$checked = $(this).attr('checked');
$rgcA = $(this).val();
$input = $('input[value="' + $rgcA + '"]');
$input.attr('checked', $checked);
$input.parent().find('input[type="checkbox"]').attr("checked", $checked);
calculate_count()
});
$('input[name="mainRgcA[]"]').live("click", function() {
$checked = $(this).attr('checked');
$rgcA = $(this).val();
$input = $('input[value="' + $rgcA + '"]');
$input.attr('checked', $checked);
calculate_count()
});
$('input[name="TrgcA[]"]').live("click", function() {
$checked = $(this).attr('checked');
$rgcA = $(this).val();
$input = $('input[value="' + $rgcA + '"]');
$input.attr('checked', $checked);
calculate_count()
});
$('input[name="TrgcA[]"]').live("click", function() {
$checked = $(this).attr('checked');
$rgcA = $(this).val();
$input = $('input[value="' + $rgcA + '"]');
$input.attr('checked', $checked);
$input.parent().find('input[type="checkbox"]').attr("checked", $checked);
calculate_count()
});
}