1<script type="text/javascript">
2	jQuery(document).ready(function() {
3		// type change
4		jQuery('#type')
5			.change(function() {
6				var type = jQuery(this).val(),
7					command_ipmi = jQuery('#commandipmi'),
8					command = jQuery('#command');
9
10				if (type == <?= ZBX_SCRIPT_TYPE_IPMI ?>) {
11					if (command.val() !== '') {
12						command_ipmi.val(command.val());
13						command.val('');
14					}
15
16					jQuery('#execute_on').add(command).closest('li').hide();
17					command_ipmi.closest('li').show();
18				}
19				else {
20					if (command_ipmi.val() !== '') {
21						command.val(command_ipmi.val());
22						command_ipmi.val('');
23					}
24
25					command_ipmi.closest('li').hide();
26					jQuery('#execute_on').add(command).closest('li').show();
27				}
28			})
29			.change();
30
31		// clone button
32		jQuery('#clone').click(function() {
33			jQuery('#scriptid, #delete, #clone').remove();
34			jQuery('#update').text(<?= CJs::encodeJson(_('Add')) ?>);
35			jQuery('#update')
36				.val('script.create')
37				.attr({id: 'add'});
38			jQuery('#name').focus();
39		});
40
41		// confirmation text input
42		jQuery('#confirmation').keyup(function() {
43			jQuery('#testConfirmation').prop('disabled', (this.value == ''));
44		}).keyup();
45
46		// enable confirmation checkbox
47		jQuery('#enable_confirmation')
48			.change(function() {
49				if (this.checked) {
50					jQuery('#confirmation')
51						.removeAttr('disabled')
52						.keyup();
53				}
54				else {
55					jQuery('#confirmation, #testConfirmation').prop('disabled', true);
56				}
57			})
58			.change();
59
60		// test confirmation button
61		jQuery('#testConfirmation').click(function() {
62			executeScript(null, null, jQuery('#confirmation').val());
63		});
64
65		// host group selection
66		jQuery('#hgstype')
67			.change(function() {
68				if (jQuery('#hgstype').val() == 1) {
69					jQuery('#hostGroupSelection').show();
70				}
71				else {
72					jQuery('#hostGroupSelection').hide();
73				}
74			})
75			.change();
76
77		// trim spaces on sumbit
78		jQuery('#scriptForm').submit(function() {
79			jQuery(this).trimValues(['#name', '#command', '#description']);
80		});
81	});
82</script>
83