  function item(_id,_field1,_field2) {
    this.id = _id;
    this.fields = new Array(_field1, _field2);
  }

  var items = new Array(106);


  items[0] = new item(7,"BIOI","Bioinformatics");
  items[1] = new item(8,"BIOL","Biology");
  items[2] = new item(10,"BLST","Black Studies");
  items[3] = new item(11,"CHEM","Chemistry");
  items[4] = new item(12,"ECON","Economics");
  items[5] = new item(14,"ENGL","English");
  items[6] = new item(16,"FREN","French");
  items[7] = new item(18,"GEOG","Geography");
  items[8] = new item(19,"GEOL","Geology");
  items[9] = new item(20,"GERM","German");
  items[10] = new item(21,"HIST","History");
  items[11] = new item(23,"INST","International Studies and Programs");
  items[12] = new item(24,"LLS","Latino/Latin American Studies");
  items[13] = new item(25,"MATH","Mathematics");
  items[14] = new item(26,"PHIL","Philosophy");
  items[15] = new item(27,"PHYS","Physics");
  items[16] = new item(28,"PSCI","Political Science");
  items[17] = new item(29,"PSYC","Psychology");
  items[18] = new item(30,"RELI","Religion");
  items[19] = new item(31,"SOC","Sociology");
  items[20] = new item(32,"SPAN","Spanish");
  items[21] = new item(123,"AERO","Aerospace Studies");
  items[22] = new item(52,"BRCT","Broadcasting");
  items[23] = new item(53,"JOUR","Journalism");
  items[24] = new item(54,"SPCH","Speech");
  items[25] = new item(71,"MUS","Music");
  items[26] = new item(73,"THEA","Theatre (was Dramatic Arts prior to Fall-02)");
  items[27] = new item(75,"AVN","Aviation Institute");
  items[28] = new item(78,"GERO","Gerontology");
  items[29] = new item(79,"ART","Art and Art History");
  items[30] = new item(82,"CSCI","Computer Science");
  items[31] = new item(83,"CJUS","Criminal Justice");
  items[32] = new item(94,"RLS","Recreation & Leisure Studies");
  items[33] = new item(95,"UBNS","Urban Studies");
  items[34] = new item(104,"FSCI","Food Science and Technology");
  items[35] = new item(108,"FPT","Fire Protection Technology");
  items[36] = new item(109,"CNST","Construction Management");
  items[37] = new item(110,"AE","Architectural Engineering");
  items[38] = new item(111,"CIVE","Civil Engineering");
  items[39] = new item(113,"CONE","Construction Engineering");
  items[40] = new item(117,"ELEC","Electrical Engineering");
  items[41] = new item(118,"ISMG","Industrial & Management Systems Engineering");
  items[42] = new item(119,"MENG","Mechanical Engineering");
  items[43] = new item(121,"CIST","College of IST Core Courses");
  items[44] = new item(122,"ISQA","Information Systems & Quantitative Analysis");
  items[45] = new item(281,"US","University Seminar");
  items[46] = new item(280,"TXCD","Textiles and Clothing Design");
  items[47] = new item(279,"TED","Teacher Education");
  items[48] = new item(278,"STAT","Statistics");
  items[49] = new item(277,"SPED","Special Education & Comm. Disorders");
  items[50] = new item(276,"SOWK","Social Work");
  items[51] = new item(275,"RUSS","Russian");
  items[52] = new item(274,"RELU","Real Estate & Land Use");
  items[53] = new item(273,"PA","Public Administration");
  items[54] = new item(272,"PE","Professional Physical Education");
  items[55] = new item(271,"PEA","Physical Education Service Program");
  items[56] = new item(270,"NUTR","Nutritional Science & Dietetics");
  items[57] = new item(269,"NWST","New Start");
  items[58] = new item(268,"NSCI","Natural Sciences");
  items[59] = new item(267,"NAMS","Native American Studies");
  items[60] = new item(266,"MILS","Military Sciences");
  items[61] = new item(265,"METE","Metallurgical Engineering");
  items[62] = new item(264,"MFAW","Master Fine Arts Writing");
  items[63] = new item(263,"MKT","Marketing");
  items[64] = new item(262,"MGMT","Management");
  items[65] = new item(261,"LIB","Library");
  items[66] = new item(260,"LAWS","Law and Society");
  items[67] = new item(259,"JAPN","Japanese");
  items[68] = new item(258,"ITAL","Italian");
  items[69] = new item(257,"MIB","International Business");
  items[70] = new item(256,"IDSG","Interior Design");
  items[71] = new item(255,"IST","Industrial Systems Technology");
  items[72] = new item(254,"HRFS","Human Resources and Family Sciences");
  items[73] = new item(253,"HORT","Horticulture");
  items[74] = new item(252,"HONR","Honors Program");
  items[75] = new item(251,"HEBR","Hebrew");
  items[76] = new item(250,"HPER","Health, Physical Education & Recreation");
  items[77] = new item(249,"HED","Health Education");
  items[78] = new item(248,"GDRH","Goodrich Program");
  items[79] = new item(247,"GET","General Engineering Technology");
  items[80] = new item(246,"FLNG","Foreign Language");
  items[81] = new item(245,"FINA","Fine Arts");
  items[82] = new item(244,"FNBK","Finance and Banking");
  items[83] = new item(243,"FMCS","Family and Consumer Sciences");
  items[84] = new item(242,"ENVE","Environmental Engineering");
  items[85] = new item(241,"EMEC","Engineering Mechanics");
  items[86] = new item(240,"ENGR","Engineering");
  items[87] = new item(239,"EET","Electronics Engineering Technology");
  items[88] = new item(238,"EDUC","Education Professional Sequence");
  items[89] = new item(237,"EDAD","Education Administration and Supervision");
  items[90] = new item(236,"DARI","DARI");
  items[91] = new item(235,"COUN","Counseling");
  items[92] = new item(234,"COOP","Cooperative Education");
  items[93] = new item(233,"CET","Construction Engineering Technology");
  items[94] = new item(232,"CEEN","Computer and Electronics Engineering");
  items[95] = new item(231,"CRP","Community and Regional Planning");
  items[96] = new item(230,"COMM","Communication");
  items[97] = new item(229,"CHIN","Chinese");
  items[98] = new item(228,"CHME","Chemical Engineering");
  items[99] = new item(227,"BSAD","Business Administration");
  items[100] = new item(226,"ARCH","Architecture");
  items[101] = new item(225,"ANTH","Anthropology");
  items[102] = new item(282,"ACCT","Accounting");
  items[103] = new item(283,"CYAF","Child, Youth, and Family Science");
  items[104] = new item(284,"WMST","Womens Studies");
  items[105] = new item(285,"IASC","Information Assurance");
function itemMatch(_index,_type,_strstr,_strlen) {
  this.matchIndex = _index;
  this.matchType = _type;
  this.matchStrStr = _strstr;
  this.matchStrLen = _strlen;
}

function autoCompleteDepartments() {
  $('autoCompleteDisplay').innerHTML = '';

  if($('autoCompleteInput').value.length < 2)
    return;

  tempArray = new Array();
  searchTerms = $('autoCompleteInput').value;

  ftsearch(tempArray,items,2,searchTerms);

  for(x = 0; x < tempArray.length && x < 10; x++) { // the && x < \d+ lets us limit results
      tempItem = items[tempArray[x].matchIndex];
      tempStrStr = tempArray[x].matchStrStr;
      tempStrLen = tempArray[x].matchStrLen;

      classType = "odd";
      if(x % 2 == 0)
        classType = "even";

      if(tempArray[x].matchType == 1) {
        tempString = '<a href="create/review/alt/2/'+tempItem.id+'" class="list '+classType+'">'+tempItem.fields[0]+' - ';
        tempString += tempItem.fields[1].slice(0,tempStrStr);
        tempString += '<u>';
        tempString += tempItem.fields[1].slice(tempStrStr,tempStrStr+tempStrLen);
        tempString += '</u>';
        tempString += tempItem.fields[1].slice(tempStrStr+tempStrLen,tempItem.fields[1].length)+'</a>';
      }
      else {
        tempString = '<a href="create/review/alt/2/'+tempItem.id+'" class="list '+classType+'">'+tempItem.fields[0].slice(0,tempStrStr);
        tempString += '<u>';
        tempString += tempItem.fields[0].slice(tempStrStr,tempStrStr+tempStrLen);
        tempString += '</u>';
        tempString += tempItem.fields[0].slice(tempStrStr+tempStrLen,tempItem.fields[0].length)
        tempString += ' - '+tempItem.fields[1]+'</a>';
      }
      $('autoCompleteDisplay').innerHTML += tempString;
  }
}

function ftsearch(returnArray,inputArray,fields,searchTerms) {

  for(x = 0; x < inputArray.length; x++) {
    for(y = 0; y < fields; y++) {
      tempIndex = inputArray[x].fields[y].toLowerCase().indexOf(searchTerms.toLowerCase());
      if(tempIndex != -1) {
        returnArray.push(new itemMatch(x,y,tempIndex,searchTerms.length));
      }
    }
  }

  searchTerms = searchTerms.split(" ");
  for(j = 0; j < searchTerms.length; j++) {
    if(searchTerms[j] == '')
      continue;

    for(x = 0; x < inputArray.length; x++) {
      for(y = 0; y < fields; y++) {
        tempIndex = inputArray[x].fields[y].toLowerCase().indexOf(searchTerms[j].toLowerCase());
        if(tempIndex != -1) {
          returnArray.push(new itemMatch(x,y,tempIndex,searchTerms[j].length));
        }
      }
    }

  }

	if(returnArray.length > 0 ) {

	  returnArray.sort(sortMatches);
	
	  // Remove dupes
	  for(x = 0; x < returnArray.length; x++) {
	    for(y = x+1; y < returnArray.length; y++) {
	      if(returnArray[x].matchIndex == returnArray[y].matchIndex) {
	        returnArray.splice(y,1);
	      }
	    }
	  }
	}

}

function sortMatches(a, b) {
	a = a.matchStrStr-a.matchStrLen;
	b = b.matchStrStr-b.matchStrLen;
	return a - b;
}

function clearACD() {
  acdElement = $('autoCompleteInput');
  if(acdElement.value == 'Enter Department Name Here (ex. CSCI)') {
    acdElement.style.color = '#000000';
    acdElement.value = '';
  }
  else if(acdElement.value == '') {
    acdElement.style.color = '#888888';
    acdElement.value = 'Enter Department Name Here (ex. CSCI)';
  }
}

