﻿function ChangeVisibility(val, targetId) {
    var elm = document.getElementById(targetId);
    if (val) {
        elm.style.display = 'block';
    }
    else {
        elm.style.display = 'none';
    }
}

function SwitchVisibility(targetId) {
    var elm = document.getElementById(targetId);
    if (elm.style.display == 'block') {
        elm.style.display = 'none';
    }
    else {
        elm.style.display = 'block';
    }
}

function ClosePopup() {
    this.document.getElementById("popup2").style.display = "none";
}

// Ajax function
function getContent(url, callback) {
    var request = new Sys.Net.WebRequest();
    request.set_url(url);
    request.set_httpVerb("GET");
    var del = Function.createCallback(getContentResults, callback);
    request.add_completed(del);
    request.invoke();
}

function getContentResults(executor, eventArgs, callback) {
    if (executor.get_responseAvailable()) {
        var test = executor.get_responseData();
        callback(eval("(" + test + ")"));
    }
    else {
        if (executor.get_timedOut())
            alert("Timed Out");
        else if (executor.get_aborted())
            alert("Aborted");
    }
}

// Si l'usager clique sur une catégorie alors on le redirige sur la première passions de catégorie
function ifCategorieGoToNextPassions(dropDownList) {
    if (dropDownList.options[dropDownList.selectedIndex].value == -2)
        dropDownList.selectedIndex += 1;
}

function addTableRow(jQtable) {
    jQtable.each(function () {
        var $table = $(this);
        // Number of td's in the last table row
        var n = $('tr:last td', this).length;
        var tds = '<tr>';
        for (var i = 0; i < n; i++) {
            tds += '<td> </td>';
        }
        tds += '</tr>';
        if ($('tbody', this).length > 0) {
            $('tbody', this).append(tds);
        } else {
            $(this).append(tds);
        }
    });
}
/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength)
}

function showStatusCompletion() {
    getContent("/fr/Action/showStatusCompletion/", function (data) { document.getElementById('mba').innerHTML = data; homePageLoad(); });
};

/**/

function hideShowDivisionPassion(id) {
    jQuery("#" + id).slideToggle(1000);
    jQuery("#" + id).css({
        'display': 'none'
    });
    jQuery("#" + id).css({
        'margin-bottom': '10px'
    });

}

function homePageLoad() {
    jQuery(".accordion").accordion({
        active: 1,
        collapsible: true,
        autoHeight: false

    });

    /*         DEBUT     CHEKBOX FIX             */
    jQuery(".accordion h3 input").click(function (evt) {
        evt.stopPropagation();
    });
    /*         FIN     CHEKBOX FIX             */

    /*       DEBUT   FORM S2             */
    jQuery("input#plus").focus(function () {
        jQuery("#form_step_2").fadeIn(900);
        return false;
    });

    /*       FIN     FORM S2             */
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
        allowresize: false
    });

    // Dialog Link
    jQuery('.pup').click(function () {
        jQuery('#mbr').dialog('open');

        return false;
    });

    jQuery('.pap').click(function () {
        jQuery('#mba').dialog('open');
        return false;
    });

    jQuery('a.pup_close').click(function () {
        jQuery(".dialog").dialog('close');
        return false;
    });

    /*       DEBUT MSG POP UP           */
    jQuery(".dialog").dialog({
        modal: true,
        zIndex: 3999,
        position: 'center'
    });

    /*----------------------------------*/
    jQuery(".dialogOpen").dialog({
        autoOpen: true,
        modal: true,
        zIndex: 3999,
        height: 420,
        width: 560,
        position: 'center'
    });

    /*       FIN MSG POP UP           */


    /* DEBUT MINI */
    jQuery(function () {

        jQuery("#explore-nav li a").click(function () {
            var curList = jQuery("#explore-nav li a.current").attr("rel");
            var jQuerynewList = jQuery(this);
            var curListHeight = jQuery("#all-list-wrap").height();
            jQuery("#all-list-wrap").height(curListHeight);
            jQuery("#explore-nav li a").removeClass("current");
            jQuerynewList.addClass("current");
            var listID = jQuerynewList.attr("rel");
            if (listID != curList) {
                jQuery("#" + curList).fadeOut(300, function () {

                    jQuery("#" + listID).fadeIn();

                    var newHeight = jQuery("#" + listID).height();

                    jQuery("#all-list-wrap").animate({
                        height: newHeight
                    });
                });
            }
            return false;
        });
    });
    /* FIN MINI */

    //Affiche les forfaits dans le tableau
    jQuery(function () {
        var url = window.location.toString();
        var value = url.substring(url.lastIndexOf('#') + 1);
        jQuery(("#forfait_00" + value)).css("display", "block");
    });

    /* DEBUT FORFAIT  */
    jQuery("#btnAds").click(function () {
        jQuery("#forfait_001").slideToggle(1000);
    });
    jQuery("#btnDif").click(function () {
        jQuery("#forfait_002").slideToggle(1000);
    });
    jQuery("#btnBann").click(function () {
        jQuery("#forfait_004").slideToggle(1000);
    });
    /* FIN FORFAIT  */

    //Affichage
    jQuery("#region").click(function (event) {
        if (jQuery("#listRegion").hasClass('hidden')) {
            jQuery("#listRegion").removeClass('hidden')
            jQuery("#listRegion").addClass('visible');
        } else {
            jQuery("#listRegion").removeClass('visible')
            jQuery("#listRegion").addClass('hidden');
        };
    });
    jQuery("#categorie").click(function (event) {
        if (jQuery("#listCategorie").hasClass('hidden')) {
            jQuery("#listCategorie").removeClass('hidden')
            jQuery("#listCategorie").addClass('visible');
        } else {
            jQuery("#listCategorie").removeClass('visible')
            jQuery("#listCategorie").addClass('hidden');
        };
    });
    //Transfert
    jQuery("#listRegion a.list").each(function (intIndex) {
        jQuery(this).bind("click", function () {
            var regionId = jQuery("#lr" + (intIndex + 1)).attr("title")
            jQuery("#regionId").val(regionId)
            jQuery("#listRegion").removeClass('visible')
            jQuery("#listRegion").addClass('hidden')
        });
    });
    jQuery("#listCategorie a.list").each(function (intIndex) {
        jQuery(this).bind("click", function () {
            var categorieId = jQuery("#lc" + (intIndex + 1)).attr("title")
            jQuery("#divId").val(categorieId)
            jQuery("#listCategorie").removeClass('visible')
            jQuery("#listCategorie").addClass('hidden')
        });
    });
    //Supprime le contenu du champ de recherche on focus
    jQuery("#inputKey").focus(function (event) {
        jQuery(this).val("")
    });

    //Affichage DatePicker
    jQuery(function () {
        jQuery("#startDate").datepicker({ dateFormat: 'yy-mm-dd' }, jQuery.datepicker.regional['fr']);
        jQuery("#endDate").datepicker({ dateFormat: 'yy-mm-dd' }, jQuery.datepicker.regional['fr']);
    });

    //Ajouter une class a toute les catégories de passions dans le ddl
    if (location.pathname != "/" && location.pathname != "/fr/Home/Home")
        jQuery("option[value*='d_']").css("background-color", "#ccc");


} /*       FIN HOME PAGE LOAD       */
