$(document).ready(function() {
$("#location-tabs > ul").show(); 
$("#location-tabs").tabs({
cookie: { 
name: "locationTab"
},
show: function(event, ui) {
$("#location-tabs > div#" + ui.panel.id).show();
$("input[name=proximity_type]").val(ui.panel.id);
}
});
$("input[name=proximity_subtype]").live("change", function() {
$("tr.proximity_subtype").removeClass("selected");
$("input[name=proximity_subtype]:checked").parents('tr:first').addClass("selected");
});
$("tr.proximity_subtype input,tr.proximity_subtype select").live("focus", function() {
$(this).parents("tr.proximity_subtype:first").find("input[type=radio]").attr("checked", true).change(); 
});
if($("input[name=proximity_subtype]:checked").size()==0) {
$("input[name=proximity_subtype]:first").attr('checked', 'checked');
}
$("input[name=proximity_subtype]:first").change()
$("input[name=community_subtype]").live("change", function() {
$("tr.community_subtype").removeClass("selected");
$("input[name=community_subtype]:checked").parents('tr:first').addClass("selected");
});
$("tr.community_subtype input,tr.community_subtype select").live("focus", function() {
$(this).parents("tr.community_subtype:first").find("input[type=radio]").attr("checked", true).change(); 
});
if($("input[name=community_subtype]:checked").size()==0) {
$("input[name=community_subtype]:first").attr('checked', 'checked');
}
$("input[name=community_subtype]:first").change()
$("select.select-items").each(function() {
$(this).attr('name2', $(this).attr('name'));
$(this).attr('name', null);
});
$("select.select-items").live("change", function() {
var thisVal = $(this).find("option:selected").val();
var thisName = $(this).attr('name2');
if(thisVal) {
$(this).find("option:selected").each(function() {
if($(this).parents('td:first').find("input[value=\""+ $(this).attr('value') + "\"]").size()==0) { 
$(this).parents('td:first').find(".selected-items").append( "<span><span class=icon>&nbsp;</span> " + $(this).text() + "<input type=hidden name=\"" + thisName + "\" value=\""+ $(this).attr('value') + "\"></span>"); 
} 
});
}
return true; 
});
$(".selected-items span:not(.icon)").live("click", function() { 
$(this).remove(); 
return true;
});
$("#button_clear").click(function() {
$("input[type=checkbox]").attr('disabled', false);
$("select.select-items option").attr('selected', false);
$(".selected-items span:not(.icon)").remove(); 
return true;
});
$('input.checkbox-all').live("click", function() { 
var checkAll = $(this).is(':checked') ? true : false;
$(this).parents('table:first').find('input[type=checkbox]').attr('disabled',checkAll).attr('checked',checkAll);
$(this).attr('disabled',false); 
return true;
}); 
$('input.checkbox-all').each(function() {
var checkAll = $(this).is(':checked') ? true : false;
if(checkAll) {
$(this).parents('table:first').find('input[type=checkbox]').attr('disabled',checkAll).attr('checked',checkAll);
} else {
$(this).parents('table:first').find('input[type=checkbox]').attr('disabled',checkAll);
}
});
});
