//define global variables

// START - Change for UK & Other countries
var money ="$ "; //put your currency symbol here.
var training_fee = 800; //Standard training fee
var setup_fee; //add a standard setup fee is you use one. AUS setup fee = one month fee
// END - Change for UK & Other countries


var restaurant_name;
var capacity;
var gross_asp;
var gross_margin;
var gross_margin;
var monthly_covers;
var monthly_revenue;
var capacity;
var monthly_fee;
var setup;
var improvement_percentage_a;
var improvement_percentage_b;
var improvement_percentage_c;
var monthly_revenue_a;
var monthly_revenue_b;
var monthly_revenue_c;
var yearly_revenue_a;
var yearly_revenue_b;
var yearly_revenue_c;
var yearly_revenue;
var additional_revenue_a;
var additional_revenue_b;
var additional_revenue_c;
var roi_a;
var roi_b;
var roi_c;



function calculate()
{

<!-- validate();-->
collect();
output();
show();
}


function validate()
{
}

function collect()
{

	
//Collect all the data from the "About Your Restaurant" fields
restaurant_name = document.getElementById("restaurant_name").value;
capacity = document.getElementById("capacity").value;
gross_asp = document.getElementById("gross_asp").value;
gross_margin = document.getElementById("gross_margin").value;

if (gross_margin>1)
{
gross_margin = gross_margin / 100; //change the integer into a decimal
}

monthly_covers = document.getElementById("monthly_covers").value;

//calculate Monthly Revenue and output to form
monthly_revenue = Math.round(gross_asp * gross_margin * monthly_covers);

//Calculate restaurantdiary fees
capacity = document.getElementById("capacity").value; //pulls monthly fee from drop down menu "Seating Capacity"
monthly_fee = capacity; 
setup_fee = parseInt(monthly_fee) // delete or comment out if you use a flat setup fee. This would be defined at the top in the variables section.
setup = setup_fee + training_fee; // Total setup cost equals setup and training fee



//calculate return on investment
//setup percentage improvements. They are set variables and not read from the form.
improvement_percentage_a = 0.01;
improvement_percentage_b = 0.05;
improvement_percentage_c = 0.1;

//Calculate the New monthly revenue.
monthly_revenue_a = Math.round((1 + improvement_percentage_a) * monthly_revenue - monthly_fee);
monthly_revenue_b  = Math.round((1 + improvement_percentage_b) * monthly_revenue - monthly_fee);
monthly_revenue_c = Math.round((1 + improvement_percentage_c) * monthly_revenue - monthly_fee);

//Calculate New Yearly Revenue
yearly_revenue_a = monthly_revenue_a * 12;
yearly_revenue_b = monthly_revenue_b * 12;
yearly_revenue_c = monthly_revenue_c * 12;

//Calculate Additional Yearly Revenue
yearly_revenue = monthly_revenue * 12; //original estimated monthly revenue x 12
additional_revenue_a = yearly_revenue_a - yearly_revenue;
additional_revenue_b = yearly_revenue_b - yearly_revenue;
additional_revenue_c = yearly_revenue_c - yearly_revenue;

//Calculate Return on Investment %
roi_a = Math.round(monthly_revenue_a/monthly_revenue*10000)/100;
roi_b = Math.round(monthly_revenue_b/monthly_revenue*10000)/100;
roi_c = Math.round(monthly_revenue_c/monthly_revenue*10000)/100;




}


function output()
{
//Output estimated monthly revenue
//monthly_covers = addCommas(monthly_covers); //BAD. Converts number to text. Causes problem latter.
document.getElementById("monthly_covers").value = monthly_covers;
monthly_revenue = addCommas(monthly_revenue);
document.getElementById("monthly_revenue").value = money + monthly_revenue;

//Output restaurantdiary Fees
setup = addCommas(setup);
document.getElementById("setup").value  = money + setup;
document.getElementById("monthly_fee").value = money +  monthly_fee;

//Output New Monthly Revenue
monthly_revenue_a = addCommas(monthly_revenue_a);
document.getElementById("monthly_revenue_a").value = money + monthly_revenue_a;
monthly_revenue_b = addCommas(monthly_revenue_b);
document.getElementById("monthly_revenue_b").value = money + monthly_revenue_b;
monthly_revenue_c = addCommas(monthly_revenue_c);
document.getElementById("monthly_revenue_c").value = money + monthly_revenue_c;

//Output New Yearly Revenue
yearly_revenue_a = addCommas(yearly_revenue_a);
document.getElementById("yearly_revenue_a").value = money + yearly_revenue_a;
yearly_revenue_b = addCommas(yearly_revenue_b);
document.getElementById("yearly_revenue_b").value = money + yearly_revenue_b;
yearly_revenue_c = addCommas(yearly_revenue_c);
document.getElementById("yearly_revenue_c").value = money + yearly_revenue_c;

//Output Additional Yearly Revenue
additional_revenue_a = addCommas(additional_revenue_a);
document.getElementById("additional_revenue_a").value = money + additional_revenue_a;
additional_revenue_b = addCommas(additional_revenue_b);
document.getElementById("additional_revenue_b").value = money + additional_revenue_b;
additional_revenue_c = addCommas(additional_revenue_c);
document.getElementById("additional_revenue_c").value = money + additional_revenue_c;


//Output Return on Investment %
document.getElementById("roi_a").value = roi_a + " %";
document.getElementById("roi_b").value = roi_b + " %";
document.getElementById("roi_c").value = roi_c + " %";

}

function show()
{

document.getElementById("monthly_revenue_label").style.display="block";
document.getElementById("monthly_revenue").style.display="block";
document.getElementById("fee_fieldset").style.display="block";
document.getElementById("roi_fieldset").style.display="block";



}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
-->
