
Swiff.Uploader=new Class({Extends:Swiff,Implements:Events,options:{path:Page.Url.staticContent('/flashobjects/fancyupload/Swiff.Uploader.swf'),target:null,zIndex:9999,height:30,width:100,callBacks:null,params:{wMode:'opaque',menu:'false',allowScriptAccess:'always'},cookieKeys:null,typeFilter:null,multiple:true,queued:true,verbose:false,url:null,method:null,data:null,mergeData:true,fieldName:null,fileSizeMin:1,fileSizeMax:null,allowDuplicates:true,timeLimit:(Browser.Platform.linux)?0:30,buttonImage:null,policyFile:null,fileListMax:0,fileListSizeMax:0,instantStart:false,appendCookieData:true,fileClass:null},initialize:function(options){this.addEvent('load',this.initializeSwiff,true).addEvent('select',this.processFiles,true).addEvent('complete',this.update,true).addEvent('fileRemove',function(file){this.fileList.erase(file);}.bind(this),true);this.setOptions(options);if(this.options.callBacks){Hash.each(this.options.callBacks,function(fn,name){this.addEvent(name,fn);},this);}
this.options.callBacks={fireCallback:this.fireCallback.bind(this)};var path=this.options.path;if(!path.contains('?')){path+='?noCache='+$time();}
this.options.container=this.box=new Element('span',{'class':'swiff-uploader-box'}).inject($(this.options.container)||document.body);this.target=$(this.options.target);if(this.target){var scroll=window.getScroll();this.box.setStyles({position:'absolute',visibility:'visible',zIndex:this.options.zIndex,overflow:'hidden',height:1,width:1,top:scroll.y,left:scroll.x});this.parent(path,{params:{wMode:'transparent'},height:'100%',width:'100%'});this.target.addEvent('mouseenter',this.reposition.bind(this,[]));this.addEvents({buttonEnter:this.targetRelay.bind(this,['mouseenter']),buttonLeave:this.targetRelay.bind(this,['mouseleave']),buttonDown:this.targetRelay.bind(this,['mousedown']),buttonDisable:this.targetRelay.bind(this,['disable'])});this.reposition();window.addEvent('resize',this.reposition.bind(this,[]));}else{this.parent(path);}
this.inject(this.box);this.fileList=[];this.size=this.uploading=this.bytesLoaded=this.percentLoaded=0;if(Browser.Plugins.Flash.version<9){this.fireEvent('fail',['flash']);}else{this.verifyLoad.delay(1000,this);}},verifyLoad:function(){if(this.loaded){return;}
if(!this.object.parentNode){this.fireEvent('fail',['disabled']);}else if(this.object.style.display=='none'){this.fireEvent('fail',['hidden']);}else if(!this.object.offsetWidth){this.fireEvent('fail',['empty']);}},fireCallback:function(name,args){if(name.substr(0,4)=='file'){if(args.length>1){this.update(args[1]);}
var data=args[0];var file=this.findFile(data.id);this.fireEvent(name,file||data,5);if(file){var fire=name.replace(/^file([A-Z])/,function($0,$1){return $1.toLowerCase();});file.update(data).fireEvent(fire,[data],10);}}else{this.fireEvent(name,args,5);}},update:function(data){$extend(this,data);this.fireEvent('queue',[this],10);return this;},findFile:function(id){for(var i=0;i<this.fileList.length;i++){if(this.fileList[i].id==id){return this.fileList[i];}}
return null;},initializeSwiff:function(){this.remote('initialize',{width:this.options.width,height:this.options.height,typeFilter:this.options.typeFilter,multiple:this.options.multiple,queued:this.options.queued,url:this.options.url,method:this.options.method,data:this.options.data,mergeData:this.options.mergeData,fieldName:this.options.fieldName,verbose:this.options.verbose,fileSizeMin:this.options.fileSizeMin,fileSizeMax:this.options.fileSizeMax,allowDuplicates:this.options.allowDuplicates,timeLimit:this.options.timeLimit,buttonImage:this.options.buttonImage,policyFile:this.options.policyFile});this.loaded=true;this.appendCookieData();},targetRelay:function(name){if(this.target){this.target.fireEvent(name);}},reposition:function(coords){coords=coords||(this.target&&this.target.offsetHeight)?this.target.getCoordinates(this.box.getOffsetParent()):{top:window.getScrollTop(),left:0,width:40,height:40};this.box.setStyles(coords);this.fireEvent('reposition',[coords,this.box,this.target]);},setOptions:function(options){if(options){if(options.url){options.url=Swiff.Uploader.qualifyPath(options.url);}
if(options.buttonImage){options.buttonImage=Swiff.Uploader.qualifyPath(options.buttonImage);}
this.parent(options);if(this.loaded){this.remote('setOptions',options);}}
return this;},setEnabled:function(status){this.remote('setEnabled',status);},start:function(){this.fireEvent('beforeStart');this.remote('start');},stop:function(){this.fireEvent('beforeStop');this.remote('stop');},remove:function(){this.fireEvent('beforeRemove');this.remote('remove');},fileStart:function(file){this.remote('fileStart',file.id);},fileStop:function(file){this.remote('fileStop',file.id);},fileRemove:function(file){this.remote('fileRemove',file.id);},fileRequeue:function(file){this.remote('fileRequeue',file.id);},appendCookieData:function(){var append=this.options.appendCookieData;if(!append){return;}
var hash={};document.cookie.split(/;\s*/).each(function(cookie){cookie=cookie.split('=');if(cookie.length==2){if($hasValue(this.options.cookieKeys)){if(this.options.cookieKeys.indexOf(cookie[0])>=0){hash['\"'+decodeURIComponent(cookie[0])+'\"']=decodeURIComponent(cookie[1]);}}
else{hash['\"'+decodeURIComponent(cookie[0])+'\"']=decodeURIComponent(cookie[1]);}}}.bind(this));var data=this.options.data||{};if($type(append)=='string'){data[append]=hash;}
else{$extend(data,hash);}
this.setOptions({data:data});},processFiles:function(successraw,failraw,queue){var cls=this.options.fileClass||Swiff.Uploader.File;var fail=[],success=[];if(successraw){successraw.each(function(data){var ret=new cls(this,data);if(!ret.validate()){ret.remove.delay(10,ret);fail.push(ret);}else{this.size+=data.size;this.fileList.push(ret);success.push(ret);ret.render();}},this);this.fireEvent('selectSuccess',[success],10);}
if(failraw||fail.length){fail.extend((failraw)?failraw.map(function(data){return new cls(this,data);},this):[]).each(function(file){file.invalidate().render();});this.fireEvent('selectFail',[fail],10);}
this.update(queue);if(this.options.instantStart&&success.length){this.start();}}});$extend(Swiff.Uploader,{STATUS_QUEUED:0,STATUS_RUNNING:1,STATUS_ERROR:2,STATUS_COMPLETE:3,STATUS_STOPPED:4,log:function(){if(window.console&&console.info){console.info.apply(console,arguments);}},unitLabels:{b:[{min:1,unit:'B'},{min:1024,unit:'kB'},{min:1048576,unit:'MB'},{min:1073741824,unit:'GB'}],s:[{min:1,unit:'s'},{min:60,unit:'m'},{min:3600,unit:'h'},{min:86400,unit:'d'}]},formatUnit:function(base,type,join){var labels=Swiff.Uploader.unitLabels[(type=='bps')?'b':type];var append=(type=='bps')?'/s':'';var i,l=labels.length,value;if(base<1){return'0 '+labels[0].unit+append;}
if(type=='s'){var units=[];for(i=l-1;i>=0;i--){value=Math.floor(base/labels[i].min);if(value){units.push(value+' '+labels[i].unit);base-=value*labels[i].min;if(!base){break;}}}
return(join===false)?units:units.join(join||', ');}
for(i=l-1;i>=0;i--){value=labels[i].min;if(base>=value){break;}}
return(base/value).toFixed(1)+' '+labels[i].unit+append;}});Swiff.Uploader.qualifyPath=(function(){var anchor;return function(path){(anchor||(anchor=new Element('a'))).href=path;return anchor.href;};})();Swiff.Uploader.File=new Class({Implements:Events,initialize:function(base,data){this.base=base;this.update(data);},update:function(data){return $extend(this,data);},validate:function(){var options=this.base.options;if(options.fileListMax&&this.base.fileList.length>=options.fileListMax){this.validationError='fileListMax';return false;}
if(options.fileListSizeMax&&(this.base.size+this.size)>options.fileListSizeMax){this.validationError='fileListSizeMax';return false;}
if(!this.extension.test(/(jpg)|(jpeg)|(gif)|(png)|(tiff)|(bmp)/i)){this.validationError='invalidFileType';return false;}
return true;},invalidate:function(){this.invalid=true;this.base.fireEvent('fileInvalid',this,10);return this.fireEvent('invalid',this,10);},render:function(){return this;},setOptions:function(options){if(options){if(options.url){options.url=Swiff.Uploader.qualifyPath(options.url);}
this.base.remote('fileSetOptions',this.id,options);this.options=$merge(this.options,options);}
return this;},start:function(){this.base.fileStart(this);return this;},stop:function(){this.base.fileStop(this);return this;},remove:function(){this.base.fileRemove(this);return this;},requeue:function(){this.base.fileRequeue(this);}});
var FancyUpload2=new Class({Extends:Swiff.Uploader,options:{queued:1,limitSize:0,limitFiles:0,validateFile:$lambda(true)},initialize:function(status,list,options){this.status=$(status);this.list=$(list);options.fileClass=options.fileClass||FancyUpload2.File;options.fileSizeMax=options.limitSize||options.fileSizeMax;options.fileListMax=options.limitFiles||options.fileListMax;this.parent(options);this.addEvents({'load':this.render,'select':this.onSelect,'cancel':this.onCancel,'start':this.onStart,'queue':this.onQueue,'complete':this.onComplete});},render:function(){this.overallTitle=this.status.getElement('.overall-title');this.currentTitle=this.status.getElement('.current-title');this.currentText=this.status.getElement('.current-text');var progress=this.status.getElement('.overall-progress');this.overallProgress=new Fx.ProgressBar(progress,{text:new Element('span',{'class':'progress-text'}).inject(progress,'after')});progress=this.status.getElement('.current-progress');this.currentProgress=new Fx.ProgressBar(progress,{text:new Element('span',{'class':'progress-text'}).inject(progress,'after')});this.updateOverall();},onSelect:function(){this.status.removeClass('status-browsing');},onCancel:function(){this.status.removeClass('file-browsing');},onStart:function(){this.status.addClass('file-uploading');this.overallProgress.set(0);},onQueue:function(){this.updateOverall();},onComplete:function(){this.status.removeClass('file-uploading');if(this.size){this.overallProgress.start(100);}else{this.overallProgress.set(0);this.currentProgress.set(0);}},updateOverall:function(){this.overallTitle.set('html',MooTools.lang.get('FancyUpload','progressOverall').substitute({total:Swiff.Uploader.formatUnit(this.size,'b')}));if(!this.size){this.currentTitle.set('html',MooTools.lang.get('FancyUpload','currentTitle'));this.currentText.set('html','');}},upload:function(){this.start();},removeFile:function(){return this.remove();}});FancyUpload2.File=new Class({Extends:Swiff.Uploader.File,render:function(){if(this.invalid){if(this.validationError){var msg=MooTools.lang.get('FancyUpload','validationErrors')[this.validationError]||this.validationError;this.validationErrorMessage=msg.substitute({name:this.name,size:Swiff.Uploader.formatUnit(this.size,'b'),fileSizeMin:Swiff.Uploader.formatUnit(this.base.options.fileSizeMin||0,'b'),fileSizeMax:Swiff.Uploader.formatUnit(this.base.options.fileSizeMax||0,'b'),fileListMax:this.base.options.fileListMax||0,fileListSizeMax:Swiff.Uploader.formatUnit(this.base.options.fileListSizeMax||0,'b')});}
this.remove();return;}
this.addEvents({'start':this.onStart,'progress':this.onProgress,'complete':this.onComplete,'error':this.onError,'remove':this.onRemove});this.info=new Element('span',{'class':'file-info'});this.element=new Element('li',{'class':'file'}).adopt(new Element('span',{'class':'file-size','html':Swiff.Uploader.formatUnit(this.size,'b')}),new Element('a',{'class':'file-remove',href:'#',html:MooTools.lang.get('FancyUpload','remove'),title:MooTools.lang.get('FancyUpload','removeTitle'),events:{click:function(){this.remove();return false;}.bind(this)}}),new Element('span',{'class':'file-name','html':MooTools.lang.get('FancyUpload','fileName').substitute(this)}),this.info).inject(this.base.list);},validate:function(){return(this.parent()&&this.base.options.validateFile(this));},onStart:function(){this.element.addClass('file-uploading');this.base.currentProgress.cancel().set(0);this.base.currentTitle.set('html',MooTools.lang.get('FancyUpload','currentFile').substitute(this));},onProgress:function(){this.base.overallProgress.start(this.base.percentLoaded);this.base.currentText.set('html',MooTools.lang.get('FancyUpload','currentProgress').substitute({rate:(this.progress.rate)?Swiff.Uploader.formatUnit(this.progress.rate,'bps'):'- B',bytesLoaded:Swiff.Uploader.formatUnit(this.progress.bytesLoaded,'b'),timeRemaining:(this.progress.timeRemaining)?Swiff.Uploader.formatUnit(this.progress.timeRemaining,'s'):'-'}));this.base.currentProgress.start(this.progress.percentLoaded);},onComplete:function(){this.element.removeClass('file-uploading');this.base.currentText.set('html',MooTools.lang.get('FancyUpload','uploadCompleted'));this.base.currentProgress.start(100);if(this.response.error){var msg=MooTools.lang.get('FancyUpload','errors')[this.response.error]||'{error} #{code}';this.errorMessage=msg.substitute($extend({name:this.name,size:Swiff.Uploader.formatUnit(this.size,'b')},this.response));var args=[this,this.errorMessage,this.response];this.fireEvent('error',args).base.fireEvent('fileError',args);}else{this.base.fireEvent('fileSuccess',[this,this.response.text||'']);}},onError:function(){this.element.addClass('file-failed');var error=MooTools.lang.get('FancyUpload','fileError').substitute(this);this.info.set('html','<strong>'+error+':</strong> '+this.errorMessage);},onRemove:function(){this.element.getElements('a').setStyle('visibility','hidden');this.element.fade('out').retrieve('tween').chain(Element.destroy.bind(Element,this.element));}});(function(){var phrases={'progressOverall':'Overall Progress ({total})','currentTitle':'File Progress','currentFile':'Uploading "{name}"','currentProgress':'Upload: {bytesLoaded} with {rate}, {timeRemaining} remaining.','uploadCompleted':'Upload completed','fileName':'{name}','remove':'Remove','removeTitle':'Click to remove this entry.','fileError':'Upload failed','validationErrors':{'duplicate':'File <em>{name}</em> is already added, duplicates are not allowed.','sizeLimitMin':'File <em>{name}</em> (<em>{size}</em>) is too small, the minimal file size is {fileSizeMin}.','sizeLimitMax':'File <em>{name}</em> (<em>{size}</em>) is too big, the maximal file size is <em>{fileSizeMax}</em>.','fileListMax':'File <em>{name}</em> could not be added, amount of <em>{fileListMax} files</em> exceeded.','fileListSizeMax':'File <em>{name}</em> (<em>{size}</em>) is too big, overall filesize of <em>{fileListSizeMax}</em> exceeded.'},'errors':{'httpStatus':'Server returned HTTP-Status <code>#{code}</code>','securityError':'Security error occured ({text})','ioError':'Error caused a send or load operation to fail ({text})'}};if(MooTools.lang){MooTools.lang.set('en-US','FancyUpload',phrases);}else{MooTools.lang={get:function(from,key){return phrases[key];}};}})();
if(!window.FancyUpload3){var FancyUpload3={};}
FancyUpload3.Attach=new Class({Extends:Swiff.Uploader,options:{queued:false,instantStart:true},initialize:function(list,selects,options)
{this.list=$(list);this.selects=$(selects)?$$($(selects)):$$(selects);options.target=this.selects[0];options.fileClass=options.fileClass||FancyUpload3.Attach.File;this.parent(options);var self=this;this.selects.addEvents({click:function()
{return false;},mouseenter:function()
{this.addClass('hover');self.reposition();},mouseleave:function()
{this.removeClass('hover');this.blur();},mousedown:function()
{this.focus();}});if(this.selects.length==2)
{this.selects[1].setStyle('display','none');this.addEvents({'selectSuccess':this.onSelectSuccess,'fileRemove':this.onFileRemove});}},onSelectSuccess:function()
{if(this.fileList.length>0)
{this.selects[0].setStyle('display','none');this.selects[1].setStyle('display','inline');this.target=this.selects[1];this.reposition();}},onFileRemove:function()
{if(this.fileList.length===0)
{this.selects[0].setStyle('display','inline');this.selects[1].setStyle('display','none');this.target=this.selects[0];this.reposition();}},start:function()
{if(Browser.Platform.linux&&window.confirm(MooTools.lang.get('FancyUpload','linuxWarning')))
{return this;}
return this.parent();}});FancyUpload3.Attach.File=new Class({Extends:Swiff.Uploader.File,render:function(){if(this.invalid){if(this.validationError){var msg=MooTools.lang.get('FancyUpload','validationErrors')[this.validationError]||this.validationError;this.validationErrorMessage=msg.substitute({name:this.name,size:Swiff.Uploader.formatUnit(this.size,'b'),fileSizeMin:Swiff.Uploader.formatUnit(this.base.options.fileSizeMin||0,'b'),fileSizeMax:Swiff.Uploader.formatUnit(this.base.options.fileSizeMax||0,'b'),fileListMax:this.base.options.fileListMax||0,fileListSizeMax:Swiff.Uploader.formatUnit(this.base.options.fileListSizeMax||0,'b'),type:this.extension});}
this.remove();return false;}
this.addEvents({'open':this.onOpen,'remove':this.onRemove,'requeue':this.onRequeue,'progress':this.onProgress,'stop':this.onStop,'complete':this.onComplete,'error':this.onError});this.ui={};this.ui.element=new Element('li',{'class':'file',id:'file-'+this.id});this.ui.title=new Element('span',{'class':'file-title',text:this.name});this.ui.size=new Element('span',{'class':'file-size',text:Swiff.Uploader.formatUnit(this.size,'b')});this.ui.cancel=new Element('a',{'class':'file-cancel',text:'Cancel',href:'#'});this.ui.cancel.addEvent('click',function(){this.remove();return false;}.bind(this));this.ui.element.adopt(this.ui.title,this.ui.size,this.ui.cancel).inject(this.base.list).highlight();var progress=new Element('img',{'class':'file-progress',src:Page.Url.staticContent('/images/fancyupload/progress-bar/bar.gif')}).inject(this.ui.size,'after');this.ui.progress=new Fx.ProgressBar(progress,{fit:true}).set(0);this.base.reposition();return this.parent();},onOpen:function(){this.ui.element.addClass('file-uploading');if(this.ui.progress){this.ui.progress.set(0);}},onRemove:function(){this.ui=this.ui.element.destroy();},onProgress:function(){if(this.ui.progress){this.ui.progress.start(this.progress.percentLoaded);}},onStop:function(){this.remove();},onComplete:function(){this.ui.element.removeClass('file-uploading');if(this.response.error){var msg=MooTools.lang.get('FancyUpload','errors')[this.response.error]||'{error} #{code}';this.errorMessage=msg.substitute($extend({name:this.name},this.response));this.base.fireEvent('fileError',[this,this.response,this.errorMessage]);this.fireEvent('error',[this,this.response,this.errorMessage]);return;}
if(this.ui.progress){this.ui.progress=this.ui.progress.cancel().element.destroy();}
this.ui.cancel=this.ui.cancel.destroy();var response=this.response.text||'';this.base.fireEvent('fileSuccess',[this,response]);},onError:function(){this.ui.element.addClass('file-failed');}});(function(){var phrases={'fileName':'{name}','cancel':Mundia.Localizer.getString('Shared.Action.Cancel'),'cancelTitle':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.cancel'),'validationErrors':{'duplicate':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.duplicate'),'sizeLimitMin':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.sizeLimitMin'),'sizeLimitMax':Mundia.Localizer.getString('Dev.Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.sizeLimitMax'),'fileListMax':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.fileListMax'),'fileListSizeMax':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.fileListSizeMax'),'invalidFileType':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.InvalidExtension')},'errors':{'httpStatus':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.httpStatus'),'securityError':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.securityError'),'ioError':Mundia.Localizer.getString('Mundia.Web.Content.scripts.Mundia.controls.fancyupload.FancyUpload3.ioError')},'linuxWarning':''};MooTools.lang={get:function(from,key){return phrases[key];}};})();
Fx.ProgressBar=new Class({Extends:Fx,options:{text:null,url:Page.Url.staticContent('/images/fancyupload/progress-bar/progress.gif'),transition:Fx.Transitions.Circ.easeOut,fit:true,link:'cancel'},initialize:function(element,options){this.element=$(element);this.parent(options);var url=this.options.url;if(url){this.element.setStyles({'background-image':'url('+url+')','background-repeat':'no-repeat'});}
if(this.options.fit){url=url||this.element.getStyle('background-image').replace(/^url\(["']?|["']?\)$/g,'');if(url){var fill=new Image();fill.onload=function(){this.fill=fill.width;fill=fill.onload=null;this.set(this.now||0);}.bind(this);fill.src=url;if(!this.fill&&fill.width){fill.onload();}}}else{this.set(0);}},start:function(to,total){return this.parent(this.now,(arguments.length==1)?to.limit(0,100):to/total*100);},set:function(to){this.now=to;var css=(this.fill)?(((this.fill/-2)+(to/100)*(this.element.width||1)||0).round()+'px'):((100-to)+'%');this.element.setStyle('backgroundPosition',css+' 0px').title=Math.round(to)+'%';var text=$(this.options.text);if(text){text.set('text',Math.round(to)+'%');}
return this;}});
var Uploader=new Class({Implements:[Options,Events],options:{container:null,queued:true,verbose:false,url:null,method:null,data:null,mergeData:true,fieldName:null,allowDuplicates:true,fileListMax:0,instantStart:false,appendCookieData:false,fileClass:null},initialize:function(options){this.setOptions(options);this.target=$(this.options.target);this.box=new Element('div').setStyles({position:'absolute',opacity:0.01,zIndex:9999,overflow:'hidden'});this.reposition();window.addEvent('resize',this.reposition.bind(this));this.box.inject(this.options.container||document.body);this.addEvents({buttonEnter:this.targetRelay.bind(this,['mouseenter']),buttonLeave:this.targetRelay.bind(this,['mouseleave']),buttonDown:this.targetRelay.bind(this,['mousedown']),buttonDisable:this.targetRelay.bind(this,['disable'])});this.uploading=0;this.fileList=[];this.createIFrame();return this;},targetRelay:function(name){if(this.target){this.target.fireEvent(name);}},createIFrame:function(){this.iframe=new Element('iframe',{src:"javascript:'<html></html>'",frameborder:'no',border:0,styles:{width:'100%',height:'100%'}}).inject(this.box);this.runner=this.createIBody.periodical(50,this);},createIBody:function(){var doc=this.iframe.contentWindow.document;if(!doc||!doc.body){return;}
$clear(this.runner);var align=(Browser.Engine.trident)?'left':'right';doc.body.innerHTML='<form method="post" enctype="multipart/form-data" id="form">'+'<input type="file" id="file" style="position:absolute;'+align+':0;top:0" />'+'<input type="submit" /><div id="data"></div></form>'+'<style type="text/css">*{margin:0;padding:0;border:0;overflow:hidden;cursor:pointer;}</style>';this.doc=doc;this.processIBody.delay(50,this);},processIBody:function(){this.doc;if(!(this.file=this.doc.getElementById('file'))||!this.file.offsetHeight){this.createIBody();return;}
$extend(this.file,{onmousedown:function(){if(Browser.Engine.presto){return true;}
(function(){this.file.click();this.fireEvent('buttonDown');}).delay(10,this);return false;}.bind(this),onfocus:function(){return false;},onchange:this.select.bind(this),onmouseover:this.fireEvent.bind(this,'buttonEnter'),onmouseout:this.fireEvent.bind(this,'buttonLeave')});},select:function(){this.file.onchange=this.file.onmousedown=this.file.onfocus=null;var name=this.file.value.replace(/^.*[\\\/]/,'');var cls=this.options.fileClass||Uploader.File;var ret=new cls(this,name,this.iframe.setStyle('display','none'));if(!ret.validate()){ret.invalidate().render();this.fireEvent('onSelectFailed',[[ret]]);return;}
this.fileList.push(ret);ret.render();this.fireEvent('onSelectSuccess',[[ret]]);if(this.options.instantStart){this.start();}
this.file=null;this.createIFrame();},reposition:function(){var pos=this.target.getCoordinates(this.box.getOffsetParent());this.box.setStyles(pos);},start:function(){this.fireEvent('beforeStart');var queued=this.options.queued;queued=(queued)?((queued>1)?queued:1):0;for(var i=0,file;file=this.fileList[i];i++){if(this.fileList[i].status!=Uploader.STATUS_QUEUED){continue;}
this.fileList[i].start();if(queued&&this.uploading>=queued){break;}}
return this;},stop:function(){this.fireEvent('beforeStop');for(var i=this.fileList.length;i>0;i--){this.fileList[i].stop();}},remove:function(){this.fireEvent('beforeRemove');for(var i=this.fileList.length;i>0;i--){this.fileList[i].remove();}},setEnabled:function(status){this.file.disabled=!!(status);if(status){this.fireEvent('buttonDisable');}}});$extend(Uploader,{STATUS_QUEUED:0,STATUS_RUNNING:1,STATUS_ERROR:2,STATUS_COMPLETE:3,STATUS_STOPPED:4,id:0,log:function(){if(window.console&&console.info){console.info.apply(console,arguments);}}});Uploader.File=new Class({Extends:Events,Implements:Options,options:{url:null,method:null,data:null,mergeData:true,fieldName:null},initialize:function(base,name,iframe){this.base=base;Uploader.id++;this.id=Uploader.id;this.name=name;this.extension=name.replace(/^.*\./,'').toLowerCase();this.status=Uploader.STATUS_QUEUED;this.dates={};this.dates.add=new Date();this.iframe=iframe.addEvents({abort:this.stop.bind(this),load:this.onLoad.bind(this)});},fireEvent:function(name){this.base.fireEvent('file'+name.capitalize(),[this]);Uploader.log('File::'+name,this);return this.parent(name,[this]);},validate:function(){var base=this.base.options;if(!base.allowDuplicates){var name=this.name;var dup=this.base.fileList.some(function(file){return(file.name==name);});if(dup){this.validationError='duplicate';return false;}}
if(base.fileListMax&&this.base.fileList.length>=base.fileListMax){this.validationError='fileListMax';return false;}
return true;},invalidate:function(){this.invalid=true;return this.fireEvent('invalid');},render:function(){return this;},onLoad:function(){if(this.status!=Uploader.STATUS_RUNNING){return;}
this.status=Uploader.STATUS_COMPLETE;var win=new Window(this.iframe.contentWindow);var doc=new Document(win.document);this.response={window:win,document:doc,text:doc.innerHTML||''};this.base.uploading--;this.dates.complete=new Date();this.fireEvent('complete');this.base.start();},start:function(){if(this.status!=Uploader.STATUS_QUEUED){return this;}
var base=this.base.options,options=this.options;var merged={};for(var key in base){merged[key]=(this.options[key]!==null)?this.options[key]:base[key];}
merged.url=merged.url||location.href;merged.method=(merged.method)?(merged.method.toLowerCase()):'post';var doc=this.iframe.contentWindow.document;var more=doc.getElementById('data');more.innerHTML='';if(merged.data){if(merged.mergeData&&base.data&&options.data){if($type(base.data)=='string'){merged.data=base.data+'&'+options.data;}
else{merged.data=$merge(base.data,options.data);}}
var query=($type(merged.data)=='string')?merged.data:Hash.toQueryString(merged.data);if(query.length){if(merged.method=='get'){if(data.length){merged.url+=((merged.url.contains('?'))?'&':'?')+query;}}else{query.split('&').map(function(value){value=value.split('=');var input=doc.createElement('input');input.type='hidden';input.name=decodeURIComponent(value[0]);input.value=decodeURIComponent(value[1]||'');more.appendChild(input);}).join('');}}}
var form=doc.forms[0];form.action=merged.url;var input=form.elements[0];input.name=merged.fieldName||'Filedata';this.status=Uploader.STATUS_RUNNING;this.base.uploading++;form.submit();this.dates.start=new Date();this.fireEvent('start');return this;},requeue:function(){this.stop();this.status=Uploader.STATUS_QUEUED;this.fireEvent('requeue');},stop:function(soft){if(this.status==Uploader.STATUS_RUNNING){this.status=Uploader.STATUS_STOPPED;this.base.uploading--;this.base.start();if(!soft){this.iframe.contentWindow.history.back();this.fireEvent('stop');}}
return this;},remove:function(){this.stop(true);this.iframe=this.iframe.destroy();this.base.fileList.erase(this);this.fireEvent('remove');return this;}});