function showField(fieldName) {
	showElement(document.getElementById(fieldName), true);
}

function hideField(fieldName) {
	showElement(document.getElementById(fieldName), false);
}

function showPublishFields() {
	publishModeId = document.getElementById('publishModeId');
	
	// publish mode for FTP
	if (1 == publishModeId.value) {
		// show table
		showField('tableAuth');

		// show fields
		showField('rowDirectory');
		showField('rowHost');

		// hide fields
		hideField('rowGroup');
		hideField('rowVpsId');
		hideField('rowUser');
	// publish mode for VPS
	} else if (2 == publishModeId.value) {
		// show fields	
		showField('rowUser');
		showField('rowGroup');
		showField('rowDirectory');
		showField('rowVpsId');
		showField('rowHost');
		
		// hide fields
		hideField('tableAuth');
	// publish mode for XCopy
	} else if (3 == publishModeId.value) {
		// show fields
		showField('rowDirectory', true);
		
		// hide fields
		hideField('rowGroup');
		hideField('rowHost');
		hideField('rowVpsId');
		hideField('tableAuth');
		hideField('rowUser');
	}
	
	return false;
}

function validateOwnForm() {
	if (validateField('SB_Validator.isHttpUrl', 'siteUrl', 'INVALID-SITE-URL')
		&& validateField('SB_Validator.notEmpty', 'siteAlias', 'EMPTY-SITE-ALIAS')
	) {
		document.forms['ownSite'].submit();
		return true;
	} else {
		return false;
	}
}

function _validateHostngSetings() {
	result = true;
	if (document.getElementById('publishModeId')) {
		if (result ) {
			if (validateFieldIfNotEmpty('SB_Validator.isHttpUrl', 'hostingUrl', 'INVALID-SITE-URL')) {
				result = result && true;
			} else {
				//toggle('sb_panel', document.getElementById('publish-settings'));
				result = false;
			}
		}
		publishModeId = document.getElementById('publishModeId');
		
		// publish mode for FTP
		if (1 == publishModeId.value) {
			if (result) {
				if ( extendedValidateField("SB_Validator.isEqual(document.getElementById('password').value, document.getElementById('confirmPassword').value)", 'confirmPassword', 'NOT-EQUAL-FTP-PASSWORD')
					&& validateFieldIfNotEmpty('SB_Validator.isPath', 'directory', 'INVALID-FTP-DIRECTORY')
				) {
					result = result && true;
				} else {
					//toggle('sb_panel',document.getElementById('publish-settings'));
					result = false;
				}
			}
		// publish mode for VPS
		} else if (2 == publishModeId.value) {
			if (result) {
				if (validateFieldIfNotEmpty('SB_Validator.isPath', 'directory', 'INVALID-VPS-DIRECTORY')
					&& validateFieldIfNotEmpty('SB_Validator.isDigits', 'vpsId', 'INVALID-VPS-VPS-ID')
				) {
					result = result && true;
				} else {
					//toggle('sb_panel',document.getElementById('publish-settings'));
					result = false;
				}
			}
		// publish mode for XCopy
		} else if (3 == publishModeId.value) {
			if (result) {
				if (validateFieldIfNotEmpty('SB_Validator.isPath', 'directory', 'INVALID-XCOPY-DIRECTORY')
				) {
					result = result && true;
				} else {
					//toggle('sb_panel',document.getElementById('publish-settings'));
					result = false;
				}
			}
		}
	}
	return result;
}

function _validateKnownSettings() {
	result = true;

	if (document.getElementById('knownUrl')) {
		if (result ) {
			if (validateFieldIfNotEmpty('SB_Validator.isHttpUrl', 'knownUrl', 'INVALID-SITE-URL')) {
				result = result && true;
			} else {
				//toggle('sb_panel', document.getElementById('publish-settings'));
				result = false;
			}
		}

		// check known publish settings
		if (result) {
			if ( extendedValidateField("SB_Validator.isEqual(document.getElementById('knownPassword').value, document.getElementById('confirmKnownPassword').value)", 'confirmKnownPassword', 'NOT-EQUAL-FTP-PASSWORD')
				&& validateFieldIfNotEmpty('SB_Validator.isHostname', 'knownHost', 'INVALID-HOST')
				&& validateFieldIfNotEmpty('SB_Validator.isPath', 'knownDirectory', 'INVALID-FTP-DIRECTORY')
			) {
				result = result && true;
			} else {
				//toggle('sb_panel',document.getElementById('publish-settings'));
				result = false;
			}
		}
	}
	return result;
}

function validateForm() {
	result = true;

	if (result ) {
		if (validateField('SB_Validator.notEmpty', 'alias', 'EMPTY-SITE-ALIAS')
			&& validateField('SB_Validator.notEmpty', 'owner', 'EMPTY-SITE-OWNER')
		) {
			result = result && true;
		} else {
			//toggle('sb_panel', document.getElementById('general'));
			result = false;
		}
	}

	if (result) {
		result = _validateHostngSetings();
	}

	if (result) {
		result = _validateKnownSettings();
	}


	if (result) {
		return true;
	} else {
		return false;
	}
}