/**
 * Block module on WYSIWYG
 *
 * @author Evgueni Palchukovsky <epalchukovsky@swsoft.com>
 * @version $Id: BlockModule.js 20346 2007-01-24 05:29:16Z adobrenko $
 * @since 2006/08/09
 * @package SB
 * @subpackage WYSIWYG
 * @copyright (c) 2004-2006, SWsoft
 */

function BlockModule(mainFrame, moduleName) {
	this.mainFrame = mainFrame;
	//this.settingsDialogLink = settingsDialogLink;
	this.moduleName = moduleName;
}

BlockModule.prototype.showSettingsDialog = function(settingsDialogLink) {
	top.sbBlockModuleEditorDialogObject.show(this.moduleName, settingsDialogLink);
}

BlockModule.prototype.removeModule = function() {
	top.sbApplyChangesObject.registerChange();
	this.mainFrame.parentNode.removeChild(this.mainFrame);
}

BlockModule.prototype.resizeMainFrame = function() {
	this.disable();
	this.resizeFrame(this.mainFrame);
	var wysiwyg = top.FCKeditorAPI.GetInstance('wysiwyg');
	if (wysiwyg && wysiwyg.Window_OnResize) {
		wysiwyg.Window_OnResize();
	}
	this.disable();
}

BlockModule.prototype.disableFormsElements = function() {
	doc = this.getPreviewFrame().contentWindow.document;
	for(i = 0; i < doc.forms.length; i++) {
		for(j = 0; j < doc.forms[i].elements.length; j++) {
			doc.forms[i].elements[j].disabled = true;
		}
	}
}

BlockModule.prototype.resizePreviewFrame = function() {
	this.disableFormsElements();
	this.resizeFrame(this.getPreviewFrame(), 1);
	if (document.all) {
		var disablerControl = this.getPreviewFrame().contentWindow.document.getElementById('disabler');
		disablerControl.style.width = '0px';
		disablerControl.style.height = '0px';
	}
}

BlockModule.prototype.resizeFrame = function(frame, ex) {
	if (ex == null) {
		ex = 0;
	}
	frame.style.height = (frame.contentWindow.document.body.scrollHeight+ex)+'px';
}

BlockModule.prototype.getPreviewFrame = function() {
	return this.mainFrame.contentWindow.document.getElementById('preview');
}

BlockModule.prototype.disable = function() {
	var doc = this.mainFrame.contentWindow.document;
	var previewHolder = doc.getElementById('previewHolder');
	var offset = previewHolder.offsetTop;
	for(	node = previewHolder.offsetParent;
			node;
			node = node.offsetParent) {
		offset += node.offsetTop;
	}
	/*
	var disablerControl = doc.getElementById('disabler');
	disablerControl.style.width = previewHolder.scrollWidth + 'px';
	disablerControl.style.height = previewHolder.scrollHeight + 'px';
	disablerControl.style.top = offset;
	*/
}