1 <% include('/elements/xmlhttp.html',
2 'url' => $p.'misc/areacodes.cgi',
3 'subs' => [ $opt{'prefix'}. 'get_areacodes' ],
7 <SCRIPT TYPE="text/javascript">
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;
15 function <% $opt{'state_prefix'} %>state_changed(what, callback) {
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';
24 what.form.<% $opt{'prefix'} %>exchange.disabled = 'disabled';
25 what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
27 var state = what.options[what.selectedIndex].value;
29 function <% $opt{'prefix'} %>update_areacodes(areacodes) {
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');
47 opt(what.form.<% $opt{'prefix'} %>areacode, '', '<% $opt{empty} %>');
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);
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 = '';
64 var areacodeerror = document.getElementById('<% $opt{'prefix'} %>areacodeerror');
65 areacodeerror.style.display = 'inline';
67 areacodeerror.textContent = reply.error;
69 areacodeerror.textContent = 'Select a different state';
74 if ( callback != null )
78 // go get the new areacodes
79 <% $opt{'prefix'} %>get_areacodes( state, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_areacodes );
85 <DIV ID="areacodewait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding area codes</B></DIV>
87 <DIV ID="areacodeerror" STYLE="display:none; font-weight: bold"><IMG SRC="<%$fsurl%>images/cross.png"></DIV>
89 <SELECT NAME="<% $opt{'prefix'} %>areacode" onChange="<% $opt{'prefix'} %>areacode_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
90 <OPTION VALUE="">Select area code</OPTION>
97 $opt{disabled} = 'disabled' unless exists $opt{disabled};
98 $opt{state_prefix} = $opt{prefix} unless exists $opt{state_prefix};