function foo(myPageTable) {
    myPageTable.find('.selectRowCheckBox').each(function(i, e) {
        var checkBox = $(e);
        var row = checkBox.parents('.mypagetable tr');
        if (checkBox.attr('checked')) {
            row.addClass('selected');
        } else {
            row.removeClass('selected');
        }
    });
}
$(document).ready(function() {
    $('.selectAllRowsCheckBox').live('click', function() {
        var clickedCheckBox = $(this);
        var myPageTable = clickedCheckBox.parents('.mypagetable');
        myPageTable.find('.selectRowCheckBox').attr('checked', clickedCheckBox.attr('checked'));
        foo(myPageTable);
    });
    $('.selectRowCheckBox').live('click', function() {
        var clickedCheckBox = $(this);
        var myPageTable = clickedCheckBox.parents('.mypagetable');
        var totalCount = myPageTable.find('.selectRowCheckBox').length;
        var selectedCount = myPageTable.find('.selectRowCheckBox:checked').length;
        var selectAllCheckBox = myPageTable.find('.selectAllRowsCheckBox');
        if (selectedCount == totalCount) {
            selectAllCheckBox.attr('checked', 'checked');
        } else {
            selectAllCheckBox.removeAttr('checked');
        }
        foo(myPageTable);
    });
    
    $("a.confirm").click(function() {
    	var href = $(this).attr('href');
    	$('<div />')
    		.html($(this).attr('msg'))
    		.dialog({
    		title: $(this).attr('title'),
    		buttons: {
                'Ok': function() {
                	document.location.href =  href;
                },
                Avbryt: function() {
                    $(this).dialog('close');
                }
            }
    	})
    	
    	return false;
    } );
});

