/**
 * Custom payment system scripts
 *
 * @copyright (c) 2004-2007, SWsoft
 */
function validateCustomPaymentSystemForm() {
	var result = false;
	var isEnabled = document.getElementById('isCustomPaymentSystemEnabled');
	if (isEnabled.checked) {
	result =
		validateField('SB_Validator.notEmpty', 'customPaymentSystemName', 'EMPTY-CUSTOM-PAYMENT-SYSTEM-NAME') &&
		validateField('SB_Validator.notEmpty', 'customPaymentSystemGateway', 'EMPTY-CUSTOM-PAYMENT-SYSTEM-GATEWAY') &&
		validateField('SB_Validator.isHttpUrl', 'customPaymentSystemGateway', 'INVALID-CUSTOM-PAYMENT-SYSTEM-GATEWAY') &&
		validateField('SB_Validator.notEmpty', 'customPaymentSystemPositiveExpression', 'EMPTY-CUSTOM-PAYMENT-SYSTEM-POSITIVE-EXPRESSION') &&
		validateField('SB_Validator.notEmpty', 'customPaymentSystemNegativeExpression', 'EMPTY-CUSTOM-PAYMENT-SYSTEM-NEGATIVE-EXPRESSION') &&
		validateCustomPaymentSystemForOwnerForm() &&
		validateCustomPaymentSystemForCustomerForm() &&
		validateCustomPaymentSystemAdditionalForm();
	} else {
		result = true;
	}
	return result;
}

function changeCustomPaymentSystemFormStatus(status) {
	_updateFieldStatus('customPaymentSystemName', status);
	_updateFieldStatus('customPaymentSystemGateway', status);
	_updateFieldStatus('customPaymentSystemRequestType', status);
	_updateFieldStatus('customPaymentSystemPositiveExpression', status);
	_updateFieldStatus('customPaymentSystemNegativeExpression', status);
	isDisabled = (status) ? false : true;
	updateCustomPaymentSystemForOwnerFormStatus(isDisabled);
	updateCustomPaymentSystemForCustomerFormStatus(isDisabled);
	updateCustomPaymentSystemAdditionalFormStatus(isDisabled);
}

function initCustomPaymentSystemForm() {
	var isEnabled = document.getElementById('isCustomPaymentSystemEnabled');
	changeCustomPaymentSystemFormStatus(isEnabled.checked);
}

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

function updateCustomPaymentSystemForOwnerFormStatus(status) {
	self.ownerSettingsList.updateStatus(status);
}

function updateCustomPaymentSystemForCustomerFormStatus(status) {
	self.customerSettingsList.updateStatus(status);
}

function updateCustomPaymentSystemAdditionalFormStatus(status) {
	self.additionalSettingsList.updateStatus(status);
}

function validateCustomPaymentSystemForOwnerForm() {
	return self.ownerSettingsList.validate();
}

function validateCustomPaymentSystemForCustomerForm() {
	return self.customerSettingsList.validate();
}

function validateCustomPaymentSystemAdditionalForm() {
	return self.additionalSettingsList.validate();
}