Datepicker not working in dialog load

Datepicker not working in dialog load

I have a dialog that is calling a page through .load(). This page contains a datepicker but when it loads in the dialog, nothing happens when I click the datepicker text field. This is not the z-index problem.

My js:
// Initiate datepicker
if (jQuery('input.datepicker').length > 0)
    jQuery('input.datepicker').datepicker({dateFormat: 'dd-mm-yy'});

// Setup and call dialog
  $('#showdialog').click(function () {
    $("#example").dialog("open");
    $("#example").load("/programs/2/edit", function() {
      $(this).dialog({
        modal:true,
        buttons: {
          "Close": function() { $(this).dialog("destroy"); }
        }
      });
    });
    return false;
  });