var IE = (document.all);
function insertRow(tableObj,tdArray,attr) {
  var lastRow = tableObj.rows.length;
  var newTR = tableObj.insertRow(lastRow)
  for (var i=0; i<tdArray.length;i++) {
    var newTD = newTR.insertCell(i);
/*
    var newText = document.createTextNode(tdArray[i]);
    newTD.appendChild(newText);
*/
    newTD.innerHTML=tdArray[i];
  }
  for (var j=0; j<attr.length; j++)
//    if (IE)
      eval("newTR."+attr[j].split("=>")[0]+"="+attr[j].split("=>")[1]);
/*
    else
      newTR.setAttribute(attr[j].split("=>")[0],attr[j].split("=>")[1]);
*/
}
function getCheckedValue(checkBoxName) {
  var vs="";
  c = document.getElementsByName(checkBoxName);
  l = c.length;
  for (var i=0; i<l; i++) {
    if (c.item(i).checked) vs+=c.item(i).value+",";
  }
  return vs.length==0 ? vs :vs.substr(0,vs.length-1);
}
function getRadio(radioName) {
  c = document.getElementsByName(radioName);
  l = c.length;
  for (var i=0; i<l; i++) {
    if (c.item(i).checked) return c.item(i).value;
  }
  return "";
}
function removeANode(id) {
  $(id).parentNode.removeChild($(id));
}
function getParentAll(parent,parentKey) {
try {
  var id = parent.id;
  while (isEmptyString(id) || id.indexOf(parentKey)==-1) {
    if (parent.tagName && parent.tagName.toLowerCase()=="body") return "";
    parent = parent.parentNode;
    if (!parent) return "";
    id = parent.id;
  }
  return parent;
 } catch (e) {return "";}
}
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the User
}

function $(id) {
  return document.getElementById(id);
}

function getObj(id) {
  return $(id);
}

function isEmptyString(s) {
  if (s==null || trim(s).length==0) return true;
  else return false;
}

function show(element) {
  $(element).style.display="block";
}

function hide(element) {
  if ($(element))
     $(element).style.display="none";
}

function vshow(id) {
  if ($(id))
    $(id).style.visibility="visible";
}

function vhide(id) {
  if ($(id))
  $(id).style.visibility="hidden";
}

function toggleShow(id,defaultStatus) {    // 0:hide, 1 display
  var ret = 0;
  if (!$(id)) return;
  if (defaultStatus==null) defaultStatus=1;
  if ($(id).style.display =="")
    if (defaultStatus==0) {show(id); ret=1}
    else hide(id);
  else
    if ($(id).style.display == "block") hide(id);
    else {show(id); ret=1;}
  return ret;
}

function vtoggleShow(id) {
  if ($(id).style.visibility == "hidden")
    vshow(id);
  else
    vhide(id);
}

function isValidString(s,ValidChars)
{
  if (ValidChars==null) ValidChars = "0123456789abcdefghijklmnopqrstuvwxyz_- ";
  var isValidStringRet=true;
  var Char;
  for (i = 0; i < s.length && isValidStringRet == true; i++)
  {
    Char = s.toLowerCase().charAt(i);
    if (ValidChars.indexOf(Char) == -1)
       isValidStringRet = false;
  }
  return isValidStringRet;

}

function getRandom(size) /* 0-size*/
{return Math.round(Math.random()*(size-1));}


function getRandomByDate() {
  var d = new Date();
  return d.getFullYear().toString()+
         d.getMonth().toString()+
         d.getDate().toString()+
         d.getHours().toString()+
         d.getMinutes().toString()+
         d.getSeconds();
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try
      {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) { xmlhttp = false; }
  }
  @else
    xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try { xmlhttp = new XMLHttpRequest(); }
    catch (e) { xmlhttp = false; }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object

function checkXMLHttpStatus() {
  if (http.readyState!=4) {
    http.abort();
    http = getHTTPObject();
  }
}

function getBrowserInnerSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var ret = new Array();
  ret[0] = myWidth;
  ret[1] = myHeight;
  return ret;
}

function waiting(id) {
  $(id).innerHTML = '<img src=\"/image/loading.gif\">';
}

function indexOfArray(a,s) {
  for (var i=0; i<a.length; i++) {
    if (a[i]==s) return i;
  }
  return -1;
}
function isArray(o) {
   if (o.constructor.toString().toLowerCase().indexOf("array")>-1) return true;
   else return false;
}

function arrayToString(ar,divider) {
 var ret = ar;
 if (isArray(ar)) {
  ret = "";
  for (var i=0; i<ar.length; i++) {
    ret += ar[i] + divider;
  }
  ret = ret.substr(0,ret.length-divider.length);
 }
 return ret;
}
function replaceStr(inStr,oldStr,newStr) {
  // This method is used to match a specifed regular expression(OldStr) against a string(inStr)
  // and replace any match with a new substring(newStr).
  var ret = inStr;
  while (ret.indexOf(oldStr)>-1) {
      ret = ret.replace(oldStr,newStr);
  }
  if (arguments.length>3) {
    for (var i=3; i<arguments.length; i+=2)
      ret = replaceStr(ret, arguments[i], arguments[i+1]);
  }
  return ret;
}


function Util_mod(a, b)
{
	return a - Math.floor(a / b) * b;
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function deleteCookie(name)
{
	var date = new Date();
	date.setTime(date.getTime() - (24 * 60 * 60 * 1000));
	setCookie(name, "", date, null, null, false);
}

function getPrefsArray()
{
	var prefs = new Array();
	var prefCookie = getCookie("my_college_prefs");
	var keysArray = Array();

	if (prefCookie != null)
	{
		var prefPairs = prefCookie.split("&&");

		for (var i = 0; i < prefPairs.length; i++)
		{
			var pairString = prefPairs[i];
			var pairKeyValue = pairString.split("=");

			if (pairKeyValue.length > 0)
			{
				var key = unescape(pairKeyValue[0]);
				var value = unescape(pairKeyValue[1]);
				prefs[key] = value;
				keysArray[keysArray.length] = key;
			}
		}
	}
	prefs["_key"] = keysArray;
	return prefs;
}

function commitPrefs(prefs)
{
	var prefsString = '';
  var keys = prefs["_key"];
  var first = true;

	for (var i = 0; i < keys.length; i++)
	{
		var key = keys[i];
		var value = prefs[key];
		var kvString = stringFormat("{0}={1}", (key), (value));

		if (!first)
			prefsString += "&&";

		prefsString += kvString;
		first = false;
	}

	var expires = new Date();
	expires.setFullYear(expires.getFullYear() + 1);
  setCookie("my_college_prefs", prefsString, expires, "/", null, false);
}

function getPref(key)
{
	var prefs = getPrefsArray();
	return prefs[key];
}

function setPref(key, value)
{
	if (key == null)
		return;

	if (value == null)
		value = '';

	var prefs = getPrefsArray();
	prefs[key] = value;

	// Check if this key is in the keys array;
	var found = false;
	var keys = prefs["_key"];

	for (i = 0; i < keys.length; i++)
	{
		if (keys[i] == key)
		{
			found = true;
			break;
		}
	}

	if (!found)
		keys[keys.length] = key;
	commitPrefs(prefs);
}

function stringFormat()
{
	var count = arguments.length - 1;

	if (count < 0)
	{
		return "";
	}

	var inputString = arguments[0];

	for (var i = 0; i < count; i++)
	{
		var pattern = "\\{" + (i) + "\\}";
		var regex = new RegExp(pattern, "g");
		inputString = inputString.replace(regex, arguments[ ( i + 1 )]);
	}

	return inputString;
}

//-------------------------- index.jsp -------------------------
  var selectedIndex = -1;
  var selectedCount = 0;
  function search_init(c) {
    document.onclick=search_bodyClick;
    Sortable.create('pane', {tag:'div',overlap:'vertical',constraint:'vertical',onUpdate:function(){new Ajax.Updater('', '', {onComplete:function(request){new Effect.Highlight('pane',{});}, parameters:Sortable.serialize('pane'), evalScripts:true, asynchronous:true})}});
    Droppables.add('trash', {accept:'collegeItems', onDrop:function(element){search_remove(element);new Ajax.Updater('', '', {onComplete:function(request){}, parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}, hoverclass:'trash_active'})
    selectedCount = c;
    selectedIndex = -1;
    $("myCount").innerHTML = selectedCount;
    index_resize();
  }
  function index_resize() {
//    $("rightPane").style.width=($("pane").offsetWidth-300)+"px";
/*
    var o = currentHotLink;
    var list = currentHotList;
    if (o!=null && list !=null) {
      var hotListObj = getObj(currentHotList.id.substring(0,currentHotList.id.indexOf("Div")));
      var hotListWidth = hotListObj? hotListObj.offsetWidth : "300";
      list.style.left = (o.parentNode.parentNode.offsetLeft+o.parentNode.offsetLeft+o.offsetLeft+o.offsetWidth-hotListWidth)+"px";
    }
*/
  }
  function search_keyInput(e) {
    e = e ? e : window.event;
    var lo = getObj("list");
    var keyCode = e.keyCode;
    if (keyCode == 40) { // 40 arrow down
      if (lo.length>0) {
        if (selectedIndex>=lo.length-1) selectedIndex=-1;
        lo.options[++selectedIndex].selected=true;
      }
    }
    else if (keyCode == 38) { // 38 arrow up
      if (lo.length>0) {
        if (selectedIndex<=0) selectedIndex=lo.length;
        lo.options[--selectedIndex].selected=true;
      }
    }
    else if (keyCode == 13) { // 13 enter
      if (selectedIndex>-1)
        search_afterSelect();
    }
    else {
      selectedIndex = -1;
      var v = trim(getObj("col").value);
      if (isEmptyString(v)) return;
      if (selectedCount>=9) {alert("Maximum is 9"); return;}
      checkXMLHttpStatus();
      url="collegeSelection.jsp?s="+escape(v);
      http.open("GET", url, true);
      http.onreadystatechange = search_afterGet;
      http.send(null);
    }
  }
function search_addHotColleges(o) {
  selectedIndex = -1;
  var v = o.value ? o.value : o;
  if (isEmptyString(v)) return;
  if (selectedCount>=9) { alert("Maximum is 9"); return;}
  checkXMLHttpStatus();
  url="collegeSelection.jsp?s="+escape(v);
  http.open("GET", url, true);
  http.onreadystatechange = search_afterAddHotColleges;
  http.send(null);
}
function search_afterAddHotColleges() {
  if (http.readyState == 4) {
    var results = http.responseText;
    getObj("collegeSelection").innerHTML = results;
  }
  setTimeout("doAddHotColleges()",100);
}

function doAddHotColleges() {
  if (!getObj("list") || getObj("list").length==0) return;
  var lo = getObj("list").options[0];
  var objs = getObj("pane").childNodes;
  for (var i=0; i<objs.length;i++) {
    var idx = objs[i].id.substring(3);
    var name = getObj("col"+idx).value;
    var id = getObj("id"+idx).value;
    if (!isEmptyString(name) && !isEmptyString(id) && id==lo.value) {
      search_hlight(idx);
      break;
    }
    else if (isEmptyString(id)) {
      search_hlight(idx);
      getObj("label"+idx).innerHTML=lo.text;
      getObj("col"+idx).value=lo.text;
      getObj("id"+idx).value=lo.value;
      selectedCount++;
      getObj("myCount").innerHTML = selectedCount;
      break;
    }
  }
}
  function search_afterSelect() {
    var lo = getObj("list");
    var objs = getObj("pane").childNodes;
    for (var i=0; i<objs.length;i++) {
      var idx = objs[i].id.substring(3);
      var name = getObj("col"+idx).value;
      var id = getObj("id"+idx).value;
      if (!isEmptyString(name) && !isEmptyString(id) && id==lo.value) {
        search_hlight(i);
        getObj("col").value="";
        hide('collegeSelection');
        break;
      }
      else if (isEmptyString(id)) {
        search_hlight(i);
        getObj("label"+i).innerHTML=lo.options[lo.selectedIndex].text;
        getObj("col"+i).value=lo.options[lo.selectedIndex].text;
        getObj("id"+i).value=lo.value;
        getObj("col").value="";
        hide('collegeSelection');
        selectedCount++;
        getObj("myCount").innerHTML = selectedCount;
        break;
      }
    }
    getObj("col").focus();
  }
  function search_listKeyup(e) {
    e = e ? e : window.event;
    var keyCode = e.keyCode;
    if (keyCode == 13) { // 13 enter
      search_afterSelect();
    }
  }
  function search_afterGet() {
    if (http.readyState == 4) {
      var results = http.responseText;
      getObj("collegeSelection").innerHTML = results;
        show("collegeSelection");
    }
  }
  var clearCount;
  var clearTimer;
  function search_clear() {
    getObj("col").value="";
//    var objs = getObj("pane").childNodes;
    clearCount = 0;
    checkXMLHttpStatus();
    url="clear.jsp";
    http.open("GET", url, true);
    http.onreadystatechange = search_doClear;
    http.send(null);
  }
  function search_doClear() {
    try {
    Effect.DropOut("div"+clearCount);
    } catch (e) {}
    clearCount++;
    if (clearCount<9)
      clearTimer = setTimeout("search_doClear()",100);
    else {
      clearTimeout(clearTimer);
      var aLine = "";
      for (var i=0;i<9;i++) {  aLine += search_createItem(i);}
      getObj("pane").innerHTML = aLine;
      search_init(0);
    }
  }
  function search_createItem(i) {
    var aLine="";
    aLine+='<div class="collegeItems" title="drag it to change order" id="div'+i+'">';
    aLine+='<span id="label'+i+'"></span>'
    aLine+='<input type="hidden" name="col" id="col'+i+'">';
    aLine+='<input type="hidden" name="id" id="id'+i+'">';
    aLine+='</div>';
    return aLine;
  }
  function search_remove(element) {
    var idx = element.id.substring(3);
    getObj("label"+idx).innerHTML="";
    getObj("col"+idx).value="";
    getObj("id"+idx).value="";
    selectedCount--;
    getObj("myCount").innerHTML = selectedCount;
  }
  function search_submit() {
    var ids = new Array();
    var names = new Array();
    var objs = getObj("pane").childNodes;
    for (var i=0; i<objs.length;i++) {
      var idx = objs[i].id.substring(3);
      var name = getObj("col"+idx).value;
      var id = getObj("id"+idx).value
      if (!isEmptyString(name) && !isEmptyString(id)) {
        ids[ids.length]=id;
        names[names.length]=name;
      }
    }
    getObj("retIds").value=arrayToString(ids,",");
    getObj("retNames").value=arrayToString(names,"~");
    if (ids.length>0)
      getObj("bodyForm").submit();
  }
  var currentHotList=null;
  var currentHotLink=null;
  var currentDx=0;
  function search_toggleHot(listId,linkId) {
    currentHotLink = getObj(linkId);
    var lastHotList = currentHotList;
    currentHotList = getObj(listId+"Div");
    if (!currentHotList) { if (lastHotList) hide(lastHotList.id); show("histDiv");$("hotCategList").selectedIndex=0;return;}
    if(currentHotList.style.display!='block') {
      var url="hotCollegeList.jsp?id="+listId;
      checkXMLHttpStatus();
      http.open("GET", url, true);
      http.onreadystatechange = function() {
        if (http.readyState == 4) {
          currentHotList.innerHTML = http.responseText;
          search_showHot();
        }
      };
      http.send(null);
    }
  }
  function search_showHot() {
    var selectObj = $("hotCategList");
    for (var i=1;i<=selectObj.length;i++) {
      hide("hot"+i+"Div");
    }
    hide("histDiv");
    show(currentHotList.id);
  }
  function search_bodyClick(e) {
    e = e ? e : window.event;
    var target = e.target ? e.target : e.srcElement;
    getObj('col').value='';
    hide('collegeSelection');
    var notInMajor = true;
    var notInMajorButton = true;
    var tagArray = new Array("span","a","input","label");
    try {
    notInMajor =
          !(!isEmptyString(getParentAll(target,"majorList"))) &&
          !(target.parentNode.tagName.toLowerCase()=="a" && !isEmptyString(getParentAll(target,"myMajor")));
    notInMajorButton =isEmptyString(getParentAll(target,"majorControl"));
    } catch (e) {}
    if ($("subDiv"+lastMajorId) && $("subDiv"+lastMajorId).style.display!="none" && notInMajor) filter_toggleShowSub(lastMajorId,1);
    var hidedCount=0;
/*
    if (getAtarget.id!="hotCategList") {
*/
    if (isEmptyString(getParentAll(target,"hotCategList"))) {
      for (var i=1;i<=$("hotCategList").length;i++) {
        if (isEmptyString(getParentAll(target,"hot"+i))) {
          hide("hot"+i+"Div");
          hidedCount++;
        }
      }
      if (hidedCount==$("hotCategList").length) {show("histDiv");$("hotCategList").selectedIndex=0;}
    }
    if (notInMajor && notInMajorButton) hide("majorList");
  }
  function search_hlight(idx) {
    for (var i=0; i<9; i++) {
      getObj("div"+i).className="collegeItems";
    }
    getObj("div"+idx).className="collegeItems active";
  }
function search_doFilter() {
  for (var i=1;i<=$("hotCategList").length;i++) {
    hide('hot'+i);
  }
  show('histDiv');
  $("hotCategList").selectedIndex=0;
  hide("filterOuterDiv");
  show("filterLoading");
  var url = "filters.jsp?rdm="+new Date().getTime();
  checkXMLHttpStatus();
  http.open("GET", url, true);
  http.onreadystatechange = function() {
    if (http.readyState == 4) {
      $("filterOuterDiv").innerHTML=http.responseText;
      selectedMajors = new Array();
      hide("filterLoading");
      show('filterOuterDiv');
    }
  };
  http.send(null);
}
//-------------------------- end for index.jsp -------------------------
//-------------------------- for filter.jsp -------------------------
var lastMajorId="";
var selectedMajors = new Array();
var majorCollegeTotalPage = 1;
var majorCollegeTotalResult = 0;
var majorCollegeCurrPage = 1;
var allCollege = "";
var displayPages = 1;
var displayOption = 1;
var sortBy = 1;
var sortDir = 1;
var interview = 3;
var campus = 4;
var size = 4;
function filter_toggleShowSub(id,defaultDisplay) {
  var spanId=$("p"+id);
  var divId = "subDiv"+id;
  if (toggleShow(divId,defaultDisplay)) $(spanId).innerHTML = "-";
  else $(spanId).innerHTML = "+";
  if (lastMajorId!="" && lastMajorId!=id) {
    hide("subDiv"+lastMajorId,1);
    $("p"+lastMajorId).innerHTML="+";
  }
  lastMajorId= id;
}
function filter_showSub(id) {
filter_toggleMajorSelection($("majorControl"),true);
var spanId=$("p"+id);
var divId = "subDiv"+id;
show(divId);
$(spanId).innerHTML = "-";
if (lastMajorId!="" && lastMajorId!=id) {
  hide("subDiv"+lastMajorId,1);
  $("p"+lastMajorId).innerHTML="+";
}
lastMajorId= id;
}
function filter_displayControl() {
  toggleShow('collegeListDiv');
  var hideCollege = $('hideCollege');
  var hideFilter = $('hideFilter');
  if (hideCollege.innerHTML.indexOf('Show')==0) {
    hideCollege.innerHTML='Hide [My Colleges]';
    hideFilter.style.visibility="visible";
  }
  else {
    hideCollege.innerHTML='Show [Colleges]';
    hideFilter.style.visibility="hidden";
  }
}
function filter_startGetMajorCol() {
  //reset
  majorCollegeCurrPage = 1;
  majorCollegeTotalPage = 1;
  majorCollegeTotalResult = 0;
  allCollege = "";
  displayPages = $("toplist").value;
  displayOption = $("displayOption").value;
  sortBy = $("sortBy").value;
  sortDir = $("sortDir").value;
  interview = getRadio("iv");
  campus = getCheckedValue("campus");
  size = getCheckedValue("size");
  $("result").innerHTML="<table id=\"cTable\" cellspacing=\"0\" cellpadding=\"0\">";
  $("result").innerHTML+="<tr><td width=\"30\"></td>";
  $("result").innerHTML+="<td>&nbsp;</td><td width=\"100\"></td>";
  $("result").innerHTML+="</tr></table>";
  filter_getMajorCollege();
}
function filter_getMajorCollege() {
  url="filterCollege.jsp?p="+majorCollegeCurrPage+"&size="+escape(size)+"&cmp="+escape(campus)+"&iv="+interview+"&do="+displayOption+"&sb="+sortBy+"&sd="+sortDir+"&x=";
  for (var i=0;i<selectedMajors.length;i++) {
    url+=escape("&csca_list2="+selectedMajors[i]);
  }
  checkXMLHttpStatus();
  http.open("GET", url, true);
  http.onreadystatechange = filter_afterGetMajorCollege;
  http.send(null);
}

function filter_afterGetMajorCollege() {
  if (http.readyState == 4) {
    var results = http.responseText;
    if (results.split("<tr").length==2 && allCollege.length==0)
      $("resultTitle").innerHTML = "0 Match Found";
    else {
      allCollege+=results;
      var w = (100*majorCollegeCurrPage)/displayPages > 100 ? 100 : 100*majorCollegeCurrPage/displayPages;
      $("bar").style.width = w+"%";
      $("tmp").innerHTML = results;
      filter_displayColList();
      if (majorCollegeCurrPage==1 && $("hiddenDiv")) {
        var tmp = $("hiddenDiv").innerHTML.split("-");
        majorCollegeTotalPage = tmp[0];
        majorCollegeTotalResult = tmp[1];
        displayPages = parseInt(displayPages)>parseInt(majorCollegeTotalPage) ? majorCollegeTotalPage : displayPages;
        $("resultTitle").innerHTML = majorCollegeTotalResult + " Match Found <span style=\"background:lightyellow;color:#333;font-size:80%;font-weight:normal\">(click a link to add the college to [My Colleges])</span>";
        if (majorCollegeTotalResult<=10) $("bar").style.width = "100%";
      }
      if (majorCollegeCurrPage<majorCollegeTotalPage && majorCollegeCurrPage<displayPages) {
        majorCollegeCurrPage++;
        setTimeout("filter_getMajorCollege()",50);
      }
   }
  }
}
function filter_displayColList() {
  var objs = $("tmp").getElementsByTagName("div");
  for (var i=0;i<objs.length;i++) {
    var o = objs[i];
    if (o.id.indexOf("cc")==0) {
      var v1=o.id.substring(2).toString();
      var sa = o.innerHTML.split("~");
      var tmps = replaceStr(sa[0],'\'','@');
      var v2='<a href="javascript:filter_doClickFilterResult(\''+tmps+'\')">'+sa[0]+sa[1]+sa[2]+'</a>';
      var v3=sa[3];
      var tdArray = new Array(v1,v2,v3);
      var trAttr = new Array();
      trAttr[0]="title=>'add it to [My Colleges]'";
      trAttr[1]="className=>'col'";
      insertRow($("cTable"),tdArray,trAttr);
    }
  }
}
function filter_doClickFilterResult(name) {
  name = replaceStr(name,"@","'");
  show('collegeListDiv');
  $("hideFilter").style.visibility="visible";
  $('hideCollege').innerHTML='Hide [My Colleges]';
  search_addHotColleges(name);
}
function filter_toggleMajorSelection(o,flag) {
  var toDisplay = flag==null ? $('majorList').style.display=='none' : flag;
  if (toDisplay) {
    $('majorList').style.display='block';
  }
  else {
    $('majorList').style.display='none';
  }
}
function filter_selectMajor(parentId,subId) {
  var selectedText = $("mj"+subId).nextSibling.firstChild.innerHTML;
  var isChecked = $("mj"+subId).checked;
  var isSelected = false;
  if (isChecked) {
    for (i=0;i<$("myMajor").childNodes.length;i++) {
      var theObj = $("myMajor").childNodes[i];
      if (theObj.id.substring(2)==parentId) {
        if (isChecked) {
          theObj.innerHTML+="<span class=\"sub\" id=\"sm"+subId+"\">"+selectedText+", </span>";
          selectedMajors[selectedMajors.length]=subId;
        }
        isSelected = true;
        break;
      }
    }
    if (!isSelected) {
      $("myMajor").innerHTML+="<div style=\"apdding:0;margin:0\" id='mm"+parentId+"'><a href=\"javascript:filter_showSub("+parentId+")\">"+$("p"+parentId).nextSibling.innerHTML+":</a><span class=\"sub l1\" id=\"sm"+subId+"\">"+selectedText+",</span></div>";
      selectedMajors[selectedMajors.length]=subId;
    }
    $("p"+parentId).nextSibling.style.fontWeight="bold";
  }
  else {
    removeANode("sm"+subId);
    if ($('mm'+parentId).childNodes.length==1) {
      removeANode('mm'+parentId);
      $("p"+parentId).nextSibling.style.fontWeight="normal";
    }
    var idx = indexOfArray(selectedMajors,subId);
//    alert(idx+"/"+selectedMajors);
    selectedMajors.splice(idx,1);
  }
  filter_startGetMajorCol();
}
function filter_campus(o) {
  if (o.id=="campus4") {
    $("campus1").checked = false;
    $("campus2").checked = false;
    $("campus3").checked = false;
  }
  else {
    $("campus4").checked = false;
  }
  filter_startGetMajorCol();
}
function filter_size(o) {
  if (o.id=="size4") {
    $("size1").checked = false;
    $("size2").checked = false;
    $("size3").checked = false;
  }
  else {
    $("size4").checked = false;
  }
  filter_startGetMajorCol();
}

//-------------------------- end for filter.jsp -------------------------
//-------------------------- for searchResult.jsp -------------------------
function result_toggle(iid) {
  var o = getObj(iid);
  var ho = getObj("h"+iid);
  if (o.className=="show") {
    o.className="hide";
    ho.className="show h";
    setPref(iid,0);
  }
  else {
    o.className = "show";
    ho.className="hide h";
    setPref(iid,1);
  }
}
function result_setPrefDisplay() {
  var prefs = getPrefsArray();
  var keys = prefs["_key"];
  for (var i=0; i<keys.length;i++) {
    var id = keys[i];
    var isDisplay = prefs[id];
    if (isDisplay==1) {
      getObj(id).className="show";
      getObj("h"+id).className="hide h";
    }
    else {
      getObj(id).className="hide";
      getObj("h"+id).className="show h";
    }
  }
}
function result_getResult() {
  checkXMLHttpStatus();
  url="search.jsp?cci="+currCollegeIndex+"&cp="+currPage+"&ct="+currTotal;
  http.open("GET", url, true);
  http.onreadystatechange = result_afterGet;
  http.send(null);
}
function result_afterGet() {
  if (http.readyState == 4) {
    var results = http.responseText;
    getObj("hd").innerHTML=results;
    var objs = getObj("hd").childNodes;
    for (var i=0;i<objs.length;i++) {
      var theId = objs[i].id;
      if (!isEmptyString(theId) && getObj("t"+theId)) {
        getObj("t"+theId).innerHTML = objs[i].innerHTML;
        currItemCount++;
        var w = 100*currItemCount/totalItemsCount > 100 ? 100 : 100*currItemCount/totalItemsCount;
        getObj("bar").style.width = w+"%";
        if (w==100) hide("loading");
      }
    }
    getObj("hd").innerHTML = "";

    currCollegeIndex++;
    if (currCollegeIndex<totalCollegeCount) {
      if (currPage==0) currTotal++;
      setTimeout("result_getResult()",10);
    }
    else {
      currCollegeIndex=0;
      currPage++;
      if (currPage<totalPage) setTimeout("result_getResult()",10);
      else result_setPrefDisplay();
    }
  }
}
//-------------------------- end for searchResult.jsp -------------------------

