BDG Scenario 3

Group.js

window.onload = window_onLoad;

function window_onLoad() {
   var xmldoc = xmldso_loc.XMLDocument;
   xmldoc.ondataavailable = updateLoc;
   xmldoc.load('../Scripts/viewData.asp?tableName=location&fieldList=LocationId,Name,MaxOccupancy&sortBy=Name');
   xmldoc = xmldso_gs.XMLDocument;
   xmldoc.ondataavailable=updateGS;
   xmldoc.load('../Scripts/viewData.asp?tableName=gradeScale&sortBy=Name');
   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=group&whereID=' + id;
      xmldso.XMLDocument.ondataavailable = loaded;
      xmldso.XMLDocument.load(xml);
   }
}

var chks = new Array("chkMeetingDays0","chkMeetingDays1",
                     "chkMeetingDays2","chkMeetingDays3",
                     "chkMeetingDays4","chkMeetingDays5",
                     "chkMeetingDays6");

// For each "1" in the ReleaseInfo bitmap, check the associated checkbox
function setInfo() {
   if (GroupRecord.readyState == 'complete') {
      var info = document.frmGroup.MeetingDays.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.frmGroup.MeetingDays.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;
      }
   }
   GroupRecord.onreadystatechange = setInfo;
   clearDirty();
}

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

function remove() {
   var theForm = document.frmGroup;
   if (theForm.GroupId.value.length != 0) {
      if (confirm(L_ConfirmDelete)) {
         theForm.procName.value = "lw_deleteGroup";
         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] != frmGroup.cmdSubmit)
            col[i].disabled = true;
      }
   }
   clearDirty();
}

function updateLoc() {
   copyToSel(xmldso_loc.XMLDocument.documentElement,document.frmGroup.LocationId);
}

function updateGS() {
   copyToSel(xmldso_gs.XMLDocument.documentElement,document.frmGroup.GradeScaleId1);
   copyToSel(xmldso_gs.XMLDocument.documentElement,document.frmGroup.GradeScaleId2);
}

// Copy values from XML nodes into SELECT tag
// (NOTE: This routine is used by multiple recordsets.)
function copyToSel(xmldoc,sel) {
   var record,node,id,name,size,opt;
   if (xmldoc) {
      record = xmldoc.firstChild;
      while (record != null) {
         size = null;
         node = record.firstChild;
         while (node != null) {
            // copy values from node into variables
            switch (node.nodeName) {
               case 'LocationId':   id = node.text; break;
               case 'GradeScaleId': id = node.text; break;
               case 'Name':         name = node.text; break;
               case 'MaxOccupancy': size = node.text; break;
            }
            node = node.nextSibling;
         }
         if (size) name = name + ' (' + size + ')';
         opt = document.createElement("OPTION");
         opt.value = id;
         opt.text = name;
         sel.options.add(opt);
         record = record.nextSibling;
      }
   }
}

function checkOccupancy() {
   var maxSize = document.frmGroup.MaxSize.value;
   var sel = document.frmGroup.LocationId;
   var id = sel.options[sel.selectedIndex].value;
   var record = xmldso_loc.XMLDocument.nodeFromID('_'+id);
   var node = record.selectSingleNode("./MaxOccupancy"); // '.' == from current
   var maxOccupancy = new Number(node.text);
   if (maxSize > maxOccupancy) {
      document.frmGroup.MaxSize.value = maxOccupancy;
      alert(L_MaxSizeExceeded);
   }
   setDirty();
}

function viewMembership() {
   var id = document.frmGroup.GroupId.value;
   if (id != "")
      top.location.href = "gate.asp?fileName=person&id=" + id;
}

function viewActivityList() {
   var id = document.frmGroup.GroupId.value;
   if (id != "")
      top.location.href = "gate.asp?fileName=activity&id=" + id;
}

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

function checkDate() {
   var theForm = document.frmGroup;
   // Not checks if EndDate is not filled in
   if(theForm.EndDate.value=="") return;
   
   if (Date.parse(theForm.BeginDate.value)) {
      var startDate = new Date(theForm.BeginDate.value);
      if (Date.parse(theForm.EndDate.value)) {
         var endDate = new Date(theForm.EndDate.value);
         if (startDate > endDate) {
            // swap date values
            var temp = theForm.BeginDate.value
            theForm.BeginDate.value = theForm.EndDate.value;
            theForm.EndDate.value = temp;
         }
         return true;
      }
   }
   return false;
}

function checkTime() {
   var theForm = document.frmGroup;
   
   //Not checks if Begin Date is not filled in
   if(theForm.EndTime.value=="") return;
   
   // Full date must be used if comparing time. Since it is required, use BeginDate
   var timeValue = theForm.BeginDate.value + ' ' + theForm.BeginTime.value;
   if (Date.parse(timeValue)) {
      var startTime = new Date(timeValue);
      timeValue = theForm.BeginDate.value + ' ' + theForm.EndTime.value;
      if (Date.parse(timeValue)) {
         var endTime = new Date(timeValue);
         if (startTime > endTime) {
            // swap time values
            var temp = theForm.BeginTime.value
            theForm.BeginTime.value = theForm.EndTime.value;
            theForm.EndTime.value = temp;
         }
         return true;
      }
   }
   return false;
}