/* Js for , Version=1775245898 */
 v.objectType = "book";;v.objectID = 784;;v.showDetail = "Show all";;v.hideDetail = "Hide";;$(document).ready(function()
{
    $.setAjaxForm('#commentForm', function(response)
    {
        if(response.result == 'success')
        {
            setTimeout(function()
            {
                var link = createLink('message', 'comment', 'objecType=' + $('#objectType').val() + '&objectID=' + $('#objectID').val());
                 $('#commentForm').closest('#commentBox').load(link, location.href="#first");
            },  
            1000);   
        }
        else
        {
            if(response.reason == 'needChecking')
            {
                $('#captchaBox').html(Base64.decode(response.captcha)).show();
            }

            if(response.locate) window.location.href = response.locate;
        }
    });

    $('#pager').find('a').click(function()
    {
        $('#commentBox').load($(this).attr('href'));
        return false;
    });

    $('a[id*=reply]').modalTrigger();

    /* Process contents. */
    $('.content-detail').each(function()
    {
        var obj = $(this);
        if(obj.height() > 100)
        {
            var buttons = "<a href='javascript:void(0)' onclick='showDetail(this)' class='showDetail'> ... " + v.showDetail + "</a>";
            buttons    += "<a href='javascript:void(0)' onclick='hideDetail(this)' class='hideDetail'> " + v.hideDetail + "</a>";
            obj.parent().append(buttons);
            obj.parent().find('.hideDetail').hide();
            obj.addClass('content-abstract');
        }
    });
});

function showDetail(obj)
{
    var tdContent = $(obj).parents('.td-content');
    tdContent.find('.content-detail').removeClass('content-abstract');
    tdContent.find('.showDetail').hide();
    tdContent.find('.hideDetail').show();
}

function hideDetail(obj)
{
    var tdContent = $(obj).parents('.td-content');
    tdContent.find('.content-detail').addClass('content-abstract');
    tdContent.find('.showDetail').show();
    tdContent.find('.hideDetail').hide();
}
$(document).ready(function()
{
    if($("#headNav nav > a:first-child").text() == 'Login'){
        $("#headNav nav > a:first-child").text('Log in'); 
    }
    if($("#headNav nav > a:last-child").text() == 'Register'){
        $("#headNav nav > a:last-child").text('Sign up'); 
    }

    $('#siteNav a[href="/user-register.html"]').remove();
    setTimeout(function() {$('#language').after($('#siteNav'));}, 200);
    
    if(typeof headerList != 'undefined') return false;
    headerList = true;
    searchICON = '<a class="search-but">' + '<i' + ' class="icon icon-search"></i></a>';
    $("#navbar li.nav-item-searchbar").prepend(searchICON);
    
    $("#words").attr('placeholder','Search');
    
    $(".search-but").click(function(){
        $("#searchbar").fadeToggle();
    });
    
    $("#reg #panel-pure #heading-title").text('Register');
    $("#login #login-region .panel-heading span").text('Login'); 
    $(".m-user-login .page-wrapper").before('<div class="banner-wrap"><div class="banner"><h3>Welcome to login</h3></div></div>');
    $(".m-user-register .page-wrapper").before('<div class="banner-wrap"><div class="banner"><h3>Welcome to register</h3></div></div>');
    $(".m-extension .page-wrapper").before('<div class="banner-wrap"><div class="banner"><h3>Extension</h3></div></div>');

    $('#language').insertAfter('#navbarWrapper');
    $('#language').next().remove();
    
    if(location.pathname.includes('download')) 
    {
        $('.article table a').click(function(e)
        {
            e.preventDefault();
            if($(this).attr('href').includes('dl'))
            {
                location.href = "/page/downloadComplete.html";
                sessionStorage.setItem('downloadUrl', $(this).attr('href'));
            }
        })
    }
    
    if(!location.href.includes('/page')) $('.navbar-nav li').removeClass('active');
});

// $(function(){
//     window.Intercom('boot', {
//       app_id: "buxeg11n",
//       bottom: 80,
//       right: 26,
//     });
// });

if(screen.width > 767){
    $("#navbar .dropdown").mouseover(function(e){
        $(this).addClass('open');
    });
    $("#navbar .dropdown").mouseout(function(e) {
        $(this).removeClass('open');
    });
};

function getCaptcha($ele)
{
    $.get(createLink('guarder', 'getCaptcha'), function(response)
    {
        if(response.result == 'success')
        {
            $ele.html(response.captchaContent);
        }
    })
}

$('#captchaBox').on('click', '.img-wrapper', function()
{
    getCaptcha($(this));
});
