// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function hideOtherSchool() {
  otherSchool = document.getElementById('other_school');
  // if both school fields exist
  if (otherSchool && document.getElementById('degree_school_id'))
    otherSchool.style.display = 'none';
}

function updateOtherSchool() {
  dropdown = document.getElementById('degree_school_id')
  // if the last option (other school) in the dropdown is selected...
  if (dropdown.selectedIndex == dropdown.options.length - 1) {
    otherSchool = document.getElementById('other_school');
    otherSchool.style.display = 'block';
    otherSchool.focus();
  } else {
    hideOtherSchool();
  }
}

function no2click()
{
    onsubmit = null;
}

window.onload = function()
{
    submitButton = document.getElementsByName('submit')[0];
    if (submitButton)
        submitButton.form.onsubmit = no2click();

    hideOtherSchool();
		setupNewRes();
		
		query = document.getElementById('query')
		if (query) {
		  query.value = ''
		  query.focus()
		}
}

function hideNewRes()
{
	document.getElementById('newRes').style.display = 'none';
}

function showNewRes()
{
	document.getElementById('newRes').style.display = 'block';
}

function setupNewRes()
{
	newResOn = document.getElementById('newResOn');
	if (newResOn)
	{
		// if new researcher radio button is selected or there was an error
		if (newResOn.checked || document.getElementById('errorExplanation'))
			showNewRes();
		else
			hideNewRes();
	}
}