// JavaScript Document


function switchMenu(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
var el = objs[i];
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
}
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
//if (typeof element == 'string')
element = document.getElementById(element);
elements.push(element);
}
return elements;
}
function collapseAll(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
objs[i].style.display = 'none';
}
}
function nextPage()
{
	document.form1.pageNum.value++; 
	document.form1.submit();
}
function prevPage()
{
	document.form1.pageNum.value--; 
	document.form1.submit();
}
function goToPage(pg)
{
	document.form1.pageNum.value = pg; 
	document.form1.submit();
}

/* Scripts for admin page */
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
var updateFlg = false;
function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
	updateFlg = true;
  }
  if(NS4) history.go(0);
}

function setTermDisplay()
{
	var theSelFrom = document.form1.termDisplay;
    for(i=0; i <=theSelFrom.options.length-1; i++)
    {
		if(	document.form1.allTermDisplay.value != "")
		{
      		document.form1.allTermDisplay.value += ","+ theSelFrom.options[i].value;
		}
		else
		{
			document.form1.allTermDisplay.value += theSelFrom.options[i].value;
		}
    }
}
function setPartTermDisplay()
{
	var theSelFrom = document.form1.partTermDisplay;
    for(i=0; i <=theSelFrom.options.length-1; i++)
    {
		if(	document.form1.allPartTermDisplay.value != "")
		{
      		document.form1.allPartTermDisplay.value += ","+ theSelFrom.options[i].value;
		}
		else
		{
			document.form1.allPartTermDisplay.value += theSelFrom.options[i].value;
		}
    }
}
function submitForm()
{
	if(updateFlg){
		setTermDisplay();
		setPartTermDisplay();
		return true;
	}
	else
	{
		alert('There are no changes to update.');
		return false;
	}
	
}
function refreshOnDemand()
{
	if(confirm('You are about to refresh the data from Banner.\n This will take couple of minutes. \nPlease click OK to confirm or CANCEL to go back'))
	{
		document.form1.rod.value="true";
		document.form1.submit();
	}
}

//-->
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

/* Scripts for course search page */
function modifyCampus(obj)
{
	if(obj.checked){
	for (var i=0; i < document.form1.campus.options.length;i++)
	{
		if(document.form1.campus.options[i].value=="1")
		{
			document.form1.campus.options[i].selected=true;
			document.form1.submit();
		}
	}
	}

}

function deselectAddReq()
{
	document.form1.addReq[1].checked = false;
	document.form1.addReq[2].checked = false;
	document.form1.addReq[3].checked = false;
}

/* Scripts for index page*/

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}