
var SWFUpload=function(init_settings){this.initSWFUpload(init_settings);};SWFUpload.prototype.initSWFUpload=function(init_settings){try{document.execCommand('BackgroundImageCache',false,true);}catch(ex1){}
try{this.customSettings={};this.settings={};this.eventQueue=[];this.movieName="SWFUpload_"+SWFUpload.movieCount++;this.movieElement=null;SWFUpload.instances[this.movieName]=this;this.initSettings(init_settings);this.loadFlash();this.displayDebugInfo();}catch(ex2){this.debug(ex2);}}
SWFUpload.instances={};SWFUpload.movieCount=0;SWFUpload.QUEUE_ERROR={QUEUE_LIMIT_EXCEEDED:-100,FILE_EXCEEDS_SIZE_LIMIT:-110,ZERO_BYTE_FILE:-120,INVALID_FILETYPE:-130};SWFUpload.UPLOAD_ERROR={HTTP_ERROR:-200,MISSING_UPLOAD_URL:-210,IO_ERROR:-220,SECURITY_ERROR:-230,UPLOAD_LIMIT_EXCEEDED:-240,UPLOAD_FAILED:-250,SPECIFIED_FILE_ID_NOT_FOUND:-260,FILE_VALIDATION_FAILED:-270,FILE_CANCELLED:-280,UPLOAD_STOPPED:-290};SWFUpload.FILE_STATUS={QUEUED:-1,IN_PROGRESS:-2,ERROR:-3,COMPLETE:-4,CANCELLED:-5};SWFUpload.prototype.initSettings=function(init_settings){this.addSetting("upload_url",init_settings.upload_url,"");this.addSetting("file_post_name",init_settings.file_post_name,"Filedata");this.addSetting("post_params",init_settings.post_params,{});this.addSetting("file_types",init_settings.file_types,"*.*");this.addSetting("file_types_description",init_settings.file_types_description,"All Files");this.addSetting("file_size_limit",init_settings.file_size_limit,"1024");this.addSetting("file_upload_limit",init_settings.file_upload_limit,"0");this.addSetting("file_queue_limit",init_settings.file_queue_limit,"0");this.addSetting("flash_url",init_settings.flash_url,"swfupload.swf");this.addSetting("flash_width",init_settings.flash_width,"1px");this.addSetting("flash_height",init_settings.flash_height,"1px");this.addSetting("flash_color",init_settings.flash_color,"#FFFFFF");this.addSetting("debug_enabled",init_settings.debug,false);this.flashReady_handler=SWFUpload.flashReady;this.swfUploadLoaded_handler=this.retrieveSetting(init_settings.swfupload_loaded_handler,SWFUpload.swfUploadLoaded);this.fileDialogStart_handler=this.retrieveSetting(init_settings.file_dialog_start_handler,SWFUpload.fileDialogStart);this.fileQueued_handler=this.retrieveSetting(init_settings.file_queued_handler,SWFUpload.fileQueued);this.fileQueueError_handler=this.retrieveSetting(init_settings.file_queue_error_handler,SWFUpload.fileQueueError);this.fileDialogComplete_handler=this.retrieveSetting(init_settings.file_dialog_complete_handler,SWFUpload.fileDialogComplete);this.uploadStart_handler=this.retrieveSetting(init_settings.upload_start_handler,SWFUpload.uploadStart);this.uploadProgress_handler=this.retrieveSetting(init_settings.upload_progress_handler,SWFUpload.uploadProgress);this.uploadError_handler=this.retrieveSetting(init_settings.upload_error_handler,SWFUpload.uploadError);this.uploadSuccess_handler=this.retrieveSetting(init_settings.upload_success_handler,SWFUpload.uploadSuccess);this.uploadComplete_handler=this.retrieveSetting(init_settings.upload_complete_handler,SWFUpload.uploadComplete);this.debug_handler=this.retrieveSetting(init_settings.debug_handler,SWFUpload.debug);this.customSettings=this.retrieveSetting(init_settings.custom_settings,{});};SWFUpload.prototype.loadFlash=function(){var html,target_element,container;if(document.getElementById(this.movieName)!==null){return false;}
try{target_element=document.getElementsByTagName("body")[0];if(typeof(target_element)==="undefined"||target_element===null){this.debug('Could not find the BODY element. SWFUpload failed to load.');return false;}}catch(ex){return false;}
container=document.createElement("div");container.style.width=this.getSetting("flash_width");container.style.height=this.getSetting("flash_height");target_element.appendChild(container);container.innerHTML=this.getFlashHTML();};SWFUpload.prototype.getFlashHTML=function(){var html="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){html='<embed type="application/x-shockwave-flash" src="'+this.getSetting("flash_url")+'" width="'+this.getSetting("flash_width")+'" height="'+this.getSetting("flash_height")+'"';html+=' id="'+this.movieName+'" name="'+this.movieName+'" ';html+='bgcolor="'+this.getSetting("flash_color")+'" quality="high" menu="false" flashvars="';html+=this.getFlashVars();html+='" />';}else{html='<object id="'+this.movieName+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+this.getSetting("flash_width")+'" height="'+this.getSetting("flash_height")+'">';html+='<param name="movie" value="'+this.getSetting("flash_url")+'">';html+='<param name="bgcolor" value="'+this.getSetting("flash_color")+'" />';html+='<param name="quality" value="high" />';html+='<param name="menu" value="false" />';html+='<param name="flashvars" value="'+this.getFlashVars()+'" />';html+='</object>';}
return html;};SWFUpload.prototype.getFlashVars=function(){var param_string=this.buildParamString();var html="";html+="movieName="+encodeURIComponent(this.movieName);html+="&uploadURL="+encodeURIComponent(this.getSetting("upload_url"));html+="&params="+encodeURIComponent(param_string);html+="&filePostName="+encodeURIComponent(this.getSetting("file_post_name"));html+="&fileTypes="+encodeURIComponent(this.getSetting("file_types"));html+="&fileTypesDescription="+encodeURIComponent(this.getSetting("file_types_description"));html+="&fileSizeLimit="+encodeURIComponent(this.getSetting("file_size_limit"));html+="&fileUploadLimit="+encodeURIComponent(this.getSetting("file_upload_limit"));html+="&fileQueueLimit="+encodeURIComponent(this.getSetting("file_queue_limit"));html+="&debugEnabled="+encodeURIComponent(this.getSetting("debug_enabled"));return html;};SWFUpload.prototype.getMovieElement=function(){if(typeof(this.movieElement)==="undefined"||this.movieElement===null){this.movieElement=document.getElementById(this.movieName);}
return this.movieElement;};SWFUpload.prototype.buildParamString=function(){var post_params=this.getSetting("post_params");var param_string_pairs=[];var i,value,name;if(typeof(post_params)==="object"){for(name in post_params){if(post_params.hasOwnProperty(name)){if(typeof(post_params[name])==="string"){param_string_pairs.push(encodeURIComponent(name)+"="+encodeURIComponent(post_params[name]));}}}}
return param_string_pairs.join("&");};SWFUpload.prototype.addSetting=function(name,value,default_value){if(typeof(value)==="undefined"||value===null){this.settings[name]=default_value;}else{this.settings[name]=value;}
return this.settings[name];};SWFUpload.prototype.getSetting=function(name){if(typeof(this.settings[name])==="undefined"){return"";}else{return this.settings[name];}};SWFUpload.prototype.retrieveSetting=function(value,default_value){if(typeof(value)==="undefined"||value===null){return default_value;}else{return value;}};SWFUpload.prototype.displayDebugInfo=function(){var key,debug_message="";debug_message+="----- SWFUPLOAD SETTINGS     ----\nID: "+this.moveName+"\n";debug_message+=this.outputObject(this.settings);debug_message+="----- SWFUPLOAD SETTINGS END ----\n";debug_message+="\n";this.debug(debug_message);};SWFUpload.prototype.outputObject=function(object,prefix){var output="",key;if(typeof(prefix)!=="string"){prefix="";}
if(typeof(object)!=="object"){return"";}
for(key in object){if(object.hasOwnProperty(key)){if(typeof(object[key])==="object"){output+=(prefix+key+": { \n"+this.outputObject(object[key],"\t"+prefix)+prefix+"}"+"\n");}else{output+=(prefix+key+": "+object[key]+"\n");}}}
return output;};SWFUpload.prototype.selectFile=function(){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SelectFile)==="function"){try{movie_element.SelectFile();}
catch(ex){this.debug("Could not call SelectFile: "+ex);}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.selectFiles=function(){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SelectFiles)==="function"){try{movie_element.SelectFiles();}
catch(ex){this.debug("Could not call SelectFiles: "+ex);}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.startUpload=function(file_id){var self=this;var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.StartUpload)==="function"){setTimeout(function(){try{movie_element.StartUpload(file_id);}
catch(ex){self.debug("Could not call StartUpload: "+ex);}},0);}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.cancelUpload=function(file_id){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.CancelUpload)==="function"){try{movie_element.CancelUpload(file_id);}
catch(ex){this.debug("Could not call CancelUpload: "+ex);}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.stopUpload=function(){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.StopUpload)==="function"){try{movie_element.StopUpload();}
catch(ex){this.debug("Could not call StopUpload: "+ex);}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.getStats=function(){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.GetStats)==="function"){try{return movie_element.GetStats();}
catch(ex){this.debug("Could not call GetStats");}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.setStats=function(stats_object){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetStats)==="function"){try{movie_element.SetStats(stats_object);}
catch(ex){this.debug("Could not call SetStats");}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.setCredentials=function(name,password){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetCredentials)==="function"){try{return movie_element.SetCredentials(name,password);}
catch(ex){this.debug("Could not call SetCredentials");}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.getFile=function(file_id){var movie_element=this.getMovieElement();if(typeof(file_id)==="number"){if(movie_element!==null&&typeof(movie_element.GetFileByIndex)==="function"){try{return movie_element.GetFileByIndex(file_id);}
catch(ex){this.debug("Could not call GetFileByIndex");}}else{this.debug("Could not find Flash element");}}else{if(movie_element!==null&&typeof(movie_element.GetFile)==="function"){try{return movie_element.GetFile(file_id);}
catch(ex){this.debug("Could not call GetFile");}}else{this.debug("Could not find Flash element");}}};SWFUpload.prototype.addFileParam=function(file_id,name,value){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.AddFileParam)==="function"){try{return movie_element.AddFileParam(file_id,name,value);}
catch(ex){this.debug("Could not call AddFileParam");}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.removeFileParam=function(file_id,name){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.RemoveFileParam)==="function"){try{return movie_element.RemoveFileParam(file_id,name);}
catch(ex){this.debug("Could not call AddFileParam");}}else{this.debug("Could not find Flash element");}};SWFUpload.prototype.setUploadURL=function(url){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetUploadURL)==="function"){try{this.addSetting("upload_url",url);movie_element.SetUploadURL(this.getSetting("upload_url"));}
catch(ex){this.debug("Could not call SetUploadURL");}}else{this.debug("Could not find Flash element in setUploadURL");}};SWFUpload.prototype.setPostParams=function(param_object){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetPostParams)==="function"){try{this.addSetting("post_params",param_object);movie_element.SetPostParams(this.getSetting("post_params"));}
catch(ex){this.debug("Could not call SetPostParams");}}else{this.debug("Could not find Flash element in SetPostParams");}};SWFUpload.prototype.setFileTypes=function(types,description){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetFileTypes)==="function"){try{this.addSetting("file_types",types);this.addSetting("file_types_description",description);movie_element.SetFileTypes(this.getSetting("file_types"),this.getSetting("file_types_description"));}
catch(ex){this.debug("Could not call SetFileTypes");}}else{this.debug("Could not find Flash element in SetFileTypes");}};SWFUpload.prototype.setFileSizeLimit=function(file_size_limit){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetFileSizeLimit)==="function"){try{this.addSetting("file_size_limit",file_size_limit);movie_element.SetFileSizeLimit(this.getSetting("file_size_limit"));}
catch(ex){this.debug("Could not call SetFileSizeLimit");}}else{this.debug("Could not find Flash element in SetFileSizeLimit");}};SWFUpload.prototype.setFileUploadLimit=function(file_upload_limit){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetFileUploadLimit)==="function"){try{this.addSetting("file_upload_limit",file_upload_limit);movie_element.SetFileUploadLimit(this.getSetting("file_upload_limit"));}
catch(ex){this.debug("Could not call SetFileUploadLimit");}}else{this.debug("Could not find Flash element in SetFileUploadLimit");}};SWFUpload.prototype.setFileQueueLimit=function(file_queue_limit){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetFileQueueLimit)==="function"){try{this.addSetting("file_queue_limit",file_queue_limit);movie_element.SetFileQueueLimit(this.getSetting("file_queue_limit"));}
catch(ex){this.debug("Could not call SetFileQueueLimit");}}else{this.debug("Could not find Flash element in SetFileQueueLimit");}};SWFUpload.prototype.setFilePostName=function(file_post_name){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetFilePostName)==="function"){try{this.addSetting("file_post_name",file_post_name);movie_element.SetFilePostName(this.getSetting("file_post_name"));}
catch(ex){this.debug("Could not call SetFilePostName");}}else{this.debug("Could not find Flash element in SetFilePostName");}};SWFUpload.prototype.setDebugEnabled=function(debug_enabled){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.SetDebugEnabled)==="function"){try{this.addSetting("debug_enabled",debug_enabled);movie_element.SetDebugEnabled(this.getSetting("debug_enabled"));}
catch(ex){this.debug("Could not call SetDebugEnabled");}}else{this.debug("Could not find Flash element in SetDebugEnabled");}};SWFUpload.prototype.flashReady=function(){var movie_element=this.getMovieElement();if(movie_element===null||typeof(movie_element.StartUpload)!=="function"){this.debug("ExternalInterface methods failed to initialize.");return;}
var self=this;if(typeof(self.flashReady_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.flashReady_handler();};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("flashReady_handler event not defined");}};SWFUpload.prototype.executeNextEvent=function(){var f=this.eventQueue.shift();if(typeof(f)==="function"){f();}}
SWFUpload.prototype.fileDialogStart=function(){var self=this;if(typeof(self.fileDialogStart_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.fileDialogStart_handler();};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("fileDialogStart event not defined");}};SWFUpload.prototype.fileQueued=function(file){var self=this;if(typeof(self.fileQueued_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.fileQueued_handler(file);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("fileQueued event not defined");}};SWFUpload.prototype.fileQueueError=function(file,error_code,message){var self=this;if(typeof(self.fileQueueError_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.fileQueueError_handler(file,error_code,message);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("fileQueueError event not defined");}};SWFUpload.prototype.fileDialogComplete=function(num_files_selected){var self=this;if(typeof(self.fileDialogComplete_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.fileDialogComplete_handler(num_files_selected);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("fileDialogComplete event not defined");}};SWFUpload.prototype.uploadStart=function(file){var self=this;if(typeof(self.fileDialogComplete_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.returnUploadStart(self.uploadStart_handler(file));};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("uploadStart event not defined");}};SWFUpload.prototype.returnUploadStart=function(return_value){var movie_element=this.getMovieElement();if(movie_element!==null&&typeof(movie_element.ReturnUploadStart)==="function"){try{movie_element.ReturnUploadStart(return_value);}
catch(ex){this.debug("Could not call ReturnUploadStart");}}else{this.debug("Could not find Flash element in returnUploadStart");}};SWFUpload.prototype.uploadProgress=function(file,bytes_complete,bytes_total){var self=this;if(typeof(self.uploadProgress_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.uploadProgress_handler(file,bytes_complete,bytes_total);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("uploadProgress event not defined");}};SWFUpload.prototype.uploadError=function(file,error_code,message){var self=this;if(typeof(this.uploadError_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.uploadError_handler(file,error_code,message);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("uploadError event not defined");}};SWFUpload.prototype.uploadSuccess=function(file,server_data){var self=this;if(typeof(self.uploadSuccess_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.uploadSuccess_handler(file,server_data);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("uploadSuccess event not defined");}};SWFUpload.prototype.uploadComplete=function(file){var self=this;if(typeof(self.uploadComplete_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.uploadComplete_handler(file);};setTimeout(function(){self.executeNextEvent();},0);}else{this.debug("uploadComplete event not defined");}};SWFUpload.prototype.debug=function(message){var self=this;if(typeof(self.debug_handler)==="function"){this.eventQueue[this.eventQueue.length]=function(){self.debug_handler(message);};setTimeout(function(){self.executeNextEvent();},0);}else{this.eventQueue[this.eventQueue.length]=function(){self.debugMessage(message);};setTimeout(function(){self.executeNextEvent();},0);}};SWFUpload.flashReady=function(){try{this.debug("Flash called back and is ready.");if(typeof(this.swfUploadLoaded_handler)==="function"){this.swfUploadLoaded_handler();}}catch(ex){this.debug(ex);}};SWFUpload.swfUploadLoaded=function(){};SWFUpload.fileDialogStart=function(){};SWFUpload.fileQueued=function(file){};SWFUpload.fileQueueError=function(file,error_code,message){try{switch(error_code){case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:this.debug("Error Code: File too big, File name: "+file.name+", File size: "+file.size+", Message: "+message);break;case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:this.debug("Error Code: Zero Byte File, File name: "+file.name+", File size: "+file.size+", Message: "+message);break;case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:this.debug("Error Code: Upload limit reached, File name: "+file.name+", File size: "+file.size+", Message: "+message);break;case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:this.debug("Error Code: File extension is not allowed, Message: "+message);break;default:this.debug("Error Code: Unhandled error occured. Errorcode: "+error_code);}}catch(ex){this.debug(ex);}};SWFUpload.fileDialogComplete=function(num_files_selected){};SWFUpload.uploadStart=function(file){return true;};SWFUpload.uploadProgress=function(file,bytes_complete,bytes_total){this.debug("File Progress: "+file.id+", Bytes: "+bytes_complete+". Total: "+bytes_total);};SWFUpload.uploadSuccess=function(file,server_data){};SWFUpload.uploadComplete=function(file){};SWFUpload.debug=function(message){if(this.getSetting("debug_enabled")){this.debugMessage(message);}};SWFUpload.uploadError=function(file,error_code,message){try{switch(errcode){case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:this.debug("Error Code: File ID specified for upload was not found, Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:this.debug("Error Code: HTTP Error, File name: "+file.name+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:this.debug("Error Code: No backend file, File name: "+file.name+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:this.debug("Error Code: IO Error, File name: "+file.name+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:this.debug("Error Code: Security Error, File name: "+file.name+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:this.debug("Error Code: Upload limit reached, File name: "+file.name+", File size: "+file.size+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:this.debug("Error Code: Upload Initialization exception, File name: "+file.name+", File size: "+file.size+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:this.debug("Error Code: uploadStart callback returned false, File name: "+file.name+", File size: "+file.size+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:this.debug("Error Code: The file upload was cancelled, File name: "+file.name+", File size: "+file.size+", Message: "+msg);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:this.debug("Error Code: The file upload was stopped, File name: "+file.name+", File size: "+file.size+", Message: "+msg);break;default:this.debug("Error Code: Unhandled error occured. Errorcode: "+errcode);}}catch(ex){this.debug(ex);}};SWFUpload.prototype.debugMessage=function(message){var exception_message,exception_values;if(typeof(message)==="object"&&typeof(message.name)==="string"&&typeof(message.message)==="string"){exception_message="";exception_values=[];for(var key in message){exception_values.push(key+": "+message[key]);}
exception_message=exception_values.join("\n");exception_values=exception_message.split("\n");exception_message="EXCEPTION: "+exception_values.join("\nEXCEPTION: ");SWFUpload.Console.writeLine(exception_message);}else{SWFUpload.Console.writeLine(message);}};SWFUpload.Console={};SWFUpload.Console.writeLine=function(message){var console,documentForm;try{console=document.getElementById("SWFUpload_Console");if(!console){documentForm=document.createElement("form");document.getElementsByTagName("body")[0].appendChild(documentForm);console=document.createElement("textarea");console.id="SWFUpload_Console";console.style.fontFamily="monospace";console.setAttribute("wrap","off");console.wrap="off";console.style.overflow="auto";console.style.width="700px";console.style.height="350px";console.style.margin="5px";documentForm.appendChild(console);}
console.value+=message+"\n";console.scrollTop=console.scrollHeight-console.clientHeight;}catch(ex){alert("Exception: "+ex.name+" Message: "+ex.message);}};

var SWFUpload;if(typeof(SWFUpload)==="function"){SWFUpload.gracefulDegradation={};SWFUpload.prototype.initSettings=function(old_initSettings){return function(init_settings){if(typeof(old_initSettings)==="function"){old_initSettings.call(this,init_settings);}
this.addSetting("swfupload_element_id",init_settings.swfupload_element_id,"swfupload_container");this.addSetting("degraded_element_id",init_settings.degraded_element_id,"degraded_container");this.addSetting("user_swfUploadLoaded_handler",init_settings.swfupload_loaded_handler,SWFUpload.swfUploadLoaded);this.swfUploadLoaded_handler=SWFUpload.gracefulDegradation.swfUploadLoaded;};}(SWFUpload.prototype.initSettings);SWFUpload.gracefulDegradation.swfUploadLoaded=function(){var swfupload_container_id,swfupload_container,degraded_container_id,degraded_container,user_swfUploadLoaded_handler;try{swfupload_element_id=this.getSetting("swfupload_element_id");degraded_element_id=this.getSetting("degraded_element_id");swfupload_container=document.getElementById(swfupload_element_id);if(swfupload_container!==null){swfupload_container.style.display="block";degraded_container=document.getElementById(degraded_element_id);if(degraded_container!==null){degraded_container.style.display="none";}}}catch(ex){this.debug(ex);}
user_swfUploadLoaded_handler=this.getSetting("user_swfUploadLoaded_handler");if(typeof(user_swfUploadLoaded_handler)==="function"){user_swfUploadLoaded_handler.apply(this);}};}
var upload = {
	swfu: null,

	init: function(uploadURL, baseURL)
	{
		var settings = {
			upload_url: uploadURL,
			flash_url: baseURL+'/flash/swfupload_f9.swf',
			file_size_limit: "20480",
			file_types: "*.*",
			file_upload_limit: 1,

			upload_start_handler: this.uploadStart,
			upload_success_handler: this.uploadSuccess,
			upload_complete_handler: this.uploadComplete,
			upload_progress_handler: this.uploadProgress,
			upload_error_handler: this.uploadError,

			file_queued_handler : this.fileQueued,
			file_queue_error_handler : this.fileQueueError,
			file_dialog_complete_handler : this.fileDialogComplete,

			swfupload_element_id: "flashUI",
			degraded_element_id: "degradedUI"
		};

		this.swfu = new SWFUpload(settings);
		try
		{
			// button crap
			Element.addClassName('uploadBegin', 'disabled');
			Form.Element.disable('uploadBegin');
			Form.Element.setValue('txtFileName', '');

			Event.observe('btnBrowse', 'click', function() { upload.swfu.cancelUpload(); upload.swfu.selectFiles(); });
			Event.observe('uploadForm', 'submit', this.submitForm.bindAsEventListener(upload));
		}
		catch(ex) { }
	},

	submitForm: function(evt)
	{
		Event.stop(evt);
		this.swfu.startUpload();
	},

	uploadStart: function()
	{
		var uploading = $('uploading');
		var uploadForm = $('uploadForm');
		if(uploading && uploadForm)
		{
			var dimen = uploadForm.getDimensions();

			uploading.style.width = (dimen.width+20)+'px';
			uploading.style.height = (dimen.height+20)+'px';
			$('uploadProgress').innerHTML = '0%';

			Element.show(uploading);
		}
		return true;	// need to do this apparently
	},

	uploadSuccess: function(file, serverData)
	{
		$('uploadProgress').innerHTML = 'File uploaded!';
		Form.Element.setValue('uploadFileName', serverData.strip());
	},

	uploadComplete: function()
	{
		$('uploadForm').submit();
	},

	uploadProgress: function(file, bytesLoaded, bytesTotal)
	{
		var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
		$('uploadProgress').innerHTML = percent + '%';
	},

	uploadError: function(file, errorCode, message)
	{
		if(console)
		{
			console.log(errorCode);
			console.log(message);
		}
	},

	fileQueued: function(file)
	{
		var inputElem = $('txtFileName');
		if(inputElem)
		{
			inputElem.value = file.name;
		}
		Element.removeClassName('uploadBegin', 'disabled');
		Form.Element.enable('uploadBegin');
	},

	fileQueueError: function(file, errorCode, message)
	{
	},

	fileDialogComplete: function(numFilesSelected, numFilesQueued)
	{
	}
};

upload.init(uploadURL, baseURL);

