function validateForm() {
	if (validateField('SB_Validator.notEmpty', 'pagesetCode', 'EMPTY-PAGESET-CODE')
		&& validateField('SB_Validator.isAlnum', 'pagesetCode', 'INVALID-PAGESET-CODE')
		&& validateField('SB_Validator.notEmpty', 'pagesetTitle', 'EMPTY-PAGESET-TITLE')
	) {
		return true;
	} else {
		return false;
	}
}

function validatePageInfo() {
	if (validateField('SB_Validator.notEmpty', 'pageTitle', 'EMPTY-PAGE-TITLE')
		&& validatePageContentSize()
	) {
		return true;
	} else {
		return false;
	}
}

function validatePageContentSize() {
	var result = true;
	
	try {
		if (document.forms.pagesetForm.pageContent && document.forms.pagesetForm.pageContent.wysiwygObject) {
			document.forms.pagesetForm.pageContent.wysiwygObject.UpdateLinkedField();
			if (document.forms.pagesetForm.pageContent.value.length > 50000) {
				alert(SbGetLocaleByKey('MAX-PAGE-SIZE-LIMIT-RICHED'));
				result = false;
			}
		}
	} catch (e) { }
	
	return result;
}

function submitForm() {
	if (!validateForm() || !validatePageInfo()) {
		return false;
	}

	addHiddenToForm('pagesetStructure', SbGetTreeXml('pageset'), 'pagesetForm');
	document.forms.pagesetForm.submit();
	return true;
}

function submitFormTemporary() {
	if (!validatePageInfo()) {
		return false;
	}
				
	addHiddenToForm('pagesetStructure', SbGetTreeXml('pageset'), 'pagesetForm');
	addHiddenToForm('isTemporarySave', 1, 'pagesetForm');
	
	document.forms.pagesetForm.submit();
	return true;
}

function submitFormByChangeLocale() {
	if (!validatePageInfo()) {
		document.forms.pagesetForm.selectedLocale.selectedIndex = originalSelectedLocaleIndex;
		return false;
	}
	
	var selectedLocale = document.forms.pagesetForm.selectedLocale.options[document.forms.pagesetForm.selectedLocale.selectedIndex].value; 
	document.forms.pagesetForm.selectedLocale.selectedIndex = originalSelectedLocaleIndex;
	
	addHiddenToForm('newSelectedLocale', selectedLocale, 'pagesetForm');
	
	addHiddenToForm('pagesetStructure', SbGetTreeXml('pageset'), 'pagesetForm');
	addHiddenToForm('isTemporarySave', 1, 'pagesetForm');
	
	document.forms.pagesetForm.submit();
	return true;
}

function deletePagesets() {
	if (countSelectedCheckBoxes() > 0) {
		if (confirm(SbGetLocaleByKey('SURE-TO-DELETE'))) {
			document.forms.listForm.action.value = '/Admin/Pagesets/Delete';
			document.forms.listForm.submit();
		}
	} else {
		alert(SbGetLocaleByKey('SELECT-FOR-DELETE'));
	}
}
