title: Closing Jquery UI popup
body: <p>I wrote a Javascript function that uses Jquery-ui.
  I am able to close the JQuery popup with </p>
  
  <pre><code>$(this).dialog("close")
  </code></pre>
  
  <p>But if I include it in an If condition, like it is in the code here, it just does not work.
  Am i missing something on how the this keyword works in JS?</p>
  
  <p>Marco</p>
  
  <pre><code>if (vars["server_url"] !== undefined)
          var serverUrl = vars["server_url"];
          var ODATA_ENDPOINT = "XRMServices/2011/OrganizationData.svc";
          var CRMObject = new Object();
          ///////////////////////////////////////////////////////////// 
          // Specify the ODATA entity collection 
          var ODATA_EntityCollection = "/custom_serviceobjectSet";
  
  
  
          var alreadyExisting = new Object;
          alreadyExisting.value = "";
          retrieveExistingPlacement(serverUrl, custom_name, placering.val(), alreadyExisting);
          setTimeout(function() {
              alert(alreadyExisting.value);
              if (alreadyExisting.value === true) {
  
                  placering.addClass("ui-state-error");
                  updateTips("Ett ServiceObject med sån placeringen redan finns.");
              }
              else if (alreadyExisting.value === false)
              {
              //alert(ordning.val());
              $("#users tbody").append("&lt;tr&gt;" +
                  "&lt;td&gt;" + CRMObject.custom_order + "&lt;/td&gt;" +
                  "&lt;td&gt;" + CRMObject.custom_Placement + "&lt;/td&gt;" +
                  "&lt;td&gt;" + CRMObject.custom_Quantity + "&lt;/td&gt;" +
                  "&lt;/tr&gt;");
              var jsonEntity = window.JSON.stringify(CRMObject);
              //Asynchronous AJAX function to Create a CRM record using OData 
              $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  datatype: "json",
                  url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,
                  data: jsonEntity,
                  beforeSend: function(XMLHttpRequest) {
                      //Specifying this header ensures that the results will be returned as JSON. 
                      XMLHttpRequest.setRequestHeader("Accept", "application/json");
                  },
                  success: function(data, textStatus, XmlHttpRequest) {
  
                      var NewCRMRecordCreated = data["d"];
                  },
                  error: function(XMLHttpRequest, textStatus, errorThrown) {
                      alert(serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection);
                      alert(errorThrown);
                      alert(XMLHttpRequest.responseText);
                  }
              });
                  alert("OUT");
  
              }
          }, 1000);
          if (alreadyExisting.value === false) 
              $("#dialog-form").dialog("close");
  }                   
  </code></pre>