uploader=function(id){
	if(this.enabled){
		this.enabled=false;
		this.id=id;
		this.form=document.getElementById('uploadForm'+id);
		this.iframe=document.getElementById('uploadIframe'+id);
		fields=this.form.getElementsByTagName('input');
		this.type='default';
		this.file=null;
		this.previewLink=false;
		this.onSucces=false;
		for (var i=0;i<fields.length;i++){
			var name=fields[i].getAttribute('name');
			switch(name){
				case 'type':
					this.type=this.type=fields[i].getAttribute('value');
					break;
				case 'file':
					this.file=fields[i];
					break;
				case 'succes':
					this.onSucces=this.type=fields[i].getAttribute('value');
					break;
			}
		}
		var obj=this;
		mainEventHandler.addListner(this.iframe,this.checkUpload,'onload',this);
		this.preview=null;
		this.preview=(this.form.getElementsByTagName('img').length>0)?this.form.getElementsByTagName('img')[0]:this.preview;
		this.form.submit();
	}
}

uploader.prototype={
	enabled:true,
	checkUpload:function(){
		var doc=(this.iframe.contentDocument)?this.iframe.contentDocument:this.iframe.contentWindow.document;
		//var doc = this.iframe.contentDocument;
		var body=doc.getElementsByTagName('body').item(0)
		var response=getTextContent(body);
		if (response){
			if (response=='error'){
				this.handleError(response);
			}else{
				this.handleSucces(response);
			}
			this.enabled=true;
		}
	},
	handleError:function(response){
		new BLError(SL_ERROR_ERROR,'Could not uplad file');
	},
	handleSucces:function(response){
		//this.file.setAttribute('disabled','true')
		this.returnUrl=response;
		switch(this.type){
			case "image":
				this.preview.style.display="block";
				this.preview.src=this.returnUrl;
				this.preview.setAttribute('title','click to view image');
				if (this.previewLink==false){
					this.previewLink=document.createElement('a');
					this.previewLink.setAttribute('target','_blank');
					this.previewLink.setAttribute('title','click to view image');
				}
				this.previewLink.setAttribute('href',this.returnUrl);
				this.preview.parentNode.replaceChild(this.previewLink,this.preview);
				this.previewLink.appendChild(this.preview);
				break;
		}
		if(this.onSucces){
			eval(this.onSucces);
		}
	}
}