// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
/*
 * Basic resize function to assure contact line hugs the bottom 
 */
var yieldCellHeight = 0;

function adjustTable(){
    //alert("in adjust Table");
    yieldCellHeight = $('yieldCell').getHeight();
    var theTable = $('bodyTable');
    bodyHeight = document.body.clientHeight
    //alert(bodyHeight)
    tempHeight = (bodyHeight < 400)?310:bodyHeight - 92
    //alert(tempHeight)
    newHeight = (tempHeight)  + "px";
    theTable.setStyle({ height:newHeight });
		$('contactSpan').show();
}

//window.onresize = adjustTable;

/*
 * Page menu controls
 */
var currentOption = "";
var currentMenu;

function showOptions(newMenu,whichOne){
	if (currentOption != ""){
		$("menu_" + currentMenu).removeClassName("optionsDiv")
		Effect.BlindUp($(currentOption))
	}
	var theNewArea = $(whichOne)
	if (theNewArea.innerHTML != "") Effect.BlindDown($(whichOne));
	$("menu_" + newMenu).addClassName("optionsDiv")
	currentOption = whichOne;
	currentMenu = newMenu;
	return false;
}
function changePage(menuItem){
	var myAction = menuItem.getAttribute("value");
	if (myAction != "") window.location.href = myAction
}

function changeDisplay(theURL){
	//alert("in changeDisplay with " + theURL);
	//check to see if I have a student selected
	theMenu = $("studID")
	theStud = theMenu.value
	//alert(theStud)
	if (theStud == "0"){
		alert("Please select a student before continuing.")
		return;
	}
	if (theURL != ""){
		new Ajax.Updater("displayArea",theURL, {evalScripts: true,
												parameters:{majorArea:1,"studID":theStud},
												method:'get'});
		//show the display area
		$("displayArea").show();
		//toggle the currentDisplay menu
	}
}

function changeStudent(theMenu){
	//alert(theMenu.value)
}

function getHelp(){
	alert("help request...");
}
function submitFeedback(){
	alert("submit feedback...");
}
function signOut(){
	alert("sign out...");
}

function limitGroup(theMenu,theUrl){
	newGroup = ($(theMenu).value)
	new Ajax.Updater("menuArea",theUrl,{evalScripts:true,parameters:{'newGroup':newGroup},method: 'post',onSuccess:function(){alert('New Student Group Loaded')}})	
}
function changeMajor(newMajor,theUrl){
	new Ajax.Updater("menuArea",theUrl,{evalScripts:true,parameters:{'newMajor':newMajor},method: 'post',onSuccess:function(){alert('New Student Group Loaded')}})	
}
function toggleClassDetails(){
	
}
function addToAndSortMenu(theMenu,theText,theValue){
  var y=document.createElement('option');
  y.text = theText
	y.value = theValue
  try {
    theMenu.add(y,null); // standards compliant
  }
  catch(ex){
    theMenu.add(y); // IE only
  }
	var menuOptions = theMenu.options
	var tempArray = new Array();
	for (i = 0; i < menuOptions.length; i++) {
		if (menuOptions[i].text == null) continue
		tempArray.push(new Array(menuOptions[i].text,menuOptions[i].value))
	}
	tempArray.sort(sortMenu);
	for (i=0; i < menuOptions.length; i++){
		theMenu.options[i].text = tempArray[i][0]
		theMenu.options[i].value = tempArray[i][1]
	}
}
function sortMenu(a,b){
	if (a < b) return -1
	if (a > b) return 1
	return 0
}
function buildStateMenu(){
	var theMenu = $('newJurisdictionMenu')
	theMenu.innerHTML = "<option value='OH'>OH</option>";
}
Ajax.Responders.register({
  onCreate: function() {
    $('workingAnimation').show();
  },
  onComplete: function() {
    $('workingAnimation').hide();
  }
});

function changeHours(theField,theID){
	fieldName = theField.getAttribute('name')
	if (fieldName.indexOf('current') > -1){
		theField.setAttribute('name', fieldName.replace(/current/,"change"));
	} else if (fieldName.indexOf('none') > -1){
		theField.setAttribute('name', fieldName.replace(/none/,"new"));
	} else if (fieldName.indexOf('new') > -1 && theField.value == '0'){
		theField.setAttribute('name', fieldName.replace(/new/,"none"));
	}	
}