function ajaxError(x, t, m){
console.log('x: '+x);
console.log('t: '+t);
console.log('m: '+m);
}
function openPdf(name,path,title){
$.ajax({
url: "https://www.planitournoi.com/ajax_call.php",
timeout: 5000,
dataType:'json',
data: {
'pdf_option' : 1,
'name' : name
},
success: function(data) {
createModal({
id:'pdfModal',
title:title,
content:data["pdf_option_html"],
zIndex:"3001",
formId:"form_modal_check",
buttons:[
modalButton({label:'Générer',click:"applyPdfOption('" +path+ "','" +name+ "');",classes:"btn btn-modal btn-primary" })
,
modalButton({label:'Annuler',click:''})
]
});
//ajaxForm("Options d\'impression",data["pdf_option_html"],"applyPdfOption('" +path+ "','" +name+ "')");
},
error: function(x, t, m) {
ajaxError(x, t, m);
}
});
}
function iflocationequalnull() {
var fr = 'rechercher-un-tournoi', en = 'find-a-tournament';
if(LOCATION_NULL == true) {
if(location.href.indexOf(fr) != -1) {
if(document.referrer.indexOf(fr) != -1) {
location.href = document.referrer;
}
else {location.href = "https://www.planitournoi.com/" + fr + ".html";}
} else if(location.href.indexOf(en) != -1) {
if(document.referrer.indexOf(en) != -1) {
location.href = document.referrer;
}
else {location.href = "https://www.planitournoi.com/" + en + ".html";}
}
}
}
function applyPdfOption(path,name){
//gender = $("#team-filters #filter_gender").val();
var instruction="";
if($("#orientation").val()!=undefined)
instruction+="&orientation="+$("#orientation").val();
if($("#size").val()!=undefined)
instruction+="&fontsize=" + $("#size").val();
if($("#color").val()!=undefined)
instruction+="&nocolor=" + $("#color").val();
/*instruction+="&name=" + name;
win = window.open("https://www.planitournoi.com/loading_pdf.html","pdf");
$(win).ready(function()
{
//$(win).attr("href",path + instruction);
//win.location.assign(path + instruction);
//alert(path + instruction);
win.loadPdf(path + instruction);
//alert("salut");
});
//win.location = path + instruction;
*/
instruction+="&name=" + name;
window.open(path + instruction);
closeAjaxForm();
}
function isMobile(){
$("#main").css('min-width',0);
$(".container").css('width',"100%");
if($("#viewport").length > 0) setTimeout(ajustMobileFinals, 3000);
}
function ajustMobileFinals(){
$("#viewport").css('width',$(window).width()-5);
}
function windowOpen(windowUri,windowWidth,windowHeight, windowName)
{
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
newWindow = window.open(windowUri, windowName, 'menubar=yes,location=yes,toolbar=yes,scrollbars=yes,resizable=true,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);
newWindow.focus();
return newWindow.name;
}
function getSmallSpinner(){
return {
lines: 8, // The number of lines to draw
length: 2, // The length of each line
width: 2, // The line thickness
radius: 6, // The radius of the inner circle
corners: 0.8, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1.8, // Rounds per second
trail: 80, // Afterglow percentage
shadow: true, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'aspinner', // The CSS class to assign to the spinner
zIndex: 2000, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
}
//all=1 tout les quotes
//all=2 juste '
//all=3 juste "
//Permet d'enlever les ' qui devient un espace et " qui devient rien
function cleanQuotes(word,all)
{
all = typeof all !== 'undefined' ? all : 1;
if (word != undefined){
if(all!=2){
word=word.replace(/'/g," ");
}
if(all!=3){
word=word.replace(/"/g,"");
}
word=word.replace(//g,"");
word=word.replace(/«/g,"");
word=word.replace(/»/g,"");
}
return word;
}
function createLoading(){
/*var html = '
';
html += '
';
html+='
Traitement
';
html+='';
html+='
';
$('body').prepend(html);*/
var opts = {
lines: 11, // The number of lines to draw
length: 4, // The length of each line
width: 6, // The line thickness
radius: 19, // The radius of the inner circle
corners: 0.8, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1.8, // Rounds per second
trail: 80, // Afterglow percentage
shadow: true, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2000, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
var html = '
';
html += '
';
html+='
Traitement
';
html+='';
html+='
';
$('body').prepend(html);
var target = document.getElementById('spinner');
var spinner = new Spinner(opts).spin(target);
}
function startLoading(cache){
if (typeof cache == 'undefined') cache = false;
if(!cache){
createLoading();
centerModals(1);
}
$("#loadingModal").modal('show');
$('body div:last').addClass("invisible");
var mobile = 0;
/*if(mobile==0)$("#loadingModal").modal('lock');*/
}
function endLoading(cache){
if (typeof cache == 'undefined') cache = false;
var mobile = 0;
/*if(mobile==0){
$("#loadingModal").modal("unlock");
$("#loadingModal").modal("hide");
}*/
if(!cache) $("#loadingModal").remove();
}
function debug(str){
if(window['console']!='undefined')
console.log(str);
}
if (!window.console) console = {log: function() {}};
function ajaxSuccess(){
$("#bravo1").remove();
$('body').append('
Opération effectuée avec succès.
');
$('#bravo1').centerHorizontal();
$('#bravo1').css("width","240");
$('#bravo1').slideDown(200,function(){
$('#bravo1').delay(1000).slideUp(200);
});
}
jQuery.fn.centerHorizontal = function () {
this.css("position","absolute");
this.css("top", Math.max(0, $(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
return this;
}
jQuery.fn.center = function (animate) {
this.css("position","absolute");
this.css("margin","0");
if(!animate){
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
}else{
this.animate({
"top": Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px",
"left": Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px"
},500);
}
return this;
}
/*
Fonction qui retourne un bouton HTML, les options disponibles sont:
label : Le texte dans le bouton (vide par défaut)
classes : La ou les classes du bouton ('btn btn-modal' par défaut)
click : La méthode appelée par l'évènement onclick du bouton (aucune par défaut)
type : Le type du bouton ('button' par défaut)
dismiss : Si le bouton ferme le modal après le click (vrai par défaut)
*/
function modalButton(options){
options.id = options.id || "";
options.label = options.label || "";
options.classes = options.classes || "btn btn-modal";
options.click = options.click || "";
options.type = options.type || "button";
options.dismiss = (typeof options.dismiss === 'undefined') ? true : options.dismiss;
var dismiss = "";
if(options.dismiss) dismiss = 'data-dismiss="modal"';
return '';
}
function modalInput(options){
options.id = options.id || "";
options.label = options.label || "";
options.classes = options.classes || "btn btn-modal";
options.click = options.click || "";
options.type = options.type || "button";
options.dismiss = (typeof options.dismiss === 'undefined') ? false : options.dismiss;
options.checked= (options.checked == true) ? 'checked' : '';
options.styled = options.styled || false;
options.align = options.align || "default"; // Ajout Francis
options.label_align = options.label_align || "default"; // Ajout Francis
var dismiss = "";
if(options.dismiss) dismiss = 'data-dismiss="modal"';
// Ajout Francis
var html = "";
if (options.align == "buttons") {
html = '
');
}
function createSuccessModal(text){
createModal({
title: 'Succès',
content : text,
isForm : false,
validate : false
});
}
/*
Fonction pour créer un modal, les options disponibles sont:
id : Le id du modal ('modal' par défaut)
target : L'endroit où le modal sera créer ('body' par défaut)
title : Le titre dans le header du modal (vide par défaut)
content : Le contenu du body du modal (vide par défaut)
close : Méthode appelé lorsque l'on clique sur la croix dans le header (aucune par défaut)
show : Si le modal doit être appelé après sa création (vrai par défaut)
locked : Empêcher de fermer le modal en cliquant à l'extérieur (vrai par défaut)
isForm : Si le modal est contenu dans un form (vrai par défaut)
validate : Si le form est validé lors de sa soumission (vrai par défaut, nécéssite isForm pour fonctionner)
buttons : Un array de boutons HTML
draggable: Permet de dragger le popup, le fond est non opaque (faux par défaut)
*/
function removeOverflowBody(){
$("body").removeClass("modal-open");
$("div.main-wrapper").removeClass("modal-open-mobile");
}
String.prototype.splice = function(
index,
howManyToDelete,
stringToInsert /* [, ... N-1, N] */
){
// Create a character array out of the current string
// by splitting it. In the context of this prototype
// method, THIS refers to the current string value
// being spliced.
var characterArray = this.split( "" );
// Now, let's splice the given strings (stringToInsert)
// into this character array. It won't matter that we
// are mix-n-matching character data and string data as
// it will utlimately be joined back into one value.
//
// NOTE: Because splice() mutates the actual array (and
// returns the removed values), we need to apply it to
// an existing array to which we have an existing
// reference.
Array.prototype.splice.apply(
characterArray,
arguments
);
// To return the new string, join the character array
// back into a single string value.
return(
characterArray.join( "" )
);
};
function createModal(options, f){
//block le scroll de la page mais pas celui du modal
if(options.id!='editable') {
$("body").addClass("modal-open");
$("div.main-wrapper").addClass("modal-open-mobile");
}
if(typeof options == 'undefined') options = {};
options.id = options.id || "modal";
options.target = options.target || "body";
options.title = options.title || "";
options.width = options.width || "auto";
options.max_width = options.max_width || '';
//options.max_height = /*options.max_height || */''; // On va calculer automatiquement la hauteur de la fenêtre à la place (Francis)
options.max_height = options.max_height || ''; // Paramètre inutilisé puisqu'on calcule automatiquement la hauteur des fenêtres maximum
options.content = options.content || "";
options.close = options.close || "";
options.showCloseButton = (typeof options.showCloseButton === 'undefined') ? true : options.showCloseButton; // This property define if the X close button is displayed. It's also the only documented property of this function...
options.method = options.method || "POST";
options.show = (typeof options.show === 'undefined') ? true : options.show;
options.locked = (typeof options.locked === 'undefined') ? true : options.locked;
options.isForm = (typeof options.isForm === 'undefined') ? true : options.isForm;
options.multipart = (typeof options.multipart === 'undefined') ? "" : 'enctype="multipart/form-data"';
options.action = (typeof options.action === 'undefined') ? "" : 'action="'+options.action+'"';
options.validate = (typeof options.validate === 'undefined') ? true : options.validate;
options.draggable = (typeof options.draggable === 'undefined') ? true : options.draggable;
options.icone = (typeof options.icone === 'undefined') ? "popup_arrow.gif" : options.icone;
options.buttons = options.buttons || [modalButton({label:'Ok',dismiss:true})];
options.input = options.input || "";
options.animate = options.animate || "";
options.height = options.height || "auto";
options.zIndex = options.zIndex || "3000";
options.formId = options.formId || "form_modal";
options.last_section=options.last_section || "";
options.bold = (typeof options.bold === 'undefined') ? false : options.bold; // Texte en gras
if(options.height!="auto" && typeof f === 'undefined')
options.height+="px";
if(options.width!="auto")
options.width+="px";
$("#"+options.id).modal('hide');
try{
$("#"+options.id).remove();
}
catch(ex){
}
if(options.max_width != '') options.max_width = "max-width:"+options.max_width+"px;";
if(options.max_height != '' && typeof f === 'undefined') options.max_height = "max-height:"+options.max_height+"px;";
else if(options.max_height != '') options.max_height = "max-height:"+options.max_height;
var form_start = "";
var form_end = "";
var closing = "";
if(options.isForm){
//$("#form_modal").remove();
//var tete = $("#form_modal").detach();
/*try{
var div = document.getElementById("form_modal");
div.parentNode.removeChild(div);
}
catch(ex){
}*/
form_start='';
}
if(options.locked) closing = ' data-keyboard="false" data-backdrop="static"';
var footer = "";
var buttonForBody=' onclick="removeOverflowBody();"';
var change='onclick="';
if(options.input)footer+= options.input;
for(var i = 0;i < options.buttons.length;i++){
if(options.buttons[i] !== "" && options.buttons[i].match(/change/g)!=null)
options.buttons[i]=options.buttons[i].splice(options.buttons[i].indexOf(change),change.length,buttonForBody);
footer+= options.buttons[i];
}
var html = form_start+'
';
html += '
'+(options.showCloseButton ? ('') : '');
html+='
'+options.title+'
'+options.content;
html+='
'+form_end;
//html = form_start + form_end;
//alert(html);
$(options.target).prepend(html);
$("button").addClass("scrollVanished");
if(options.validate && options.isForm){
$('#form_modal').submit(function(){
return emptyFields("form_modal");
});
}
$(".scrollVanished").click(function(){
removeOverflowBody();
});
$("#" + options.id).on('show.bs.modal', function() {
// On mémorise la hauteur d'origine de la fenêtre modal (utile lorsqu'on doit ajuster sa hauteur selon la résolution)
if ( ! $(this).is("[origin-height]")) {
//console.log($(this).css("overflow"));
//console.log($(this).height());
$(this).attr("origin-height", $(this).height());
centerModals(1);
}
});
if(options.show) {
// Evenement lorsqu'une fenetre est ouverte
$("#" + options.id).on('show.bs.modal', function() {
// On ignore la fenêtre de chargement
if ($(this).attr("id") != "loadingModal") {
// S'il n'y a pas de fenetre backdrop, on en crée une
if ($("#modal-backdrop").length == 0) {
$("body").append('');
} else {
// Sinon, on place le backdrop derrière la nouvelle fenêtre
if (options.zIndex - 1 > $("#modal-backdrop").css('z-index')) {
$("#modal-backdrop").css('z-index', options.zIndex - 1);
}
}
}
});
// Evenement lorsqu'une fenetre est cachee
$("#" + options.id).on('hidden.bs.modal', function() {
// S'il reste encore au moins un popup, on déplace la fenêtre backdrop derrière le suivant
if ($('div.modal:not([aria-hidden="true"])').length != 0) {
var index_highest = 0;
$('div.modal:not([aria-hidden="true"])').each(function() {
// On ignore la fenêtre de chargement
if ($(this).attr("id") != "loadingModal") {
var index_current = parseInt($(this).css("z-index"), 10);
if(index_current > index_highest) {
index_highest = index_current;
}
}
});
$("#modal-backdrop").css('z-index', index_highest - 1);
} else {
$("#modal-backdrop").remove();
}
});
// On enlève le backdrop, on utilisera le notre à la place
$("#" + options.id).modal({
backdrop: false
});
$("#"+options.id).modal('show');
if($.browser.msie && parseFloat($.browser.version)<8){
$("#"+options.id).css("width",$('.modal-body').outerWidth());
$("#"+options.id).center();
}
}
if(options.draggable) {
$("#"+options.id).draggable({ cancel: "#gmap,input,textarea,select,.modal-body,.modal-footer" });
$("#"+options.id+" .modal-header").css('cursor','pointer');
//$("#"+options.id+" .modal-footer").css('cursor','pointer');
$(".modal-backdrop").css('opacity','0.4');
}
if(options.animate){
$("#"+options.id).on('hide', function () {
$(".modal-backdrop").remove();
$("#form_modal").remove();
})
}
//alert(html);
/*$("#"+options.id).centerHorizontal();*/
}
/*
div = le div(objet) auquel le popup sera relativement attaché
id = le id utilisé lors de l'appel de la fonction $(id).modal('show')
title = le texte du h3 du titre
content = le contenu du modal
type: 0 = aucun style, 1 = style de success, 2 = style d'erreur
type: 3 = confirmation,type = 4 formulaire
type:5 = formulaire ajax
footer = permets de mettre ses propres boutons dans le footer
buttons = function javascript apeller par Oui
*/
function createPopUp(div,id,title,content,type,footer,buttons){
$("#"+id).modal('hide');
$("#"+id).remove();
var headerStyle = "";
var bodyStyle = "";
var footerStyle = "text-align:center";
var form_start = "";
var form_end = "";
var closing = "";
if(type == 3){
method = footer;
}
footer = footer || '';
if(type == 1){
var footerStyle="background-color:#dff0d8";
}
else if(type == 2){
var footerStyle="background-color:#f2dede";
}
else if(type ==3){
closing = 'data-keyboard="false" data-backdrop="static"';
if (typeof buttons == 'undefined') {
method = method || '$('+"'"+'#form'+id.substr(5)+"'"+').submit()';
footer = '';
}else{
$("#form_modal").remove();
var form_start='';
footer = footer;
}
}
else if(type == 4){
closing = 'data-keyboard="false" data-backdrop="static"';
$("#form_modal").remove();
var form_start='';
}else if(type==5){
method = footer;
method = method || '$('+"'"+'#form'+id.substr(5)+"'"+').submit()';
footer = '';
}
headerStyle = "background-image:url('https://www.planitournoi.com/image/popup_header.gif');background-repeat:repeat-x;";
var html = form_start+'
';
html += '
';
html+='
'+title+'
'+content;
html+='
'+form_end;
div.prepend(html);
if(type == 4){
$('#form_modal').submit(function() {
return emptyFields("form_modal");
});
}
}
function ajaxPopup(title,content){
var buttons = Array();
buttons[0] = modalButton({label:'Fermer',dismiss:true,classes:'btn btn-primary'});
createModal({id:'standard-ajax-form',title:title,content:content,buttons:buttons,draggable:true,width:' '});
}
function imagePopup(title,content,animate,back,next){
var buttons = Array();
var count = 0;
if(back){
buttons[count] = back;
count++
}
if(next){
buttons[count] = next;
count++
}
buttons[count] = modalButton({label:'Fermer',dismiss:true,classes:'btn btn-danger'});
createModal({locked:false,show:false,width:" ",id:'image-popup',title:title,content:content,buttons:buttons,draggable:true,animate:animate});
}
function ajaxForm2(options){
if(typeof options == 'undefined') options = {};
options.title = options.title || "";
options.content = options.content || "";
options.callback = options.callback || "";
options.width = options.width || "";
var buttons = Array();
buttons[0] = modalButton({label:'Enregistrer',click:options.callback,dismiss:false,classes:'btn btn-primary'});
buttons[1] = modalButton({label:'Annuler',dismiss:true, click:'iflocationequalnull()'});
createModal({id:'standard-ajax-form',title:options.title,content:options.content,buttons:buttons,draggable:true,width:options.width});
}
function ajaxForm(title,content,callback){
var buttons = Array();
buttons[0] = modalButton({label:'Enregistrer',click:callback,dismiss:false,classes:'btn btn-primary'});
buttons[1] = modalButton({label:'Annuler',dismiss:true});
createModal({id:'standard-ajax-form',title:title,content:content,buttons:buttons,draggable:true});
}
function ajaxForm3(title,content,callback, max_height){
var buttons = Array();
buttons[0] = modalButton({label:'Enregistrer',click:callback,dismiss:false,classes:'btn btn-primary'});
buttons[1] = modalButton({label:'Annuler',dismiss:true});
createModal({id:'standard-ajax-form',title:title,content:content,buttons:buttons,draggable:true, max_height: max_height}, 'true');
}
function ajaxForm4(options, max_height){
if(typeof options == 'undefined') options = {};
options.title = options.title || "";
options.content = options.content || "";
options.callback = options.callback || "";
options.width = options.width || "";
var buttons = Array();
buttons[0] = modalButton({id:'save_location',label:'Enregistrer',click:options.callback,dismiss:false,classes:'btn btn-primary'});
buttons[1] = modalButton({id:'cancel_map',label:'Annuler',dismiss:true, click:'iflocationequalnull()',classes:'btn btn-primary'});
createModal({id:'standard-ajax-form',title:options.title,content:options.content,buttons:buttons,draggable:true,width:options.width, max_height: max_height}, 'true');
}
function ajaxFormYesNo(title,content,callback){
var buttons = Array();
buttons[0] = modalButton({label:'Oui',click:callback,dismiss:false,classes:'btn btn-modal btn-primary'});
buttons[1] = modalButton({label:'Non',dismiss:true});
createModal({id:'standard-ajax-form',title:title,content:content,buttons:buttons,draggable:true});
}
function ajaxFormExport(title,content,callback){
var buttons = Array();
buttons[0] = modalButton({label:'Exporter',click:callback,dismiss:false,classes:'btn btn-primary'});
buttons[1] = modalButton({label:'Annuler',dismiss:true});
createModal({id:'standard-ajax-form',title:title,content:content,buttons:buttons,draggable:false});
}
function ajaxFormImport(title,text){
var buttons = Array();
buttons[0] = modalButton({label:'Ajouter',click:'addImport()',dismiss:false,classes:'btn btn-primary'});
buttons[1] = modalButton({label:'Remplacer',click:'overwriteImport()',dismiss:false,classes:'btn btn-primary'});
buttons[2] = modalButton({label:'Annuler',dismiss:true});
createModal({
title: title,
content : text,
isForm : false,
validate : false,
zIndex : "3002",
buttons:buttons,
draggable:false
});
}
function closeAjaxForm(){
$("#standard-ajax-form").remove();
$(".modal-backdrop").remove();
}
function jsAlert(title,content,type,callback){
/*if(type==3){
ajaxForm(title,content,callback);
}else{*/
createPopUp($('body'),"standard-confirm",title,content,type,callback);
$("#standard-confirm").modal('show');
//createErrorModal(content,title,' ');
//}
}
function nullCallBack(){}
//Donne le focus au premier élément avec le css d'erreur
function focusError(){
var errors = $('div.control-group.error:first');
var inputName = "#"+errors.attr("id").slice(0,-4);
$(inputName).focus();
}
//Vérifie tous les champs d'un form, si l'un est vide retourne false;
function emptyFields(form,requiredOnly,popup){
if(typeof requiredOnly == 'undefined') requiredOnly = false;
if(typeof popup == 'undefined') popup = true;
$(document.activeElement).keypress(function(e) {
if (e.keyCode == '13') {
e.preventDefault();
}
});
$("#"+form).find("button").prop("disabled",true);
var valid = true;
try{
$("#"+form+" :input[data-original-title]:visible").each(function(){
//$("#"+form+" :input:visible").each(function(){
var input = $(this);
if(input.is('[type="text"],[type="password"],textarea')){
if($.trim(input.val())==""){
if(requiredOnly){
if(input.hasClass('required_field')){
input.tooltip('show');
valid = notValid(input);
}
}else{
input.tooltip('show');
valid = notValid(input);
}
}
}else if(input.is('select')){
if(input.find('option:selected').html() == "" || input.find('option:selected').html() == " "){
input.tooltip('show');
valid = notValid(input);
// Petit fix pour les "select" personnalisés
var select = $("#" + input.attr("id") + "_msddHolder");
if (select.length != 0) {
select.css("overflow", "visible");
if ( ! popup) select.find(".tooltip").css("top", "0px");
select.find(".tooltip").css("left", "+=3px");
select.find(".tooltip-inner").css("white-space", "nowrap");
select.find(".tooltip-arrow").css("top", "10px");
}
}
}
});
}
catch(ex){
}
if($("#"+form+" .error").length > 0) valid = false;
else if($("#"+form+" .errorInput").length > 0) valid = false;
if(!valid)$("#"+form).find("button").prop("disabled", false);
if(!valid && $(".modal").length == 0 && popup) createErrorModal("Le formulaire contient des erreurs");
return valid;
}
/* Fonction qui verifie la date de naissance */
function checkBirthDate(date_ref, year_min, year_max, target){
if($("#player_type option:selected").attr('data-status') == 1 && $("#player_birthdate").val() != "" && date_ref){
var year = $("#player_birthdate").val();
if(!((year_min == 0 || year <= year_min) && (year_max == 0 || year >= year_max))){
if(year_max != 0 && year_min != 0){
createErrorAlert({
target:target,
text:"Les joueurs de cette division doivent être nés entre le "+year_max+" et le "+year_min+"."
});
}else if(year_max != 0){
createErrorAlert({
target:target,
text:"Les joueurs de cette division doivent être nés après le "+year_max+"."
});
}else{
createErrorAlert({
target:target,
text:"Les joueurs de cette division doivent être nés avant le "+year_min+"."
});
}
return false;
}
}
return true;
}
//Si un input est invalide, le css et le tooltip d'erreur s'affichent
function notValid(input){
var nameDiv = "#"+input.attr("name")+"_div";
$(nameDiv).addClass('error');
return false;
}
function isEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test($.trim(email));
}
function emailExists(input,nameDiv,pageAjax,ajaxError,type){
var emailExist = true;
$.ajax({
url: pageAjax,
async: false, // Appel Synchrone
data: {
'email': input.val(),
'type': type
},
dataType: 'json',
success: function(data) {
if (pageAjax=='organization_subscribe.php' )
{
if(!data.result) {
$(nameDiv).removeClass('error');
$(nameDiv).removeClass('checkingEmail'); // Pour savoir quand le courriel est vérifié
input.tooltip('hide');
}
else if(data.org_unactivated) {
createErrorModal('Le compte associé à ce courriel a été désactivé. Veuillez contacter le support technique de PlaniTournoi en utilisant le formulaire de contact',"",600);
//input.attr('title','Le compte associé à ce courriel a été désactivé. Veuillez contacter le support technique de PlaniTournoi en utilisant le formulaire de contact').tooltip('fixTitle').tooltip('show');
$(nameDiv).removeClass('success');
$(nameDiv).addClass('error');
emailExist = false;
}
else {
input.attr('title', ajaxError).tooltip('fixTitle').tooltip('show');
$(nameDiv).removeClass('success');
$(nameDiv).addClass('error');
emailExist = false;
}
}
}
});
return emailExist;
}
//Un input contenant un email, si pageAjax est différent de null le e-mail sera vérifié avec la base de données
function emailField(input,pageAjax,type,requiredField) {
// Si le champ est requis
requiredField = requiredField || false;
input.unbind('blur');
input.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: (requiredField ? "Champ requis" :
"Adresse courriel invalide")
});
input.bind('blur', function() {
var nameDiv= "#"+this.attributes["name"].value+"_div";
if (requiredField && $.trim(input.val()).length == 0) { // Champs requis
input.attr('title', "Champ requis").tooltip('fixTitle').tooltip('show');
$(nameDiv).addClass('error');
input.tooltip('show');
} else if(!isEmail($.trim(input.val())) && $.trim(input.val()).length > 0) {
input.attr('title', "Adresse courriel invalide").tooltip('fixTitle').tooltip('show');
$(nameDiv).addClass('error');
input.tooltip('show');
} else if (pageAjax != null && isEmail($.trim(input.val()))) {
$(nameDiv).addClass('checkingEmail'); // Pour savoir si on est entrain de vérifier le courriel
emailExists(input,nameDiv,pageAjax,'Cette adresse courriel existe déjà',type);
}
});
input.bind('blur keyup', function() {
var nameDiv= "#"+this.attributes["name"].value+"_div";
if((isEmail($.trim(input.val())) && ! $(nameDiv).hasClass('checkingEmail'))) {
$(nameDiv).removeClass('error');
input.tooltip('hide');
}
});
}
function numericFieldNoTooltip(input){
input.bind('blur keyup', function() {
var value = $(this).val();
if(value.slice(-1) == ","){
$(this).val(value.slice(0,-1)+".");
value = $(this).val();
}
if(value != ""){
if($.isNumeric(value)) $(this).removeClass('errorInput');
else $(this).addClass('errorInput');
}else $(this).addClass('errorInput');
});
}
function numericField(input,message){
if (typeof message == 'undefined') {
input.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: message
});
}
input.bind('blur keyup', function() {
if($.isNumeric($.trim($(this).val())))
{
$(this).removeClass('errorInput');
input.tooltip('hide');
}else{
$(this).addClass('errorInput');
input.tooltip('show');
}
});
}
// Valide si un élément contient un chiffre ou un nombre positif
function positiveNumericField(input,message){
if (typeof message != 'undefined') {
input.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: message
});
}
input.bind('blur keyup', function() {
if($.isNumeric($.trim($(this).val())) && $.trim($(this).val()) >= 0)
{
$(this).removeClass('errorInput');
input.tooltip('hide');
}else{
$(this).addClass('errorInput');
input.tooltip('show');
}
});
}
// Pour valider si la valeur d'un champ est entre un interval donné
function requiredNumericFieldBetween(input,message,min,max){
input.addClass('required_field');
if (typeof message != 'undefined') {
input.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: message
});
}
input.bind('blur keyup', function() {
var nameDiv= "#"+this.attributes["name"].value+"_div";
if($.isNumeric($.trim($(this).val())) && $.trim($(this).val()) >= min && $.trim($(this).val()) <= max)
{
$(nameDiv).removeClass('error');
$(this).removeClass('errorInput');
input.tooltip('hide');
}else{
$(this).addClass('errorInput');
input.tooltip('show');
}
});
}
function requiredField(input){
var placement = "right";
// Si on est en mobile, on affiche le tooltip en bas du champs requis
if ($(window).width() < 768) {
placement = "bottom";
}
input.addClass('required_field');
input.tooltip({
placement: placement,
trigger: "manual",
html:"true",
title: "Champ requis"
});
input.bind('change keyup', function() {
var nameDiv= "#"+this.attributes["name"].value+"_div";
if($.trim($(this).val()).length > 0)
{
$(nameDiv).removeClass('error');
input.tooltip('hide');
}
});
}
function removeRequiredField(input){
input.removeClass('required_field');
var nameDiv= "#"+input.attr('name')+"_div";
$(nameDiv).removeClass('error');
input.tooltip('hide');
}
function forbiddenCharacters(input,characters){
input.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: "Champ requis"
});
input.bind('blur keyup', function() {
var text = $.trim($(this).val());
var nameDiv= "#"+this.attributes["name"].value+"_div";
var invalid = false;
if(!invalid){
for(var i = 0; i < characters.length;i++){
if(text.indexOf(characters[i]) > -1)
{
invalid = true;
}
}
}
if(invalid){
$(nameDiv).addClass('error');
input.tooltip('show');
}else{
$(nameDiv).removeClass('error');
input.tooltip('hide');
}
});
}
function compareField(input1,input2){
input2.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: "Les mots de passe ne sont pas identiques"
});
input2.bind('blur', function() {
input1_val = $.trim(input1.val());
input2_val = $.trim(input2.val());
var nameDiv= "#"+input2.attr("name")+"_div";
if(input1_val != input2_val && input2_val.length > 0)
{
$(nameDiv).addClass('error');
input2.tooltip('show');
}
else if( input2_val.length > 0)
{
$(nameDiv).removeClass('error');
input2.tooltip('hide');
}
});
input1.bind('blur', function() {
input1_val = $.trim(input1.val());
input2_val = $.trim(input2.val());
var nameDiv= "#"+input2.attr("name")+"_div";
if(input1_val != input2_val && input2_val.length > 0)
{
$(nameDiv).addClass('error');
input2.tooltip('show');
}
else if( input2_val.length > 0)
{
$(nameDiv).removeClass('error');
input2.tooltip('hide');
}
});
input1.bind('keyup', function() {
input1_val = $.trim(input1.val());
input2_val = $.trim(input2.val());
var nameDiv= "#"+input2.attr("name")+"_div";
if(input1_val == input2_val && input2_val.length > 0)
{
$(nameDiv).removeClass('error');
input2.tooltip('hide');
}
});
input2.bind('keyup', function() {
input1_val = $.trim(input1.val());
input2_val = $.trim(input2.val());
var nameDiv= "#"+input2.attr("name")+"_div";
if(input1_val == input2_val)
{
$(nameDiv).removeClass('error');
input2.tooltip('hide');
}
});
}
function minimumLength(input,length){
input.tooltip({
placement: "right",
trigger: "manual",
html:"true",
title: length+" caractères minimum"
});
input.bind('blur keyup', function() {
var nameDiv= "#"+this.attributes["name"].value+"_div";
var lengthNow = $.trim($(this).val()).length;
if(lengthNow >= length)
{
$(nameDiv).removeClass('error');
input.tooltip('hide');
}
});
input.bind('blur', function() {
var nameDiv= "#"+this.attributes["name"].value+"_div";
var lengthNow = $.trim($(this).val()).length;
if(lengthNow < length && lengthNow > 0)
{
$(nameDiv).addClass('error');
input.tooltip('show');
}
});
}
//Changer le label en fonction du type, si type est 0, c'est un label de checkbox et l'image sera changée. Si le type est égal à 1, le label n'est pas lié à un checkbox et une classe lui sera appliqué.
function labelClick(that,pageLoad,type){
if (typeof type == 'undefined') {
type = 0;
}
if(pageLoad != 1){
chk = $("#chk"+that.slice(3));
chk.trigger('click');
}
if(type == 0){
var icon = $("#ico"+that.slice(3));
icon.toggleClass('checkbox_checked');
icon.toggleClass('checkbox_unchecked');
}else{
$("#"+that).toggleClass('labelChecked');
}
}
function buttonModal(div){
div.on('show', '.modal', function(){
$(this).css({'margin-top':'-165px',
'margin-left':'155px','position':'absolute'});
});
}
/*function centerModals(first){
$('.modal').each( function(){
$(this).css({'margin-top':($(window).height()-$(this).height())/2,'top':'0','margin-left':($(window).width()-$(this).width())/2});
if($(this).css("display") == "block"){
$(this).modal('show');
}
// Si la hauteur du navigateur excède celle de la fenêtre modal, on applique la propriété overflow: visible à la fenêtre modal
// de sorte que son contenu soit scrollable. Ensuite, pour éviter des problèmes avec les listes déroulantes, on applique la classe
// dropup à toutes les listes déroulantes de cette fenêtre modal, de sorte que les listes se déroulent vers le haut plutôt que vers le bas
var diff = $(window).height() - $(this).height() - 73; // Le 73 représente plus ou moins les marges (en haut et en bas du modal)
if (diff < 0) {
$('.modal-body').css("overflow", "");
$('.modal-body').css("overflow-x", "hidden");
$('.modal-body').css("overflow-y", "auto");
$('.selectpicker').addClass("dropup");
$('.selectpicker').selectpicker('refresh');
}
});
if(first == 1){
$(window).resize(function() {
centerModals();
});
$('body').on('show', '.modal', function(){
$(this).css({'margin-top':($(window).height()-$(this).height())/2,'top':'0','margin-left':($(window).width()-$(this).width())/2});
});
}
}*/
function centerModals(first){
$('.modal').each( function(){
modal_id = $(this).attr("id") || "";
modal_body = $(this).find(".modal-body");
$(this).css({'margin-top':($(window).height()-$(this).height())/2,'top':'0','margin-left':($(window).width()-$(this).width())/2});
if($(this).css("display") == "block"){
$(this).modal('show');
}
// Si la hauteur du navigateur excède celle de la fenêtre modal, on applique la propriété overflow: visible à la fenêtre modal
// de sorte que son contenu soit scrollable. Ensuite, pour éviter des problèmes avec les listes déroulantes, on applique la classe
// dropup à toutes les listes déroulantes de cette fenêtre modal, de sorte que les listes se déroulent vers le haut plutôt que vers le bas
var modal_body_height = modal_body.height();
if (modal_body_height == 0) modal_body_height = $(this).height() - 92;
var diff_height_modal = $(this).height() - modal_body_height; // 92px
var diff_window = $(window).height() - $(this).height() - 50; // 50 pour qu'on se garde une marge (15px en haut et en bas)
var new_height = $(this).height() + diff_window - diff_height_modal;
change = false;
if (diff_window < 0) {
// On calcule la hauteur pour qu'on ait toujours une marge
modal_body.css("max-height", new_height + "px");
change = true;
} else if ($(this).height() < $(this).attr("origin-height")) {
if (new_height > ($(this).attr("origin-height") - diff_height_modal)) new_height = $(this).attr("origin-height") - diff_height_modal;
modal_body.css("max-height", new_height + "px");
change = true;
}
var diff_height = $(this).height() - $(this).attr("origin-height"); // Quand la fenêtre change de hauteur
// On vérifie si le contenu de la fenêtre est scrollé ou non
var height_to_compare;
if (modal_body.prop("scrollHeight") > modal_body.prop("clientHeight")) {
height_to_compare = modal_body.prop("scrollHeight");
} else {
height_to_compare = modal_body.height();
}
if (change) {
modal_body.css("overflow", "");
modal_body.css("overflow-x", "hidden");
modal_body.css("overflow-y", "auto");
modal_body.find('.selectpicker').each(function() {
var multiple = $(this).attr("multiple");
if (typeof multiple === typeof undefined || multiple === false) {
$(this).addClass("dropup");
$(this).selectpicker('refresh');
}
});
} else if (modal_body.css("overflow") == "auto" && modal_body.css("overflow-y") != "auto" && ! isNaN(diff_height) && height_to_compare == ($(this).attr("origin-height") - diff_height_modal)) {
modal_body.css("overflow", "visible");
modal_body.find('.dropup').removeClass("dropup");
modal_body.find('.selectpicker').each(function() {
var multiple = $(this).attr("multiple");
if (typeof multiple === typeof undefined || multiple === false) {
$(this).selectpicker('refresh');
}
});
}
});
if(first == 1){
$(window).resize(function() {
centerModals();
});
$('body').on('show', '.modal', function(){
$(this).css({'margin-top':($(window).height()-$(this).height())/2,'top':'0','margin-left':($(window).width()-$(this).width())/2});
});
}
}
//Si un checkbox est "checked", lui assigner l'image de "checked"
function checkCheckboxes(type,div){
type = type || 0;
div = div || '#content';
$(div).find('input:checked').each(function(){
labelClick("lbl"+$(this).attr('id').slice(3),1,type);
});
}
function add_text(field,template){
template = prompt("Nom du template",template)
if (template=="" || template == null)
{
return;
}
value = prompt("Français","")
if (value=="" || value == null)
{
return;
}
window.open("adm/list_text.php?add_text=1&text_name="+field+"&text_fr="+value+"&text_template_name="+template+"&close=1")
location.reload();
}
function lockUnlock(){
// save the original function object
var _superModal = $.fn.modal;
// add locked as a new option
$.extend( _superModal.defaults, {
locked: false
});
// create a new constructor
var Modal = function(element, options) {
_superModal.Constructor.apply( this, arguments )
}
// extend prototype and add a super function
Modal.prototype = $.extend({}, _superModal.Constructor.prototype, {
constructor: Modal
, _super: function() {
var args = $.makeArray(arguments)
// call bootstrap core
_superModal.Constructor.prototype[args.shift()].apply(this, args)
}
, lock : function() {
this.options.locked = true
}
, unlock : function() {
this.options.locked = false
}
, hide: function() {
if (this.options.locked) return
this._super('hide')
}
});
// override the old initialization with the new constructor
$.fn.modal = $.extend(function(option) {
var args = $.makeArray(arguments),
option = args.shift()
// this is executed everytime element.modal() is called
return this.each(function() {
var $this = $(this)
var data = $this.data('modal'),
options = $.extend({}, _superModal.defaults, $this.data(), typeof option == 'object' && option)
if (!data) {
$this.data('modal', (data = new Modal(this, options)))
}
if (typeof option == 'string') {
data[option].apply( data, args )
}
});
}, $.fn.modal);
}
function ajaxPage(header){
if (typeof header == 'undefined') {
header = 0;
}
lockUnlock();
centerModals(1);
if(header == 0){
$("body").on({
ajaxStart: function() {
startLoading();
},
ajaxStop: function() {
endLoading();
}
});
}
ajaxError = function(x, t, m) {
if(t==="timeout") {
endLoading();
createPopUp($('body'),"errorConn","Erreur","La connexion au serveur n'a pas pu être établie. Veuillez rafraichir.");
$("#errorConn").modal('show');
} else {
//alert(m);
}
$("#modal").modal('hide');
}
}
function getDaysInMonth(m, y) {
return /8|3|5|10/.test(--m)?30:m==1?(!(y%4)&&y%100)||!(y%400)?29:28:31;
}
function isValidDate(date){
var array = date.split('-');
if(array[1] > 12) return false;
if(array[2] > getDaysInMonth(array[1],array[0])) return false;
return true;
}
function checkboxPage(){
$("#content").on('click','i',function(){
if(!$(this).hasClass('checkbox_disabled')){
if($(this).hasClass('checkbox_unchecked')){
$(this).addClass('checkbox_checked');
$(this).removeClass('checkbox_unchecked');
}else if ($(this).hasClass('checkbox_checked')){
$(this).removeClass('checkbox_checked');
$(this).addClass('checkbox_unchecked');
}
}
});
}
function confirmDelete(method){
createPopUp($('body'),"confirmDelete",'Attention','Êtes-vous certain?',3,method);
$("#confirmDelete").modal('show');
}
function updateStatusBar(animate){
if($("#status_bar").length>0){
$.ajax({
url: "https://www.planitournoi.com/ajax_call.php",
dataType: 'json',
data: {
'get_status_bar':true,
'animate':animate
},
success: function(data) {
if(animate){
$("#status_bar #state-bar").fadeOut("100",function(){
$("#status_bar").replaceWith(data["status_bar"]);
});
}else{
$("#status_bar").replaceWith(data["status_bar"]);
}
},
error: function(x, t, m) {
//ajaxError(x, t, m);
}
});
}
}
function updateStatusBox(id,alert_id,callback){
$.ajax({
url: "https://www.planitournoi.com/ajax_call.php",
timeout: 5000,
dataType: 'json',
data: {
'get_status_box':true,
'get_alert_box':alert_id
},
success: function(data) {
$(id).replaceWith(data["status_box"]);
if(alert_id){
$(alert_id).replaceWith(data["alert_box"]);
}
if(callback) callback();
},
error: function(x, t, m) {
ajaxError(x, t, m);
}
});
}
function setScrollPane(){
// console.log('set');
$('.scroll-pane').jScrollPane({showArrows: true,mouseWheelSpeed: 50});
}
function setScrollPaneHidden(){
//console.log('set hidden');
$('.scroll-pane-hidden').jScrollPane({showArrows: true,mouseWheelSpeed: 50});
}
function setScrollPaneElement(element){
//console.log('set element');
$(element).jScrollPane({showArrows: true, mouseWheelSpeed: 50});
}
function unsetScrollPaneElement(div){
//console.log('unset element');
var element = $(div).jScrollPane();
var api = element.data('jsp');
api.destroy();
}
function unsetScrollPane(){
//console.log('unset');
var element = $('.scroll-pane').jScrollPane();
var api = element.data('jsp');
api.destroy();
}
function resetScrollPane(){
var element = $('.scroll-pane').jScrollPane();
var api = element.data('jsp');
api.reinitialise({showArrows: true,mouseWheelSpeed: 50});
}
(function ($, undefined) {
$.fn.getCursorPosition = function() {
var el = $(this).get(0);
var pos = 0;
if('selectionStart' in el) {
pos = el.selectionStart;
} else if('selection' in document) {
el.focus();
var Sel = document.selection.createRange();
var SelLength = document.selection.createRange().text.length;
Sel.moveStart('character', -el.value.length);
pos = Sel.text.length - SelLength;
}
return pos;
}
})(jQuery);
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function setCaretToPos (input, pos) {
setSelectionRange(input, pos, pos);
}
function checkChk(chk){
chk.toggleClass('checkbox_checked');
chk.toggleClass('checkbox_unchecked');
}
function chkUncheck(chk){
chk.removeClass('checkbox_checked');
chk.addClass('checkbox_unchecked');
}
function chkCheck(chk){
chk.removeClass('checkbox_unchecked');
chk.addClass('checkbox_checked');
}
function showHelp(id,hidable) {
if (hidable == undefined) {
var hidable = false;
}
$.ajax({
url: "https://www.planitournoi.com/help.php",
type: 'POST',
dataType: 'json',
data: {
id :id,
action: 'view',
hidable: hidable
},
success: function( data ) {
if (data.error != undefined) return false;
var buttons = Array();
buttons[0] = modalButton({label:'Fermer',dismiss:true,classes:"btn btn-modal btn-primary"});
var checked=false;
if (data.hidden!=undefined)checked = data.hidden;
if (hidable) {/*Permet de cacher le bouton stop_showing si la fenêtre n'est pas "cachable"*/
var check =modalInput({id:'checkHide',styled:true,label:'Ne plus afficher',type:"checkbox",click:"hideHelp('"+id+"',$(this).is(':checked'))",checked:checked});
}
createModal({
title:data.title,
input:check,
width:600,
/*buttons:(hidable)?[modalButton({ label:"Ne plus afficher",click:"hideHelp('"+id+"')",dismiss:true,classes:"btn btn-modal btn-primary" })]:"",*/
buttons:buttons,
content:data.content,
draggable:true,
icone:"question.gif"
});
}
});
}
function hideHelp(id,checked) {
checkChk($("#checkHide").prev());
var action = 'hide';
if(!checked)action='unhide';
$.ajax({
url: "https://www.planitournoi.com/help.php",
type: 'POST',
dataType: 'json',
data: {
id :id,
action: action
}
});
}
function print_r(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
$.fn.scrollTo = function( target, options, callback ){
if(typeof options == 'function' && arguments.length == 2){ callback = options; options = target; }
var settings = $.extend({
scrollTarget : target,
offsetTop : 50,
duration : 500,
easing : 'swing'
}, options);
return this.each(function(){
var scrollPane = $(this);
var scrollTarget = (typeof settings.scrollTarget == "number") ? settings.scrollTarget : $(settings.scrollTarget);
var scrollY = (typeof scrollTarget == "number") ? scrollTarget : scrollTarget.offset().top + scrollPane.scrollTop() - parseInt(settings.offsetTop);
scrollPane.animate({scrollTop : scrollY }, parseInt(settings.duration), settings.easing, function(){
if (typeof callback == 'function') { callback.call(this); }
});
});
}
function isOverflowed(element){
return element.prop('scrollHeight') > (element.prop('clientHeight')+1) || element.prop('scrollWidth') > (element.prop('clientWidth')+1);
}
function ajustOverflow(element){
element.css('overflow','auto');
element.css('line-height','22px');
if(isOverflowed(element)) element.css('line-height',element.css('font-size'));
element.css('overflow','hidden');
}
function checkIfOverflow(element,align_oveflowed){
if(typeof align_oveflowed == 'undefined') var align_oveflowed = false;
if(align_oveflowed && !isOverflowed(element)){
element.css('line-height',"23px");
element.css('overflow','hidden');
}else{
if(isOverflowed(element)){
element.css('line-height',parseInt(element.css('line-height').slice(0,-2))-1+"px");
element.css('font-size',parseInt(element.css('font-size').slice(0,-2))-1+"px");
align_oveflowed = false;
checkIfOverflow(element,align_oveflowed);
}else{
element.css('overflow','hidden');
}
}
}
function completeTodo(code,elem){
var buttons = Array();
buttons[0] = modalButton({id:'complete-todo',label:'Oui',dismiss:true,classes:"btn btn-modal btn-primary"});
buttons[1] = modalButton({label:'Fermer',dismiss:true,classes:"btn btn-modal"});
elem = $(elem);
/*createModal({
title:"Attention",
width:' ',
buttons:buttons,
content:"Vous n’avez aucune configuration à faire dans cette section?",
draggable:true,
});*/
//$("#complete-todo").on("click",function(){
ajaxPage();
$.ajax({
url: "https://www.planitournoi.com/ajax_call.php",
timeout: 5000,
dataType: 'json',
data: {
'todo_complete_action_code':code,
'get_status_bar':true
},
success: function(data) {
if(data["action_removed"])elem.remove();
if(data["status_bar"]) $("#status_bar").replaceWith(data["status_bar"]);
},
error: function(x, t, m) {
}
});
//});
}
//Méthode pour que les bootstrap-select se positionne au bon endroit quand on les ouvre.
$(".dropdown-toggle").live('click',function(){
var div = $(this).parent();
var container = div.find('.inner');
var scroll = div.find('li.selected');
container.scrollTop(scroll.offset().top - container.offset().top + container.scrollTop());
});
function isUrl(s) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}
function errorUpload(error_code){
var error_text = "Une erreur s'est produite pendant le téléchargement. ";
if(error_code == 1) error_text += "La taille du fichier ne peut dépasser 50M.";
else if(error_code == 2) error_text += "La taille du fichier ne peut dépasser 50M.";
else if(error_code == 3) error_text += "Le fichier n'a été que partiellement téléchargé.";
else if(error_code == 4) error_text += "Aucun fichier n'a été téléchargé.";
else if(error_code == 5) error_text += "Une erreur s'est produite.";
else if(error_code == 6) error_text += "Une erreur s'est produite.";
else if(error_code == 7) error_text += "Une erreur s'est produite.";
else if(error_code == 8) error_text += "Une erreur s'est produite.";
else if(error_code == 9) error_text += "Le fichier n'est pas une image valide. Les images acceptés se terminent en \".jpg\",\".jpeg\",\".png\" ou \".gif\".";
else if(error_code == 10) error_text += "Un virus a été détecté dans le fichier.";
else if(error_code == 11) error_text += "Certains fichiers n'ont pu être téléchargés.";
else error_text = 0;
return error_text;
}
function popupVideo(video){
$.ajax({
url: "https://www.planitournoi.com/ajax_call.php",
timeout: 5000,
dataType:'JSON',
data: {
'video_name' : video
},
success: function(data) {
createModal({
content:data["html"],
title:data["title"],
draggable:true,
width:data["width"],
buttons:[modalButton({label:"Fermer"})]
});
centerModals();
$("#modal").find('.modal-body').css('padding-top',0);
},
error: function(x, t, m) {
ajaxError(x, t, m);
}
});
}
function updateCredits(){
$.ajax({
url: "https://www.planitournoi.com/ajax_call.php",
type:'POST',
dataType:'JSON',
data: {
'number_credits' : 1
},
success: function(data) {
$("#header_credits").html(""+data.credit+" crédits restant");
$("#header_credits_bonus").html(data.credit_bonus+" crédits gratuit");
}
});
}
function tableScrollTo(td_to_scroll,div_scroll,after,notfound){
if(typeof td_to_scroll.get(0) != 'undefined'){
div_scroll.animate({
scrollTop: td_to_scroll.offset().top - div_scroll.offset().top + div_scroll.scrollTop(),
scrollLeft: td_to_scroll.offset().left - (div_scroll.offset().left+135) + div_scroll.scrollLeft()
});
if(typeof after != 'undefined') after;
}else{
if(typeof notfound != 'undefined') notfound;
}
}
/*fonction d'exportation de excel en javascript, voir version pour php, utility.php exportExcel*/
function DownloadJSON2CSV(objArray)
{
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
if(line != '') line += ';'
if(array[i][index] !=null)
line += array[i][index];
else
line +='';
//line += array[i][index] + ',';
}
// Here is an example where you would wrap the values in double quotes
// for (var index in array[i]) {
// line += '"' + array[i][index] + '",';
// }
//line.slice(0,line.Length-1);
str += line + '\r\n';
}
/* var uri = 'data:application/vnd.ms-excel;base64,'+escape(str);
alert(uri);
document.getElementById("dlink").href = uri;
document.getElementById("dlink").download = 'team.xls';
document.getElementById("dlink").click();*/
//downloadWithName(escape(str),'team_list.csv');
if (navigator.appName != 'Microsoft Internet Explorer')
{
window.open('data:text/csv;charset=ISO-8859-15;filename:"team_list.csv",' + escape(str));
}
else
{
var popup = window.open('','csv','');
popup.document.body.innerHTML = '
' + str + '
';
}
}
(function( $ ){
$.fn.customcheck = function() {
$(this).each(function(){
var style= $(this).attr("style");
$(this).hide();
var original_check = $(this);
var disabled = ($(this).attr("disabled") == "disabled") ? true : false; // Francis
var checked = $(this).is(":checked");
var check=""; // Francis
if(checked)check=""; // Francis
var check_i = $(check);
check_i.attr("style",style);
check_i.on("click",function(){
if ( ! $(this).hasClass("checkbox_disabled")) { // Ajout Francis
if($(this).hasClass("checkbox_unchecked")){
//$(this).removeClass("checkbox_unchecked");
//$(this).addClass("checkbox_checked");
original_check.attr("checked",true);
}else{
//$(this).removeClass("checkbox_checked");
//$(this).addClass("checkbox_unchecked");
original_check.attr("checked",false);
}
//original_check.trigger("click");
original_check.trigger("change");
}
});
original_check.on("change",function(){
if($(this).is(":checked")){
check_i.removeClass("checkbox_unchecked");
check_i.addClass("checkbox_checked");
check_i.attr("checked",true);
}else{
check_i.removeClass("checkbox_checked");
check_i.addClass("checkbox_unchecked");
check_i.removeAttr("checked",false);
}
});
original_check.on("click",function(){
//alert($(this).is(":checked"));
//$(this).attr("checked",$(this).is(":checked"))
//return false;
});
$(this).after(check_i);
});
};
})( jQuery );