function pbgWindows(gid) {
   this.gid = gid;
   this.newWindowArray = new Array();
}

pbgWindows.prototype.doCreateWork = function(winPtr, strPageToOpen, winName, features) {
   winPtr.winObj = window.open(strPageToOpen, winName, features);
   winPtr.winName = winName;
   winPtr.features = features;
}

pbgWindows.prototype.createWindow = function(strPageToOpen, winName, features) {
   // See if we have an entry in the array with this window name
   var i;
   for (i=0; i < this.newWindowArray.length; i++) {
      if (this.newWindowArray[i].winName == winName)
         break;
   }
   // If we dropped out of the loop (meaning we don't have any window with this name),
   // then create it at the end of the array (arrayLen will be the next element).
   if (i == this.newWindowArray.length) {
      this.newWindowArray[i] = new Object();
      this.doCreateWork(this.newWindowArray[i], strPageToOpen, winName, features);
   }
   // If the previously existing window with this name is not open, open a new window for it
   else if (!this.newWindowArray[i].winObj || this.newWindowArray[i].winObj.closed) {
      this.doCreateWork(this.newWindowArray[i], strPageToOpen, winName, features);
   }
   // The window with this name is open, go to the new page and refocus
   else {
      // Make sure the feature string is the same as before.
      // If not, close the existing window and open a new one.
      if (!this.newWindowArray[i].features || this.newWindowArray[i].features != features) {
         this.newWindowArray[i].winObj.close();
         this.doCreateWork(this.newWindowArray[i], strPageToOpen, winName, features);
      }
      else
         // Window has the same name and features, so just update the location.
         this.newWindowArray[i].winObj.location.href = strPageToOpen;
   }
   // Set focus to the newly referenced window and return it.
   this.newWindowArray[i].winObj.focus();
   return this.newWindowArray[i].winObj;
}

pbgWindows.prototype.createFullWindow = function(strPageToOpen) {
   return this.createWindow(strPageToOpen,
                               'win' + this.gid,
                               'status=yes,toolbar=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,width=700,height=700,top=20,left=20,screenX=20,screenY=20');
}

pbgWindows.prototype.createPopupWindow = function(strPageToOpen) {
   return this.createWindow(strPageToOpen,
                               'win' + this.gid,
                               'status=yes,toolbar=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,width=700,height=700,top=20,left=20,screenX=20,screenY=20');
}

pbgWindows.prototype.createSimplePopupWindow = function(strPageToOpen) {
   return this.createWindow(strPageToOpen,
                               'win' + this.gid,
                               'status=no,toolbar=no,location=no,menubar=no,resizable=yes,scrollbars=yes,width=700,height=700,top=20,left=20,screenX=20,screenY=20');
}

