﻿/// <reference path="/Script/jquery-1.3.2.min.js" />

$(document).ready(function() {
	$("#onOwn").find("input").keyup(function() {
		$("#onOwn").find(".totalProfit").calc(
		// the equation to use for the calculation
		"feePerHour * workingHours * weeksPerYear",

		// define the variables used in the equation, these can be a jQuery object
		{
		feePerHour: $("#onOwn").find(".feePerHour"),
		workingHours: $("#onOwn").find(".workingHours"),
		weeksPerYear: $("#onOwn").find(".weeksPerYear")
	},
	// define the formatting callback, the results of the calculation are passed to this function
		function(s) {
			//alert(s);

			var income = s;
			var expenses = $("#onOwn").find(".laboratoryExpenses").val();
			var profit = income - expenses;

			if (s <= 0) {
				$("#onOwn").find(".totalProfit").addClass("negative");
			} else if ($("#onOwn").find(".totalProfit").hasClass("negative")) {
				$("#onOwn").find(".totalProfit").removeClass("negative");
			}

			return profit;
		},
	// define the finish callback, this runs after the calculation has been complete
		function($this) {

			var total = $this.text();
			var totalExpenses = total * $("#onOwn").find(".totalExpenses").text() / 100;
			//var totalRevenue = total - totalExpenses;

			if (totalExpenses < 0) {
				totalRevenue = parseInt(total) + parseInt(totalExpenses)
			} else {
				totalRevenue = parseInt(total) - parseInt(totalExpenses)
			}


			$("#onOwn").find(".totalRevenue").text(
				totalRevenue
			);

			if (totalRevenue <= 0) {
				$("#onOwn").find(".totalRevenue").addClass("negative");
			} else if ($("#onOwn").find(".totalRevenue").hasClass("negative")) {
				$("#onOwn").find(".totalRevenue").removeClass("negative");
			}
		}
	)
});
});

$(document).ready(function() {
	$("#onRent").find("input").keyup(function() {
		$("#onRent").find(".totalProfit").calc(
		// the equation to use for the calculation
		"feePerHour * workingHours * weeksPerYear",

		// define the variables used in the equation, these can be a jQuery object
		{
		feePerHour: $("#onRent").find(".feePerHour"),
		workingHours: $("#onRent").find(".workingHours"),
		weeksPerYear: $("#onRent").find(".weeksPerYear")
	},
	// define the formatting callback, the results of the calculation are passed to this function
		function(s) {

			var income = s;
			var expenses = $("#onRent").find(".laboratoryExpenses").val();
			var profit = income - expenses;

			if (s <= 0) {
				$("#onRent").find(".totalProfit").addClass("negative");
			} else if ($("#onRent").find(".totalProfit").hasClass("negative")) {
				$("#onRent").find(".totalProfit").removeClass("negative");
			}

			return profit;
		},
	// define the finish callback, this runs after the calculation has been complete
		function($this) {

			var total = $this.text();
			var rentExpenses = total * $("#onRent").find(".rentPercentage").val() / 100;
			var totalRevenue = total - rentExpenses - $("#onRent").find(".totalExpenses").val();

			$("#onRent").find(".totalRevenue").text(
					totalRevenue
					);

			if (totalRevenue <= 0) {
				$("#onRent").find(".totalRevenue").addClass("negative");
			} else if ($("#onRent").find(".totalRevenue").hasClass("negative")) {
				$("#onRent").find(".totalRevenue").removeClass("negative");
			}

		}
	)
});
});


$(document).ready(function() {
	$("#onHealthCareCenter").find("input").keyup(function() {
		$("#onHealthCareCenter").find(".totalProfit").calc(
		// the equation to use for the calculation
		"feePerHour * workingHours * weeksPerYear",

		// define the variables used in the equation, these can be a jQuery object
		{
		feePerHour: $("#onHealthCareCenter").find(".feePerHour"),
		workingHours: $("#onHealthCareCenter").find(".workingHours"),
		weeksPerYear: $("#onHealthCareCenter").find(".weeksPerYear")
	},
	// define the formatting callback, the results of the calculation are passed to this function
		function(s) {

			if (s <= 0) {
				$("#onHealthCareCenter").find(".totalProfit").addClass("negative");
			} else if ($("#onHealthCareCenter").find(".totalProfit").hasClass("negative")) {
			$("#onHealthCareCenter").find(".totalProfit").removeClass("negative");
			}
		
			return s;
		},
	// define the finish callback, this runs after the calculation has been complete
		function($this) {

			var total = $this.text();
			var rentExpenses = total * $("#onHealthCareCenter").find(".rentPercentage").val() / 100;
			var totalRevenue = total - rentExpenses - $("#onHealthCareCenter").find(".totalExpenses").val();

			$("#onHealthCareCenter").find(".totalRevenue").text(
				totalRevenue
				);

			if (totalRevenue <= 0) {
				$("#onHealthCareCenter").find(".totalRevenue").addClass("negative");
			} else if ($("#onHealthCareCenter").find(".totalRevenue").hasClass("negative")) {
			$("#onHealthCareCenter").find(".totalRevenue").removeClass("negative");
			}

			
		}
	)
});
});