//  Filename: calc_gross_profit.js  //  Function: functions to calculate gross profit margin and gross profit  //  Author: Barry Hood -- design@delinear.co.uk  //  Date: 2005.05.06
function gross_profit_calculator(form_name){var gp_margin=strip_common_elements(document.getElementById(form_name).gp_margin.value);var gp_sales=strip_common_elements(document.getElementById(form_name).gp_sales.value);var error_array=new Array;var error_count=0;if(!check_number_valid(gp_sales)){error_array[error_count]="\tThe sales revenue field";error_count++;}if(!check_number_valid(gp_margin)){error_array[error_count]="\tThe profit margin field";error_count++;}if(error_array.length>0){var error_message;error_message=(error_array.length>1)?"The following fields are incorrect. Please check the fields and try again:\n\n":"The following field is incorrect. Please check the fields and try again:\n\n";for(i=0;i<error_array.length; i++){error_message+=error_array[i];error_message+="\n";}document.getElementById(form_name).gp_profit.value='';document.getElementById(form_name).gp_cost.value='';alert(error_message);return false;}var gp_profit=0;var gp_cost=0;gp_profit=(gp_margin*(gp_sales/100));gp_cost=(gp_sales-gp_profit);document.getElementById(form_name).gp_cost.value=format_number_output(gp_cost,2,',','£');document.getElementById(form_name).gp_profit.value=format_number_output(gp_profit,2,',','£');return false;}function gross_profit_margin_calculator(form_name){var gpm_sales=strip_common_elements(document.getElementById(form_name).gpm_sales.value);var gpm_cost=strip_common_elements(document.getElementById(form_name).gpm_cost.value);var error_array=new Array;var error_count=0;if(!check_number_valid(gpm_sales)){error_array[error_count]="\tThe sales revenue field";error_count++;}if(!check_number_valid(gpm_cost)){error_array[error_count]="\tThe total cost field";error_count++;}if(error_array.length>0){var error_message;error_message=(error_array.length>1)?"The following fields are incorrect. Please check the fields and try again:\n\n":"The following field is incorrect. Please check the fields and try again:\n\n";for(i=0;i<error_array.length;i++){error_message+=error_array[i];error_message+="\n";}document.getElementById(form_name).gpm_profit.value='';document.getElementById(form_name).gpm_margin.value='';alert(error_message);return false;}var gpm_profit=0;var gpm_margin=0;gpm_profit=(gpm_sales-gpm_cost);gpm_margin=(((gpm_sales-gpm_cost)/gpm_sales)*100);document.getElementById(form_name).gpm_profit.value=format_number_output(gpm_profit,2,',','£');document.getElementById(form_name).gpm_margin.value=format_number_output(gpm_margin,2,',')+'%';return false;}