RT# 82137 - default payment amount now has processing fee in total if processing...
[freeside.git] / httemplate / elements / select-region.html
1 <% include('/elements/xmlhttp.html',
2               'url'  => $p.'misc/regions.cgi',
3               'subs' => [ $opt{'prefix'}. 'get_regions' ],
4           )
5 %>
6
7 <SCRIPT TYPE="text/javascript">
8
9   function opt(what,value,text) {
10     var optionName = new Option(text, value, false, false);
11     var length = what.length;
12     what.options[length] = optionName;
13   }
14
15   function <% $opt{'state_prefix'} %>state_changed(what, callback) {
16
17     what.form.<% $opt{'prefix'} %>region.disabled = 'disabled';
18     what.form.<% $opt{'prefix'} %>region.style.display = 'none';
19     var regionwait = document.getElementById('<% $opt{'prefix'} %>regionwait');
20     regionwait.style.display = 'inline';
21     var regionerror = document.getElementById('<% $opt{'prefix'} %>regionerror');
22     regionerror.style.display = 'none';
23
24     what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
25
26     state = what.options[what.selectedIndex].value;
27
28     function <% $opt{'prefix'} %>update_regions(regions) {
29
30       var reply = JSON.parse(regions);
31       // blank the current region
32       for ( var i = what.form.<% $opt{'prefix'} %>region.length; i >= 0; i-- )
33           what.form.<% $opt{'prefix'} %>region.options[i] = null;
34       // blank the current phonenum too
35       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
36           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
37       if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
38         opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
39       }
40
41 %     if ($opt{empty}) {
42         opt(what.form.<% $opt{'prefix'} %>region, '', '<% $opt{empty} %>');
43 %     }
44
45       // add the new regions
46       var regionArray = reply.regions;
47       for ( var s = 0; s < regionArray.length; s++ ) {
48           var regionLabel = regionArray[s];
49           if ( regionLabel == "" )
50               regionLabel = '(n/a)';
51           opt(what.form.<% $opt{'prefix'} %>region, regionArray[s], regionLabel);
52       }
53
54       regionwait.style.display = 'none';
55       if ( regionArray.length >= 1 ) {
56         what.form.<% $opt{'prefix'} %>region.disabled = '';
57         what.form.<% $opt{'prefix'} %>region.style.display = '';
58       } else {
59         var regionerror = document.getElementById('<% $opt{'prefix'} %>regionerror');
60         regionerror.style.display = 'inline';
61         if ( reply.error ) {
62           regionerror.textContent = reply.error;
63         } else {
64           regionerror.textContent = 'Select a different state';
65         }
66       }
67
68       //run the callback
69       if ( callback != null ) 
70         callback();
71     }
72
73     // go get the new regions
74     <% $opt{'prefix'} %>get_regions( state, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_regions );
75
76   }
77
78 </SCRIPT>
79
80 <DIV ID="<% $opt{'prefix'} %>regionwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding regions</B></DIV>
81
82 <DIV ID="<% $opt{'prefix'} %>regionerror" STYLE="display:none; font-weight: bold"><IMG SRC="<%$fsurl%>images/cross.png"></DIV>
83
84 <SELECT NAME="<% $opt{'prefix'} %>region" onChange="<% $opt{'prefix'} %>region_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
85   <OPTION VALUE="">Select region</OPTION>
86 </SELECT>
87
88 <%init>
89
90 my %opt = @_;
91
92 $opt{disabled} = 'disabled' unless exists $opt{disabled};
93
94 </%init>