如何从超链接调用jQuery中的另一个函数?

I'm having a link as follows :

<div id="demo-testpack">
          <a href="#" class="user-not-loggedin">Demo Test Packages</a>
      </div>

On clicking on this link I'm calling following jQuery code :

$(function() {  
  $("#user-popup-login").dialog({ autoOpen: false }); 
  $( ".user-not-loggedin" )
    .click(function() {
    $( "#user-popup-login" ).dialog( "option", "width", 400 );
    $( "#user-popup-login" ).dialog( "option", "modal", true );
    $( "#user-popup-login" ).dialog( "open" );

    return false;
  });

The pop up gets opened after this function some fields and some links are there in the pop up. One link is as follows in the popup:

<div id="registern"><a href="#" class="register-btn">Register Now</a></div>

On click of this link I want to execute the following code which results in opening of another popup. The jQuery code for this is as follows :

$(function() {  
    $("#create-user-form").dialog({ autoOpen: false }); 
    $( ".register-btn" )
        .click(function() {
        $( "#create-user-form" ).dialog( "option", "width", 560 );
        $( "#create-user-form" ).dialog( "option", "modal", true );
        $( "#create-user-form" ).dialog( "open" );

        return false;
    });

    $( ".get-start" )
        .click(function() {
        $( "#create-user-form" ).dialog( "option", "width", 560 );
        $( "#create-user-form" ).dialog( "option", "modal", true );
        $( "#create-user-form" ).dialog( "open" );

        return false;
    });         

    //This function is used to submit User Registration form
    $('#user_registration_form').live('submit', function() { 
         $('.register').attr('disabled', 'disabled');
         show_request('#registration_error');
            $.ajax({   
                type: $(this).attr('method'),
                url: $(this).attr('action'), 
                data:$(this).serialize(),
                dataType: 'json',
                success: function(response) { 
                    $('.register').removeAttr('disabled', 'disabled');
                    var reg_error = response.reg_error;    

                    if(reg_error=='yes') {
                        var error_msg      = response.error_msg; 
                        var dialog_title   = 'Input Errors Found';                 
                        var dialog_message = error_msg; 
                        $("#registration_error").html(error_msg);
                    } else {
                        $("#registration_error").html('');
                        $( "#create-user-form" ).dialog('close');
                        var suc_msg   = response.suc_msg; 
                        var dialog_title   = 'Registered Successfully';                 
                        var dialog_message = suc_msg; 

                        var $dialog = $("<div class='ui-state-success'></div>")
                        .html("<p class='ui-state-error-success'>"+dialog_message+"</p>")
                        .dialog({
                             autoOpen: false,
                             modal:true,
                             title: dialog_title,
                             width: 500,                       
                             buttons:{
                             'OK': function() {
                                $(this).dialog('close');
                                 }
                             }                                             
                        });
                        $dialog.dialog('open'); 
                        $('#user_registration_form')[0].reset();    
                    }

                } 
            });    
            return false;
    }); 
});

Now what I want to achieve is when user clicks on the above link the previously opened popup should close and only this new popup should display. I did lots of tricks but not succeeded. Can anyone help me out on how to achieve this?Thanks in Advance.

I'm going to guess this is scope issue because the call to popup('open') on $( "#create-user-form" ) in a different anonymous function than where you are trying to close it. Try putting the calls to open and close it in the same document.ready shorthand anonymous function.

I tried and tried and reacThis can be achieved by following code snippet. It really did magic for me.

if($( "#user-popup-login" ).dialog( "open" ))
        $( "#user-popup-login" ).dialog( "close" );