﻿// These values are assigned by the aspx page
var _languageDropDownListID;
var _countyDropDownListID;
var _jobSeekersImageButtonID;
var _employersImageButtonID;
var _appRootPath;

function loadPage() {
  preloadSectionButtons();
  setSectionButtonsEnabled(stepsComplete());
}

function preloadSectionButtons() {
  var tmp;
  tmp = new Image();
  tmp.src = _appRootPath + 'Images/LandingPage/JobSeekersButtonOn.gif';
  tmp = new Image();
  tmp.src = _appRootPath + 'Images/LandingPage/EmployersButtonOn.gif';
  tmp = new Image();
  tmp.src = _appRootPath + 'Images/LandingPage/es/JobSeekersButtonOn.gif';
  tmp = new Image();
  tmp.src = _appRootPath + 'Images/LandingPage/es/EmployersButtonOn.gif';
}

function onLanguageChanged() {
  var path = getLangCountyPath();
  document.location.href = path + 'Default.aspx';
}

function onCountyChanged() {
  setSectionButtonsEnabled(stepsComplete());
}

function getLangCountyPath() {
  var langDDL, countyDDL;
  var lang, county;
  
  langDDL = document.getElementById(_languageDropDownListID);
  countyDDL = document.getElementById(_countyDropDownListID);
  
  lang = langDDL.options[langDDL.selectedIndex].value;
  county = countyDDL.options[countyDDL.selectedIndex].value;
  
  if (lang == '')
    lang = 'en';
  
  if (county == '') {
    return _appRootPath + lang + '/';
  } else {
    return _appRootPath + lang + '/' + county + '/';
  }
}

function stepsComplete() {
  var langDDL;
  var countyDDL;
  langDDL = document.getElementById(_languageDropDownListID);
  countyDDL = document.getElementById(_countyDropDownListID);
  return langDDL.options[langDDL.selectedIndex].value != '' &&
         countyDDL.options[countyDDL.selectedIndex].value != '';
}

function setSectionButtonsEnabled(enabled) {
  var src;
  var langDDL;
  var lang;
  
  langDDL = document.getElementById(_languageDropDownListID);
  lang = langDDL.options[langDDL.selectedIndex].value;
  
  if (lang == '')
    lang = 'en';

  src = _appRootPath + 'Images/LandingPage/' + (lang=='en' ? '' : lang + '/') + 'JobSeekersButton' + (enabled ? 'On' : 'Off') + '.gif'
  document.getElementById(_jobSeekersImageButtonID).src = src;
  src = _appRootPath + 'Images/LandingPage/' + (lang=='en' ? '' : lang + '/') + 'EmployersButton' + (enabled ? 'On' : 'Off') + '.gif'
  document.getElementById(_employersImageButtonID).src = src;
}

function onHelpClick() {
  if (!stepsComplete()) {
    alert('Please select your county before continuing to the help page.');
  } else {
    document.location.href = getLangCountyPath() + 'Help.aspx';
  }
  return false;
}
