function upload(btn_id, txt_id, field_name, allowed_extensions, response_msg, error_msg, action) {
	
	if (action == undefined) {
		action = '/admin/cms_categories/upload';
	}
	
	new Insertion.After(btn_id, new Element('span', {id:txt_id+'_response', style:'display:none; margin:0 0 0 5px; padding:5px; float:left;'}));
	
	var button = $(btn_id), interval;
	
	new AjaxUpload('#'+btn_id, {
		action: action,
		name: field_name,
		onSubmit : function(file , ext){
			var regexp = new RegExp('^('+allowed_extensions+')$', 'i');
			if (!(ext && regexp.test(ext))){
				$(txt_id+'_response').className = 'red';
				$(txt_id+'_response').update(error_msg+allowed_extensions);
				$(txt_id+'_response').show();
				return false;
			} else {
				$(txt_id+'_response').className = '';
				$(txt_id+'_response').update('');
				$(txt_id+'_response').hide();
			}
			button.update('Uploading');
			this.disable();
			interval = window.setInterval(function(){
				var text = button.innerHTML;
				if (text.length < 13){
					button.update(text + '.');					
				} else {
					button.update('Uploading');				
				}
			}, 100);
		},
		onComplete: function(file, response) {
			var json = response.evalJSON();
			button.update('Upload');
			window.clearInterval(interval);
			this.enable();
			if(json.status == 'success') {
				$(txt_id+'_response').className = 'green';
				$(txt_id).value = file;
				$(txt_id+'_response').update(response_msg+file+' '+json.message);
				$(txt_id+'_response').show();
			} else if(json.status == 'failed') {
				$(txt_id+'_response').className = 'red';
				$(txt_id+'_response').update(json.errors);
				$(txt_id+'_response').show();
			}					
		}
	});
}
