var parts = location.href.split('/');
if(parts[parts.length-2]!=sessionStorage.configData){
    location.href="../error.html";
}
$(function () {
    $('[data-toggle="tooltip"]').tooltip()
})

var temp=false;
function machineSeriesSelection(selectedValue) {
    switch (selectedValue) {
        case 'LYRA-OCS-2000':
            window.location.href = '../LYRA-OCS-2000/index.html';
            break;
        case 'LYRA-OCS-1000':
            window.location.href = '../LYRA-OCS-1000/index.html';
            break;
        case 'LYRA-OCS-1100':
            window.location.href = '../LYRA-OCS-1100/index.html';
            break;
        case 'LYRA-PPS-1000':
            window.location.href = '../LYRA-PPS-1000/index.html';
            break;
        case 'LYRA-PPS-2000':
            window.location.href = '../LYRA-PPS-2000/index.html';
            break;
        case 'LYRA-SML-2000':
            window.location.href = '../LYRA-SML-2000/index.html';
            break;
        case 'LYRA-NGP2-2000':
            window.location.href = '../LYRA-NGP2-2000/index.html';
            break;
        case 'Generic Device':
            window.location.href = '../Generic-Device/index.html';
            break;
        default:
            window.location.href = '../LYRA-TERA-2000/index.html';
    }
}


function tabsFunctionality() {
    // console.log("tabs functionality");
    $("#setupTabs li:not(:last-child)").on("click", function() {
        var $this = $(this).attr('data-tab');
        $("#setupTabs li").removeClass('current');
        $(".tab-content").removeClass('current');

        $(this).addClass('current');
        $("#"+$this).addClass('current');

    });
    if($("#setupTabs li:last-child").attr("id") != "debug-tab"){
        $("#setupTabs li:last-child").on("click", function() {
            var $this = $(this).attr('data-tab');
            $("#setupTabs li").removeClass('current');
            $(".tab-content").removeClass('current');
    
            $(this).addClass('current');
            $("#"+$this).addClass('current');
    
        });
    }
}

var bTriggered = false;

function nestedAccordionFunctionality() {
    if(bTriggered)
        return false;
    
    bTriggered = true;

    $('#general-tab,#optical-comb-tab,#demux-tab,#demo-demux-tab,#demo-optical-comb-tab,#idac-comb-tab,#vdac-comb-tab').on('click', function(e) {
        e.preventDefault();
        var $this = $(this);
        
        if($this.hasClass('icon')) {
            $this.removeClass('icon')
        } else {
            $this.addClass('icon');
        }
        
        if ($this.next().hasClass('show-level')) {
            $this.next().removeClass('show-level');
        } else {
            $this.next().addClass('show-level');
        }

        if(temp==false){
            if($this.next().find('second-level-child').hasClass('icon')) {
                $this.next().find('second-level-child').removeClass('icon');
            }

            if($this.next().find('third-level').hasClass('show-level')) {
                $this.next().find('third-level').removeClass('show-level');
            }

            if($this.next().children('ul').find('.third-level').hasClass('show-level')) {
                $this.next().children('ul').find('.third-level').removeClass('show-level');
            }

            if($this.next().children('ul').find('.second-level-child').hasClass('icon')) {
                $this.next().children('ul').find('.second-level-child').removeClass('icon');
            }
        }
        temp=false;
    });

    $('.second-level-child').on('click', function(e) {
        e.preventDefault();
        var $this = $(this);

        if($this.data("level")=="1"){
            if($('#optical-comb-tab').hasClass('icon')==false) {
                temp=true;
                $('#optical-comb-tab').trigger('click');  
            }   
        }
        else{
            if($('#demux-tab').hasClass('icon')==false) {
                temp=true;
                $('#demux-tab').trigger('click');  
            } 
        }    

        if($this.hasClass('icon')) 
            $this.removeClass('icon');
        else 
            $this.addClass('icon');
        

        if($this.next().hasClass('show-level')) 
            $this.next().removeClass('show-level');
        else
            $this.next().addClass('show-level');

        $this.nextAll().find('.third-level-child').addClass('icon');
        $this.nextAll().find('.third-level-child').next().addClass('show-level');    

        if($this.hasClass('icon')==true) {
           // $('.customClass').scroll();

            $(".customClass").animate({
              scrollTop: ($this.offset().top)-$(".customClass").offset().top + $(".customClass").scrollTop()
            }, 1500);
        }   
        
    });

  $('.third-level-child').on('click', function(e) {
        e.preventDefault();
        var $this = $(this);

        if($this.hasClass('icon')) {
            $this.removeClass('icon')
        } else {
            $this.addClass('icon');
        }

        if ($this.next().hasClass('show-level')) {
            $this.next().removeClass('show-level')
        } else {
            $this.next().addClass('show-level');
        }
    });
}

// tabsFunctionality();

// navbar
function openNav(divID, width) {
    document.getElementById(divID).style.width = width;
}

function closeNav(divID) {
    document.getElementById(divID).style.width = "0";
}
window.addEventListener('resize', hideEthDiv);

function hideEthDiv(){
    ethDiv=document.getElementById('ethernetAppendDiv');
    if(ethDiv!==null){
        ethPaNode=ethDiv.parentNode.parentNode;
        if(window.innerWidth<990){
            if(ethPaNode.classList[3]===undefined){
                ethPaNode.classList+=" hideDiv" ;
            }
        } else{
            ethPaNode.classList="col-lg-3 col-sm-4 connection";
        }
    }
}
hideEthDiv()