var service = new voice_comm_service; var voice_comms = new voice_comm; function init_page() { voice_comms = new voice_comm( 11, 'Voice Comm Server', 425.50, 500.00, 10, 128, 42.50, 50.00 ); voice_comms.add_server_type( 60, '55', 'Teamspeak 2', 0.00, 0.00 ); voice_comms.add_server_type( 61, '50', 'Ventrilo', 0.00, 0.00 ); voice_comms.add_payment_term( 1, 0.00 ); voice_comms.add_payment_term( 3, 0.10 ); voice_comms.add_payment_term( 12, 0.20 ); voice_comms.add_payment_term( 6, 0.15 ); // Populate server_type select box temp = Array(); for ( j in voice_comms.server_types ) { temp.push( voice_comms.server_types[j].name + '#:#' + j ); } temp.sort(); server_types_select = document.getElementById( "server_types" ).options; j = 0; for ( i in temp ) { data = String( temp[ i ] ); data = data.split( "#:#" ); temp_option = new Option( data[ 0 ], data[ 1 ], 0, 0 ); server_types_select[j++] = temp_option; } service.service_typeid = server_types_select[0].value; // Populate max_clients select box max_clients_select = document.getElementById( "max_clients" ).options; j = 0; for ( i = voice_comms.min_clients; i <= voice_comms.max_clients; i++ ) { temp_option = new Option( i, i, 0, 0 ); max_clients_select[j++] = temp_option; } service.max_clients = max_clients_select[0].value; // Update other stuff update_payment_terms(); update_service(); update_pricing(); } function update_service() { // Service type service.server_type = document.getElementById( "server_types" )[document.getElementById( "server_types" ).selectedIndex].value; // Operating system service.max_clients = document.getElementById( "max_clients" )[document.getElementById( "max_clients" ).selectedIndex].value; // Payment term payment_terms = document.getElementById( "actionForm" ).paymentterm; if ( 'undefined' != typeof( payment_terms ) ) { for( i = 0; i < payment_terms.length; i++ ) { if ( payment_terms[i].checked ) { service.payment_term = payment_terms[i].value; } } } } function update_payment_terms() { payment_terms = document.getElementById( "actionForm" ).paymentterm; current_payment_term = 0; if ( 'undefined' != typeof( payment_terms ) ) { for( i = 0; i < payment_terms.length; i++ ) { if ( payment_terms[i].checked ) { current_payment_term = payment_terms[i].value; } } } else { current_payment_term = 3; } tdpt = document.getElementById( "td_payment_terms" ); tdpt.innerHTML = ''; payment_terms = voice_comms.payment_terms; if ( payment_terms.length > 0 ) { cpt_exists = 0; def_pt = 0; for( i in payment_terms ) { if ( def_pt == 0 ) { def_pt = payment_terms[i].payment_term; } if ( payment_terms[i] ) { cpt_exists = ( payment_terms[i].payment_term == current_payment_term ) ? 1 : cpt_exists; } } if ( cpt_exists == 0 ) { current_payment_term = def_pt; } for( i = 0; i < payment_terms.length; i++ ) { if ( payment_terms[i] ) { checked = ( payment_terms[i].payment_term == current_payment_term ) ? ' checked="checked"' : ''; tdpt.innerHTML += ' ' + payment_terms[i].payment_term + ' Month(s) ( ' + payment_terms[i].discount * 100 + '% discount )
' } } } } function update_pricing() { update_service(); total = service.cost(); multiplier = ( 1 - service.discount ) * service.payment_term; // update breakdown td_breakdown = document.getElementById( "breakdown" ); td_breakdown.innerHTML = voice_comms.name + ": £" + format_currency( Math.round( service.base_cost * multiplier ) / 100 ) + "
"; total = voice_comms.incvat; td_breakdown.innerHTML += "Server Type: " + voice_comms.server_types[service.server_type].name + ": £" + format_currency( Math.round( service.server_type_cost * multiplier ) / 100 ) + "
" total += voice_comms.server_types[service.server_type].incvat; td_breakdown.innerHTML += "Max Clients: " + service.max_clients + ": £" + format_currency( Math.round( service.max_client_cost * multiplier ) / 100 ) + "
" total += service.max_client_cost; // update running_total td_running_total = document.getElementById( "running_total" ); td_running_total.innerHTML = "£" + format_currency( Math.round( total * multiplier ) / 100 ); // update extra_money_info td_extra_money_info = document.getElementById( "extra_money_info" ); td_extra_money_info.innerHTML = ""; if ( voice_comms.payment_terms[service.payment_term].discount > 0 ) { td_extra_money_info.innerHTML += "Discount: £" + format_currency( Math.round( service.discount_cost ) / 100 ) + "
"; td_extra_money_info.innerHTML += "Equivalent Monthly: £" + format_currency( Math.round( ( total / service.payment_term * multiplier ) ) / 100 ); } } function format_currency( fAmount ) { aAmount = fAmount.toString().split( "." ); if ( aAmount[1] ) { if ( aAmount[1].length == 1 ) { aAmount[1] += "0"; } } else { aAmount[1] = "00"; } return aAmount[0] + "." + aAmount[1]; }