+# prolly should be in database
+my %plans = (
+
+ 'flat' => {
+ 'name' => 'Flat rate',
+ 'fields' => {
+ 'setup_fee' => { 'name' => 'Setup fee for this package' },
+ 'recur_fee' => { 'name' => 'Recurring fee for this package' },
+ },
+ 'setup' => 'what.setup_fee.value',
+ 'recur' => 'what.recur_fee.value',
+ },
+
+ 'flat_comission' => {
+ 'name' => 'Flat rate with recurring referral comission as credit',
+ 'fields' => {
+ 'setup_fee' => { 'name' => 'Setup fee for this package' },
+ 'recur_fee' => { 'name' => 'Recurring fee for this package' },
+ 'comission_amount' => { 'name' => 'Comission amount' },
+ 'comission_depth' => { 'name' => 'Number of layers' },
+ },
+ 'setup' => 'what.setup_fee.value',
+ 'recur' => '\'$cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ) ; \' + what.recur_fee.value + \';\'',
+ },
+
+);
+
+%>
+
+<SCRIPT>
+var svcdb = null;
+var something = null;
+
+function changed(what) {
+ layer = what.options[what.selectedIndex].value;
+<% foreach my $layer ( keys %plans ) { %>
+ if (layer == "<%= $layer %>" ) {
+ <% foreach my $not ( grep { $_ ne $layer } keys %plans ) { %>
+ if (document.getElementById) {
+ document.getElementById('d<%= $not %>').style.visibility = "hidden";
+ } else {
+ document.l<%= $not %>.visibility = "hidden";
+ }
+ <% } %>
+ if (document.getElementById) {
+ document.getElementById('d<%= $layer %>').style.visibility = "visible";
+ } else {
+ document.l<%= $layer %>.visibility = "visible";
+ }
+ }
+<% } %>
+}
+
+</SCRIPT>
+<BR>
+Price plan <SELECT NAME="plan" SIZE=1 onChange="changed(this)">
+<% foreach my $layer (keys %plans ) { %>
+<OPTION VALUE="<%= $layer %>"<%= ' SELECTED'x($layer eq $plan) %>><%= $plans{$layer}->{'name'} %>
+<% } %>
+</SELECT></FORM>
+
+<SCRIPT>
+function fchanged(what) {
+ fixup(what.form);
+}
+
+function fixup(what) {
+<% foreach my $f ( qw( pkg comment freq ), @fixups ) { %>
+ what.<%= $f %>.value = document.dummy.<%= $f %>.value;
+<% } %>
+ what.plan.value = document.dummy.plan.options[document.dummy.plan.selectedIndex].value;
+<% foreach my $p ( keys %plans ) { %>
+ if ( what.plan.value == "<%= $p %>" ) {
+ what.setup.value = <%= $plans{$p}->{setup} %>;
+ what.recur.value = <%= $plans{$p}->{recur} %>;
+ }
+<% } %>
+}
+</SCRIPT>
+
+<% #foreach my $layer ( 'konq_kludge', keys %plans ) {
+ foreach my $layer ( 'konq_kludge', keys %plans ) {
+ my $visibility = "hidden";
+%>
+<SCRIPT>
+if (document.getElementById) {
+ document.write("<DIV ID=\"d<%= $layer %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
+} else {
+<% $visibility="show" if $visibility eq "visible"; %>
+ document.write("<LAYER ID=\"l<%= $layer %>\" VISIBILITY=\"<%= $visibility %>\">");
+}
+</SCRIPT>
+
+<FORM NAME="<%= $layer %>" ACTION="process/part_pkg.cgi" METHOD=POST onSubmit="fixup(this)">
+<INPUT TYPE="hidden" NAME="plan" VALUE="<%= $plan %>">
+<INPUT TYPE="hidden" NAME="pkg" VALUE="<%= $hashref->{pkg} %>">
+<INPUT TYPE="hidden" NAME="comment" VALUE="$<%= hashref->{comment} %>">
+<INPUT TYPE="hidden" NAME="freq" VALUE="<%= $hashref->{freq} %>">
+<% foreach my $f ( @fixups ) { %>
+<INPUT TYPE="hidden" NAME="<%= $f %>" VALUE="">
+<% } %>
+
+<%
+if ( $cgi->param('clone') ) {
+ print qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $cgi->param('clone'), qq!">!;
+}
+if ( $cgi->param('pkgnum') ) {
+ print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $cgi->param('pkgnum'), qq!">!;
+}
+print qq!<INPUT TYPE="hidden" NAME="pkgpart" VALUE="$hashref->{pkgpart}">!,
+%>
+
+<% my $href = $plans{$layer}->{'fields'};
+ foreach my $field ( keys %{ $href } ) { %>
+<%= $href->{$field}{'name'} %>:
+<INPUT TYPE="text" NAME="<%= $field %>" VALUE="<%= $ref->{$field}{'default'} %>" onChange="fchanged(this)"><BR>
+<% } %>
+
+<FONT SIZE="-2">
+Setup expression <INPUT TYPE="text" NAME="setup" SIZE="100%" VALUE="<%= $hashref->{setup} %>"><BR>
+Recurring espression <INPUT TYPE="text" NAME="recur" SIZE="100%" VALUE="<%= $hashref->{recur} %>"><BR>
+</FONT>
+
+<%