Merge branch 'patch-6' of https://github.com/gjones2/Freeside (#13854 as this bug...
[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 = '';
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       // blank the current region
31       for ( var i = what.form.<% $opt{'prefix'} %>region.length; i >= 0; i-- )
32           what.form.<% $opt{'prefix'} %>region.options[i] = null;
33       // blank the current phonenum too
34       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
35           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
36       if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
37         opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
38       }
39
40 %     if ($opt{empty}) {
41         opt(what.form.<% $opt{'prefix'} %>region, '', '<% $opt{empty} %>');
42 %     }
43
44       // add the new regions
45       var regionArray = eval('(' + regions + ')' );
46       for ( var s = 0; s < regionArray.length; s++ ) {
47           var regionLabel = regionArray[s];
48           if ( regionLabel == "" )
49               regionLabel = '(n/a)';
50           opt(what.form.<% $opt{'prefix'} %>region, regionArray[s], regionLabel);
51       }
52
53       regionwait.style.display = 'none';
54       if ( regionArray.length >= 1 ) {
55         what.form.<% $opt{'prefix'} %>region.disabled = '';
56         what.form.<% $opt{'prefix'} %>region.style.display = '';
57       } else {
58         var regionerror = document.getElementById('<% $opt{'prefix'} %>regionerror');
59         regionerror.style.display = '';
60       }
61
62       //run the callback
63       if ( callback != null ) 
64         callback();
65     }
66
67     // go get the new regions
68     <% $opt{'prefix'} %>get_regions( state, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_regions );
69
70   }
71
72 </SCRIPT>
73
74 <DIV ID="<% $opt{'prefix'} %>regionwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding regions</B></DIV>
75
76 <DIV ID="<% $opt{'prefix'} %>regionerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different state</B></DIV>
77
78 <SELECT NAME="<% $opt{'prefix'} %>region" onChange="<% $opt{'prefix'} %>region_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
79   <OPTION VALUE="">Select region</OPTION>
80 </SELECT>
81
82 <%init>
83
84 my %opt = @_;
85
86 $opt{disabled} = 'disabled' unless exists $opt{disabled};
87
88 </%init>