/**
 * Apply changes scripts
 *
 * @copyright (c) 2004-2006, SWsoft
 */

function SB_ApplyChanges(modalFormId) {
	this.isUserDataChanged = false;
	this.isForcedYes = false;
	this.object = document.getElementById(modalFormId);
	this.yesMethod = null;
	this.noMethod = null;
	this.savedWindowTitle = document.title;
}

SB_ApplyChanges.prototype.isSavingRequired = function(object) {
	return (this.isForcedYes || this.isUserDataChanged);
}

SB_ApplyChanges.prototype.registerChange = function() {
	if (!this.isUserDataChanged && (this.savedWindowTitle == document.title)) {
		document.title = document.title + ' (' + SbGetLocaleByKey('CONTENT-MODIFIED') + ') ';
	}
	
	this.isUserDataChanged = true;
}

SB_ApplyChanges.prototype.uregisterChange = function() {
	document.title = this.savedWindowTitle;
	this.isUserDataChanged = false;
}

SB_ApplyChanges.prototype.registerForcedSaving = function() {
	this.isForcedYes = true;
}

SB_ApplyChanges.prototype.uregisterForcedSaving = function() {
	this.isForcedYes = false;
}

SB_ApplyChanges.prototype.show = function(yesMethod, noMethod) {
	if (this.isForcedYes) {
		if (null != yesMethod) {
			yesMethod();
		}
	} else {
		this.yesMethod = yesMethod;
		this.noMethod = noMethod;
		this.object.show();
	}
}

SB_ApplyChanges.prototype.hide = function() {
	this.yesMethod = null;
	this.noMethod = null;
	this.object.hide();
}

SB_ApplyChanges.prototype.cancel = function() {
	this.hide();
}

SB_ApplyChanges.prototype.yes = function() {
	var result = false;
	this.object.hide();
	if (null != this.yesMethod) {
		result = this.yesMethod();
	}
	return result;
}

SB_ApplyChanges.prototype.no = function() {
	var result = false;
	this.object.hide();
	if (null != this.noMethod) {
		result = this.noMethod();
	}
	return result;
}