var wysiwygWin	= null;
var wysiwyg		= null;

function wysiwygGo(nodeId) {
	FCKeditorAPI= null; 
	__FCKeditorNS = null; 
	
	var wIframe = document.getElementById('wysiwyg___Frame');
	wIframe.parentNode.removeChild(wIframe);

	var editorFileFullPath = '/wysiwyg/editor/fckeditor.wizard.php?page=' + nodeId;
	Init_wysiwyg(editorFileFullPath);
}			

function onNodeSelect(nodeId, nodeType) {
	if (!validateForm()) {
		return false;
	}
	var node = document.getElementById(nodeId);
	sbNavigationObject.setViewParam('currentPageId', nodeId);
	sbNavigationObject.addHidden('currentPageId', currentPageId);
	sbNavigationObject.go(sbBaseUrl + node.editView);
	return false;
}

function registerPageEditView(nodeId, editView) {
	var node = document.getElementById(nodeId);
	node.editView = editView;
}

function validateForm() {
	if (validateField('SB_Validator.notEmpty', 'pageTitle', 'EMPTY-PAGE-TITLE')
		&& validateField('SB_Validator.notEmpty', 'pageFileName', 'EMPTY-PAGE-FILE-NAME')
		&& extendedValidateField("SB_Validator.isRegex($('pageFileName').value, /^[-_a-z0-9\.]+$/i)", 'pageFileName', 'INVALID-PAGE-FILE-NAME')
	) {
		result = true;
	} else {
		result = false;
	}
	
	if (result) {		
		if (knownPagesFileNames.any(function(fileName) { return (fileName == $('pageFileName').value); })) {
			alert(SbGetLocaleByKey('DUPLICATE-PAGE-FILE-NAME'));
			return false;
		}
	}
	
	return result;
}

function plainPageButtonOnClick() {
	$('isPlainPage').value = (0 == $('isPlainPage').value) ? 1 : 0;	
	sbApplyChangesObject.registerForcedSaving();
	sbNavigationObject.go();
}

function siteMapOnResize() {
	var siteMapMinHeight = 20;
	var topPadding = 60;
	var bottomPadding = 20;
	
	// force container minimal size, cause if element is hidden this can be incorrect
	$('edit').setStyle({ height: siteMapMinHeight + 'px' });
		
	var siteMapHeight = $('LeftPanelDiv').getHeight() - $('pageInfoTd').getHeight() - topPadding - bottomPadding;
	
	if (siteMapHeight > siteMapMinHeight) {
		$('edit').setStyle({ height: siteMapHeight + 'px' });
	}
}
