// Copyright 2010 Google Inc.  All Rights Reserved.

/**
 * @fileoverview Global functions used to change languages and search
 * on all pages.
 * @author Michael Rigoli
 */

/**
 * This function makes it less verbose to get an element by its id.
 * @param {param} elementId HTML element supplied to function.
 * @return {object} Returns the object associated with the id submitted.
 */
function $(elementId) {
  return document.getElementById(elementId);
}

/**
 * Changes language directory based on form input.
 * @param {string} lang Variable supplied by the language dropdown menu.
 */
function changeLanguage(lang) {
  window.location.href = lang.options[lang.selectedIndex].value +
      window.location.href.split('/').pop();
}

/**
 * Sends search query to search page in pound '#' format.
 */
function searchQuery() {
  window.location.href = 'search.html#q=' + $('q').value;
}

/**
 * This function toggles the promo layer on the home page.
 * @param {string} layer Users promo selection.
 */
function togglePromo(layer){
  var promoCount = $('promo-control').getElementsByTagName('li').length;

  for (var x = 1; x < promoCount + 1; x++) {
    $('ga-promo-' + x).style.display = 'none';
    $('ptb-' + x).style.color = '#0083c8';
    $('ptb-' + x).style.backgroundColor = '#fff';
  }

  gweb.fx.fadeIn($('ga-promo-' + layer), 100);
  $('ga-promo-' + layer).style.display = 'block'
  $('ptb-' + layer).style.color = '#fff';
  $('ptb-' + layer).style.backgroundColor = '#0083c8';
}

/**
 * Toggles IQ lesson description.
 * @param {string} id Id of element that will be displayed or hidden.
 */
function toggleIqDisplay(id) {
  var ele = $('info-' + id);

  if (ele.style.display == 'none' || ele.style.display == '') {
    ele.style.display = 'block';
  } else {
    ele.style.display = 'none';
  }
}


