﻿/// <reference path="/Script/jquery-1.3.2.min.js" />



jQuery(document).ready(function() {
	jQuery("#onOwn").find("input").keyup(function() {
		jQuery("#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: jQuery("#onOwn").find(".feePerHour"),
		workingHours: jQuery("#onOwn").find(".workingHours"),
		weeksPerYear: jQuery("#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 = jQuery("#onOwn").find(".laboratoryExpenses").val();
			var profit = income - expenses;

			if (s <= 0) {
				jQuery("#onOwn").find(".totalProfit").addClass("negative");
			} else if (jQuery("#onOwn").find(".totalProfit").hasClass("negative")) {
				jQuery("#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 * jQuery("#onOwn").find(".totalExpenses").text() / 100;
			//var totalRevenue = total - totalExpenses;

			if (totalExpenses < 0) {
				totalRevenue = parseInt(total) + parseInt(totalExpenses)
			} else {
				totalRevenue = parseInt(total) - parseInt(totalExpenses)
			}


			jQuery("#onOwn").find(".totalRevenue").text(
				totalRevenue
			);

			if (totalRevenue <= 0) {
				jQuery("#onOwn").find(".totalRevenue").addClass("negative");
			} else if (jQuery("#onOwn").find(".totalRevenue").hasClass("negative")) {
				jQuery("#onOwn").find(".totalRevenue").removeClass("negative");
			}
		}
	)
});
});

jQuery(document).ready(function() {
	jQuery("#onRent").find("input").keyup(function() {
		jQuery("#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: jQuery("#onRent").find(".feePerHour"),
		workingHours: jQuery("#onRent").find(".workingHours"),
		weeksPerYear: jQuery("#onRent").find(".weeksPerYear")
	},
	// define the formatting callback, the results of the calculation are passed to this function
		function(s) {

			var income = s;
			var expenses = jQuery("#onRent").find(".laboratoryExpenses").val();
			var profit = income - expenses;

			if (s <= 0) {
				jQuery("#onRent").find(".totalProfit").addClass("negative");
			} else if (jQuery("#onRent").find(".totalProfit").hasClass("negative")) {
				jQuery("#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 * jQuery("#onRent").find(".rentPercentage").val() / 100;
			var totalRevenue = total - rentExpenses - jQuery("#onRent").find(".totalExpenses").val();

			jQuery("#onRent").find(".totalRevenue").text(
					totalRevenue
					);

			if (totalRevenue <= 0) {
				jQuery("#onRent").find(".totalRevenue").addClass("negative");
			} else if (jQuery("#onRent").find(".totalRevenue").hasClass("negative")) {
				jQuery("#onRent").find(".totalRevenue").removeClass("negative");
			}

		}
	)
});
});


jQuery(document).ready(function() {
	jQuery("#onHealthCareCenter").find("input").keyup(function() {
		jQuery("#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: jQuery("#onHealthCareCenter").find(".feePerHour"),
		workingHours: jQuery("#onHealthCareCenter").find(".workingHours"),
		weeksPerYear: jQuery("#onHealthCareCenter").find(".weeksPerYear")
	},
	// define the formatting callback, the results of the calculation are passed to this function
		function(s) {

			if (s <= 0) {
				jQuery("#onHealthCareCenter").find(".totalProfit").addClass("negative");
			} else if (jQuery("#onHealthCareCenter").find(".totalProfit").hasClass("negative")) {
			jQuery("#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 * jQuery("#onHealthCareCenter").find(".rentPercentage").val() / 100;
			var totalRevenue = total - rentExpenses - jQuery("#onHealthCareCenter").find(".totalExpenses").val();

			jQuery("#onHealthCareCenter").find(".totalRevenue").text(
				totalRevenue
				);

			if (totalRevenue <= 0) {
				jQuery("#onHealthCareCenter").find(".totalRevenue").addClass("negative");
			} else if (jQuery("#onHealthCareCenter").find(".totalRevenue").hasClass("negative")) {
			jQuery("#onHealthCareCenter").find(".totalRevenue").removeClass("negative");
			}

			
		}
	)
});
});
