Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / elements / order_pkg.js
1 function pkg_changed () {
2   var form = document.OrderPkgForm;
3   var discountnum = form.discountnum;
4   var opt = form.pkgpart.options[form.pkgpart.selectedIndex];
5
6   usageprice_pkg_changed( opt.value );
7
8   if ( form.pkgpart.selectedIndex > 0 ) {
9
10     var date_button = document.getElementById('start_date_button');
11     var date_button_disabled = document.getElementById('start_date_disabled');
12     var date_text = document.getElementById('start_date_text');
13
14     var radio_now = document.getElementById('start_now');
15     var radio_on_hold = document.getElementById('start_on_hold');
16     var radio_on_date = document.getElementById('start_on_date');
17
18     form.submitButton.disabled = false;
19     if ( discountnum ) {
20       if ( opt.getAttribute('data-can_discount') == 1 ) {
21         form.discountnum.disabled = false;
22         discountnum_changed(form.discountnum);
23       } else {
24         form.discountnum.disabled = true;
25         discountnum_changed(form.discountnum);
26       }
27     }
28
29     // if this form element exists, then the start date is a future
30     // package change date; don't replace it
31     if ( form.delay ) {
32       return;
33     }
34     form.start_date_text.value = opt.getAttribute('data-start_date');
35     if ( opt.getAttribute('data-can_start_date') == 1 ) {
36       date_text.style.backgroundColor = '#ffffff';
37       date_text.disabled = false;
38       date_button.style.display = '';
39       date_button_disabled.style.display = 'none';
40       if ( radio_on_date ) {
41         // un-disable all the buttons that might get disabled
42         radio_on_date.disabled = false;
43         radio_now.disabled = false;
44         // if a start date has been entered, assume the user wants it
45         if ( form.start_date_text.value.length > 0 ) {
46           radio_now.checked = false;
47           radio_on_date.checked = true;
48         } else {
49           // if not, default to now
50           radio_now.checked = true;
51         }
52       }
53     } else { // the package is either fixed start date or start-on-hold
54       date_text.style.backgroundColor = '#dddddd';
55       date_text.disabled = true;
56       date_button.style.display = 'none';
57       date_button_disabled.style.display = '';
58       if ( radio_on_date ) {
59         if ( opt.getAttribute('data-start_on_hold') == 1 ) {
60           // disallow all options but "On hold"
61           radio_on_hold.checked = true;
62           radio_now.checked = false;
63           radio_now.disabled = true;
64         } else {
65           // disallow all options but "On date"
66           radio_on_hold.checked = false;
67           radio_now.checked = true;
68           radio_now.disabled = false;
69         }
70       }
71     }
72
73   } else {
74     form.submitButton.disabled = true;
75     if ( discountnum ) { form.discountnum.disabled = true; }
76     discountnum_changed(form.discountnum);
77   }
78
79 }
80
81 function standardize_new_location() {
82   var form = document.OrderPkgForm;
83   var loc = form.locationnum;
84   if (loc.type == 'select-one' && loc.options[loc.selectedIndex].value == -1){
85     standardize_locations();
86   } else {
87     form.submit();
88   }
89 }
90
91 function submit_abort() {
92   document.OrderPkgForm.submitButton.disabled = false;
93   nd(1);
94 }