/*** Format Window ***/
var sorter={
  dAcr:['U', 'M', 'T', 'W', 'R', 'F', 'S'],  // Day acronyms
  
  moveUp:function(selID) {
    var k = g(selID).selectedIndex;
    if (k<=0) {return;} // Can't move up
    this.swapOption(selID, k, k-1);
    
    // Update cFile
    if (selID == 'classSelect') {
      this.swapOption('courseNamesOpt', k, k-1);
      this.updateCFile(k, k-1);
      cFile.changeCourse();
    }
    else {
      this.updatePOrder();
      pView.updateShowValues();
    }
  },
  
  moveDown:function(selID) {
    var k = g(selID).selectedIndex;
    if (k >= g(selID).getElementsByTagName('option').length-1 || k<0) {return;} // Can't move down
    this.swapOption(selID, k, k+1);
    
    // Update cFile
    if (selID == 'classSelect') {
      this.swapOption('courseNamesOpt', k, k+1);
      this.updateCFile(k, k+1);
      cFile.changeCourse();
    }
    else {
      this.updatePOrder();
      pView.updateShowValues();
    }
  },
  
  // Course order changes
  updateCFile:function(y, z) {
    cFile.courseName.swap(y, z);
    cFile.instructor.swap(y, z);
    cFile.roomNumber.swap(y, z);
    cFile.startTime.swap(y, z);
    cFile.endTime.swap(y, z);
    cFile.days.swap(y, z);
    cFile.credits.swap(y, z);
  },
  
  // Swap the text in two <OPTION>
  swapOption:function(selID, y, z) {
    var temp = g(selID).getElementsByTagName('option')[y].text+"";
    g(selID).getElementsByTagName('option')[y].text = g(selID).getElementsByTagName('option')[z].text;
    g(selID).getElementsByTagName('option')[z].text = temp;
    g(selID).selectedIndex=z;
  },
  
  // Day Acronym change
  updatedAcr:function() {
    var t = g('dAcrContainer').getElementsByTagName('input');
    this.dAcr = [t[0].value, t[1].value, t[2].value, t[3].value, t[4].value, t[5].value, t[6].value];
  },
  
  updatePOrder:function() {
    var opts = g('sortSelect').getElementsByTagName('optgroup')[0].getElementsByTagName('option');
    for (var i=0; i<opts.length; i++) {
      pView.pOrder[i] = opts[i].text;
    }
  }
};