﻿var current_tab = '0';
var current_lv = '0';
var numColumn = 3;
var showMenu = 0;
var customTabOpen = 3;
var isSpecificCareerLevelHtmlLoaded = false;
var new_tab2_backup;
var isCurrentCustom = "false";

function show_next_lv1(next_tab, isNextCustom) 
{
    $('#1tab' + current_tab).removeClass('on');
    $('#1tab' + next_tab).addClass('on');
    $('#1tab' + current_tab).wrapInner("<a href=\"javascript:void(0);\" id=\"1tab" + current_tab + "-link\"></a>");
    $('#1tab' + next_tab + '-link').replaceWith($('#1tab' + next_tab + '-link').text());

    if (isCurrentCustom == "true" || isCurrentCustom == "True")    // currently displaying custom tab
    {
        // hide the tab shown in 4th position
        if (isNextCustom && next_tab > 2 && current_tab > 2) 
        {
            $('#1tab' + current_tab).hide();
        }
        // hide the content
        $('#tab-' + current_tab + '-0-0').hide();
    }
    else 
    {   // currently displaying non-custom tab
        hide_lv2_tabs();    
        $('#tab-' + current_tab + '-' + current_lv + '-0').hide();
        $('#tab-' + current_tab + '-' + current_lv + '-1').hide();
        $('#tab-' + current_tab + '-' + current_lv + '-2').hide();
    }

    if (isNextCustom == "true" || isNextCustom == "True") 
    {   // custom tab is selected
        // show tab
        if (next_tab > 2) 
        {
            $('#1tab' + customTabOpen).hide();  // will hide any currently opened custom tab if there any
            $('#1tab' + next_tab).show();
            customTabOpen = next_tab;
        }
        // show content
        $('#tab-' + next_tab + '-0-0').show();
    }
    else 
    {   // non-custom tab is selected
        show_lv2_tabs();
        $('#tab-' + next_tab + '-' + current_lv + '-0').show();
        $('#tab-' + next_tab + '-' + current_lv + '-1').show();
        $('#tab-' + next_tab + '-' + current_lv + '-2').show();
    }

    // in case the box was left opened
    $('#selection_box').removeClass("showMenu");
    showMenu = 0;

    current_tab = next_tab;
    isCurrentCustom = isNextCustom;
}

function insert_specific_career_level_sections_html(data) {
    if (!isSpecificCareerLevelHtmlLoaded) {
        $(".indexBrowse .carrier").append(data);
        isSpecificCareerLevelHtmlLoaded = true;
    }
    $.unblockUI();
    show_nex_lv2_impl();
}

function show_nex_lv2_impl() {
    new_tab2 = new_tab2_backup;
    
    $('#2tab' + current_lv).replaceWith("<a href=\"javascript:void(0);\" onclick =\"show_next_lv2(" + current_lv + ")\" id=\"2tab" + current_lv + "\">" + $('#2tab' + current_lv).text() + "</a>");
    $('#2tab' + new_tab2).replaceWith("<span onclick =\"show_next_lv2(" + new_tab2 + ")\" id=\"2tab" + new_tab2 + "\">" + $('#2tab' + new_tab2).text() + "</span>");

    // close currently opened columns
    $('#tab-' + current_tab + '-' + current_lv + '-0').hide();
    $('#tab-' + current_tab + '-' + current_lv + '-1').hide();
    $('#tab-' + current_tab + '-' + current_lv + '-2').hide();

    $('#tab-' + current_tab + '-' + new_tab2 + '-0').show();
    $('#tab-' + current_tab + '-' + new_tab2 + '-1').show();
    $('#tab-' + current_tab + '-' + new_tab2 + '-2').show();

    current_lv = new_tab2; 
}


function show_next_lv2(new_tab2) {
    if (!isSpecificCareerLevelHtmlLoaded) {
        $.blockUI();
        new_tab2_backup = new_tab2;
        var ajax = JobsDB_Controllers_HomeController_GetJobBrowserSpecificCareerLevelSectionsHtmlActionClass.ObjectFactory.getInstance();
        ajax.addOnSuccessListener(insert_specific_career_level_sections_html);
        ajax.submitWithResultInJson();
    } else {
        new_tab2_backup = new_tab2;
        show_nex_lv2_impl();
    }
}
JobsDB_System.IncludeJs('Controllers/HomeController_GetJobBrowserSpecificCareerLevelSectionsHtml.js');

function hide_lv2_tabs() 
{
    $('.jobLv').hide();
}

function show_lv2_tabs() 
{
    $('.jobLv').show();
}

function show_selection_box() 
{
    if (showMenu == 0) {
        $('#selection_box').addClass("showMenu");
        showMenu = 1;
    }
    else {
        $('#selection_box').removeClass("showMenu");
        showMenu = 0;
    }
}
