﻿var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18179766-1']);
_gaq.push(['_setDomainName', '.apsynth.com']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

window.onload = function () {
    var helper = document.getElementById('helpDiv');
    if (helper != null && helper != undefined && ((helper.innerText != "" && helper.innerText != undefined && helper.innerText.match("^[a-zA-Z0-9][a-zA-Z0-9 ]+$")) || (helper.textContent != undefined && helper.textContent.match("^[a-zA-Z0-9][a-zA-Z0-9 ]+$")))) {
        //            helper.childNodes.length > 1 && !helper.childNodes.item(0).is("Text") && !helper.childNodes.item(2).is("Text"))  {
        helper.style.visibility = 'visible';
    }

    adjustLayout();
};

function adjustLayout() {

    var leftColumn = document.getElementById("leftCol");
    var rightColumn = document.getElementById("mainCol");
    var main = document.getElementById("main");


    if (leftColumn == null || rightColumn == null || main == null)
        return;

    var leftColumnheight = leftColumn.offsetHeight;
    var rightColumnheight = rightColumn.offsetHeight;

    if (leftColumnheight > rightColumnheight) {
        var maxheight = leftColumnheight;
    } else {
        var maxheight = rightColumnheight;
    }


    //leftColumn.style.height = maxheight + 10 + 'px';
    //rightColumn.style.height = maxheight + 10 + 'px';

    main.style.minHeight = maxheight + 20 + 'px';
}

function initCascadingDropDown(parentDropDown, childDropDown, selectedChild) {
    //Make a copy in memory of all the subcat options
    domains = childDropDown.children().clone();
    //Default subcat to "Orders"
    updateCascadingDropDown(parentDropDown, childDropDown);
    childDropDown.children().each(function () {
        if ($(this).attr("class") == parentDropDown.val() && $(this).attr('value') && selectedChild.val()) {
            $(this).attr("selected", true);
        }
    });
}

function updateCascadingDropDown(parentDropDown, childDropDown) {
    var sector = parentDropDown.val();

    //Remove all items from drop down
    childDropDown.children().remove();
    //For each subcat item: test if it belongs in eCat, if so add it
    $(domains).each(function () {
        if (($(this).attr("class") == sector)) {
            childDropDown.append($(this).clone()[0]);
        }
    });
}

//Slide utilisé pour l'aide dans l'édition de version notemment
function SlideContentBlockHeader(minheight, maxheight, element) {
    if ($(element).height() <= minheight + 10)
        $(element).animate({ height: maxheight }, 200);
    else
        $(element).animate({ height: minheight }, 200);
}

function clearMsgBoxes() {
    $('#errorBox').fadeOut('slow');
    $('#msgBox').fadeOut('slow');
}

function displayResponseMsgs(response) {
    var data = $.parseJSON(response.get_data());

    if (data.msgs && data.msgs.length > 0) {
        $('#msgBox').html(data.msgs[0]);
        $('#msgBox').fadeIn('slow');
    }

    if (data.errorMsgs && data.errorMsgs.length > 0) {
        $('#errorBox').html(data.errorMsgs[0]);
        $('#errorBox').fadeIn('slow');
    }

    //$("a[rel*=facebox]").facebox({ isIdSet: true });
}

function slideUpAll(ids) {
    $('div[id^="' + ids + '"]').slideUp('slow');
}

function ChangeOnglet(onglet, index) {
    var tailleMoveSlide = 150;
    var vitesseSlide = 'slow';

    $.get('/build_applications/' + onglet, function (data) {
        $('#appInfo').html(data);
        LoadScripts();
        onCompletedLoadVersion();
    });

    if (onglet.startsWith("Publication")) {

    }
}

var isFlipping = false;

var t_mouseenter;
function flipAppBlock(blockId, hide) {
    var blockHeight = $('#' + blockId).height();

    if (hide) {
        t_mouseenter = setTimeout(function () {
            clearTimeout($('#' + blockId).data('time_anim'));
            $('#' + blockId).data('time_anim',
            setTimeout(function () {
                $('#' + blockId).stop(true).animate({ top: '0px' }, 'fast');
            })
        );
        });
    }
    else {
        t_mouseenter = setTimeout(function () {
            clearTimeout($('#' + blockId).data('time_anim'));
            $('#' + blockId).data('time_anim',
            setTimeout(function () {
                $('#' + blockId).stop(true).animate({ top: -blockHeight }, 'fast');
            })
        );
        });
    }
   
}
