This commit was generated by cvs2svn to compensate for changes in r9232,
[freeside.git] / httemplate / elements / select-exchange.html
1 <% include('/elements/xmlhttp.html',
2               'url'  => $p.'misc/exchanges.cgi',
3               'subs' => [ $opt{'prefix'}. 'get_exchanges' ],
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{'prefix'} %>areacode_changed(what, callback) {
16
17     what.form.<% $opt{'prefix'} %>exchange.disabled = 'disabled';
18     what.form.<% $opt{'prefix'} %>exchange.style.display = 'none';
19     var exchangewait = document.getElementById('<% $opt{'prefix'} %>exchangewait');
20     exchangewait.style.display = '';
21     var exchangeerror = document.getElementById('<% $opt{'prefix'} %>exchangeerror');
22     exchangeerror.style.display = 'none';
23
24     what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
25
26     areacode = what.options[what.selectedIndex].value;
27
28     function <% $opt{'prefix'} %>update_exchanges(exchanges) {
29
30       // blank the current exchange
31       for ( var i = what.form.<% $opt{'prefix'} %>exchange.length; i >= 0; i-- )
32           what.form.<% $opt{'prefix'} %>exchange.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       opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
37
38 %     if ($opt{empty}) {
39         opt(what.form.<% $opt{'prefix'} %>exchange, '', '<% $opt{empty} %>');
40 %     }
41
42       // add the new exchanges
43       var exchangeArray = eval('(' + exchanges + ')' );
44       for ( var s = 0; s < exchangeArray.length; s++ ) {
45           var exchangeLabel = exchangeArray[s];
46           if ( exchangeLabel == "" )
47               exchangeLabel = '(n/a)';
48           opt(what.form.<% $opt{'prefix'} %>exchange, exchangeArray[s], exchangeLabel);
49       }
50
51       exchangewait.style.display = 'none';
52       if ( exchangeArray.length >= 1 ) {
53         what.form.<% $opt{'prefix'} %>exchange.disabled = '';
54         what.form.<% $opt{'prefix'} %>exchange.style.display = '';
55       } else {
56         var exchangeerror = document.getElementById('<% $opt{'prefix'} %>exchangeerror');
57         exchangeerror.style.display = '';
58       }
59
60       //run the callback
61       if ( callback != null ) 
62         callback();
63     }
64
65     // go get the new exchanges
66     <% $opt{'prefix'} %>get_exchanges( areacode, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_exchanges );
67
68   }
69
70 </SCRIPT>
71
72 <DIV ID="exchangewait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding cities / exchanges</B></DIV>
73
74 <DIV ID="exchangeerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different area code</B></DIV>
75
76 <SELECT NAME="<% $opt{'prefix'} %>exchange" onChange="<% $opt{'prefix'} %>exchange_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
77   <OPTION VALUE="">Select city / exchange</OPTION>
78 </SELECT>
79
80 <%init>
81
82 my %opt = @_;
83
84 $opt{disabled} = 'disabled' unless exists $opt{disabled};
85
86 </%init>