$(function () {
if(ac){document.location=$('#myInfos').attr("href");}
});
$(document).ready(function(){
// Récupération du token de validation de compte s'il est passé en paramètre ocation.search).vk)
if (eni.url.params().tk) {
// on lance la validation du compte
params = eni.url.params();
params['cl'] = eni.lng.code();
window.history.pushState('', document.title, document.location.pathname);
eni.axc({Async:true,Type:'script', Url:'./actiris/ajax/validation.aspx', Data:params, Msg:$('#Login').data("validation")});
}
// Mot de passe oublié
$('#ForgetPWD').on('click', function (e) {
e.preventDefault();
eni.msg({ Type:"forgetPwd",
Title:this.title,
Content:box_forgetPwd,
init:function(){$(this).find("input").focus(function(){$(this).removeClass('Error');});} });
return false;
})
// Connexion
$('#login, #password').on('change textInput input propertychange', function(){
$label = $('label[for="'+$(this).attr('id')+'"]');
if ($(this).val().length > 0){
if($label.text().length > 0){
if($label.attr('data-title') == undefined){$label.attr('data-title', $label.html())}
//$label.html("");
}
}else{
$label.html($label.attr('data-title'));
}
});
$('#btnLogin').click(function(){
var _form={},
_errors='',
_feilds_incomplete=0,
$form = $('#Login');
// Suppression de la class Error
$form.find('input[type=email], input[type=password]').removeClass('Error')
.each(function(){
$field=$(this);
if ($field.attr('required') == 'required'){
if ($field.val().length == 0) {
$field.addClass('Error');
_feilds_incomplete += 1;
}
}
if($field.attr('type') == "email"){
if (!email_pattern.test($field.val())){
$field.addClass('Error');
_errors = $field.data('error');
}
}
})
if (_feilds_incomplete > 0) {
// désactivation des input
$('#login, #password, #cpassword, #btnLogin').blur().attr('disabled','disabled');
// généraion du message d'erreur
lab_login = $('#login').attr("placeholder");
lab_pwd = $('#password').attr("placeholder");
_errors=$form.data('incomplete').replace('%login%', lab_login).replace('%password%', lab_pwd);
}else if($("#cpassword").is(":visible")){
// test confirmation du mot de passe
if ($("#password").val() != $("#cpassword").val()){_errors=$("#cpassword").data('error')}
}
if (_errors.length == 0) {
$('#launch_Portail').remove();
$launch_Portail = $('');
$('#Login').append($launch_Portail);
// Si tous les champs sont valides alors on envoie le formulaire
$($form.find('input[type=email], input[type=password]').serializeArray()).each(function(){_form[this.name] = this.value;});
// désactivation des input après sérialisation
$('#login, #password, #cpassword, #btnLogin').blur().attr('disabled','disabled');
// Ajout code Langue
_form['cl'] = eni.lng.code();
/*if($("#cpassword").is(":visible")){_form['wrong'] = $("#cpassword").data('error')}
else{_form['wrong'] = $form.data('wrong');}*/
eni.axc({Async:false,Type:'script', Url:'./actiris/ajax/login.aspx', Data:_form, Msg:$('#Login').data("inProgress"), fn:function(){
// Bug sous IE pas de création auto du cookie il faut retirer l'option "expires"
//if (window.navigator.userAgent.indexOf('Trident/') > -1) {eval(this.Return.replace(" expires=-1;", ""))}
$('#login, #password, #cpassword, #btnLogin').removeAttr('disabled');
ac = Cookies('_usr');
if(ac){
ac = $.parseJSON(ac);
$launch_Portail.attr('href', ac.url)
$launch_Portail[0].click();
$launch_Portail.remove();
document.location = $('#logoENI').attr("href");
}
}});
}else{
// Sinon alerte
eni.msg({ Title: "", Content: _errors, fn:function(){$('#login, #password, #cpassword, #btnLogin').removeAttr('disabled');}});
}
});
$('#login').keypress(function(e){validLogin.call(this,e);})
.focus();
$('#password').keypress(function(e){validLogin.call(this,e);})
$('#cpassword').keypress(function(e){validLogin.call(this,e);})
});
validLogin = function (e) {
$This = $(this);
if (e.keyCode == 13) {
if ($This.val().length > 0){
switch ($This.attr("id")){
case "login":
if ($("#password").val().length==0){$("#password").focus()}
else if ($("#cpassword").is(":visible") && $("#cpassword").val().length==0){$("#cpassword").focus()}
else{$('#btnLogin').click()}
break;
case "password":
if($("#login").val().length==0){$("#login").focus()}
else if ($("#cpassword").is(":visible") && $("#cpassword").val().length==0){$("#cpassword").focus()}
else{$('#btnLogin').click()}
break;
case "cpassword":
if($("#login").val().length==0){$("#login").focus()}
else if ($("#password").val().length==0){$("#password").focus()}
else{$('#btnLogin').click()}
break;
}
}
}
}
confirmPWD = function() {
$('#login').attr('disabled', 'disabled');
$('#Login').focus();
$('#cpassword, #lblConfirmPwd').removeClass('hidden');
$("#cpassword").val('');
$("#cpassword").focus();
}
changePwd = function(){
eni.cleanLoader();
this.focus();
var $form,
_form={},
_title='',
_errors='',
_lst_feilds_incomplete='',
_lst_feilds_error='';
// Récupération du formulaire prêt à être envoyé
$form = $(this).closest('form');
_title = $form.attr('data-error');
//_errors = _title;
// Suppression de la class Error
$form.find('input, textarea').not('[hidden]').removeClass('Error')
.each(function(){
$field=$(this);
if ($field.attr('required') == 'required'){
if ($field.val().length == 0) {
$field.addClass('Error');
_lst_feilds_incomplete += '
' + $field.attr('placeholder') + '';
}
}
if ($field.val().length > 0){
switch($field.attr('type')) {
case "email":
emails = $field.val().split(",");
match = false;
for(i=0;i0?'
':'') + (_title.length>0?'- ':'') + $field.attr('data-error').replace("%INPUT%", $field.attr('placeholder'));
}
break;
default:
}
}
})
if (_lst_feilds_error.length > 0) {_errors+=((_title + _errors).length>0?'
':'') + _lst_feilds_error}
if (_lst_feilds_incomplete.length > 0) {_errors+=((_title + _errors).length>0?'
':'') + (_title.length>0?'- ':'') + $form.attr('data-incomplete')}
if (_errors.length == 0) {
$form.parent().parent().parent().find('.dlgBtnClose').click();
// Si tous les champs sont valides alors on envoie le formulaire
$($form.find('input, textarea, select').serializeArray()).each(function(){
_form[this.name] = this.value;
});
_form["cl"] = eni.lng.code();
eni.axc({Async:true,Type:'script', Url:'./actiris/ajax/forgetPwd.aspx', Data:_form, Msg:job_in_progress});
}else{
// Sinon alerte
eni.msg({ Title: '', Content: _title + _errors});
}
return false;
}
params = function(_url) {
var parts = _url.replace("?", "").split("&");
var query_string = {};
for (var i = 0; i < parts.length; i++) {
var pair = parts[i].split("=");
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
} else if (typeof query_string[pair[0]] === "string") {
var arr = [query_string[pair[0]], decodeURIComponent(pair[1])];
query_string[pair[0]] = arr;
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}