title: Cannot set property 'className' of null
body: <p>Can anyone tell me why I am getting the error stated in the title? I understand that it means "wrapper" is null, but I can't figure out why it is null.</p>
  
  <p>This is the html:</p>
  
  <pre><code>@using OP.App_Code
  @using OP.Controllers
  
  @{
      ViewBag.Title = "Patients";
  }
  
  &lt;div class="title"&gt;
      &lt;div&gt;
          &lt;h1 style="float: left"&gt;@ViewBag.Title&lt;/h1&gt;
      &lt;/div&gt;
      &lt;div class="rmm" style="float: right; display: inline-block"&gt;
          &lt;ul&gt;
              &lt;li&gt;&lt;a href="javascript:void(0)" id="NewPatient"&gt;New Patient&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="javascript:void(0)" class="DeleteLink"&gt;Delete Patient(s)&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="content"&gt;
      &lt;div id="patient_table"&gt;
          &lt;table id="patients"&gt;
              &lt;tr&gt;
                  &lt;th class="checkBox"&gt;&lt;/th&gt;
                  &lt;th id="p_name"&gt;Patient Name&lt;/th&gt;
                  &lt;th id="p_site"&gt;Site&lt;/th&gt;
                  &lt;th id="dob"&gt;Date of Birth&lt;/th&gt;
                  &lt;th id="ssn"&gt;SSN&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
      &lt;div class="modal_content"&gt;
          &lt;div id="modal_window"&gt;
              &lt;div style="text-align: right;"&gt;&lt;a id="modal_close" href="#"&gt;close &lt;b&gt;X&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;
  
              &lt;p&gt;Complete the form below to add a new patient:&lt;/p&gt;
  
              &lt;form id="add_patient" method="POST" action="#" accept-charset="UTF-8"&gt;
              &lt;p&gt;&lt;label&gt;First Name&lt;strong&gt;*&lt;/strong&gt;&lt;br&gt;
              &lt;input type="text" autofocus required size="48" name="fname" value=""&gt;&lt;/label&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Last Name&lt;strong&gt;*&lt;/strong&gt;&lt;br&gt;
              &lt;input type="text" autofocus required size="48" name="lname" value=""&gt;&lt;/label&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Birthdate (mm/dd/yyyy)&lt;strong&gt;*&lt;/strong&gt;&lt;br&gt;
              &lt;input type="text" autofocus required size="48" name="bday" value=""&gt;&lt;/label&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Site Name&lt;strong&gt;*&lt;/strong&gt;&lt;br&gt;
              &lt;input type="text" autofocus required size="48" name="location" value=""&gt;&lt;/label&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;SSN&lt;strong&gt;*&lt;/strong&gt;&lt;br&gt;
              &lt;input type="text" autofocus required size="48" name="ssn" value=""&gt;&lt;/label&gt;&lt;/p&gt;
              &lt;p&gt;&lt;input type="submit" name="feedbackForm" value="Add Patient"&gt;&lt;/p&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;script src="@Url.Content("~/Scripts/PatientFormModal.js")" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>This is the javascript where "wrapper is used"</p>
  
  <pre><code>var modal_init = function () {
      var wrapper = document.getElementById("modal_content");
      var window = document.getElementById("modal_window");
  
      var openModal = function (e) {
          wrapper.className = "overlay";
          window.style.marginTop = (-modal_window.offsetHeight) / 2 + "px";
          window.style.marginLeft = (-modal_window.offsetWidth) / 2 + "px";
          e.preventDefault ? e.preventDefault() : e.returnValue = false;
      };
  
      var closeModal = function (e) {
          wrapper.className = "";
          e.preventDefault ? e.preventDefault() : e.returnValue = false;
      };
  
      var clickHandler = function (e) {
          if (!e.target) e.target = e.srcElement;
          if (e.target.tagName == "DIV") {
              if (e.target.id != "modal_window") closeModal(e);
          }
      };
  
      var keyHandler = function (e) {
          if (e.keyCode == 27) closeModal(e);
      };
  
      if (document.addEventListener) {
          document.getElementById("NewPatient").addEventListener("click", openModal, false);
          document.getElementById("modal_close").addEventListener("click", closeModal, false);
          document.addEventListener("click", clickHandler, false);
          document.addEventListener("keydown", keyHandler, false);
      } else {
          document.getElementById("NewPatient").attachEvent("onclick", openModal);
          document.getElementById("modal_close").attachEvent("onclick", closeModal);
          document.attachEvent("onclick", clickHandler);
          document.attachEvent("onkeydown", keyHandler);
      }
  };
  </code></pre>