
function alertPopupHelper(headerAllias, messageAllias, confirmAllias, cancelAllias, callbackTrue, callbackFalse) {

	this.headerText = typeof phrases[headerAllias] == 'undefined' ? headerAllias : phrases[headerAllias];
	this.messageText = typeof phrases[messageAllias] == 'undefined'  ? messageAllias : phrases[messageAllias];
	this.confirmText = typeof phrases[confirmAllias]  == 'undefined' ? confirmAllias : phrases[confirmAllias];
	this.cancelText = typeof phrases[cancelAllias] == 'undefined'  ? cancelAllias : phrases[cancelAllias];

	this.callbackTrue = callbackTrue;

	if (!callbackFalse || (typeof callbackFalse) != 'function') {

		callbackFalse = function() {
			this.hide();
		}
	}

	this.callbackFalse = callbackFalse;

	this.init();
}

alertPopupHelper.prototype.init = function() {

	this.whiteLayer = $('#' + whiteLayerId);
	this.container = $('#' + alertContainerId);

	this.countDownContainerId = whiteLayerId + '-count-down';
	this.countDownContainer = '';
}

alertPopupHelper.prototype.hide = function() {

	this.hideBox();
	this.hideBackground();
}

alertPopupHelper.prototype.hideBox = function() {

	this.container.addClass('hidden');
	this.container.html('');
}

alertPopupHelper.prototype.hideBackground = function() {
	this.whiteLayer.addClass('hidden');
}

alertPopupHelper.prototype.appendConfirmButton = function() {

	var self = this;

	var button = $('<span class="btn-xxl-blue">' + this.confirmText + '</span>');

	button.click(function() {
		self.callbackTrue()
	})

	return button;
}

alertPopupHelper.prototype.appendDeclineButton = function() {

	var self = this;

	var button = $('<span class="btn-xxl-grey">' + this.cancelText + '</span>');

	button.click(function() {
		self.callbackFalse()
	})

	return button;
}

alertPopupHelper.prototype.colorize = function(cssClass) {

	$('#admin-popup-container', this.container).addClass('content-' + cssClass);
	$('#admin-popup-container div.header', this.container).addClass('header-' + cssClass);
}

alertPopupHelper.prototype.appendDeclineIcon = function() {

	var self = this;

	return $('<a></a>')
		.attr('href', '#')
		.addClass('popup-close')
		.text('X')
		.click(function(event) {

			event.preventDefault()
			self.callbackFalse()
		})
}

alertPopupHelper.prototype.show = function(cssClass, hideConfirmButton, hideDeclineButton, showDeclineIcon) {

	this.whiteLayer.removeClass('hidden');

	this.countDownContainer = $('<h1 class="hidden"><!-- count down --></h1>').attr('id', this.countDownContainerId);

	var popup =
		$('<div id="admin-popup-container">' +
		    '<div class="content-popup">' +
		        '<h2>' + this.messageText + '</h2>' +
		        '<div class="btns" style="padding-top: 22px"></div>' +
		    '</div>' +
		'</div>');

	popup.find('div.content-popup').prepend(this.countDownContainer);

	/* not used for now
	if (showDeclineIcon) {
		popup.find('div.content-popup').prepend(this.appendDeclineIcon());
	}
	*/

	if (!hideConfirmButton && this.confirmText) {
		popup.find('div.content-popup div.btns').append(this.appendConfirmButton());
	}

	if (!hideDeclineButton && this.cancelText) {
		popup.find('div.content-popup div.btns').append(this.appendDeclineButton());
	}

	this.colorize(cssClass ? cssClass : 'blue');

	this.container.append(popup).removeClass('hidden');
}

// deprecated, left for backward compatibility
alertPopupHelper.prototype.dialog = function(cssClass) {
	this.show(cssClass)
}

alertPopupHelper.test = function() {

	//return;

	// 1.
	var callbackFalse = function() {
		popup1.hide();
	}

	var popup1 = new alertPopupHelper('alert', 'Testing alertPopupHelper: redColor, buttonCancel, customCancelAction', '', 'button_cancel', callbackFalse);
	alert(1);
	popup1.show('red', true, false);

	// 2.
	var callbackTrue = function() {
		popup2.hide();
	}

	var popup2 = new alertPopupHelper('alert', 'Testing alertPopupHelper: defaultColor, buttonConfirm, buttonCancel, customConfirmAction, defaultCancelAction', 'button_confirm', 'button_cancel', callbackTrue);
	alert(2);
	popup2.show('blue', false, false);

	// 3.
	var callbackTrue = function() {
		popup3.hide();
	}

	var callbackFalse = function() {
		popup3.hide();
	}

	popup3 = new alertPopupHelper('alert', 'Testing alertPopupHelper: redColor, buttonConfirm, buttonCancel, customConfirmAction, customCancelAction, cancelIcon', 'button_confirm', 'button_cancel', callbackTrue, callbackFalse);
	alert(3);
	popup3.show('red', false, false, true);
}

