BDG Scenario 3

Person.js

window.onload = window_onLoad;

function window_onLoad() {
   var win = parent.frames("LEFTPANE").window;
   if (win && win.document.readyState == "complete")
      win.selectFirst();
}

function load(id) {
   if (isDirty) location.reload(); // force page reload
   else {
      var xml = '../Scripts/viewData.asp?tableName=person&whereID=' + id
      xmldso.XMLDocument.ondataavailable = loaded;
      xmldso.XMLDocument.load(xml);
   }
}

var chks = new Array("chkReleaseFirstName","chkReleaseLastName",
                     "chkReleaseIDNumber","chkReleaseEmailName",
                     "chkReleaseTelephone","chkReleaseStreet",
                     "chkReleaseCity","chkReleaseRegion",
                     "chkReleasePostalCode","chkReleaseCountry",
                     "chkReleaseContactFullName","chkReleaseContactTelephone",
                     "chkReleaseContactRelationship");

// For each "1" in the ReleaseInfo bitmap, check the associated checkbox
function setInfo() {
   if (PersonRecord.readyState == 'complete') {
      var info = document.frmPerson.ReleaseInfo.value;
      for (var i=0; i<info.length; i++) {
         document.all(chks[i]).checked = (info.substr(i,1)=="1"?true:false);
      }
   }
}

// copy checkbox state back into ReleaseInfo field
function updateInfo() {
   var info = "";
   for (var i=0; i<chks.length; i++) {
      info = info + (document.all(chks[i]).checked?"1":"0");
   }
   document.frmPerson.ReleaseInfo.value = info;
}

// called when XML data has been fully loaded
function loaded() {
   var col;
   if (col = document.all.tags('BUTTON')) {
      for (var i=0; i < col.length; i++) {
         col[i].disabled = false;
      }
   }
   PersonRecord.onreadystatechange = setInfo;
   clearDirty();
}

// called when Submit button is pressed
function update() {
   var theForm = document.frmPerson;
   if(validateForm(theForm)){
      if (theForm.PersonId.value.length == 0) {
         theForm.procName.value = "lw_addPerson";
         theForm.actionBtn.value = "ADD";
      }
      updateInfo();
      clearDirty();
      return true;
   }
   else
      return false;
}

function remove() {
   var theForm = document.frmPerson;
   if (theForm.PersonId.value.length != 0) {
      if (confirm(L_ConfirmDelete)) {
         theForm.procName.value = "lw_deletePerson";
         theForm.actionBtn.value = "DELETE";
         theForm.submit();
      }
   }
}

function refresh() {
   var col;
   if (col = document.all.tags('BUTTON')) {
      for (var i=0; i < col.length; i++) {
         if (col[i] != frmPerson.cmdSubmit)
            col[i].disabled = true;
      }
   }
   clearDirty();
}

function viewSchedule() {
   var id = document.frmPerson.PersonId.value;
   if (id != "")
      top.location.href = "gate.asp?fileName=personGroup&pid=" + id;
}

// called from IFRAME script returned by DB action
function updateView(actn,id) {
   switch (actn) {
   case 'ADD': 
      // set new ID in form
      document.frmPerson.elements("ID").value = id;
      document.frmPerson.PersonId.value = id;
      // return form to "CHANGE" mode
      document.frmPerson.actionBtn.value = "CHANGE";
      document.frmPerson.procName.value = "lw_changePerson";
      parent.frames("LEFTPANE").reloadList(id);
      loaded();
      break;
   case 'DELETE': 
      document.frmPerson.reset();
      parent.frames("LEFTPANE").reloadList(null);
      break;
   case 'CHANGE': 
      parent.frames("LEFTPANE").reloadList(id);
      break;
   }
}