var wysiwygWin	= null;
var wysiwyg		= null;

function FCKeditor_OnComplete(editorInstance) {
	try{
		wysiwygWin = document.getElementById('wysiwyg___Frame').contentWindow;				
		wysiwyg = editorInstance;
	}catch(e){};
}

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;
}

