// 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.form1.smallfullbathrooms.options[document.form1.smallfullbathrooms.selectedIndex].value *SmallFullBathroomRate) + (document.form1.mediumfullbathrooms.options[document.form1.mediumfullbathrooms.selectedIndex].value * MediumFullBathroomRate) + (document.form1.largefullbathrooms.options[document.form1.largefullbathrooms.selectedIndex].value * LargeFullBathroomRate) + (document.form1.extralargefullbathrooms.options[document.form1.extralargefullbathrooms.selectedIndex].value * ExtraLargeFullBathroomRate);
	//alert(totalFullBathrooms);
		////calculate pricing for half bathrooms
	var totalHalfBathrooms = (document.form1.smallhalfbathrooms.options[document.form1.smallhalfbathrooms.selectedIndex].value * SmallHalfBathroomRate) + (document.form1.mediumhalfbathrooms.options[document.form1.mediumhalfbathrooms.selectedIndex].value * MediumHalfBathroomRate) + (document.form1.largehalfbathrooms.options[document.form1.largehalfbathrooms.selectedIndex].value * LargeHalfBathroomRate) + (document.form1.extralargehalfbathrooms.options[document.form1.extralargehalfbathrooms.selectedIndex].value * ExtraLargeHalfBathroomRate);
//alert(totalHalfBathrooms);
	
	//alert(totalKitchens);
	//calculate pricing for Kitchens
   var totalKitchens = (document.form1.smallkitchens.options[document.form1.smallkitchens.selectedIndex].value * SmallKitchenRate) + (document.form1.mediumkitchens.options[document.form1.mediumkitchens.selectedIndex].value * MediumKitchenRate) + (document.form1.largekitchens.options[document.form1.largekitchens.selectedIndex].value * LargeKitchenRate) + (document.form1.extralargekitchens.options[document.form1.extralargekitchens.selectedIndex].value * ExtraLargeKitchenRate);
	//alert(totalKitchens);

	//calculate pricing for Living Rooms
 var totalLivingRooms = (document.form1.smalllivingrooms.options[document.form1.smalllivingrooms.selectedIndex].value * SmallLivingRoomRate) + (document.form1.mediumlivingrooms.options[document.form1.mediumlivingrooms.selectedIndex].value * MediumLivingRoomRate) + (document.form1.largelivingrooms.options[document.form1.largelivingrooms.selectedIndex].value * LargeLivingRoomRate) + (document.form1.extralargelivingrooms.options[document.form1.extralargelivingrooms.selectedIndex].value * ExtraLargeLivingRoomRate);
		//alert(totalLivingRooms);
		
		//calculate pricing for Dining Rooms
    var totalDiningRooms = (document.form1.smalldiningrooms.options[document.form1.smalldiningrooms.selectedIndex].value * SmallDiningRoomRate) + (document.form1.mediumdiningrooms.options[document.form1.mediumdiningrooms.selectedIndex].value * MediumDiningRoomRate) + (document.form1.largediningrooms.options[document.form1.largediningrooms.selectedIndex].value * LargeDiningRoomRate) + (document.form1.extralargediningrooms.options[document.form1.extralargediningrooms.selectedIndex].value * ExtraLargeDiningRoomRate);
	//alert(totalDiningRooms);
	//calculate pricing for Offices
    var totalOffices = (document.form1.smalloffices.options[document.form1.smalloffices.selectedIndex].value * SmallOfficeRate) + (document.form1.mediumoffices.options[document.form1.mediumoffices.selectedIndex].value * MediumOfficeRate) + (document.form1.largeoffices.options[document.form1.largeoffices.selectedIndex].value * LargeOfficeRate) + (document.form1.extralargeoffices.options[document.form1.extralargeoffices.selectedIndex].value * ExtraLargeOfficeRate);
	//alert(totalOffices);
	//calculate pricing for Bedrooms
    var totalBedrooms = (document.form1.smallbedrooms.options[document.form1.smallbedrooms.selectedIndex].value * SmallBedroomRate) + (document.form1.mediumbedrooms.options[document.form1.mediumbedrooms.selectedIndex].value * MediumBedroomRate) + (document.form1.largebedrooms.options[document.form1.largebedrooms.selectedIndex].value * LargeBedroomRate) + (document.form1.extralargebedrooms.options[document.form1.extralargebedrooms.selectedIndex].value * ExtraLargeBedroomRate);
	//alert(totalBedrooms);
	//calculate pricing for Windows
    var totalWindows = (document.form1.smallwindows.options[document.form1.smallwindows.selectedIndex].value * SmallWindowRate) + (document.form1.mediumwindows.options[document.form1.mediumwindows.selectedIndex].value * MediumWindowRate) + (document.form1.largewindows.options[document.form1.largewindows.selectedIndex].value * LargeWindowRate) + (document.form1.extralargewindows.options[document.form1.extralargewindows.selectedIndex].value * ExtraLargeWindowRate);
	//alert(totalWindows);
	//calculate pricing for Dogs
    var totalDogs = (document.form1.smalldogs.options[document.form1.smalldogs.selectedIndex].value * SmallDogRate) + (document.form1.mediumdogs.options[document.form1.mediumdogs.selectedIndex].value * MediumDogRate) + (document.form1.largedogs.options[document.form1.largedogs.selectedIndex].value * LargeDogRate) + (document.form1.extralargedogs.options[document.form1.extralargedogs.selectedIndex].value * ExtraLargeDogRate);
	//calculate pricing for Cats
    var totalCats = (document.form1.smallcats.options[document.form1.smallcats.selectedIndex].value * SmallCatRate) + (document.form1.mediumcats.options[document.form1.mediumcats.selectedIndex].value * MediumCatRate) + (document.form1.largecats.options[document.form1.largecats.selectedIndex].value * LargeCatRate) + (document.form1.extralargecats.options[document.form1.extralargecats.selectedIndex].value * ExtraLargeCatRate);
	//set total pet up charge
	var TotalPetUpCharge = (totalDogs + totalCats)/100;
	var FrequencyAdjustment = 0;
	
	//set the frequency adjustment
	if (document.form1.cleaningfrequency.options[document.form1.cleaningfrequency.selectedIndex].value == "Weekly") {
		var FrequencyAdjustment = WeeklyDiscount/100;
		//FrequencyAdjustment = 100;
	} 
	if (document.form1.cleaningfrequency.options[document.form1.cleaningfrequency.selectedIndex].value == "Biweekly") {
		var FrequencyAdjustment = BiWeeklyDiscount/100;
	} 
	if (document.form1.cleaningfrequency.options[document.form1.cleaningfrequency.selectedIndex].value == "Monthly") {
		var FrequencyAdjustment = MonthlyDiscount/100;
	} 
	if (document.form1.cleaningfrequency.options[document.form1.cleaningfrequency.selectedIndex].value == "OnCall") {
		var FrequencyAdjustment = OnCallDiscount/100;
	} 
	
	//set day of cleaning adjustment
	if (document.form1.dayofweek.options[document.form1.dayofweek.selectedIndex].value == "Monday") {
		var DayAdjustment = MondayDiscount/100;
	} 
	if (document.form1.dayofweek.options[document.form1.dayofweek.selectedIndex].value == "Tuesday") {
		var DayAdjustment = TuesdayDiscount/100;
	} 
	if (document.form1.dayofweek.options[document.form1.dayofweek.selectedIndex].value == "Wednesday") {
		var DayAdjustment = WednesdayDiscount/100;
	} 
	if (document.form1.dayofweek.options[document.form1.dayofweek.selectedIndex].value == "Thursday") {
		var DayAdjustment = ThursdayDiscount/100;
	} 
	if (document.form1.dayofweek.options[document.form1.dayofweek.selectedIndex].value == "Friday") {
		var DayAdjustment = FridayDiscount/100;
	} 
	if (document.form1.dayofweek.options[document.form1.dayofweek.selectedIndex].value == "Saturday") {
		var DayAdjustment = SaturdayDiscount/100;
	} 
	if (document.form1.dayofweek.options[document.form1.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.myform1.outputtext.value = totalBathrooms;
	//document.myform1.outputtext.value = SmallFullBathroomRate; */
	
	//document.form1.rate.value = "$  " + FrequencyAdjustment;
	document.form1.rate.value = "$  " + CleaningRate.toFixed(2);
	//document.form1.rate.value = "$  " + CleaningRate;
	document.form1.initialcleaningrate.value = "$  " + InitialCleaning.toFixed(2);
    
}
 