
/**
 * Display a home entry and hide the others
 * 
 * @param int HTML Id of the list
 * @param int HTML Id of the list item
 * @return void
 */
function showHomeEntry($list_id, $list_item_id)
{
    // the <ul> in question
    var $home_entry_list;

    // the <li>'s of that <ul> in an array
    var $home_entry_list_item_arr;

    // one of the <li>'s
    var $home_entry_list_item;


    // get the scenario <ul>
    $home_entry_list = document.getElementById($list_id);

    // guard: list found
    if (!$home_entry_list) {
        return;
    }

    // traverse the home entry array, hide all except selected entry
    $home_entry_list_item_arr = $home_entry_list.childNodes;
    for (var $i = 0; $i < $home_entry_list_item_arr.length ; $i++)
    {
        // load the home entry <li>
        $home_entry_list_item = $home_entry_list_item_arr[$i];

        // unselect if it is not the caller scenario item
        if ($home_entry_list_item.id == $list_item_id) {
            $home_entry_list_item.className = 'show';
        } else {
            // hide the rest
            $home_entry_list_item.className = 'hide';
        }
    }
}

/**
 * Toggle the form visibility
 *
 * @param string Form wrapper id
 * @param string Classname value string
 * @return void
 */
function setFormVisibility($form_wrapper_name, $class_str)
{
    var $form_wrapper;

    if ($form_wrapper = document.getElementById($form_wrapper_name))
    {
        $form_wrapper.className = 'vb-form-wrapper ' + $class_str;
    }
}

/**
 * Toggle the search type between 'simple' and 'advanced'
 *
 * This function sets the div #search_container class and changes the anchor
 * values and href of the calling anchor such that the state can be toggled back
 *
 * @param HTMLAnchorElement Calling anchor (toggle link)
 * @return void
 */
function toggleSearchType($anchor)
{
    var $search_container = document.getElementById('search-container');
    var $anchor;

    if ($search_container.className == 'simple')
    {
        $search_container.className = 'advanced';
        $anchor.href = 'werkzoekenden/vacatures_zoeken';
        $anchor.innerHTML = '&raquo; Simpel zoeken';

    } else {
        $search_container.className = 'simple';
        $anchor.href = 'werkzoekenden/uitgebreid_vacatures_zoeken';
        $anchor.innerHTML = '&raquo; Uitgebreid zoeken';
    }
}

/**
 * Sort the vacancy list
 *
 * This function finds the vacancy sorter (select box), determines the chosen sort order and
 * sets this value in the search simple or advanced serach form (depending on the current
 * search type (see toggleSearchType())) and submits the form resulting in a new, sorted, search
 *
 * @return void
 */
function sortSearchList()
{
    var $search_container     = document.getElementById('search-container');

    var $search_simple_form   = document.getElementById('search-simple');
    var $search_advanced_form = document.getElementById('search-advanced');

    var $sorter               = document.getElementById('search-sorter');

    // guard: check for selected index/
    if ($sorter.selectedIndex==-1)
    {
        return false;
    }

    //alert($sorter.selectedIndex);
    //alert($sorter.options[$sorter.selectedIndex].value);
    $selected_sort_id = $sorter.options[$sorter.selectedIndex].value

    // set the selected sort order in the hidden sorter fields and submit the search form
    if ($search_container.className == 'simple')
    {
        $search_simple_form.elements['search[sortorder]'].value = $selected_sort_id;
        $search_simple_form.submit();
    } else {
        $search_advanced_form.elements['search[sortorder]'].value = $selected_sort_id;
        $search_advanced_form.submit();
    }
}

/**
 * Goto another App
 *
 * @return void
 */
function switchApp()
{
    var $selector = document.getElementById('vb-selector');

    // guard: check for selected index/
    if ($selector.selectedIndex == -1) {
        return false;
    }

    $href = $selector.options[$selector.selectedIndex].value;
    window.location.href = $href;
}

/**
 * Toggle the state of an item between 'selected' and 'not selected'
 *
 * @param string Selection name like 'my_vacancies'
 * @param HTMLInputElement A checkbox
 * @param string Cookie path (PATH_TO_ROOT)
 * @return void
 */
function toggleMySelection($selection_name, $checkbox, $path)
{
    var $cookie_name           = $selection_name + '_cookie';
    var $id                    = $checkbox.value;
    var $doc_selection_count   = document.getElementById($selection_name + '-count');
    var $doc_selection_count_s = document.getElementById($selection_name + '-count-s');

    // guard: check input to be a valid numeric id
    if (!(parseInt($id)>0)) {
        return false;
    }

    // if the checkbox is checked, set the item id in the cookie
    if ($checkbox.checked) {
        window[$cookie_name]["id_" + $id] = $id;
    // item was set unchecked, delete cookie value
    } else {
        delete window[$cookie_name]["id_" + $id];
    }

    // store the data for 31 days
    window[$cookie_name].store(31, $path);

    // update the item-count in the document
    $id_count = window[$cookie_name].countValue();

    $doc_selection_count.innerHTML   = $id_count;
    $doc_selection_count_s.innerHTML = ($id_count==1) ? '' : ($selection_name=='my_cvs' ? '&rsquo;': '') + 's';
}

// init 'my_selection' cookies
var my_vacancies_cookie = new Cookie("my_vacancies");
var my_cvs_cookie       = new Cookie("my_cvs");

/*/ init google 160 x 600
var google_ad_client    = "pub-5370749923859314";
var google_ad_width     = 120;
var google_ad_height    = 600;
var google_ad_format    = "120x600_as";
var google_ad_type      = "text";
var google_ad_channel   = "5016650736";
var google_color_border = "FFFFFF";
var google_color_bg     = "FFFFFF";
var google_color_link   = "0030A3";
var google_color_url    = "0030A3";
var google_color_text   = "424242";
/* */

/*/
var google_ad_client    = "pub-5370749923859314";
var google_ad_width     = 120;
var google_ad_height    = 240;
var google_ad_format    = "120x240_as";
var google_ad_type      = "text";
var google_ad_channel   = "5016650736";
var google_color_border = "FFFFFF";
var google_color_bg     = "FFFFFF";
var google_color_link   = "0030A3";
var google_color_url    = "0030A3";
var google_color_text   = "424242";
/* */

/*/ wide skyscraper
var google_ad_client    = "pub-5370749923859314";
var google_ad_width     = 160;
var google_ad_height    = 600;
var google_ad_format    = "160x600_as";
var google_ad_type      = "text";
var google_ad_channel   = "5016650736";
var google_color_border = "FFFFFF";
var google_color_bg     = "FFFFFF";
var google_color_link   = "0030A3";
var google_color_url    = "0030A3";
var google_color_text   = "424242";
/* */