PAMWF.ENNewsForm = Class.create( PAMWF.Form, {
	_noClose: false,
	
	initialize: function ( $super, options) {
		$super(options);
		PAMWF.ENNews = this;
	},
	
	switchTab: function( tab ) {
		$('tabRow').select('li').invoke( 'removeClassName', 'selected');
		$('Tab_'+tab).addClassName('selected');
		$('formSections').select('.formSection').invoke('hide');
		$('Body_'+tab).show();
	},
	
	setupImages: function() {
		var recordid = $('newsRecordid').value;
		
		if (recordid)
		{
			new PAMWF.Dialog('http://www.enworld.org/newsAdmin/images.phtml?parentid='+recordid);			
		}
		else
		{
			this._noClose = true;
			$('newsSubmit').click();			
		}

	},
	
	_submitSuccess: function ( $super, t ) {
		if (!this._noClose) {
			$super(t);
		}
		else
		{
			var recordid = t.responseXML.getElementsByTagName('recordid')[0].firstChild.nodeValue;
			$('newsRecordid').value = recordid;
			this._noClose = false;
			new PAMWF.Dialog('http://www.enworld.org/newsAdmin/images.phtml?parentid='+recordid);
		}
	}
});

PAMWF.ENFileForm = Class.create( PAMWF.FileForm, {
	progressDialog: null,
	_bbuserid: null,
	_bbpassword: null,
	_parentid: null,
	
	initialize: function ( $super, options )
	{
		$super(options);
		
		this._bbuserid = options.vbuserid;
		this._bbpassword = options.vbuserpassword;
	},
	
	swfOpen: function (obj, name)
	{
		$('progressAction').update('Uploading ' + name );
	},
	
	swfProgress: function( obj, load, total ) 
	{
		$('progressBar').setStyle({ width: Math.ceil( load/total * 400 ) + 'px' });
		PAMWF.console.info('Progress '+load+' / '+total);		
	},
	
	_completeSubmission: function( $super )
	{
		$('progressAction').update('Finishing...' + name );
		this.progressDialog._close();
		$super();
	},
	
	_submitSuccess: function ($super, t)
	{	
		if (this._uploaders.length == 0)
		{
			this.progressDialog._close();
		}
		
		$super( t ); 
	},
	
	_buildFlashQueryString: function( $super, uploader )
	{		
		return '?action=saveFlash&field='+uploader._name+'&bbuserid='+this._bbuserid+'&bbpassword='+this._bbpassword+'&recordid='+this._recordid;
	},
	
	_validate: function( $super )
	{
		if ($super())
		{
			$('progressAction').update('Initializing...' + name );						
			this.progressDialog = new PAMWF.Dialog('progressDialog');
			return true;
		}
		else
		{
			return false;
		}
	}
});
