/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.0.0 Alpha 5
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2009 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
function vB_YUI_Upload(E,D,B,A,F){this.uploader=null;if(YAHOO.util.Dom.get("yui_selectfiles")&&E==0){this.phrases=null;this.extensions=null;this.max_file_size=0;this.attachlimit=0;this.uploadform=F;this.filelist=null;this.errors=0;this.success=false;this.active=false;this.progress={};this.totalsize=0;this.target=D;this.postvars=B;this.fieldname=A;this.events={updatetotal:new YAHOO.util.CustomEvent("updatetotal",this),upload:new YAHOO.util.CustomEvent("upload",this),handleresponse:new YAHOO.util.CustomEvent("handlereponse",this),handleresponse_noerrors:new YAHOO.util.CustomEvent("handleresponse_noerrors",this),handleresponse_errors:new YAHOO.util.CustomEvent("handleresponse_errors",this),select:new YAHOO.util.CustomEvent("select",this),clear:new YAHOO.util.CustomEvent("clear",this),ready:new YAHOO.util.CustomEvent("ready",this),uploaddone:new YAHOO.util.CustomEvent("uploaddone",this)};YAHOO.widget.Uploader.SWFURL="clientscript/yui/uploader/assets/uploader.swf";try{this.uploader=new YAHOO.widget.Uploader("yui_selectfiles");this.uploader.subscribe("contentReady",this.ready,this,true);this.uploader.subscribe("fileSelect",this.select,this,true);this.uploader.subscribe("uploadProgress",this.uploadprogress,this,true);this.uploader.subscribe("uploadComplete",this.complete,this,true);this.uploader.subscribe("uploadCompleteData",this.handleresponse,this,true);this.uploader.subscribe("uploadError",this.error,this,true);YAHOO.util.Event.on("yui_uploadfiles","click",this.upload,this,true);YAHOO.util.Event.on("yui_clearlist","click",this.clear,this,true);YAHOO.util.Event.on("uploadprogress_ul","click",this.cancel,this,true);YAHOO.util.Event.on("yui_selectfiles","mouseover",this.handleselectbutton,this,true);YAHOO.util.Event.on("yui_selectfiles","mouseout",this.handleselectbutton,this,true)}catch(C){}}}vB_YUI_Upload.prototype.handleselectbutton=function(A){if(YAHOO.util.Dom.hasClass("yui_selectfilestext","yui_selectfiles_hover")){YAHOO.util.Dom.removeClass("yui_selectfilestext","yui_selectfiles_hover")}else{YAHOO.util.Dom.addClass("yui_selectfilestext","yui_selectfiles_hover")}};vB_YUI_Upload.prototype.moveflashobj=function(){var B=YAHOO.util.Dom.getRegion("yui_selectfilestext");if(B){YAHOO.util.Dom.setStyle("yui_selectfiles","width",B.width-2+"px");YAHOO.util.Dom.setStyle("yui_selectfiles","height",B.height-2+"px");var A=YAHOO.util.Dom.getXY("yui_selectfilestext");YAHOO.util.Dom.setXY("yui_selectfiles",A)}if(is_moz){YAHOO.util.Dom.setStyle("yui_selectfiles","overflow-x","");YAHOO.util.Dom.setStyle("yui_selectfiles","overflow-y","");YAHOO.util.Dom.setStyle("yui_selectfiles","overflow","");YAHOO.util.Dom.setStyle("yui_selectfiles","overflow","auto")}};vB_YUI_Upload.prototype.uploadprogress=function(D){var A=YAHOO.util.Dom.get(D.id);var C=Math.floor(100-((D.bytesLoaded/D.bytesTotal)*100))/100;YAHOO.util.Dom.setStyle(A,"backgroundPosition",(-1*(400*C))+"px 0");this.progress[D.id]=D.bytesLoaded;var B=0;for(i in this.progress){B+=this.progress[i]}var C=Math.floor((B/this.totalsize)*100);YAHOO.util.Dom.setStyle("yui_progressbar","width",C+"%")};vB_YUI_Upload.prototype.updatetotal=function(){var B=0;var A=0;for(i in this.filelist){B++;A+=this.filelist[i].size}if(B==0){this.filelist=null;this.events.updatetotal.fire()}YAHOO.util.Dom.get("yui_totalfiles").innerHTML=B;YAHOO.util.Dom.get("yui_totalsize").innerHTML=format_filesize(A)};vB_YUI_Upload.prototype.cancel=function(D){YAHOO.util.Event.stopEvent(D);var C=YAHOO.util.Event.getTarget(D);if(C.nodeName.toUpperCase()=="BUTTON"){var A=null;if(A=YAHOO.util.Dom.getAncestorBy(C,function(E){if(E.nodeName.toUpperCase()=="LI"){return E}return false})){var B=YAHOO.util.Dom.get(A.id);if(B){try{this.uploader.cancel(A.id);this.uploader.removeFile(A.id);delete (this.filelist[A.id])}catch(D){}B.parentNode.removeChild(B);this.updatetotal()}}}};vB_YUI_Upload.prototype.error=function(A){A.data="error: "+A.status;this.handleresponse(A)};vB_YUI_Upload.prototype.complete=function(A){};vB_YUI_Upload.prototype.upload=function(F){if(this.filelist!=null){var B=0;this.totalsize=0;this.progress={};for(i in this.filelist){this.totalsize+=this.filelist[i].size;B++;this.progress[i]=0}this.uploader.setSimUploadLimit(1);var E=YAHOO.util.Dom.get(this.uploadform).getElementsByTagName("input");if(E.length){for(i in E){if(E[i].type=="hidden"){var C=E[i].name.match(/^values\[([^\]]+)\]$/);if(C){this.postvars[C[0]]=E[i].value}}}}var G=YAHOO.util.Dom.get("uploadprogress_ul");var D=G.getElementsByTagName("button");if(D.length){for(var A=1;A<D.length;A++){YAHOO.util.Dom.addClass(D[A],"hidden")}}this.events.upload.fire();YAHOO.util.Dom.addClass("yui_clearlist","hidden");YAHOO.util.Dom.removeClass("yui_clearlist","displayinline");YAHOO.util.Dom.addClass("yui_uploadfiles","hidden");YAHOO.util.Dom.removeClass("yui_uploadfiles","displayinline");YAHOO.util.Dom.addClass("yui_selectfilestext","hidden");YAHOO.util.Dom.removeClass("yui_selectfilestext","displayinline");YAHOO.util.Dom.setStyle("yui_progressbar","width",0);YAHOO.util.Dom.removeClass("yui_progressbar_container","hidden");this.uploader.uploadAll(this.target,"POST",this.postvars,this.fieldname)}};vB_YUI_Upload.prototype.displayerror=function(E,C){var B=YAHOO.util.Dom.get(E);YAHOO.util.Dom.setStyle(B,"backgroundPosition","-400px 0");var A=YAHOO.util.Dom.getElementsByClassName("exclamationimg","img",B);var D=YAHOO.util.Dom.getElementsByClassName("acceptimg","img",B);YAHOO.util.Dom.removeClass(A[0],"hidden");YAHOO.util.Dom.addClass(D[0],"hidden");YAHOO.util.Dom.setAttribute(A[0],"title",A[0].title+" "+C)};vB_YUI_Upload.prototype.handleresponse=function(D){var A=YAHOO.util.Dom.get(D.id);var E=D.data.match(/^ok - ([\d]+) - ([01])/);if(E){var C=YAHOO.util.Dom.getElementsByClassName("acceptimg","img",A);YAHOO.util.Dom.removeClass(C[0],"hidden");this.success=true;this.events.uploaddone.fire(E[1],E[2])}else{this.errors++;var B=D.data.match(/^error: (.*)$/);this.displayerror(D.id,B?B[1]:this.phrases.upload_failed)}this.progress[D.id]=this.filelist[D.id].size;delete (this.filelist[D.id]);this.uploader.removeFile(D.id);this.updatetotal();if(this.filelist==null){YAHOO.util.Dom.addClass("yui_progressbar_container","hidden");if(this.success){this.events.handleresponse.fire()}YAHOO.util.Dom.addClass("yui_clearlist","displayinline");YAHOO.util.Dom.removeClass("yui_clearlist","hidden");if(this.errors==0){this.clear(D);this.events.handleresponse_noerrors.fire()}else{this.events.handleresponse_errors.fire()}}};vB_YUI_Upload.prototype.ready=function(A){this.uploader.setAllowMultipleFiles(true);this.active=true;this.events.ready.fire()};vB_YUI_Upload.prototype.setvars=function(F,C,G,D){this.phrases=C;this.extensions=F;this.attachlimit=G;this.max_file_size=D;var E="";for(var A in F){E+=(E!=""?";":"")+"*."+A}var B=new Array({description:this.phrases.all_files,extensions:E});this.uploader.setFileFilters(B)};vB_YUI_Upload.prototype.select=function(F){if(F.fileList!=null){if(this.filelist){for(var H in this.filelist){var E=YAHOO.util.Dom.get(this.filelist[H].id);if(E){E.parentNode.removeChild(E)}}}var D=YAHOO.util.Dom.getElementsByClassName("asset_div","","asset_upload_list");var K=0;this.filelist=F.fileList;for(var H in F.fileList){var J="";var B=F.fileList[H].id;var E=YAHOO.util.Dom.get("sampleli");var C=E.cloneNode(true);YAHOO.util.Dom.get("uploadprogress_ul").appendChild(C);YAHOO.util.Dom.setAttribute(C,"id",B);YAHOO.util.Dom.removeClass(C,"hidden");var A=YAHOO.util.Dom.getElementsByClassName("name","div",C);A[0].innerHTML=F.fileList[H].name;YAHOO.util.Dom.setAttribute(A[0],"title",F.fileList[H].name);var L=YAHOO.util.Dom.getElementsByClassName("size","div",C);L[0].innerHTML=format_filesize(F.fileList[H].size);if(this.max_file_size&&F.fileList[H].size>this.max_file_size){J=this.phrases.file_is_too_large}else{var G=F.fileList[H].name.lastIndexOf(".");if(G!=-1){var I=F.fileList[H].name.substr(G+1).toLowerCase();if(!YAHOO.lang.hasOwnProperty(this.extensions,I)){J=this.phrases.invalid_file}else{if(this.extensions[I]!=0&&F.fileList[H].size>this.extensions[I]&&!PHP.in_array(I,new Array("jpg","jpe","jpeg","gif","png"),true)){J=this.phrases.file_is_too_large}else{if(this.attachlimit==0||(D.length+K)<this.attachlimit){K++}else{J=this.phrases.maximum_number_of_attachments_reached}}}}else{J=this.phrases.invalid_file}}if(J){this.uploader.removeFile(B);delete (this.filelist[B]);this.displayerror(B,J)}}YAHOO.util.Dom.removeClass("yui_clearlist","hidden");YAHOO.util.Dom.removeClass("yui_uploadfiles","hidden");YAHOO.util.Dom.addClass("yui_clearlist","displayinline");YAHOO.util.Dom.addClass("yui_uploadfiles","displayinline");this.moveflashobj();this.events.select.fire();this.errors=0}this.updatetotal()};vB_YUI_Upload.prototype.clear=function(D){try{this.uploader.cancel()}catch(D){}try{this.uploader.clearFileList()}catch(D){}var E=YAHOO.util.Dom.get("uploadprogress_ul");var B=E.getElementsByTagName("li");if(B.length){var C=B.length;for(var A=1;A<C;A++){E.removeChild(B[1])}}YAHOO.util.Dom.addClass("yui_clearlist","hidden");YAHOO.util.Dom.addClass("yui_uploadfiles","hidden");YAHOO.util.Dom.addClass("yui_selectfilestext","displayinline");YAHOO.util.Dom.removeClass("yui_clearlist","displayinline");YAHOO.util.Dom.removeClass("yui_uploadfiles","displayinline");YAHOO.util.Dom.removeClass("yui_selectfilestext","hidden");YAHOO.util.Dom.removeClass("upload_controls_close3","hidden");this.moveflashobj();this.events.clear.fire();this.filelist=null;this.updatetotal();this.errors=0;this.success=false};function number_format(F,C,I,E){var B=F,A=C;B=!isFinite(+B)?0:+B;A=!isFinite(+A)?0:Math.abs(A);var L=(typeof E=="undefined")?",":E;var D=(typeof I=="undefined")?".":I;var K=(A>0)?B.toFixed(A):Math.round(B).toFixed(A);var J=Math.abs(B).toFixed(A);var H,G;if(J>=1000){H=J.split(/\D/);G=H[0].length%3||3;H[0]=K.slice(0,G+(B<0))+H[0].slice(G).replace(/(\d{3})/g,L+"$1");K=H.join(D)}else{K=K.replace(".",D)}return K}function format_filesize(C){if(C==0){return C}var A=2;var B="";if(C>=1073741824){C=C/1073741824;B="GB"}else{if(C>=1048576){C=C/1048576;B="MB"}else{if(C>=1024){C=C/1024;A=1;B="KB"}else{C=C/1024;A=2;B="KB"}}}return number_format(C,A)+" "+B};