function validateForm() {
	var result = validatePaymentSystems();
	if (!result) {
		sb_panel.tooglePage("payments");
		self.sbApplyChangesObject.registerForcedSaving();
	}
	return result;
}

function validatePaymentSystems() {
	if (isPaymentChecked('checkMoneyOrder')) {
		if (!(validateField('SB_Validator.notEmpty', 'check_money_order_make_payable_to', 'CHECK-MONEY-ORDER-PAY-EMPTY')
			&& validateField('SB_Validator.notEmpty', 'check_money_order_address', 'CHECK-MONEY-ORDER-ADDRESS-EMPTY'))
		) {
			return false;
		}
	}
	if (isPaymentChecked('payPal')) {
		if (!(validateField('SB_Validator.notEmpty', 'paypal_email', 'PAYPAL-ACCOUNT-EMPTY')
			&& validateField('SB_Validator.isEmail', 'paypal_email', 'PAYPAL-ACCOUNT-NOT-VALID'))
		) {
			return false;
		}
	}
	if (isPaymentChecked('authorizeNet')) {
		if (!(validateField('SB_Validator.notEmpty', 'authorize_login', 'AUTHORIZENET-LOGIN-EMPTY')
			&& validateField('SB_Validator.notEmpty', 'authorize_transaction_key', 'AUTHORIZENET-KEY-EMPTY'))
		) {
			return false;
		}
	}
	if (isPaymentChecked('checkout')) {
		if (!(validateField('SB_Validator.notEmpty', 'checkout_vendor_account_number', 'CHECKOUT-NUMBER-EMPTY')
			&& validateField('SB_Validator.isDigits', 'checkout_vendor_account_number', 'CHECKOUT-NUMBER-NOT-VALID'))
		) {
			return false;
		}
	}
	if (isPaymentChecked('worldPay')) {
		if (!(validateField('SB_Validator.notEmpty', 'world_installation_id', 'WORLDPAY-ID-EMPTY')
			&& validateField('SB_Validator.isInt', 'world_installation_id', 'WORLDPAY-ID-NOT-VALID'))
		) {
			return false;
		}
	}
	if (isPaymentChecked('bluePay')) {
		if (!(validateField('SB_Validator.notEmpty', 'bluepay_merchant_id', 'BLUEPAY-ID-EMPTY')
			&& validateField('SB_Validator.isInt', 'bluepay_merchant_id', 'BLUEPAY-ID-NOT-VALID')
			&& validateField('SB_Validator.notEmpty', 'bluepay_secret_key', 'BLUEPAY-KEY-EMPTY'))
		) {
			return false;
		}
	}
	if (isPaymentChecked('custom')) {
		return self.customSettingsOwnerList.validate();
	}
	return true;
}

function changePaymentStatus(code, status) {
	switch (code) {
		case 'checkMoneyOrder':
			changeFieldStatus('check_money_order_make_payable_to', status);
			changeFieldStatus('check_money_order_address', status);
			break;
		case 'payPal':
			changeFieldStatus('paypal_email', status);
			break;
		case 'authorizeNet':
			changeFieldStatus('authorize_login', status);
			changeFieldStatus('authorize_transaction_key', status);
			break;
		case 'checkout':
			changeFieldStatus('checkout_vendor_account_number', status);
			var description = document.getElementById(code+'_description');
			description.style.display = status ? '' : 'none';
			break;
		case 'bluePay':
			changeFieldStatus('bluepay_merchant_id', status);
			changeFieldStatus('bluepay_secret_key', status);
			break;
		case 'worldPay':
			changeFieldStatus('world_installation_id', status);
			break;
		case 'custom':
			self.customSettingsOwnerList.updateStatus(!status);
			break;
	}
}

function changeFieldStatus(id, status) {
	var field = document.getElementById(id);
	field.disabled = (status) ? false : true;
}

function isPaymentChecked(code) {
	var field = document.getElementById(code);
	if (!field) {
		return false;
	}
	return !field.disabled && field.checked;
}