var popup = {

  stackView: [],

  openPopup: function (pid, target) {
    common.changeVal($(target));
    var id = common.getId($(target));

    var d = {
      targetId: id
    };

    this.stackView.push(d);

    $("#main").hide();
    $("#popup div.container").hide();
    $("#popup div." + pid).show();

  },
  closePopup: function (pid) {

    var d = this.stackView.pop();

    if (d == undefined) {
      $("#main").show();
      return;
    }

    $("#popup div." + pid).hide();

    var target = $("#" + d.targetId);
    if (this.stackView.length == 0) {
      $("#main").show();
    } else {
      $(target).closest(".container").show();
    }
    //$(target).focus();
    return target;
  }

}
