stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / elements / select-areacode.html
1 <% include('/elements/xmlhttp.html',
2               'url'  => $p.'misc/areacodes.cgi',
3               'subs' => [ $opt{'prefix'}. 'get_areacodes' ],
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'} %>areacode.disabled = 'disabled';
18     what.form.<% $opt{'prefix'} %>areacode.style.display = 'none';
19     var areacodewait = document.getElementById('<% $opt{'prefix'} %>areacodewait');
20     areacodewait.style.display = 'inline';
21     var areacodeerror = document.getElementById('<% $opt{'prefix'} %>areacodeerror');
22     areacodeerror.style.display = 'none';
23
24     what.form.<% $opt{'prefix'} %>exchange.disabled = 'disabled';
25     what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
26
27     var state = what.options[what.selectedIndex].value;
28
29     function <% $opt{'prefix'} %>update_areacodes(areacodes) {
30
31       var reply = JSON.parse(areacodes);
32       // blank the current areacode
33       for ( var i = what.form.<% $opt{'prefix'} %>areacode.length; i >= 0; i-- )
34           what.form.<% $opt{'prefix'} %>areacode.options[i] = null;
35       // blank the current exchange too
36       for ( var i = what.form.<% $opt{'prefix'} %>exchange.length; i >= 0; i-- )
37           what.form.<% $opt{'prefix'} %>exchange.options[i] = null;
38       opt(what.form.<% $opt{'prefix'} %>exchange, '', 'Select city / exchange');
39       // blank the current phonenum too
40       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
41           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
42       if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
43         opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
44       }
45
46 %     if ($opt{empty}) {
47         opt(what.form.<% $opt{'prefix'} %>areacode, '', '<% $opt{empty} %>');
48 %     }
49
50       // add the new areacodes
51       var areacodeArray = reply.areacodes;
52       for ( var s = 0; s < areacodeArray.length; s++ ) {
53           var areacodeLabel = areacodeArray[s];
54           if ( areacodeLabel == "" )
55               areacodeLabel = '(n/a)';
56           opt(what.form.<% $opt{'prefix'} %>areacode, areacodeArray[s], areacodeLabel);
57       }
58
59       areacodewait.style.display = 'none';
60       if ( areacodeArray.length >= 1 ) {
61         what.form.<% $opt{'prefix'} %>areacode.disabled = '';
62         what.form.<% $opt{'prefix'} %>areacode.style.display = '';
63       } else {
64         var areacodeerror = document.getElementById('<% $opt{'prefix'} %>areacodeerror');
65         areacodeerror.style.display = 'inline';
66         if ( reply.error ) {
67           areacodeerror.textContent = reply.error;
68         } else {
69           areacodeerror.textContent = 'Select a different state';
70         }
71       }
72
73       //run the callback
74       if ( callback != null ) 
75         callback();
76     }
77
78     // go get the new areacodes
79     <% $opt{'prefix'} %>get_areacodes( state, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_areacodes );
80
81   }
82
83 </SCRIPT>
84
85 <DIV ID="areacodewait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding area codes</B></DIV>
86
87 <DIV ID="areacodeerror" STYLE="display:none; font-weight: bold"><IMG SRC="<%$fsurl%>images/cross.png"></DIV>
88
89 <SELECT NAME="<% $opt{'prefix'} %>areacode" onChange="<% $opt{'prefix'} %>areacode_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
90   <OPTION VALUE="">Select area code</OPTION>
91 </SELECT>
92
93 <%init>
94
95 my %opt = @_;
96
97 $opt{disabled}     = 'disabled'   unless exists $opt{disabled};
98 $opt{state_prefix} = $opt{prefix} unless exists $opt{state_prefix};
99
100 </%init>