combine ticket notification scrips, #15353
[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 = '';
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       // blank the current areacode
32       for ( var i = what.form.<% $opt{'prefix'} %>areacode.length; i >= 0; i-- )
33           what.form.<% $opt{'prefix'} %>areacode.options[i] = null;
34       // blank the current exchange too
35       for ( var i = what.form.<% $opt{'prefix'} %>exchange.length; i >= 0; i-- )
36           what.form.<% $opt{'prefix'} %>exchange.options[i] = null;
37       opt(what.form.<% $opt{'prefix'} %>exchange, '', 'Select city / exchange');
38       // blank the current phonenum too
39       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
40           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
41       if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
42         opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
43       }
44
45 %     if ($opt{empty}) {
46         opt(what.form.<% $opt{'prefix'} %>areacode, '', '<% $opt{empty} %>');
47 %     }
48
49       // add the new areacodes
50       var areacodeArray = eval('(' + areacodes + ')' );
51       for ( var s = 0; s < areacodeArray.length; s++ ) {
52           var areacodeLabel = areacodeArray[s];
53           if ( areacodeLabel == "" )
54               areacodeLabel = '(n/a)';
55           opt(what.form.<% $opt{'prefix'} %>areacode, areacodeArray[s], areacodeLabel);
56       }
57
58       areacodewait.style.display = 'none';
59       if ( areacodeArray.length >= 1 ) {
60         what.form.<% $opt{'prefix'} %>areacode.disabled = '';
61         what.form.<% $opt{'prefix'} %>areacode.style.display = '';
62       } else {
63         var areacodeerror = document.getElementById('<% $opt{'prefix'} %>areacodeerror');
64         areacodeerror.style.display = '';
65       }
66
67       //run the callback
68       if ( callback != null ) 
69         callback();
70     }
71
72     // go get the new areacodes
73     <% $opt{'prefix'} %>get_areacodes( state, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_areacodes );
74
75   }
76
77 </SCRIPT>
78
79 <DIV ID="areacodewait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding area codes</B></DIV>
80
81 <DIV ID="areacodeerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different state</B></DIV>
82
83 <SELECT NAME="<% $opt{'prefix'} %>areacode" onChange="<% $opt{'prefix'} %>areacode_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
84   <OPTION VALUE="">Select area code</OPTION>
85 </SELECT>
86
87 <%init>
88
89 my %opt = @_;
90
91 $opt{disabled}     = 'disabled'   unless exists $opt{disabled};
92 $opt{state_prefix} = $opt{prefix} unless exists $opt{state_prefix};
93
94 </%init>