function getCookie(nom)
{
    deb = document.cookie.indexOf(nom + "=");

    if (deb >= 0) {
        deb += nom.length + 1;
        fin = document.cookie.indexOf(";",deb);
        if (fin < 0) fin = document.cookie.length
        return unescape(document.cookie.substring(deb,fin))
    }

    return ""
}

function voted() {
    isCookie = getCookie('voted');

    if(isCookie != "" && isCookie == "voted_survey") {
        return true;
    }

    return false;
}

/**
 * Returns the result of sondage
 */
function getSondage(response)
{
    $.getJSON("/sondage/ajax/do/"+response, function(data)
    {
        var percent = 0;
        var html    = '';

        $.each(data.response, function(index, obj) {
            percent = (obj.vote * 100) / data.total;

            html += '<div class="question">'+ obj.text +'</div>';
            html += '<div class="surveyWrapper">';
            html += '<div class="surveyPercentBar" style="width: '+ percent.toFixed(2) +'%">&nbsp;</div>';
            html += '</div>';
            html += '<div class="surveyPercent">'
            html += percent.toFixed(2) +'%';
            html += '</div>';
        });

        $("#result_survey").html(html);

    });
}

/**
 * Simple Tabs
 */
function simpleTabs(e, content)
{
    $("." + content).hide(); //Hide all content
    $(e + " li:first").addClass("active").show(); //Activate first tab
    $("." + content + ":first").show(); //Show first tab content

    //On Click Event
    $(e + " li").click(function() {
        $(e + " li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $("." + content).hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
}

/**
 * Resize a block with the height size from another bloc
 */
function blockHeightResizeFrom(block, to) {
    if($(to) && $(block)) {

        var lh = $(block).height();
        var rh = $(to).height();

        if (lh >= rh){
            $(to).height(lh);
        } else {
            $(block).height(rh);
        };
    }
}

