﻿var updateTimer=null;jQuery(document).ready(function($){$('<div id="progressContainer"><table id="progress" style="width:100%"><tr><th colspan="2" align="left" class="title">Uploading File</th></tr><tr><td colspan="2" class="bar"><div style="border:#70736A solid 1px;background:#FFFFFF;position:relative;height:1.6em;"><div id="progressBar" style="position:absolute;top:0;left:0;width:0;background:#D3DABB;height:1.6em;"></div><div id="progressPercentDone" style="position:absolute;top:0;left:0;width:100%;line-height:1.6em;text-align:center;color:#70736A;">0.00%</div></div></td></tr><tr><th align="right">Current File:</th><td id="progressCurrentFileName" /></tr><tr><th align="right">Time Left:</th><td id="progressTimeLeft" /></tr><tr><th align="right">Upload Left:</th><td id="progressUploadLeft" /></tr><tr><th align="right">Transfer Rate:</th><td id="progressTransferRate" /></tr><tr><th /><td><b><a href="javascript:CancelUpload();">Cancel</a></b></td></tr></table></div>').hide().appendTo('body');$('<a id="progressLink" href="#TB_inline?height=150&width=350&inlineId=progressContainer&modal=true" class="thickbox" />').hide().appendTo('body');tb_init('#progressLink')});function RandomUploadId(){return Math.floor(Math.random()*10000000)+(new Date()).getTime()%1000000000}function StartUpload(a,b){var c=a.find(':file').filter(function(){return $(this).val().length!=0});if(c.length==0)return true;var d=RandomUploadId();var e=$(a.attr('action').split(/[?&]/));var f=e.get(0);e=$.makeArray(e.slice(1).filter(function(){return this.indexOf('uploadid=')!=0}));e[e.length]='uploadid='+d;a.attr('action',f+'?'+e.join('&'));UpdateUpload({TimeLeft:'',CurrentFileName:'',PercentDone:'0.00%',UploadLeft:'',TransferRate:'',UploadStatus:'',UploadStatusString:''});if(updateTimer)clearTimeout(updateTimer);updateTimer=setTimeout(function(){TimerPulse(b,{uploadid:d})},500);$('#progressLink').click();return true};function TimerPulse(b,c){c['random']=RandomUploadId();updateTimer=null;jQuery.ajax({type:'GET',url:b,data:c,success:function(a){if(UpdateUpload(a)){updateTimer=setTimeout(function(){TimerPulse(b,c)},1000)}},error:CancelUpload,dataType:'json'})};function StopTimerPulse(){if(updateTimer!=null)clearTimeout(updateTimer);updateTimer=null};function ClearUpload(a){var b=$('#'+a).wrap('<div></div>').parent().html();$('#'+a).parent().replaceWith($(b));return true};function CancelUpload(){if(window.stop)window.stop();else if(window.document&&window.document.execCommand)window.document.execCommand('Stop');StopTimerPulse();tb_remove()};function UpdateUpload(c){$.each(c,function(a,b){$('#progress #progress'+a).text(b)});$('#progress #progressBar').css('width',c.PercentDone);if(c.UploadStatus=='Complete'){return false}else if(c.UploadStatus=='Cancelled'){tb_remove();return false}return true};