/**
 * Fotolia purchase image form scripts
 *
 * @copyright (c) 2004-2008, SWsoft
 */
function InitConfirmationStepManager() {
	self.fotoliaConfirmationStepManager = new FotoliaConfirmationStepManager();
}

var FotoliaConfirmationStepManager = Class.create();
FotoliaConfirmationStepManager.prototype = {

	/**
	 * Form object
	 *
	 * @var SbWysiwygForm
	 * @access private
	 */
	_formObject: null,

	/**
	 * Form object sizes
	 *
	 * @var object
	 * @access private
	 */
	_formSizes: null,

	/**
	 * Object constructor
	 *
	 * @access public
	 * @param string
	 * @return void
	 */
	initialize: function() {
		this._formObject = self.parent.fotoliaPurchaseImageFormObject;
	},

	/**
	 * Starts progress indicator
	 *
	 * @access public
	 * @param string
	 * @return void
	 */
	startPurchaseProgress: function() {
		this._saveInitialFormSizes();
		$('fotoliaConfirmationStepContainer').hide();
		this._formObject.changeSize(400, 150);
		$('fotoliaConfirmationStepProgressContainer').show();
		self.sbProgressBar.resetEventsListeners();
		self.sbProgressBar.usePreloader = false;
		self.sbProgressBar.setExpectedTime(10000);
		self.sbProgressBar.process();
	},

	/**
	 * Showes error
	 *
	 * @access public
	 * @param string
	 * @return void
	 */
	showError: function(errorText) {
		this._endPurchaseProgress();
		$('fotoliaPurchaseErrorTextContainer').innerHTML = errorText.stripScripts();
		errorText.evalScripts();
		$('fotoliaConfirmationStepProgressContainer').hide();
		this._restoreInitialFormSizes();
		$('fotoliaConfirmationStepContainer').show();
		$('fotoliaPurchaseErrorContainer').show();
	},

	/**
	 * Showes fatal error
	 *
	 * @access public
	 * @param string
	 * @return void
	 */
	fatalError: function(html) {
		this._endPurchaseProgress();
		self.document.body.innerHTML = html.stripScripts();
		html.evalScripts();
		this._restoreInitialFormSizes();
	},

	/**
	 * Showes success dialog
	 *
	 * @access public
	 * @return void
	 */
	showSuccessDialog: function() {
		var manager = this;
		self.sbProgressBar.addOnHideEvent(
			function() {
				manager.endShowSuccessDialog();
			}
		);
		this._endPurchaseProgress();
	},

	/**
	 * Showes success dialog
	 *
	 * @access public
	 * @return void
	 */
	endShowSuccessDialog: function() {
		$('fotoliaConfirmationStepProgressContainer').hide();
		this._formObject.changeSize(400, 200);
		$('fotoliaConfirmationStepDoneContainer').show();
	},

	/**
	 * Closes modal form
	 *
	 * @access public
	 * @return void
	 */
	closeForm: function() {
		this._formObject.close();
	},

	/**
	 * Ends progress indicator
	 *
	 * @access private
	 * @param string
	 * @return void
	 */
	_endPurchaseProgress: function() {
		self.sbProgressBar.endProcess();
	},

	/**
	 * Saves initial form sizes
	 *
	 * @access private
	 * @return void
	 */
	_saveInitialFormSizes: function() {
		this._formSizes = this._formObject.getDimensions();
	},

	/**
	 * Restores initial form sizes
	 *
	 * @access private
	 * @return void
	 */
	_restoreInitialFormSizes: function() {
		this._formObject.changeSize(this._formSizes.width, this._formSizes.height);
	}
}