").appendTo("#fileNames").on("click",function(){var index=$(this).data("index");$(this).remove();if(isAdvancedUpload){var tempDroppedFiles=[];droppedFiles.forEach(function(value,indexArray){if(indexArray!=index){tempDroppedFiles.push(value)}});droppedFiles=tempDroppedFiles;index=0;$(".trashFile").each(function(){$(this).data("index",index);index++})}else{$input.val("")}})};var validateForm=function(){var errors=[];if($("input:text[name=lastName]").val()==""){errors.push("Le nom est un champ obligatoire.")}if($("input:text[name=firstName]").val()==""){errors.push("Le prénom est un champ obligatoire.")}if($("input:text[name=email]").val().match(/^[^-_a-z0-9]*([-_a-z0-9]+(?:\.[-_a-z0-9]+)*@[^.-][-a-z0-9.]+\.[a-z]{2,6}).*$/i)==null){errors.push("L'adresse e-mail est un champ obligatoire et doit être une adresse valide.")}if($("input:text[name=title]").val()==""){errors.push("Le titre est un champ obligatoire.")}if($("textarea[name=subject]").val()==""){errors.push("Le sujet est un champ obligatoire.")}if(errors.length>0){displayError(errors);return false}else{return true}};var displayError=function(errorArray){var errorString="
";for(var error in errorArray){errorString+="
"+errorArray[error]+"
"}errorString+="
";$(errorString).appendTo("#errors")};var removeErrors=function(){$("#errors").empty()};$form.append('');$input.on("change",function(e){$.each(e.target.files,function(){if(isAdvancedUpload){for(var index in droppedFiles){if(droppedFiles[index].name===this.name){var errors=[];errors.push("Les fichiers doivent avoir des noms différents.");displayError(errors);$("#errors").delay(3e3).fadeOut(function(){$("#errors").empty();$("#errors").fadeIn()});return}}droppedFiles.push(this);displayFile(this,droppedFiles.length-1)}else{displayFile(this,0)}})});if(isAdvancedUpload){$dragZone.addClass("has-advanced-upload");$dragZone.on("drag dragstart dragend dragover dragenter dragleave drop",function(e){e.preventDefault();e.stopPropagation()});$dragZone.on("dragover dragenter",function(){$dragZone.addClass("is-dragover")});$dragZone.on("dragleave dragend drop",function(){$dragZone.removeClass("is-dragover")});$dragZone.on("drop",function(e){$.each(e.originalEvent.dataTransfer.files,function(){droppedFiles.push(this);displayFile(this,droppedFiles.length-1)})})}$form.on("submit",function(e){if($form.hasClass("is-uploading"))return false;removeErrors();if(!validateForm())return false;$form.addClass("is-uploading").removeClass("is-error");if(isAdvancedUpload){e.preventDefault();$("textarea",$form).text($("textarea",$form).val());var $clonedForm=$form.clone();$clonedForm.find('.dragZone input[type="file"]').remove();var ajaxData=new FormData($clonedForm.get(0));if(droppedFiles){$.each(droppedFiles,function(i,file){ajaxData.append($input.attr("name"),file)})}$.ajax({url:$form.attr("action"),type:$form.attr("method"),data:ajaxData,dataType:"json",cache:false,contentType:false,processData:false,crossDomain:true,async:true,complete:function(){$form.removeClass("is-uploading")},success:function(data,textStatus,jqXHR){if(data.success){window.location.href="/alertez-nous/confirmation"+(lightbox?"?lightbox":"")}else{$("#progressBar").removeClass("active");displayError(data.listErrors)}},error:function(error,textStatus,errorThrown){$("#progressBar").removeClass("active");if(error.statusText!=undefined&&error.statusText.match(/.+Access.+denied.+/i)){displayError(["Le service n'est pour le moment pas supporté sur votre navigateur."])}else if(error.responseText!=""){var errorArray=[];errorArray.push(error.responseText);displayError(errorArray)}else{displayError(["Le service n'est pas accessible. Merci de réessayer plus tard."])}},xhr:function(){var myXhr=$.ajaxSettings.xhr();if(myXhr.upload){$("#progressBar").addClass("active");myXhr.upload.addEventListener("progress",showProgress,false)}else{console.log("Uploadproress is not supported.")}return myXhr}})}else{var iframeName="uploadiframe"+(new Date).getTime(),$iframe=$('');$("body").append($iframe);$form.attr("target",iframeName);$iframe.one("load",function(){var data=$.parseJSON($iframe.contents().find("body").text());if(data.success){window.location.href="/alertez-nous/confirmation"+(lightbox?"?lightbox":"")}else{$("#progressBar").removeClass("active");displayError(data.listErrors)}$iframe.remove()})}});$restart.on("click",function(e){e.preventDefault();$form.removeClass("is-error is-success");$input.trigger("click")});$input.on("focus",function(){$input.addClass("has-focus")});$input.on("blur",function(){$input.removeClass("has-focus")})})(jQuery,window,document);$(document).ready(function(){var $dropZone=$(".dropZone");$dropZone.on("dragenter",function(e){e.preventDefault();$(this).addClass("active")});$dropZone.on("dragover",function(e){e.preventDefault()});$dropZone.on("dragleave",function(e){e.preventDefault();$(this).removeClass("active")});$dropZone.on("drop",function(e){$(this).removeClass("active");e.preventDefault()})});