// LATERAL LINK CAREER CENTER

function setupFormButton(form_id, select_id, button_id)
{
   Event.observe(button_id, 'click', function() { if($F(select_id) != '') { $(form_id).submit() } } );
}

function navOn(x)	{
	if (x == "firmsnapshots")	{
		document.getElementById('firmsnapshots').style.backgroundPosition = '0px -74px';
		document.getElementById('firmcomparisons').style.backgroundPosition = '-150px -37px';
		document.getElementById('resources').style.backgroundPosition = '-317px -37px';
		}
	else if (x == "firmcomparisons"	)	{
		document.getElementById('firmsnapshots').style.backgroundPosition = '0px -37px';
		document.getElementById('firmcomparisons').style.backgroundPosition = '-150px -74px';
		document.getElementById('resources').style.backgroundPosition = '-317px -37px';
		}
	else if (x == "resources")	{
		document.getElementById('firmsnapshots').style.backgroundPosition = '0px -37px';
		document.getElementById('firmcomparisons').style.backgroundPosition = '-150px -37px';
		document.getElementById('resources').style.backgroundPosition = '-317px -74px';
		}
}

function navOff(x)	{
	if (x == "firmsnapshots")	{
		document.getElementById('firmsnapshots').style.backgroundPosition = '0px -37px';
		document.getElementById('firmcomparisons').style.backgroundPosition = '-150px -37px';
		document.getElementById('resources').style.backgroundPosition = '-317px -37px';
		}
	else if (x == "firmcomparisons"	)	{
		document.getElementById('firmsnapshots').style.backgroundPosition = '0px -37px';
		document.getElementById('firmcomparisons').style.backgroundPosition = '-150px -37px';
		document.getElementById('resources').style.backgroundPosition = '-317px -37px';
		}
	else if (x == "resources")	{
		document.getElementById('firmsnapshots').style.backgroundPosition = '0px -37px';
		document.getElementById('firmcomparisons').style.backgroundPosition = '-150px -37px';
		document.getElementById('resources').style.backgroundPosition = '-317px -37px';
		}	
}


function sendMail(name) {
	domain = "laterallink.com";
 	window.location = ("mailto:" + name + "@" + domain );
}

function showFields(expr) {
  $$(expr).each(function(element) { element.show(); });
}

function hideFields(expr) {
  $$(expr).each(function(element) {
    element.hide();
    element.select('select', 'input').each(function(field) { field.clear(); });
  });
}

var EMPLOYMENT_STATUS_LAW_FIRM = '1';
var EMPLOYMENT_STATUS_IN_HOUSE = '2';
var JOB_TYPE_LAW_FIRM = '1';
var JOB_TYPE_IN_HOUSE = '2';
var JOB_TYPE_OTHER = '5';

function changeEmploymentStatus() {
  $('office_loader').hide();
  var employer_type = $('user_current_employer_type_id');
  switch ($F('user_employment_status_id')) {
    case EMPLOYMENT_STATUS_LAW_FIRM:
      hideFields('.in_house');
      showFields('.law_firm');
      changeAccount(false);
      employer_type.value = JOB_TYPE_LAW_FIRM;
      break;
    case EMPLOYMENT_STATUS_IN_HOUSE: // In-House
      hideFields('.law_firm');
      showFields('.in_house');
      employer_type.value = JOB_TYPE_IN_HOUSE;
      break;
    default: // Others
      hideFields('.law_firm, .in_house');
      employer_type.value = JOB_TYPE_OTHER;
    }
}

function changeAccount(update) {
  var accountSelect = $('user_current_employer_account_id');
  changeSelect(accountSelect, 'other_employer');

  // if account clear, hide office
  if (accountSelect.selectedIndex == 0) {
    hideFields('#account_office, #other_office');

  // else if update, get office fields from server
  } else if (update) {
    $('office').innerHTML = '';
    $('office_loader').show();
    new Ajax.Updater('office', '/career_center/home/render_office_fields/' + accountSelect.value, { asynchronous: true, evalScripts: true,
      onFailure: function() { alert('Sorry, we experienced an unexpected error. For assistance, please contact info@laterallink.com') },
      onSuccess: function() { $('office_loader').hide(); }});

  // else if other account, show other office
  } else if (Element.visible('other_employer')) {
    hideFields('#account_office');
    showFields('#other_office');

  // else show according to office selection
  } else {
    changeSelect('user_current_employer_account_office_id', 'other_office');
  }
}

function jobAction(id, type) {
  new Ajax.Request('/career_center/resources/job_action/' + id + '?type=' + type, { asynchronous: true });
}

