function setField(selector, text) {
  if (text == "") {
    $(selector).parent("tr").hide();
  }
  else {
    $(selector).text(text);
  }
}

$(document).ready(function() {
  key = window.location.search.substring(1);
  officer = officers[key];

  if (officer == null) {
    return;
  }

  loc = locations[officer["location"]];

  $("#section").text(loc.name);

  if (officer.photo == "") {
    $("#profile img").hide();
  }
  else {
    $("#profile img")[0].src = officer.photo;
  }

  jQuery.each(["name", "title2", "title", "phone", "cell", "fax", "pager", "efax", "tollfree", "homefax"], function() {
    selector = "#" + this;

    if (officer[this] == "") {
      $(selector).parent("tr").remove();
    }
    else {
      $(selector).text(officer[this]);
    }
  });

  if ($("#phone2")) {
    $("#phone2").text(officer.phone);
  }

  $("#email").attr("href", "mailto:" + officer.email);

  $("#loanapp").attr("href", "https://www.bfsmortgage.com/loanapp/bfs-" + key + "/controlServlet"); 

  if (officer.bio == "") {
    $("#bio").hide();
  }
  else {
    $("#bio").attr("href", "bios/" + key + ".html");
  }

  addr = loc.address
  if (loc.address2 != "") {
    addr += "<br/> " + loc.address2;
  }
  addr += "<br/>" + loc.city + ", " + loc.state + " " + loc.zip;
  
  $("#address").html(addr);

  $("#profile").show();

  $("#apply").click(function() {
    $("#first").hide();
    $("#jump").show();
  });
});
