/*######################################################################## fonction.js Version 2.72 Date 12/06/2014 ########################################################################*/ /* * Version 1.72 - Ajout de la fonction CarAlea */ SortList=function(a){var b=$.makeArray($("#"+a+" option")).sort(function(a,b){return $(a).text()<$(b).text()?-1:1});$("#"+a).empty().html(b)}; Compte_A_Rebours = function(a){ dd = a.split("/"); jd = dd[0]; md = dd[1]; ad = dd[2]; var b = new Date(ad, md-1, jd); var auDate = new Date(); var c = new Date(auDate.getFullYear(),auDate.getMonth(),auDate.getDate()); return Math.round((b - c) / 864E5); }; DateLongue = function(a) { T = a.split("/"); a = T[2]; return T[0] + " " + " Janvier F\u00e9vrier Mars Avril Mai Juin Juillet Ao\u00fbt Septembre Octobre Novembre D\u00e9cembre".split(" ")[parseInt(T[1])] + " " + a; }; DateDiff = function(a, b) { dd = a.split("/"); df = b.split("/"); jd = dd[0]; md = dd[1]; ad = dd[2]; var c = new Date(ad, md-1, jd); jf = df[0]; mf = df[1]; af = df[2]; return Math.round((new Date(af, mf-1, jf) - c) / 864E5); }; Notification = function(message) { $.blockUI({ message: '
' + message + '
', fadeIn: 700, fadeOut: 700, timeout: 2000, showOverlay: false, centerY: true, css: { width: '350px', top: '266px', left: '45%', right: '0', border: '#000 1px solid', padding: '2px', backgroundColor: '#696c6c', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', 'border-radius': '10px', opacity: 1, color: '#fff' } }); }; /* * CarAlea */ CarAlea = function(taille, chaine) { var randomstring = ''; var charCount = 0; var numCount = 0; for (var i = 0; i < taille; i++) { // If random bit is 0, there are less than 3 digits already saved, and there are not already 5 characters saved, generate a numeric value. if ((Math.floor(Math.random() * 2) == 0) && numCount < 3 || charCount >= 5) { var rnum = Math.floor(Math.random() * 10); randomstring += rnum; numCount += 1; } else { // If any of the above criteria fail, go ahead and generate an alpha character from the chars string var rnum = Math.floor(Math.random() * chaine.length); randomstring += chaine.substring(rnum, rnum + 1); charCount += 1; } } return randomstring; }; str_replace = function(remplace, par, chaine) { var reg = new RegExp("(" + remplace + ")", "g"); return chaine.replace(reg, par); }; maxlength = function(text, length) { if (text.value.length > length) { text.value = text.value.substr(0, length); } }; /*######################################################################## MID ########################################################################*/ // fonction permettant de revoyer une partie d'une chaine de caractère. // utilisation : Mid("chaine",PositionDebut,PositionFin) Mid = function(str, start, len) { if (start < 0 || len < 0) return ""; var iEnd, iLen = String(str).length; if (start + len > iLen) iEnd = iLen; else iEnd = start + len; return String(str).substring(start, iEnd); } /*######################################################################## DECIMAL ########################################################################*/ // Arrondi un chiffreNbrdécimal // utilisation : decimal(122.659,2) retourne 122.66 decimal = function(valeur, nbrdecimal) { if ((valeur == '') || (valeur == null)) { return ''; } Diviseur = Math.pow(10, nbrdecimal) return Math.round(Diviseur * parseFloat(valeur, 10)) / Diviseur } /*######################################################################## LEFT ########################################################################*/ // fonction permettant de revoyer un nombre de caractere de la partie gauche d'une chaine // utilisation : Left("chaine",3) renvoie "cha" Left = function(a, b) { return 0 >= b ? "" : b > String(a).length ? a : String(a).substring(0, b) }; /*######################################################################## RIGHT ########################################################################*/ // fonction permettant de revoyer un nombre de caractere de la partie droite d'une chaine // utilisation : Right("chaine",3) renvoie "ine" Right = function(a, b) { if (0 >= b) return""; if (b > String(a).length) return a; var c = String(a).length; return String(a).substring(c, c - b); }; /*######################################################################## ISEMPTY ########################################################################*/ // Cette fonction permet de déterminé si une chaine est vide // utilisation : IsEmpty("t") retourn false IsEmpty=function(a){ return""===a.trim()||null===a?!0:!1; }; /*######################################################################## ISNUMERIC ########################################################################*/ // fonction permettant de déterminer si la chaine contient un numérique et/ou un réel // Format 0.25 ou +100 ou -10.5 mais pas .5 ou E+1.10 ou 10,5 // utilisation : IsNumeric('123') retourne true isNumber = function(str) { var pattern = /^\d+$/; return pattern.test(str); // returns a boolean }; /*######################################################################## INNUMRANGE ########################################################################*/ // Fonction permettant de déterminé si la variable A est compris entre D et F // utilisation : InNumRange(3,1,10) retourne true InNumRange = function(A, D, F) { return (parseFloat(A) >= parseFloat(D) && parseFloat(A) <= parseFloat(F)); }; /*######################################################################## IS_DATERANGE ########################################################################*/ // fonction permettant de déterminé si la date A est compris entre les dates D et F // utilisation : InDateRange("12/02/2008","01/01/2009","01/03/2008") retourne true InDateRange = function(A, D, F) { DateA = new Date(A); DateD = new Date(D); DateF = new Date(F); return (DateA.getTime() >= DateD.getTime() && DateA.getTime() <= DateF.getTime()); }; /*######################################################################## TOUCHE_INTERDITE ########################################################################*/ // fonction permettant d'interdit la frappe d'un code touche mis en parametre. e correspond � l'objet event. // utilisation : onKeyPress="javascript:Touche_interdite(event,13);" // 13 = code touche "Entrée" Touche_interdite = function(e, CodeTouche) { if (e.keyCode === CodeTouche) { e.returnValue = false; } else if (e.which === CodeTouche) { e.preventDefault(); } }; /*######################################################################## ALPHA_INTERDIT ########################################################################*/ // fonction permettant d'interdit la saisie de toutes touche non alpha // utilisation : onKeyPress="javascript:alpha_interdit(event);" alpha_interdit = function(e) { if (e.keyCode < 96 || e.keyCode > 105 || e.which < 96 || e.which > 105) { e.returnValue = false; return false; } else { return true; } }; /** * affiche une bo�te de dialogue d'information sur l'expiration imminente de la session utilisateur : * si l'utilisateur clique sur OK, la page est recharg�e pour r�initialiser le chronom�tre de session * @param int minutes d�lai avant l'expiration de la session */ rappelSession = function(minutes) { var msg = 'Votre session expirera dans ' + minutes + ' minute'; if (minutes > 1) msg += 's'; msg += '.\nVoulez-vous recharger la page pour éviter la déconnexion automatique ?'; msg += '.\nAttention, toutes données non enregistrées seront perdues.'; jConfirm(msg, 'Attention', function(r) { if (r) { window.parent.location.reload(); } }); } /** * affiche une alerte sur l'expiration de la session et redirige vers une autre page * @param string url URL de redirection en cas de d�connexion */ expirationSession = function(url) { window.parent.location.href = url; }; /** * affiche des avertissements sur le d�lai d'expiration de la session : * - un premier au bout de (expiration-rappel) minutes (par ex. : 20-3 = 17 minutes) * - un second au bout de (expiration) minutes (par ex. : 20 minutes) * @param int expiration delai en minutes d'expiration de la session * @param int rappel delai en minutes avant l'expiration de la session pour l'affichage du rappel * @param string redirection URL de redirection en cas de d�connexion */ session = function(expiration, rappel, redirection) { // affichage du rappel var chronoRappel = setTimeout('rappelSession(' + rappel + ')', (expiration - rappel) * 60 * 1000); //console.log("TSESSSION : " + (expiration-rappel) +' '+ expiration) // une fois le rappel affich, on avertit uniquement de l'expiration var chronoExpiration = setTimeout('expirationSession(\'' + redirection + '\')', expiration * 60 * 1000); }; //Source https://github.com/sharikul/FuncJS/blob/master/funcjs.js str_replace = function(o, n, s) { var new_, old, string; if (!(o === void 0 || n === void 0 || s === void 0 || o === null || n === null || s === null || o === "" || n === "" || s === "")) { try { old = o; new_ = n; string = s; if (typeof old === "string" && typeof new_ === "string" && typeof string === "string") { return string.replace(old, new_); } else { throw new TypeError("Neither '" + old + "' or '" + new_ + "' are string values. BOTH of these arguments must be of string data."); } } catch (err) { return alert(err.message); } } else { throw new Error("The 'str_replace' function expects three arguments."); } }; strip_tags = function(e) { var closing_tag, opening_tag, _tag_object, _tag_string; if (!(e === void 0 || e === null || e === "")) { _tag_string = e; if (typeof _tag_string === "string") { opening_tag = _tag_string.match(/<[A-Za-z0-9='"\s+]+>/g); closing_tag = _tag_string.match(/<\/[A-Za-z0-9='"\s+]+>/g); if (opening_tag && opening_tag) { _tag_string = _tag_string.replace(/<[A-Za-z0-9='"\s+]+>/g, ""); _tag_string = _tag_string.replace(/<\/[A-Za-z0-9='"\s+]+>/g, ""); return trim(_tag_string); } else { throw new TypeError("The provided argument doesn't look like it has tags within it."); } } else { if (typeof _tag_string === "object") { _tag_object = _tag_string.outerHTML; _tag_object = _tag_object.replace(/\n/g, ""); opening_tag = _tag_object.match(/<[A-Za-z0-9='"\s+]+>/g); closing_tag = _tag_object.match(/<\/[A-Za-z0-9='"\s+]+>/g); if (opening_tag && closing_tag) { _tag_object = _tag_object.replace(/<[A-Za-z0-9='"\s+]+>/g, ""); _tag_object = _tag_object.replace(/<\/[A-Za-z0-9='"\s+]+>/g, ""); return trim(_tag_object); } else { throw new TypeError("The provided argument doesn't look like it has tags within it."); } } } } else { throw new Error("The 'strip_tags' function expects one argument in the form of a string or object."); } };