var seconds=0;var minutes=0;var hours=0;var get_status_url;var total_upload_size=0;var total_kbytes=0;var CPB_loop=false;var CPB_width=0;var CPB_bytes=0;var CPB_time_width=500;var CPB_time_bytes=15;var CPB_hold=true;var CPB_byte_timer;var CPB_status_timer;var BPB_width_inc=0;var BPB_width_new=0;var BPB_width_old=0;var BPB_timer;var UP_timer;function checkFileNameFormat(){if(!check_file_name_format){return false;}var found_error=false;JQ(":file").each(function(){if(JQ(this).val()!=""){var file_name_path=JQ(this).val().split("\\");var file_name=file_name_path[file_name_path.length-1];if(file_name.length>max_file_name_chars){alert("Le nom du fichier ne peut pas avoir plus de "+max_file_name_chars+" caracteres.");found_error=true;}if(file_name.length<min_file_name_chars){alert("Le nom du fichier ne peut pas avoir moins de "+min_file_name_chars+" caracteres.");found_error=true;}if(!check_file_name_regex.test(file_name)){alert(check_file_name_error_message);found_error=true;}}});return found_error;}function checkAllowFileExtensions(){if(!check_allow_extensions_on_client){return false;}var found_error=false;JQ(":file").each(function(){if(JQ(this).val()!=""){var file_name_path=JQ(this).val().split("\\");var file_name=file_name_path[file_name_path.length-1];var file_extension=file_name.slice(file_name.indexOf(".")).toLowerCase();if(!file_extension.match(allow_extensions)){alert('Nous sommes desole, mais envoyer un fichier avec l\'extension "'+file_extension+'" n\'est pas autorise.');found_error=true;}}});return found_error;}function checkDisallowFileExtensions(){if(!check_disallow_extensions_on_client){return false;}var found_error=false;JQ(":file").each(function(){if(JQ(this).val()!=""){var file_name_path=JQ(this).val().split("\\");var file_name=file_name_path[file_name_path.length-1];var file_extension=file_name.slice(file_name.indexOf(".")).toLowerCase();if(file_extension.match(disallow_extensions)){alert('Nous sommes desole, mais envoyer un fichier avec l\'extension "'+file_extension+'" n\'est pas autorise.');found_error=true;}}});return found_error;}function checkNullFileCount(){if(!check_null_file_count){return false;}var found_file=false;JQ(":file").each(function(){if(JQ(this).val()!=""){found_file=true;}});if(!found_file){alert("Veuillez choisir un fichier a envoyer.");return true;}else{return false;}}function checkDuplicateFileCount(){if(!check_duplicate_file_count){return false;}var found_duplicate=false;var duplicate_count=0;var file_count=0;var duplicate_msg="Un fichier portant le meme nom est deja present, veuillez renommer celui-ci avant de l\'envoyer.\n\n";var file_name_array=new Array();JQ(":file").each(function(){if(JQ(this).val()!=""){var file_name_path=JQ(this).val().split("\\");var file_name=file_name_path[file_name_path.length-1];file_name_array[file_count]=file_name;file_count++;}});for(var i=0;i<file_count;i++){duplicate_count=0;for(var j=0;j<file_count;j++){if(file_name_array[i]===file_name_array[j]){duplicate_count++;}}if(duplicate_count>1){duplicate_msg+='Duplicate file "'+file_name_array[i]+'" detected in slot '+(i+1)+".\n";found_duplicate=true;}}if(found_duplicate){alert(duplicate_msg);return true;}else{return false;}}function checkNullReceivers(){receivers_count=0;JQ("#receivers input[type='checkbox']").each(function(){if(JQ(this).attr('checked'))receivers_count++;});if(receivers_count==0){alert('Vous devez choisir des destinataires pour cet envoi');return true;}else return false;}function resetForm(){location.href=self.location;}function showDebugMessage(message){JQ("#ubr_debug").append(message+"<br>");}function clearDebugMessage(){JQ("#ubr_debug").html("");}function showAlertMessage(message){JQ("#ubr_alert").html(message);}function clearAlertMessage(){JQ("#ubr_alert").html("");}function stopDataLoop(){clearInterval(UP_timer);clearInterval(BPB_timer);CPB_loop=false;}function iniFilePage(){resetProgressBar();clearAlertMessage();JQ(":file").each(function(){JQ(this).attr("disabled",false);JQ(this).val("");});JQ("#upload_button").attr("disabled",false);JQ("#progress_bar").hide();document.uu_upload.reset();}function resetProgressBar(){CPB_loop=false;clearInterval(BPB_timer);clearInterval(UP_timer);seconds=0;minutes=0;hours=0;CPB_width=0;CPB_bytes=0;CPB_hold=true;total_upload_size=0;total_kbytes=0;JQ("#upload_status").css("width","0px");if(show_percent_complete){JQ("#percent_complete").html("0%");}if(show_files_uploaded){JQ("#files_uploaded").html("0");}if(show_files_uploaded){JQ("#total_uploads").html("");}if(show_current_position){JQ("#current_position").html("0");}if(show_current_position){JQ("#total_kbytes").html("");}if(show_elapsed_time){JQ("#elapsed_time").html("00:00:00");}if(show_est_time_left){JQ("#est_time_left").html("00:00:00");}if(show_est_speed){JQ("#est_speed").html("0");}}function linkUpload(){if(checkFileNameFormat()){return false;}if(checkAllowFileExtensions()){return false;}if(checkDisallowFileExtensions()){return false;}if(checkNullFileCount()){return false;}if(checkDuplicateFileCount()){return false;}if(show_files_uploaded){var total_uploads=0;JQ(":file").each(function(){if(JQ(this).val()!=""){total_uploads++;}});JQ("#total_uploads").html(total_uploads);}JQ.getScript(path_to_link_script,function(){});}function startUpload(upload_id,debug_upload){JQ("#uu_upload").attr("action",path_to_upload_script+"?upload_id="+upload_id);JQ("#uu_upload").submit();JQ(":file,button,select,:checkbox").each(function(){JQ(this).attr("disabled",true);});JQ("#upload_div").hide();JQ('.loading').unbind('ajaxStart').unbind('ajaxStop');if(!debug_upload){initializeProgressBar(upload_id);}}function stopUpload(){try{window.stop();}catch(e){try{document.execCommand("Stop");}catch(e){}}JQ(":file").each(function(i){JQ(this).attr("disabled",false);});}function initializeProgressBar(upload_id){JQ.getScript(path_to_set_progress_script+'?upload_id='+upload_id,function(){});}function getProgressStatus(){JQ.getScript(get_status_url,function(){});}function startProgressBar(upload_id,upload_size,start_time){total_upload_size=upload_size;total_kbytes=Math.round(total_upload_size/1024);CPB_loop=true;JQ("#progress_bar").dialog({width:800,height:400,bgiframe:true,modal:true,resizable:false,draggable:false});showAlertMessage("Progression du transfert en cours ");if(show_current_position){JQ("#total_kbytes").html(total_kbytes+" ");}if(show_elapsed_time){UP_timer=setInterval("getElapsedTime()",1000);}get_status_url=path_to_get_progress_script+"?upload_id="+upload_id+"&start_time="+start_time+"&total_upload_size="+total_upload_size;getProgressStatus();if(cedric_progress_bar==1){if(show_current_position){smoothCedricBytes();}smoothCedricStatus();}}function setProgressStatus(total_bytes_read,files_uploaded,current_file,bytes_read,lapsed_time){var byte_speed=0;var time_remaining=0;if(lapsed_time>0){byte_speed=total_bytes_read/lapsed_time;}if(byte_speed>0){time_remaining=Math.round((total_upload_size-total_bytes_read)/byte_speed);}if(cedric_progress_bar==1){if(byte_speed!=0){var temp_CPB_time_width=Math.round(total_upload_size*1000/(byte_speed*progress_bar_width));var temp_CPB_time_bytes=Math.round(1024000/byte_speed);if(temp_CPB_time_width<5001){CPB_time_width=temp_CPB_time_width;}if(temp_CPB_time_bytes<5001){CPB_time_bytes=temp_CPB_time_bytes;}}else{CPB_time_width=500;CPB_time_bytes=15;}}var percent_complete=Math.floor(100*parseInt(total_bytes_read)/parseInt(total_upload_size));var progress_bar_status=Math.floor(progress_bar_width*(parseInt(total_bytes_read)/parseInt(total_upload_size)));var remaining_sec=(time_remaining%60);var remaining_min=(((time_remaining-remaining_sec)%3600)/60);var remaining_hours=((((time_remaining-remaining_sec)-(remaining_min*60))%86400)/3600);if(remaining_sec<10){remaining_sec="0"+remaining_sec;}if(remaining_min<10){remaining_min="0"+remaining_min;}if(remaining_hours<10){remaining_hours="0"+remaining_hours;}var est_time_left=remaining_hours+":"+remaining_min+":"+remaining_sec;var est_speed=Math.round(byte_speed/1024);var current_position=Math.round(total_bytes_read/1024);if(cedric_progress_bar==1){if(cedric_hold_to_sync){if(progress_bar_status<CPB_width){CPB_hold=true;}else{CPB_hold=false;CPB_width=progress_bar_status;CPB_bytes=current_position;}}else{CPB_hold=false;CPB_width=progress_bar_status;CPB_bytes=current_position;}JQ("#upload_status").css("width",progress_bar_status+"px");}else if(bucket_progress_bar==1){BPB_width_old=BPB_width_new;BPB_width_new=progress_bar_status;if((BPB_width_inc<BPB_width_old)&&(BPB_width_new>BPB_width_old)){BPB_width_inc=BPB_width_old;}clearInterval(BPB_timer);BPB_timer=setInterval("incrementProgressBar()",10);}else{JQ("#upload_status").css("width",progress_bar_status+"px");}if(show_current_position){JQ("#current_position").html(current_position);}if(show_current_file){JQ("#current_file").html(current_file);}if(show_percent_complete){JQ("#percent_complete").html(percent_complete+"%");}if(show_files_uploaded){if(files_uploaded>0){JQ("#files_uploaded").html(files_uploaded);}}if(show_est_time_left){JQ("#est_time_left").html(est_time_left);}if(show_est_speed){JQ("#est_speed").html(est_speed);}if(!JQ("#progress_bar").dialog('isOpen'))JQ("#progress_bar").dialog('open');}function incrementProgressBar(){if(BPB_width_inc<BPB_width_new){BPB_width_inc++;JQ("#upload_status").css("width",BPB_width_inc+"px");}}function smoothCedricStatus(){if(CPB_width<progress_bar_width&&!CPB_hold){CPB_width++;JQ("#upload_status").css("width",CPB_width+"px");}if(CPB_loop){clearTimeout(CPB_status_timer);CPB_status_timer=setTimeout("smoothCedricStatus()",CPB_time_width);}}function smoothCedricBytes(){if(CPB_bytes<total_kbytes&&!CPB_hold){CPB_bytes++;JQ("#current_position").html(CPB_bytes);}if(CPB_loop){clearTimeout(CPB_byte_timer);CPB_byte_timer=setTimeout("smoothCedricBytes()",CPB_time_bytes);}}function getElapsedTime(){seconds++;if(seconds==60){seconds=0;minutes++;}if(minutes==60){minutes=0;hours++;}var hr=""+((hours<10)?"0":"")+hours;var min=""+((minutes<10)?"0":"")+minutes;var sec=""+((seconds<10)?"0":"")+seconds;JQ("#elapsed_time").html(hr+":"+min+":"+sec);}function addUploadSlot(num){if(upload_range<max_upload_slots){if(num==upload_range){JQ("#upload_slots").append('<div><input type="file" class="ubrUploadSlot" id="upfile_'+upload_range+'" name="upfile_'+upload_range+'" size="90" value=""></div>');JQ("#upfile_"+upload_range).bind("keypress",function(e){if(e==13){return false;}});JQ("#upfile_"+upload_range).bind("change",function(e){addUploadSlot(upload_range);});upload_range++;}}}
