/**
 * Object yuploader
 * 	Client-Side upload script (Javascript and Flash), using
 *	FileReference(http://www.devpro.it/FileReference/)
 * 	and SWFObject(http://blog.deconcept.com/swfobject/)
 *
 * Demo test page:
 * http://proj.ycicom.net/yuploader/example.html
 *
 * @author              Le Thach Thao
 * @site		myblog.ycicom.net
 * @date                2006/01/26
 * @version             beta1
 */
function yuploader() {
	
	this.init = function(settings) {
		
		// store user's settings into the object
		this.settings = settings;
		
		// Create SWFObject 
		var soIdName = 'swf' + Math.round((Math.random() * 1234567890));		
		var so = new SWFObject(this.settings["swf_file_path"], soIdName, "0", "0", "8", "#000000");
		
		// Make sure that user's Flash Plug-in version is higher than 8 or Not
		if(deconcept.SWFObjectUtil.getPlayerVersion(so.getAttribute("version")).major >= 8) {
			
			so.write(this.settings["target"]);
			
			
			this.fileRef = new FileReference();			
			this.fileRef.init(this.settings["target"], soIdName);
			
			var listener = new Object();
			
			// invoked when a user chose a file
			listener.onSelect = this.settings["upload_select_callback"];
			
			// common error functions
			listener.onError = this.settings["upload_error_callback"];
			
			listener.onHTTPError =
			listener.onIOError =
			listener.onSecurityError = function(file, errorString) {
				if(errorString == undefined)
					errorString = 'HTTP I/O Error';
				this.onError(file, errorString);
			}
			
			// invoked on cancel when upload start
			listener.onOpen = this.settings["upload_start_callback"];
			
			// invoked on cancel when upload dialog is open
			listener.onCancel = this.settings["upload_cancel_callback"];

			// ... while file is uploaded / downloaded
			listener.onProgress = this.settings["upload_progress_callback"];
			
			// invoked when file is uploaded / downloaded
			listener.onComplete = this.settings["upload_complete_callback"];
			
			this.fileRef.addListener(listener);
		}
	}
	
	this.browse = function () {
		this.fileRef.browse();
	}
	
	this.upload = function () {
		this.fileRef.upload(this.settings["upload_backend"]);
	}
	
	this.cancel = function () {
		this.fileRef.cancel();
	}
}

/**
 * SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
if(!document.createElement||!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute("version"),_7);
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){
_16.push(key+"="+_18[key]);}
return _16;
},getSWFHTML:function(){
var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}
_19+="/>";
}else{
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}
_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();
return true;
}else{
if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(_23,_24){
var _25=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_25=new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{
var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
for(var i=3;axo!=null;i++){
axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
_25=new deconcept.PlayerVersion([i,0,0]);}}
catch(e){}
if(_23&&_25.major>_23.major){return _25;}
if(!_23||((_23.minor!=0||_23.rev!=0)&&_25.major==_23.major)||_25.major!=6||_24){
try{_25=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}
catch(e){}}}
return _25;};
deconcept.PlayerVersion=function(_29){
this.major=parseInt(_29[0])!=null?parseInt(_29[0]):0;
this.minor=parseInt(_29[1])||0;
this.rev=parseInt(_29[2])||0;};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}return true;};
deconcept.util={getRequestParameter:function(_2b){
var q=document.location.search||document.location.hash;
if(q){
var _2d=q.indexOf(_2b+"=");
var _2e=(q.indexOf("&",_2d)>-1)?q.indexOf("&",_2d):q.length;
if(q.length>1&&_2d>-1){
return q.substring(q.indexOf("=",_2d)+1,_2e);
}}return "";}};
if(Array.prototype.push==null){
Array.prototype.push=function(_2f){
this[this.length]=_2f;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for backwards compatibility
var SWFObject=deconcept.SWFObject;



/**
 * Object FileReference
 * Unofficial Andrea Giammarchi JavaScript porting for original
 *      FileReference FLash 8 and ActionScript 2.0 class.
 * Original and official Macromedia documentation link ( thank you Macromedia ) :
 * http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002204.html
 *
 * Demo test page:
 * http://www.devpro.it/FileReference/
 *
 * Special Thanks:
 * Albano Daniele Salvatore for its support and debug [ www.phpsoft.it ]
 * ---------------------------------------------
 * @dependenciesrequires Flash 8 plug in and FileReference_List.swf file
 * [ http://www.devpro.it/FileReference/ ]
 * @author              Andrea Giammarchi
 * @site		www.devpro.it
 * @date                2005/10/24
 * @lastmod             2005/11/08 11:00
 * @version             1.0b , tested with FF 1.0.7, IE 6, Opera 8
 */
function FileReference() {
	/** List of all PUBLIC methods */
	// init
		/** 
		 * Public unofficial and required method
		 * ( this method does not exist on original FileReference Flash 8 class )
		 * 
		 * Creates object that will recieve informations from JavaScript FileReference driver.
		 * You have to call this initializzator before use this object and after document (body) is loaded.
		 * The simplest way is to pass this method on onload body function.
		 *
		 *      this.init( HTMLElementID:String ):Void
		 *
		 * @param	String		unique id for an html element where flash object will be created
		 * NOTE: don't worry about your layout, it will be unvisible.
		 */
	
	// addListener
		/** 
		 * Public official method
		 * http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002205.html
		 */
	
	// browse
		/** 
		 * Public official method
		 * http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002206.html
		 */

	// cancel
		/**
		* Public official method
		* http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002207.html
		*/

	// download
		/**
		 * Public official method
		 * http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002210.html
		 */

	// removeListener
		/**
		 * Public official method
		 * http://livedocs.macromedia.com/flash/8/main/00002233.html
		 */
	
	// upload
		/**
		 * Public official method
		 * http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002225.html
		 */
	
	return __commonFileReferenceConstructor();
}

function __commonFileReferenceConstructor() {
	var frName = 'fr' + Math.round((Math.random() * 1234567890));
	document[frName] = new __FileReference(frName);
	return document[frName];
}

function __FileReference(frName) {
	this.init = function(divId, dname) {
		var cientBrowser = navigator.userAgent.toLowerCase();
		if(cientBrowser.split('opera').length > 1 && !navigator.javaEnabled()) {
			__supported = false;
		}
		if(__supported && __fromList == false) {
			if(document.getElementById)
				divId = document.getElementById(divId);
			else
				divId = document.all[divId];
			divId.style.display = 'inline';
			divId.style.position = 'absolute';
			divId.style.top = divId.style.left = '0px';
			arguments = new Array(arguments[0], dname);
		}
		else if(__supported && __fromList == true) {
			if(document.getElementById)
				divId = document.getElementById(divId);
			else
				divId = document.all[divId];
		}
		if(__supported) {
			__flash.name = arguments[1];
			__flash.__requires_change__ = true;
		}
	}
	this.addListener = function(listener) {
		if(__supported)
			__listener.push(listener);
	}
	this.browse = function() {
		var done = false;
		if(__supported) {
			this.__checkObject();
			var tmplist = '';
			if(arguments.length == 1) {
				var b = arguments[0].length;
				for(var a = 0; a < b; a++) {
					tmplist += arguments[0][a].description + '\n' + arguments[0][a].extension;
					if((a + 1) < b)
						tmplist += '\n\n';
				}
			}
			__flash.SetVariable('__typelist', tmplist);
			__flash.TCallLabel('_root', '__callBrowse');
			done = __flash.GetVariable('__sentinel');
		}
		return done;
	}
	this.cancel = function() {
		if(__supported) {
			this.__checkObject();
			__flash.TCallLabel('_root', '__callCancel');
			this.__setVariables(Array(null, null, null, null, null, null));
		}
	}
	this.download = function(url) {
		var done = false;
		if(__supported) {
			this.__checkObject();
			if(arguments.length == 2)
				__flash.SetVariable('__fileName', arguments[1]);
			else
				__flash.SetVariable('__fileName', '');
			__flash.SetVariable('__serverFile', url);
			__flash.TCallLabel('_root', '__callDownload');
			done = __flash.GetVariable('__sentinel');
		}
		return done;
	}
	this.removeListener = function(listener) {
		var done = false;
		if(__supported) {
			var tmplst = Array();
			for(var a = 0; a < __listener.length; a++) {
				if(__listener[a] != listener)
					tmplst.push(__listener[a]);
				else
					done = true;
			}
			__listener = tmplst;
		}
		return done;
	}
	this.upload = function(url) {
		var done = false;
		if(__supported) {
			this.__checkObject();
			__flash.SetVariable('__serverFile', url);
			__flash.TCallLabel('_root', '__callUpload');
			done = __flash.GetVariable('__sentinel');
		}
		return done;
	}
	function __callBackManager(evt, file) {
		if(__supported) {
			var al = new Number(arguments.length - 2);
			if(file[0] != "undefined")
				this.__setVariables(file);
			for(var a = 0; a < __listener.length; a++) {
				if(__listener[a][evt]) {
					if(al == 0)
						__listener[a][evt](this);
					else if(al == 1)
						__listener[a][evt](this, arguments[2]);
					else
						__listener[a][evt](this, arguments[2], arguments[3]);
				}
			}
		}
	}
	function __checkObject() {
		if(__flash.__requires_change__) {
			__flash.__requires_change__ = false;
			__flash = document[__flash.name];
			__flash.SetVariable('__JSObject', 'document.' + frName);
		}
		if(__fromList == true) {
			__flash.SetVariable('__realReference', this.name);
			__flash.TCallLabel('_root', '__setRealReference');
		}
	}
	function __setFromList(how) {
		__fromList = how;
	}
	function __setVariables(file) {
		this.name = file[0];
		this.creator = file[1];
		this.creationDate = file[2];
		this.modificationDate = file[3];
		this.size = file[4];
		this.type = file[5];
	}
	var __supported = true;
	var __fromList = false;
	var __flash = new Object();
	var __listener = new Array();
	this.__callBackManager = __callBackManager;
	this.__setFromList = __setFromList;
	this.__setVariables = __setVariables;
	this.__checkObject = __checkObject;
	this.name = 
	this.creator = 
	this.creationDate = 
	this.modificationDate = 
	this.size = 
	this.type = null;
}