8cd0f5f2a319c974c8fbd13fd04ad34d9474dbcf
[freeside.git] / httemplate / elements / order_pkg.js
1 function pkg_changed () {
2   var form = document.OrderPkgForm;
3   var discountnum = form.discountnum;
4
5   if ( form.pkgpart.selectedIndex > 0 ) {
6
7     var opt = form.pkgpart.options[form.pkgpart.selectedIndex];
8     var date_button = document.getElementById('start_date_button');
9     var date_button_disabled = document.getElementById('start_date_disabled');
10     var date_text = document.getElementById('start_date_text');
11
12     var radio_now = document.getElementById('start_now');
13     //var radio_on_hold = document.getElementById('start_on_hold');
14     var radio_on_date = document.getElementById('start_on_date');
15
16     form.submitButton.disabled = false;
17     if ( discountnum ) {
18       if ( opt.getAttribute('data-can_discount') == 1 ) {
19         form.discountnum.disabled = false;
20         discountnum_changed(form.discountnum);
21       } else {
22         form.discountnum.disabled = true;
23         discountnum_changed(form.discountnum);
24       }
25     }
26
27 // if this form element exists, then the start date is a future
28 // package change date; don't replace it
29     if ( form.delay ) {
30       return;
31     }
32     form.start_date_text.value = opt.getAttribute('data-start_date');
33     if ( opt.getAttribute('data-can_start_date') == 1 ) {
34       date_text.style.backgroundColor = '#ffffff';
35       date_text.disabled = false;
36       date_button.style.display = '';
37       date_button_disabled.style.display = 'none';
38       if ( radio_on_date ) {
39         radio_on_date.disabled = false;
40         if ( form.start_date_text.value.length > 0 && radio_now.checked ) {
41           radio_now.checked = false;
42           radio_on_date.checked = true;
43         }
44       }
45     } else {
46       date_text.style.backgroundColor = '#dddddd';
47       date_text.disabled = true;
48       date_button.style.display = 'none';
49       date_button_disabled.style.display = '';
50       if ( radio_on_date ) {
51         if ( radio_on_date.checked ) {
52           radio_on_date.checked = false;
53           radio_now.checked = true;
54         }
55         radio_on_date.disabled = true;
56       }
57     }
58
59   } else {
60     form.submitButton.disabled = true;
61     if ( discountnum ) { form.discountnum.disabled = true; }
62     discountnum_changed(form.discountnum);
63   }
64 }
65
66 function standardize_new_location() {
67   var form = document.OrderPkgForm;
68   var loc = form.locationnum;
69   if (loc.type == 'select-one' && loc.options[loc.selectedIndex].value == -1){
70     standardize_locations();
71   } else {
72     form.submit();
73   }
74 }
75
76 function submit_abort() {
77   document.OrderPkgForm.submitButton.disabled = false;
78   nd(1);
79 }