// javascripts/dynamic_depts.js.erb
var departments = new Array();
  departments.push(new Array(1, "Administrative Computing", 1));
  departments.push(new Array(1, "Athletic Department", 48));
  departments.push(new Array(1, "Beaverton Community Employment Resource Centre", 68));
  departments.push(new Array(1, "Board of Governors", 72));
  departments.push(new Array(1, "Bookstore", 17));
  departments.push(new Array(1, "Budgets and Financial Planning", 64));
  departments.push(new Array(1, "Business and Industry Development Services Management and Computer Training", 56));
  departments.push(new Array(1, "Campus Health Centre", 4));
  departments.push(new Array(1, "Central Scheduling", 40));
  departments.push(new Array(1, "Centre for Academic Excellence and Innovation", 30));
  departments.push(new Array(1, "Centre for Students with Disabilities and Learner Support Centre", 26));
  departments.push(new Array(1, "Chief Operating Officer’s Office", 28));
  departments.push(new Array(1, "Communications and Marketing", 36));
  departments.push(new Array(1, "Continuing Education", 8));
  departments.push(new Array(1, "Corporate Training Services (BIDS)", 44));
  departments.push(new Array(1, "Durham College Admissions and Recruitment", 21));
  departments.push(new Array(1, "Durham College Office of the Registrar", 35));
  departments.push(new Array(1, "Early Learning Centre", 51));
  departments.push(new Array(1, "Facilities Management", 41));
  departments.push(new Array(1, "Facilities Operations", 65));
  departments.push(new Array(1, "Financial Services", 13));
  departments.push(new Array(1, "Food Services", 49));
  departments.push(new Array(1, "Foundation and Advancement", 37));
  departments.push(new Array(1, "Hired Career Services", 2));
  departments.push(new Array(1, "Housekeeping Services", 61));
  departments.push(new Array(1, "Human Resource Development Canada Resource Centre", 46));
  departments.push(new Array(1, "Human Resources - DC", 47));
  departments.push(new Array(1, "Information Technology Services - ITS", 19));
  departments.push(new Array(1, "International Studies", 29));
  departments.push(new Array(1, "Learner Support Centre", 67));
  departments.push(new Array(1, "Learning Resources", 27));
  departments.push(new Array(1, "Mobile Computing and Media Services", 24));
  departments.push(new Array(1, "Office of Institutional Research and Government Relations", 69));
  departments.push(new Array(1, "Payroll and Purchasing", 52));
  departments.push(new Array(1, "Police Learning Centre", 73));
  departments.push(new Array(1, "Port Hope Community Employment Resource Centre", 55));
  departments.push(new Array(1, "Port Perry Community Employment Resource Centre", 58));
  departments.push(new Array(1, "President's Office", 63));
  departments.push(new Array(1, "Print Shop", 57));
  departments.push(new Array(1, "Reception", 45));
  departments.push(new Array(1, "School of Business, IT & Management", 12));
  departments.push(new Array(1, "School of Continuing Education", 25));
  departments.push(new Array(1, "School of Health & Community Services", 7));
  departments.push(new Array(1, "School of Interdisciplinary Studies & Employment Services", 10));
  departments.push(new Array(1, "School of Justice & Emergency Services", 5));
  departments.push(new Array(1, "School of Media, Art & Design", 6));
  departments.push(new Array(1, "School of Science and Engineering Technology (Oshawa Campus)", 9));
  departments.push(new Array(1, "School of Skilled Trades, Apprenticeship & Renewable Technology (Whitby Campus)", 75));
  departments.push(new Array(1, "Security", 70));
  departments.push(new Array(1, "Shipping & Receiving/Mail Services", 15));
  departments.push(new Array(1, "Skills Training Centre", 3));
  departments.push(new Array(1, "Student Centre", 62));
  departments.push(new Array(1, "Student Services - Whitby", 42));
  departments.push(new Array(1, "Student Support Services", 34));
  departments.push(new Array(1, "Technical Services", 18));
  departments.push(new Array(1, "Test Centre", 16));
  departments.push(new Array(1, "The Library", 39));
  departments.push(new Array(1, "Uxbridge Campus", 33));

function institutionSelected() {
  var institution_id = $('user_institution_id').getValue();
  var options = $('user_department_id').options;
	var dept_id = $('user_department_id').getValue(); // preserve the department value during reload (edits, updates)
  options.length = 1;
  departments.each(function(department) {
    if (department[0] == institution_id) {
      options[options.length] = new Option(department[1], department[2], dept_id == department[2]);
    }
  });
  if (options.length == 1) {
    $('department_field').hide();
  } else {
    $('department_field').show();
  }
}

document.observe('dom:loaded', function() {
  institutionSelected();
  $('user_institution_id').observe('change', institutionSelected);
});