var lang=[
  // English
  [
    // Edit Fields
    ["Course",
     "Instructor",
     "Room",
     "Start Time",
     "End Time",
     "Credits",
     "Select Course...",
     "Delete",
     "Add Course"],
    
    // Labels
    ["Courses", 
     "Fields",
     "Show Fields",
     "Day Acronyms",
     "Days"],
    
    // Weekdays
    ["Sunday",
     "Monday",
     "Tuesday",
     "Wednesday",
     "Thursday",
     "Friday",
     "Saturday"],
    
    // Week acronyms
    ["U",
     "M",
     "T",
     "W",
     "R",
     "F",
     "S"],
    
    // Tabs
    ["Edit Fields",
     "Format",
     "Preview",
     "File Menu"],
    
    // Fields
    ["Course Name",
     "Instructor",
     "Time",
     "Days",
     "Room",
     "Credits"],
    
    // Buttons
    ["New",
     "Save",
     "Save As...",
     "Load...",
     "Manage...",
     "Export...",
     "OK",
     "Yes",
     "No",
     "Cancel",
     "Change Name",
     "Change Password",
     "File Info",
     "Load",
     "Select All",
     "Select None",
     "Invert Selection",
     "Delete",
     "Copy",
     "Merge",
     "Export List",
     "Export Schedule"],
    
    // Save As
    ["File Name",
     "File Password",
     "Password Protect"],
    
    // Load
    ["There are no files saved.",
     " is password protected.",
     " was last saved",
     "It contains ",
     " courses.",
     "Enter the password for ",
     " to continue.",
     "That password is incorrect.",
     "Enter the new name.",
     "Enter the new password."],
     
    // Management
    ["There are no files saved.",
     "Are you sure you would like to <strong>delete<\/strong> the selected files?",
     "Are you sure you would like to <strong>copy<\/strong> the selected files?",
     "Are you sure you would like to <strong>merge<\/strong> the selected files?",
     "You cannot merge files that are password protected."],
     
   // Misc
   ["New Course",
    "Untitled Schedule",
    "There are no courses entered.",
    true] // Use 24 hour clock?
  ]
];

var langObj={
  currentLanguage:0,
  
  changeLang:function(r) {
    
    var cLang = lang[r], t = null, i = 0;
    fSystem.dateObj.is12Hour = cLang[10][3];
    data.set('lang', r);
    this.currentLanguage = r;
    
    // Tabs
    t = g('nav').getElementsByTagName('a');
    for (i=0; i<cLang[4].length; i++) {
      t[i].innerHTML = cLang[4][i];
    }
    
    // Edit Fields
    t = g('editFields').getElementsByTagName('label');
    t[0].innerHTML = cLang[0][0];
    t[1].innerHTML = cLang[0][1];
    t[2].innerHTML = cLang[0][2];
    t[3].innerHTML = cLang[0][3];
    t[4].innerHTML = cLang[0][4];
    t[5].innerHTML = cLang[0][5];
    g('courseNames').getElementsByTagName('option')[0].text = cLang[0][6];
    g('_EDITFIELDS_Delete').value = cLang[0][7];
    g('_EDITFIELDS_AddCourse').value = cLang[0][8];
    
    t = g('editFields').getElementsByTagName('fieldset')[0].getElementsByTagName('span');
    for (i=0; i<t.length; i++) {
      t[i].innerHTML = cLang[2][i];
    }
    t = g('dAcrContainer').getElementsByTagName('label');
    for (i=0; i<t.length; i++) {
      t[i].innerHTML = cLang[2][i];
    }
    fSystem.dateObj.weekdays = [].concat(cLang[2]);
    fSystem.dateObj.weekAcr = [].concat(cLang[3]);
    g('editFields').getElementsByTagName('legend')[0].innerHTML = cLang[1][4];
    
    // Format
    g('classSelect').getElementsByTagName('optgroup')[0].label = cLang[1][0];
    g('sortSelect').getElementsByTagName('optgroup')[0].label = cLang[1][1];
    g('showFieldsFieldset').getElementsByTagName('legend')[0].innerHTML = cLang[1][2];
    g('dAcrContainer').parentNode.getElementsByTagName('legend')[0].innerHTML = cLang[1][3];
    
    // Fields
    for (i=0; i<cLang[5].length; i++) {
      g('showFieldsFieldset').getElementsByTagName('span')[i].innerHTML = cLang[5][i];
    }
    pView.pNames = [].concat(cLang[5]);
    
    t = g('showFieldsFieldset').getElementsByTagName('input');
    for (i=0; i<t.length; i++) {
      g('sortSelect').getElementsByTagName('option')[parseInt(t[i].value)].text = pView.pOrder[parseInt(t[i].value)] = cLang[5][i];
    }
    
    // Button text
    t = g('mainMenu').getElementsByTagName('input');
    for (i=0; i<t.length; i++) {
      t[i].value = cLang[6][i];
    }
    g('_LOAD_okFileInfo').value = g('_LOAD_okPassFail').value = g('_LOAD_okNewName').value = g('_LOAD_okNewPass').value = g('_MANAGE_noMerge').value = cLang[6][6];
    g('_MANAGE_okPrompt').value = cLang[6][7];
    g('_MANAGE_noPrompt').value = cLang[6][8];
    
    // Load buttons
    t = g('_LOAD_buttonContainer').getElementsByTagName('input');
    t[t.length-1].value = cLang[6][9];
    for (i=0; i<t.length-1; i++) {
      t[i].value = cLang[6][i+10];
    }
    
    // Manage buttons
    t = g('_MANAGE_buttonContainer').getElementsByTagName('input');
    t[t.length-1].value = cLang[6][9];
    for (i=0; i<t.length-1; i++) {
      t[i].value = cLang[6][i+14];
    }
    
    // Save buttons
    t = g('saveMenu').getElementsByTagName('label');
    for (i=0; i<t.length; i++) {
      t[i].innerHTML = cLang[7][i];
    }
    g('_SAVE_buttonContainer').getElementsByTagName('input')[0].value = cLang[6][1];
    g('_SAVE_buttonContainer').getElementsByTagName('input')[1].value = cLang[6][9];
    
    // Blank all Q
    t = document.getElementsByTagName('q');
    for (i=0; i<t.length; i++) {
      t[i].innerHTML = "";
    }
    
    // Load dialogs
    g('_LOAD_emptyStack').innerHTML = cLang[8][0];
    t = g('_LOAD_infoBox').getElementsByTagName('span');
    t[0].innerHTML = cLang[8][1];
    t[1].innerHTML = cLang[8][2];
    t[3].innerHTML = cLang[8][3];
    t[5].innerHTML = cLang[8][4];
    t = g('_LOAD_enterPassword').getElementsByTagName('span');
    t[0].innerHTML = cLang[8][5];
    t[1].innerHTML = cLang[8][6];
    g('_LOAD_passwordFail').getElementsByTagName('div')[0].innerHTML = cLang[8][7];
    g('_LOAD_newFileName').getElementsByTagName('span')[0].innerHTML = cLang[8][8];
    g('_LOAD_newPassword').getElementsByTagName('span')[0].innerHTML = cLang[8][9];
    
    // Management dialogs
    g('_MANAGE_emptyStack').innerHTML = cLang[9][0];
    g('_MANAGE_deletePrompt').innerHTML = cLang[9][1];
    g('_MANAGE_copyPrompt').innerHTML = cLang[9][2];
    g('_MANAGE_mergePrompt').innerHTML = cLang[9][3];
    g('_MANAGE_noMergePrompt').getElementsByTagName('div')[0].innerHTML = cLang[9][4];
    
    // Export buttons
    t = g('exportMenu').getElementsByTagName('input');
    t[0].value = cLang[6][20];
    t[1].value = cLang[6][21];
    t[2].value = cLang[6][9];
  }
};