//***************************************************************************************************
// Fonction de contrôle de formulaire.
//***************************************************************************************************
function checkLengthNameFirstName(ctrl1,ctrl2,lng)
{
    var msg_fr = "Le nom + le prénom ne doivent pas dépasser 30 caractères."
    var msg_ge = "Name und Vorname dürfen nicht mehr als 30 Zeichen umfassen."
    if((String(ctrl1.value).length+String(ctrl2.value).length)>=30)
    {
        ctrl1.focus()
        if(lng.toLowerCase()=="ge")
        {
            alert(msg_ge);
        }
        else
        {
           alert(msg_fr); 
        }
        return false;
    }    
    return true;
}


//***************************************************************************************************
// Fonction visuelle.
//***************************************************************************************************
function toggle(me)
{
    if (document.getElementById(me))
    {
        if(document.getElementById(me).style.display == 'none')
            document.getElementById(me).style.display = '';
        else
            document.getElementById(me).style.display = 'none';
    }
}


function toggleSelCountry()
{
    if (document.getElementById('lMenuSelCountry').style.display == 'none')
    {
        document.getElementById('lMenuSelCountryArrow').src = 'images/pictos/whiteArrow_up.png';
        document.getElementById('tabSelCountry').style.backgroundImage = "url('images/left_menu/bg_lMenuHeader_sel.png')";
        document.getElementById('tabSelCountry').style.color = "#000000";
    }   
    else
    {
        document.getElementById('lMenuSelCountryArrow').src = 'images/pictos/whiteArrow_down.png';
        document.getElementById('tabSelCountry').style.backgroundImage = "url('images/left_menu/bg_lMenuHeader.png')";
        document.getElementById('tabSelCountry').style.color = "#FFFFFF";
    }
    
    toggle('lMenuSelCountry');
}


function lMenuSwitchSel(Sel)
{
    if(document.getElementById('lMenu'+Sel)&&document.getElementById('lMenu'+Sel).style.display == 'none')
    {
        document.getElementById('lMenu'+Sel).style.display = '';
        document.getElementById('lMenu'+Sel+'Arrow').src = 'images/pictos/whiteArrow_up.png';
        
        var cMenu = new Cookie(' dfMenu');
        
        if (!cMenu.Section)
        {
            cMenu.Section = Sel;
            cMenu.store();
        }
        else
        {
            if (cMenu.Section.indexOf(Sel) == -1)
            {
                cMenu.Section += '#'+Sel;
            }
        }
    }
    else 
    {
        if(document.getElementById('lMenu'+Sel))
        {
            document.getElementById('lMenu'+Sel).style.display = 'none';
            document.getElementById('lMenu'+Sel+'Arrow').src = 'images/pictos/whiteArrow_down.png';
        }
        
        var cMenu = new Cookie(' dfMenu');
        if (cMenu.Section)
        {
            if (cMenu.Section.indexOf(Sel) != -1)
            {
                var tabSec = cMenu.Section.split('#');
                cMenu.Section = "";
                for (i=0 ; i<tabSec.length ; i++)
                    if (tabSec[i] != Sel && tabSec[i] != "")
                        cMenu.Section += '#'+ tabSec[i];
            }
        }
    }
    cMenu.store(30);
}


//***************************************************************************************************
// Classe utilitaire de gestion de cookie.
//***************************************************************************************************

function Cookie(name)
{

    this.$name = name;
 
    var allcookies = document.cookie;
    if (allcookies == "") return;

    var cookies = allcookies.split(';');
    var cookie = null;
    for(var i = 0; i < cookies.length; i++)
    {
        if (cookies[i].substring(0, name.length+1) == (name + "="))
        {
            cookie = cookies[i];
            break;
        }
    }
    
    if (cookie == null) return;

    var cookieval = cookie.substring(name.length+1);

    var a = cookieval.split('&');
    for(var i=0; i < a.length; i++)
        a[i] = a[i].split(':');

    for(var i = 0; i < a.length; i++)
    {
        this[a[i][0]] = decodeURIComponent(a[i][1]);
    }
}

Cookie.prototype.store = function(daysToLive, path, domain, secure)
{

    var cookieval = "";
    for(var prop in this)
    {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + encodeURIComponent(this[prop]);
    }

    var cookie = this.$name + '=' + cookieval;
    if (daysToLive || daysToLive == 0)
    {
        cookie += "; max-age=" + (daysToLive*24*60*60);
    }

    if (path) cookie += "; path=" + path;
    if (domain) cookie += "; domain=" + domain;
    if (secure) cookie += "; secure";

    document.cookie = cookie;
}

Cookie.prototype.remove = function(path, domain, secure) {
    // Delete the properties of the cookie
    for(var prop in this) {
        if (prop.charAt(0) != '$' && typeof this[prop] != 'function') 
            delete this[prop];
    }

    // Then, store the cookie with a lifetime of 0
    this.store(0, path, domain, secure);
}
