// Developed by:  Montie E. Brown, Jr.
// Contact Info: MontieBrown.com
// Filename: calc.js
// Description: Calculates prices for an estimate
// JavaScript Document
function calculate() {
	//FULL bathroom rates
	var SmallFullBathroomRate 	= 	7.5;
	var MediumFullBathroomRate 	= 	10;
	var LargeFullBathroomRate	=	15;
	var ExtraLargeFullBathroomRate	=	20;
	//HALF bathroom rates
	var SmallHalfBathroomRate 	= 	4;
	var MediumHalfBathroomRate 	= 	5;
	var LargeHalfBathroomRate	=	6;
	var ExtraLargeHalfBathroomRate	=	7;
	//Kitchen rates
	var SmallKitchenRate 		= 	10;
	var MediumKitchenRate 		= 	15;
	var LargeKitchenRate		=	20;
	var ExtraLargeKitchenRate	=	25;
	//Living Room rates
	var SmallLivingRoomRate 		= 	7.5;
	var MediumLivingRoomRate  		= 	10;
	var LargeLivingRoomRate 		=	12.5;
	var ExtraLargeLivingRoomRate 	=	15;
	//Dining Room rates
	var SmallDiningRoomRate 		= 	6;
	var MediumDiningRoomRate  		= 	7;
	var LargeDiningRoomRate			=	8;
	var ExtraLargeDiningRoomRate 	=	9;
	//Office rates
	var SmallOfficeRate 			= 	5;
	var MediumOfficeRate 			= 	6;
	var LargeOfficeRate				=	7;
	var ExtraLargeOfficeRate 		=	8;
	//Bedroom rates
	var SmallBedroomRate 			= 	7.5;
	var MediumBedroomRate 			= 	10;
	var LargeBedroomRate			=	12.5;
	var ExtraLargeBedroomRate 		=	15;	
	//Windows Rates
	var SmallWindowRate 			= 	1;
	var MediumWindowRate 			= 	1.1;
	var LargeWindowRate				=	1.25;
	var ExtraLargeWindowRate 		=	1.50;	
	
	//Dog Upcharge (as a percentages)
	var SmallDogRate 			= 	5;
	var MediumDogRate 			= 	10;
	var LargeDogRate 			=	15;
	var ExtraLargeDogRate  		=	20;
	//Cat Upcharge (as a percentages)
	var SmallCatRate 			= 	2.5;
	var MediumCatRate  			= 	2.5;
	var LargeCatRate  			=	2.5;
	var ExtraLargeCatRate   	=	2.5;
	
	//First Cleaning Charge (as a percentage)
	var FirstCleaningCharge 	=	40;
	
	//Lowest Cleaning Rate
	var LowestCleaningRate =	85;
	
	//Lowest Initial Cleaning Rate
	var LowestInitialCleaningRate =	100;
	
	//Cleaning Frequency Discounts (as a percentage)
	var WeeklyDiscount 		=	-12.5;
	var BiWeeklyDiscount	=	-7.5;
	var MonthlyDiscount		=	0;
	var OnCallDiscount		=	10;
	
	//Cleaning Day Discounts (as a percentage)
	var MondayDiscount		=	-20;
	var TuesdayDiscount		=	-15;
	var WednesdayDiscount	=	0;
	var ThursdayDiscount	=	0;
	var FridayDiscount		=	20;
	var SaturdayDiscount	=	12.5;
	var SundayDiscount		=	12.5;
	
	
	
	
	//calculate pricing for full bathrooms
    var totalFullBathrooms = (document.form.smallfullbathrooms.options[document.form.smallfullbathrooms.selectedIndex].value *SmallFullBathroomRate) + (document.form.mediumfullbathrooms.options[document.form.mediumfullbathrooms.selectedIndex].value * MediumFullBathroomRate) + (document.form.largefullbathrooms.options[document.form.largefullbathrooms.selectedIndex].value * LargeFullBathroomRate) + (document.form.extralargefullbathrooms.options[document.form.extralargefullbathrooms.selectedIndex].value * ExtraLargeFullBathroomRate);
	//calculate pricing for half bathrooms
    var totalHalfBathrooms = (document.form.smallhalfbathrooms.options[document.form.smallhalfbathrooms.selectedIndex].value * SmallHalfBathroomRate) + (document.form.mediumhalfbathrooms.options[document.form.mediumhalfbathrooms.selectedIndex].value * MediumHalfBathroomRate) + (document.form.largehalfbathrooms.options[document.form.largehalfbathrooms.selectedIndex].value * LargeHalfBathroomRate) + (document.form.extralargehalfbathrooms.options[document.form.extralargehalfbathrooms.selectedIndex].value * ExtraLargeHalfBathroomRate);
	//calculate pricing for Kitchens
    var totalKitchens = (document.form.smallkitchens.options[document.form.smallkitchens.selectedIndex].value * SmallKitchenRate) + (document.form.mediumkitchens.options[document.form.mediumkitchens.selectedIndex].value * MediumKitchenRate) + (document.form.largekitchens.options[document.form.largekitchens.selectedIndex].value * LargeKitchenRate) + (document.form.extralargekitchens.options[document.form.extralargekitchens.selectedIndex].value * ExtraLargeKitchenRate);
	//calculate pricing for Living Rooms
    var totalLivingRooms = (document.form.smalllivingrooms.options[document.form.smalllivingrooms.selectedIndex].value * SmallLivingRoomRate) + (document.form.mediumlivingrooms.options[document.form.mediumlivingrooms.selectedIndex].value * MediumLivingRoomRate) + (document.form.largelivingrooms.options[document.form.largelivingrooms.selectedIndex].value * LargeLivingRoomRate) + (document.form.extralargelivingrooms.options[document.form.extralargelivingrooms.selectedIndex].value * ExtraLargeLivingRoomRate);
	//calculate pricing for Dining Rooms
    var totalDiningRooms = (document.form.smalldiningrooms.options[document.form.smalldiningrooms.selectedIndex].value * SmallDiningRoomRate) + (document.form.mediumdiningrooms.options[document.form.mediumdiningrooms.selectedIndex].value * MediumDiningRoomRate) + (document.form.largediningrooms.options[document.form.largediningrooms.selectedIndex].value * LargeDiningRoomRate) + (document.form.extralargediningrooms.options[document.form.extralargediningrooms.selectedIndex].value * ExtraLargeDiningRoomRate);
	//calculate pricing for Offices
    var totalOffices = (document.form.smalloffices.options[document.form.smalloffices.selectedIndex].value * SmallOfficeRate) + (document.form.mediumoffices.options[document.form.mediumoffices.selectedIndex].value * MediumOfficeRate) + (document.form.largeoffices.options[document.form.largeoffices.selectedIndex].value * LargeOfficeRate) + (document.form.extralargeoffices.options[document.form.extralargeoffices.selectedIndex].value * ExtraLargeOfficeRate);
	//calculate pricing for Bedrooms
    var totalBedrooms = (document.form.smallbedrooms.options[document.form.smallbedrooms.selectedIndex].value * SmallBedroomRate) + (document.form.mediumbedrooms.options[document.form.mediumbedrooms.selectedIndex].value * MediumBedroomRate) + (document.form.largebedrooms.options[document.form.largebedrooms.selectedIndex].value * LargeBedroomRate) + (document.form.extralargebedrooms.options[document.form.extralargebedrooms.selectedIndex].value * ExtraLargeBedroomRate);
	//calculate pricing for Windows
    var totalWindows = (document.form.smallwindows.options[document.form.smallwindows.selectedIndex].value * SmallWindowRate) + (document.form.mediumwindows.options[document.form.mediumwindows.selectedIndex].value * MediumWindowRate) + (document.form.largewindows.options[document.form.largewindows.selectedIndex].value * LargeWindowRate) + (document.form.extralargewindows.options[document.form.extralargewindows.selectedIndex].value * ExtraLargeWindowRate);
	//calculate pricing for Dogs
    var totalDogs = (document.form.smalldogs.options[document.form.smalldogs.selectedIndex].value * SmallDogRate) + (document.form.mediumdogs.options[document.form.mediumdogs.selectedIndex].value * MediumDogRate) + (document.form.largedogs.options[document.form.largedogs.selectedIndex].value * LargeDogRate) + (document.form.extralargedogs.options[document.form.extralargedogs.selectedIndex].value * ExtraLargeDogRate);
	//calculate pricing for Cats
    var totalCats = (document.form.smallcats.options[document.form.smallcats.selectedIndex].value * SmallCatRate) + (document.form.mediumcats.options[document.form.mediumcats.selectedIndex].value * MediumCatRate) + (document.form.largecats.options[document.form.largecats.selectedIndex].value * LargeCatRate) + (document.form.extralargecats.options[document.form.extralargecats.selectedIndex].value * ExtraLargeCatRate);
	
	//set total pet up charge
	var TotalPetUpCharge = (totalDogs + totalCats)/100;
	var FrequencyAdjustment = 0;
	
	//set the frequency adjustment
	if (document.form.cleaningfrequency.options[document.form.cleaningfrequency.selectedIndex].value == "Weekly") {
		var FrequencyAdjustment = WeeklyDiscount/100;
		//FrequencyAdjustment = 100;
	} 
	if (document.form.cleaningfrequency.options[document.form.cleaningfrequency.selectedIndex].value == "Biweekly") {
		var FrequencyAdjustment = BiWeeklyDiscount/100;
	} 
	if (document.form.cleaningfrequency.options[document.form.cleaningfrequency.selectedIndex].value == "Monthly") {
		var FrequencyAdjustment = MonthlyDiscount/100;
	} 
	if (document.form.cleaningfrequency.options[document.form.cleaningfrequency.selectedIndex].value == "OnCall") {
		var FrequencyAdjustment = OnCallDiscount/100;
	} 
	
	//set day of cleaning adjustment
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Monday") {
		var DayAdjustment = MondayDiscount/100;
	} 
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Tuesday") {
		var DayAdjustment = TuesdayDiscount/100;
	} 
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Wednesday") {
		var DayAdjustment = WednesdayDiscount/100;
	} 
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Thursday") {
		var DayAdjustment = ThursdayDiscount/100;
	} 
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Friday") {
		var DayAdjustment = FridayDiscount/100;
	} 
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Saturday") {
		var DayAdjustment = SaturdayDiscount/100;
	} 
	if (document.form.dayofweek.options[document.form.dayofweek.selectedIndex].value == "Sunday") {
		var DayAdjustment = SundayDiscount/100;
	} 
	
	
	//Determine Cleaning Rates
	var SubTotal = totalFullBathrooms + totalHalfBathrooms + totalKitchens + totalLivingRooms + totalDiningRooms + totalOffices + totalBedrooms + totalWindows;
	
	//var Adjustments = (SubTotal * TotalPetUpCharge) + (SubTotal * DayAdjustment) + (SubTotal * FrequencyAdjustment);
	//********************************************************
	var AdjustedSubTotal = SubTotal + (SubTotal * TotalPetUpCharge);
	
	//********************************************************
	var InitialCleaning = AdjustedSubTotal + (AdjustedSubTotal * (FirstCleaningCharge/100));
	if (InitialCleaning < LowestInitialCleaningRate) {
		InitialCleaning = LowestInitialCleaningRate;
	}
	
	
	//adjust for cleaning frequency 
	AdjustedSubTotal = AdjustedSubTotal + (AdjustedSubTotal * FrequencyAdjustment);
	//adjust for day rate
	var CleaningRate = AdjustedSubTotal + (AdjustedSubTotal * DayAdjustment);
	if (CleaningRate < LowestCleaningRate) {
		CleaningRate = LowestCleaningRate;
	}
	
	//document.myform.outputtext.value = totalBathrooms;
	//document.myform.outputtext.value = SmallFullBathroomRate; */
	
	//document.form.rate.value = "$  " + FrequencyAdjustment;
	document.form.rate.value = "$  " + CleaningRate.toFixed(2);
	//document.form.rate.value = "$  " + CleaningRate;
	document.form.initialcleaningrate.value = "$  " + InitialCleaning.toFixed(2);
}
