if (!FTVi)
    var FTVi = {};
FTVi.auth = {};

FTVi.auth.loginFacebook = function ()
{
    newWin = window.open(facebookUrl, 'facebookLoginPiFtv', 'width=1024,height=400');
    newWin.focus();
};

FTVi.auth.loginTwitter = function ()
{
    newWin = window.open(twitterUrl, 'twitterLoginPiFtv', 'width=1024,height=400');
    newWin.focus();
};

FTVi.auth.loginFinishFacebook = function (data)
{
    if (data) {
        if(data.profile) {
            var uid = data.profile.uid;
            var id = data.profile.id;
            var username = data.profile.username;
            var fullname = data.profile.fullname;
            var zipcode = data.profile.zipcode;
            var avatar = data.profile.avatar;
            var createdAt = data.profile.createdAt;
            var deletedAt = data.profile.deletedAt;
            var profileType = data.profile.profileType;
            var email = data.profile.email;
            // var services = JSON.stringify(data.profile.services, FTVi.auth.replacer);
            // var profile = JSON.stringify(data.profile, FTVi.auth.replacer);
            var services = $.parseJSON(data.profile.services);
            
            // on supprime l'objet services du profile
           delete data.profile.services;
           
            var profile = $.parseJSON(data.profile);
            // var profile = $.parseJSON(profileJson);
            
            // On enregistre les cookies dont on aura besoin
            // alert(profile);
            
            FTVi.auth.setCookie("uid", uid, 365);
            FTVi.auth.setCookieMinute("profile", profile, 30);
            FTVi.auth.setCookieMinute("services", services, 120);
            document.location.href = document.URL;
            return;
        } else {
            var userName = data.facebookName;
            var facebookId = data.facebookId;
            var email = data.email;
            if (profileUrl != document.URL) {
                var cookieAuth = {};
                cookieAuth.externalConnexionId = facebookId;
                cookieAuth.externalConnexionType = 'facebook';
                cookieAuth.externalConnexionName = userName;
                cookieAuth.login = userName;
                cookieAuth.email = email;
                FTVi.auth.setCookieMinute("externalAuth", JSON.stringify(cookieAuth, FTVi.auth.replacer), 120);
                // FTVi.auth.setCookieMinute("externalAuth", $.parseJSON(cookieAuth), 120);
                document.location.href = profileUrl;
            } else {
                $("#externalConnexionId").val(facebookId);
                $("#externalConnexionType").val('facebook');
                $("#externalConnexionName").val(userName);
                $("#login").val(userName);
                $("#email").val(email);
                slideUp('loginBoxContainer');
            }
        }
    } else {
        alert('Un problème de connexion avec votre compte Facebook a eu lieu.');
    }
};

FTVi.auth.loginFinishTwitter = function (data)
{
    if (data) {
        if(data.profile) {
            var uid = data.profile.uid;
            var id = data.profile.id;
            var username = data.profile.username;
            var fullname = data.profile.fullname;
            var zipcode = data.profile.zipcode;
            var avatar = data.profile.avatar;
            var createdAt = data.profile.createdAt;
            var deletedAt = data.profile.deletedAt;
            var profileType = data.profile.profileType;
            var email = data.profile.email;
            // var services = JSON.stringify(data.profile.services, FTVi.auth.replacer);
            // var profile = JSON.stringify(data.profile, FTVi.auth.replacer);
            var services = $.parseJSON(data.profile.services);
            
            // on supprime l'objet services du profile
            delete data.profile.services;
            
            var profile = $.parseJSON(data.profile);
            // On enregistre les cookies dont on aura besoin
            
            FTVi.auth.setCookie("uid", uid, 365);
            FTVi.auth.setCookieMinute("profile", profile, 30);
            FTVi.auth.setCookieMinute("services", services, 120);
            document.location.href = document.URL;
            return;
        } else {
            var userName = data.twitterName;
            var twitterId = data.twitterId;
            var email = data.email;
            
            if (profileUrl != document.URL) {
                var cookieAuth = {};
                cookieAuth.externalConnexionId = twitterId;
                cookieAuth.externalConnexionType = 'twitter';
                cookieAuth.externalConnexionName = userName;
                cookieAuth.login = userName;
                cookieAuth.email = email;
                FTVi.auth.setCookieMinute("externalAuth", JSON.stringify(cookieAuth, FTVi.auth.replacer), 120);
                // FTVi.auth.setCookieMinute("externalAuth", $.parseJSON(cookieAuth), 120);
                document.location.href = profileUrl;
            } else {
                $("#externalConnexionId").val(twitterId);
                $("#externalConnexionType").val('twitter');
                $("#login").val(userName);
                $("#email").val(email);
                $("#externalConnexionName").val(userName);
                slideUp('loginBoxContainer');
            }
        }
    } else {
        alert('Un problème de connexion avec votre compte Twitter a eu lieu.');
    }
};

FTVi.auth.loginPi = function (redirectProfil)
{
    if (redirectProfil == false) {
        var piEmail = $('#piEmail').val();
        var piPassword = $('#piPassword').val();
    } else {
        var piEmail = $('#piEmailFooter').val();
        var piPassword = $('#piPasswordFooter').val();
    }
    
    var error = false;
    
    //if (!isEmail(piEmail))
    if (piEmail.length < 1) {
        error = true;
        $('#piEmail').addClass('errorFound');
    }
    else
        $('#piEmail').removeClass('errorFound');
    
    if (piPassword.length < 1) {
        error = true;
        $('#piPassword').addClass('errorFound');
    }
    else
        $('#piPassword').removeClass('errorFound');
    
    if (error == true) {
        $('#errorMessageLogin').show();
        return;
    }
    else
    {
        $('#errorMessageLogin').hide();
        $.post(
            piUrl, 
            { 
                email: piEmail, 
                password: FTVi.auth.sha1(piPassword)
            },
            function(data) 
            {
                FTVi.auth.loginAction(data, redirectProfil);
            }
        );
    }
};

FTVi.auth.loginAction = function (data, redirectProfil)
{
    var status = data.status;
    if (status == 'NOK') {
        if (!redirectProfil) {
            alert('Connexion impossible, merci de vérifier vos identifiants.');
        } else {
            $('#errorMessageLogin').show();
        }
        return;
    } else {
        $('#errorMessageLogin').hide();
        var uid = data.profile.uid;
        var id = data.profile.id;
        var username = data.profile.username;
        var fullname = data.profile.fullname;
        var zipcode = data.profile.zipcode;
        var avatar = data.profile.avatar;
        var createdAt = data.profile.createdAt;
        var deletedAt = data.profile.deletedAt;
        var profileType = data.profile.profileType;
        var email = data.profile.email;
        var services = JSON.stringify(data.profile.services, FTVi.auth.replacer);
        delete data.profile.services;
        var profile = JSON.stringify(data.profile, FTVi.auth.replacer);
        
        // On enregistre les cookies dont on aura besoin
        
        FTVi.auth.setCookie("uid", uid, 365);
        FTVi.auth.setCookieMinute("profile", profile, 30);
        FTVi.auth.setCookieMinute("services", services, 120);
        document.location.href = document.URL;
        return;
    }
};

FTVi.auth.uploadPhoto = function ()
{
    var form = document.getElementById('profileForm');
    form.action = urlFormPhoto;
    form.target = 'uploadIframe';
    var valPhoto = $('#photo').val();
    valPhoto = (valPhoto + '').toLowerCase();
    var tabExt = valPhoto.split('.');
    var extension = tabExt[tabExt.length - 1];
    if (extension != 'gif' && extension != 'jpg' && extension != 'jpeg' && extension != 'png') {
        alert('Merci de charger un fichier de type jpg, gif ou png.');
        return;
    }
    
    form.submit();
    form.action = '#';
    form.target = '_self';
};

FTVi.auth.uploadPhotoAccount = function ()
{
    var form = document.getElementById('profileFormAccount');
    form.action = urlFormPhoto;
    form.target = 'uploadIframeAccount';
    var valPhoto = $('#photo').val();
    valPhoto = (valPhoto + '').toLowerCase();
    var tabExt = valPhoto.split('.');
    var extension = tabExt[tabExt.length - 1];
    if (extension != 'gif' && extension != 'jpg' && extension != 'jpeg' && extension != 'png') {
        alert('Merci de charger un fichier de type jpg, gif ou png.');
        return;
    }
    
    form.submit();
    form.action = '#';
    form.target = '_self';
}

FTVi.auth.sendCreateForm = function ()
{
    var error = false;
    
    var login = $('#login').val();
    var email = $('#email').val();
    var password = $('#password').val();
    var codePostal = $('#codePostal').val();
    var avatar = $('#photoUrl').val();
    var externalConnexionType = $('#externalConnexionType').val();
    var externalConnexionId = $('#externalConnexionId').val();
    var externalConnexionName = $('#externalConnexionName').val();
    
    var offresInfoDirect = $('#offresInfoDirect').attr('checked');
    var offresPartenaires = $('#offresPartenaires').attr('checked');
    var conditionsGenerales = $('#conditionsGenerales').attr('checked');
    
    if (conditionsGenerales == false) {
        error = true;
        $('#conditionsGeneralesSpan').addClass('errorCheckbox');
    } else {
        $('#conditionsGeneralesSpan').removeClass('errorCheckbox');
    }
    
    if (login.length < 1) {
        error = true;
        $('#login').addClass('errorFound');
    } else {
        $('#login').removeClass('errorFound');
    }
    
    if (email.length < 1 || !FTVi.auth.isEmail(email)) {
        error = true;
        $('#email').addClass('errorFound');
    } else {
        $('#email').removeClass('errorFound');
    }
    
    if (password.length < 1 || !FTVi.auth.isAlphaNum(password)) {
        error = true;
        $('#password').addClass('errorFound');
    } else {
        $('#password').removeClass('errorFound');
    }
    if (codePostal.length < 1) {
        error = true;
        $('#codePostal').addClass('errorFound');
    }
    else
        $('#codePostal').removeClass('errorFound');
    
    if (error == true) {
        $('#errorMessageDiv').show();
        return;
    } else {
        $('#errorMessageDiv').hide();
        $.post(
            urlWebservice, { 
                username: login, 
                email: email, 
                password: FTVi.auth.sha1(password), 
                avatar: avatar, 
                externalType: externalConnexionType, 
                externalId: externalConnexionId, 
                externalName: externalConnexionName, 
                zipcode: codePostal
            },
            function(data) {
                var uid = data.profile.uid;
                if (!uid.match('-')) {
                    alert("Une erreur s'est produite. Merci de recommencer.");
                    return;
                }
                var services = JSON.stringify(data.profile.services, FTVi.auth.replacer);
                delete data.profile.services;
                var profile = JSON.stringify(data.profile, FTVi.auth.replacer);
                // On enregistre les cookies dont on aura besoin
                
                FTVi.auth.setCookie("uid", uid, 365);
                FTVi.auth.setCookieMinute("profile", profile, 30);
                FTVi.auth.setCookieMinute("services", services, 120);
                document.location.href = urlAccount + '?create=on';
                return;
            }
        );
    } 
};

FTVi.auth.updateAccount = function ()
{
    var error = false;
    
    var login = $('#loginAccount').val();
    var email = $('#emailAccount').val();
    var password = $('#passwordAccount').val();
    var codePostal = $('#codePostalAccount').val();
    var avatar = $('#photoUrl').val();
    
    var profileString = unescape(FTVi.auth.getCookie('profile'));
    // var profile = eval('(' + profileString + ')');
    var profile = JSON.parse(profileString);
    var uid = profile.uid;
    
    if (login.length < 1) {
        error = true;
        $('#loginAccount').addClass('errorFound');
    } else {
        $('#loginAccount').removeClass('errorFound');
    }
    
    if (email.length < 1 || !FTVi.auth.isEmail(email)) {
        error = true;
        $('#emailAccount').addClass('errorFound');
    } else {
        $('#emailAccount').removeClass('errorFound');
    }
    
    if (codePostal.length < 1)
    {
        error = true;
        $('#codePostalAccount').addClass('errorFound');
    } else {
        $('#codePostalAccount').removeClass('errorFound');
    }
    
    if (error == true) {
        $('#errorMessageDiv').show();
        return;
    } else {
        $('#errorMessageDiv').hide();
        if (password.length > 0)
        {
            $.post(
                urlWebserviceUpdate, 
                { 
                    uid: uid, 
                    username: login, 
                    email: email, 
                    password: FTVi.auth.sha1(password), 
                    avatar: avatar, 
                    zipcode: codePostal
                },
                function(data) 
                {
                    if (!data.uid.match('-')) {
                        alert("Une erreur s'est produite. Merci de recommencer.");
                        return;
                    }
                    var uid = data.uid;
                    var services = JSON.stringify(data.services, FTVi.auth.replacer);
                    delete data.services;
                    var profile = JSON.stringify(data, FTVi.auth.replacer);
                    // On enregistre les cookies dont on aura besoin
                    
                    FTVi.auth.setCookie("uid", uid, 365);
                    FTVi.auth.setCookieMinute("profile", profile, 30);
                    FTVi.auth.setCookieMinute("services", services, 120);
                    document.location.href = urlAccount + '?modifiy=on';
                    return;
                }
            );
        }
        else
        {
            $.post(
                urlWebserviceUpdate, { 
                    uid: uid, 
                    username: login, 
                    email: email, 
                    avatar: avatar, 
                    zipcode: codePostal
                },
                function(data) {
                    if (!data.profile.uid.match('-')) {
                        alert("Une erreur s'est produite. Merci de recommencer.");
                        return;
                    }
                    var uid = data.profile.uid;
                    var services = JSON.stringify(data.profile.services, FTVi.auth.replacer);
                    delete data.profile.services;
                    var profile = JSON.stringify(data.profile, FTVi.auth.replacer);
                    // On enregistre les cookies dont on aura besoin
                    
                    FTVi.auth.setCookie("uid", uid, 365);
                    FTVi.auth.setCookieMinute("profile", profile, 30);
                    FTVi.auth.setCookieMinute("services", services, 120);
                    document.location.href = urlAccount + '?modifiy=on';
                    return;
                }
            );
        }
    } 
};

FTVi.auth.setCookie = function (cookieName, cookieValue, cookieExpiration)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + cookieExpiration);
    cookieValue = escape(cookieValue) + ((cookieExpiration == null) ? "" : "; expires=" + exdate.toUTCString()) + "; path=/";
    document.cookie = cookieName + "=" + cookieValue;
};

FTVi.auth.setCookieMinute = function (cookieName, cookieValue, cookieExpiration)
{
    var exdate = new Date();
    exdate.setTime(exdate.getTime() + (cookieExpiration * 60000));
    cookieValue = escape(cookieValue) + ((cookieExpiration == null) ? "" : "; expires=" + exdate.toUTCString()) + "; path=/";
    document.cookie = cookieName + "=" + cookieValue;
};

FTVi.auth.getCookie = function (cookieName)
{
    var nameEQ = cookieName + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
            c = c.substring(1, c.length);
		}
        if (c.indexOf(nameEQ) == 0) {
            return c.substring(nameEQ.length, c.length);
        }
	}
	return null;
};

FTVi.auth.delCookie = function (cookieName) 
{
    if (FTVi.auth.getCookie(cookieName)) {
        document.cookie = cookieName + "=" +"; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
};


FTVi.auth.skipForm = function (userId, cookieVal, externalConnexionType)
{
    setCookie("uid", cookieVal, 365);
    alert('OK');
};

FTVi.auth.isAlphaNum = function (str)
{
    var regex = /^([a-zA-Z0-9])+$/;
    if (regex.test(str)) {
        return true;
    }
    return false;
};

FTVi.auth.isEmail = function (email) 
{
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,6})+$/;
    if (regex.test(email)) {
        return true;
    }
    return false;
};

FTVi.auth.replacer = function (key, value) 
{
    if (typeof value === 'number' && !isFinite(value)) {
        return String(value);
    }
    return value;
};

FTVi.auth.reviver = function (key, value) 
{
    var type;
    if (value && typeof value === 'object') {
        type = value.type;
        if (typeof type === 'string' && typeof window[type] === 'function') {
            return new (window[type])(value);
        }
    }
    return value;
};

FTVi.auth.sha1 = function(str)
{
    return hex_sha1(str);
};

FTVi.auth.stringify = function (jsonData, tabMultiple) {
    var tab = "";
    if(!tabMultiple){
        tabMultiple = 1;
    }
    
    for (var i = 1; i <= tabMultiple; i++){
        tab += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";;
    }
    var strJsonData = '{<br/>';
    var itemCount = 0;
    for (var item in jsonData) {
        if (itemCount > 0) {
            strJsonData += ', <br/>';
        }
        var temp = jsonData[item];
        if (typeof(temp) == 'object') {
            tabMultiple++;
            var s = FTVi.auth.stringify(temp, tabMultiple);
            tabMultiple--;
        }
        else {
            tabMultiple--
            var s = '"' + temp + '"';
        }
        strJsonData += tab + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"' + item + '":' + s;
        itemCount++;
    }
    strJsonData += '<br/>' + tab + '}';
    return strJsonData;
};

var hexcase=0;var b64pad="";function hex_sha1(a){return rstr2hex(rstr_sha1(str2rstr_utf8(a)))}function hex_hmac_sha1(a,b){return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}function sha1_vm_test(){return hex_sha1("abc").toLowerCase()=="a9993e364706816aba3e25717850c26c9cd0d89d"}function rstr_sha1(a){return binb2rstr(binb_sha1(rstr2binb(a),a.length*8))}function rstr_hmac_sha1(c,f){var e=rstr2binb(c);if(e.length>16){e=binb_sha1(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binb_sha1(a.concat(rstr2binb(f)),512+f.length*8);return binb2rstr(binb_sha1(d.concat(g),512+160))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binb(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(24-c%32)}return a}function binb2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(24-c%32))&255)}return a}function binb_sha1(v,o){v[o>>5]|=128<<(24-o%32);v[((o+64>>9)<<4)+15]=o;var y=Array(80);var u=1732584193;var s=-271733879;var r=-1732584194;var q=271733878;var p=-1009589776;for(var l=0;l<v.length;l+=16){var n=u;var m=s;var k=r;var h=q;var f=p;for(var g=0;g<80;g++){if(g<16){y[g]=v[l+g]}else{y[g]=bit_rol(y[g-3]^y[g-8]^y[g-14]^y[g-16],1)}var z=safe_add(safe_add(bit_rol(u,5),sha1_ft(g,s,r,q)),safe_add(safe_add(p,y[g]),sha1_kt(g)));p=q;q=r;r=bit_rol(s,30);s=u;u=z}u=safe_add(u,n);s=safe_add(s,m);r=safe_add(r,k);q=safe_add(q,h);p=safe_add(p,f)}return Array(u,s,r,q,p)}function sha1_ft(e,a,g,f){if(e<20){return(a&g)|((~a)&f)}if(e<40){return a^g^f}if(e<60){return(a&g)|(a&f)|(g&f)}return a^g^f}function sha1_kt(a){return(a<20)?1518500249:(a<40)?1859775393:(a<60)?-1894007588:-899497514}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};

$(document).ready(function() 
{
    if (!document.URL.match('logout')) {
        breakingNews();
        setTimeout('breakingNews()', 300000); // on recharge le breakingNews toutes les 5 minutes
    }
    
    // on met à jour le formulaire de MAJ du compte
    if (urlAccount == document.URL || urlAccount == document.URL + '/') {
        var profileCookie = unescape(FTVi.auth.getCookie('profile'));
        if (profileCookie.length > 0 && profileCookie != 'null') {
            // var profile = eval('(' + profileCookie + ')');
            var profile = JSON.parse(profileCookie);
            if (typeof(profile) == 'object') {
                var uid = profile.uid;
                var id = profile.id;
                var username = profile.username;
                var fullname = profile.fullname;
                var zipcode = profile.zipcode;
                var email = profile.email;
                var avatar = '';
                
                avatar = profile.avatar;
                
                if (avatar.length < 1) {
                    avatar = '/info/skin/www/img/icn/icn_avatar.jpg';
                }
                
                $('#photoUrl').val(avatar);
                $('#loginAccount').val(username);
                $('#emailAccount').val(email);
                $('#codePostalAccount').val(zipcode);
                document.getElementById('avatar').src = avatar;
            }
        } else {
            document.location.href = profileUrl;
        }
    }
    
    if (profileUrl == document.URL || profileUrl == document.URL + '/') {
        var externalAuthCookie = unescape(FTVi.auth.getCookie('externalAuth'));
        if (externalAuthCookie.length > 0 && externalAuthCookie != 'null') {
            // var cookieAuth = eval('(' + externalAuthCookie + ')');
            var cookieAuth = JSON.parse(externalAuthCookie);
            if (cookieAuth) {
                $("#externalConnexionId").val(cookieAuth.externalConnexionId);
                $("#externalConnexionType").val(cookieAuth.externalConnexionType);
                $("#externalConnexionName").val(cookieAuth.externalConnexionName);
                $("#login").val(cookieAuth.login);
                $("#email").val(cookieAuth.email);
            }
        }
    }
    var profileCookie = unescape(FTVi.auth.getCookie('profile'));
    if (profileCookie.length > 0 && profileCookie != 'null') {
        var profile = JSON.parse(profileCookie);
        // var profile = eval('(' + profileCookie + ')'); // pour ie
        if (profile) {
            var uid = profile.uid;
            var id = profile.id;
            var username = profile.username;
            var fullname = profile.fullname;
            var zipcode = profile.zipcode;
            var avatar = '';
            
            avatar = profile.avatar;
            
            if (avatar.length < 1) {
                avatar = '/info/skin/www/img/icn/icn_avatar.jpg';
            }
            
            var createdAt = profile.createdAt;
            var deletedAt = profile.deletedAt;
            var profileType = profile.profileType;
            var email = profile.email;
            
            var html = '<div class="welcomeMsg">Bienvenue, ' + username + '</div>';
            html += '<ul>';
            html += '<li class="myAccount"><a href="' + urlAccount + '">Mon compte<img src="' + avatar + '" border="0" width="25" height="25" class="avatar"></a></li>';
            html += '<li class="logOff"><a href="' + urlLogout + '">Se déconnecter</a></li>';
            html += '</ul>';
            $('#personalInfo').removeClass('personalInfo');
            $('#personalInfo').addClass('off');
            $('#personalInfo').html(html);
        }
    } else {
        var uid = FTVi.auth.getCookie('uid');
        if (uid) {
            $.post(
                urlWebserviceRead, { 
                    uid: uid
                },
                function(data) 
                {
                    if (!data.profile.uid.match('-')) {
                        alert("Une erreur s'est produite. Merci de recommencer.");
                        return;
                    }
                    var uid = data.profile.uid;
                    var services = JSON.stringify(data.profile.services, FTVi.auth.replacer);
                    delete data.profile.services;
                    var profile = JSON.stringify(data.profile, FTVi.auth.replacer);
                    // On enregistre les cookies dont on aura besoin
                    
                    FTVi.auth.setCookie("uid", uid, 365);
                    FTVi.auth.setCookieMinute("profile", profile, 30);
                    FTVi.auth.setCookieMinute("services", services, 120);
                    document.location.href = document.URL;
                    return;
                }
            );
        }
    }
});
