function moneyFormat(m) {
	// Find the period if exists
	m = m.toString();
	dot = m.indexOf('.');
	if (dot > -1) {
		// Grab up to the second decimal place
		var Ma = m.substring(0,dot + 3);
		// Concantenate the two strings for money format
		m = Ma;
		return m;
	} else {return m;}
}

function calculate() {
	// Make sure they selected a height
	if (document.frmCompare.selHeight.value == 0) {
		alert('Please select a height.');
		return false;
	}
	// Make sure they selected a width
	if (document.frmCompare.selWidth.value == 0) {
		alert('Please select a width.');
		return false;
	}

	// Pull only round numbers
	var height = document.frmCompare.selHeight.value;
	var width = document.frmCompare.selWidth.value;
	// Signs made with in-house shop are always same price
	var totalMake = 3.90 * (width * height);
	// Signs purchase price to be calculated
	var totalBuy = 0;
	var perSqFt = 0;
	
	// Do calculations
	switch (height) {
		case '1':
			switch (width) {
				case '1':	// 1x1
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '2':	// 1x2
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '3':	// 1x3
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '4':	// 1x4
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '5':	// 1x5
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '6':	// 1x6
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '7':	// 1x7
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '8':	// 1x8
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '9':	// 1x9
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '10':	// 1x10
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
			}
			break;
		case '2':
			switch (width) {
				case '1':	// 2x1
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '2':	// 2x2
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '3':	// 2x3
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '4':	// 2x4
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '5':	// 2x5
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '6':	// 2x6
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '7':	// 2x7
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '8':	// 2x8
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '9':	// 2x9
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '10':	// 2x10
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
			}
			break;
		case '3':
			switch (width) {
				case '1':	// 3x1
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '2':	// 3x2
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '3':	// 3x3
					perSqFt = 17;
					totalBuy = perSqFt * (height * width);
					break;
				case '4':	// 3x4
					perSqFt = 17;
					totalBuy = perSqFt * (height * width);
					break;
				case '5':	// 3x5
					perSqFt = 15;
					totalBuy = perSqFt * (height * width);
					break;
				case '6':	// 3x6
					perSqFt = 14;
					totalBuy = perSqFt * (height * width);
					break;
				case '7':	// 3x7
					perSqFt = 13;
					totalBuy = perSqFt * (height * width);
					break;
				case '8':	// 3x8
					perSqFt = 13;
					totalBuy = perSqFt * (height * width);
					break;
				case '9':	// 3x9
					perSqFt = 13;
					totalBuy = perSqFt * (height * width);
					break;
				case '10':	// 3x10
					perSqFt = 13;
					totalBuy = perSqFt * (height * width);
					break;
			}
			break;
		case '4':
			switch (width) {
				case '1':	// 4x1
					perSqFt = 21.10;
					totalBuy = perSqFt * (height * width);
					break;
				case '2':	// 4x2
					perSqFt = 19;
					totalBuy = perSqFt * (height * width);
					break;
				case '3':	// 4x3
					perSqFt = 17;
					totalBuy = perSqFt * (height * width);
					break;
				case '4':	// 4x4
					perSqFt = 15;
					totalBuy = perSqFt * (height * width);
					break;
				case '5':	// 4x5
					perSqFt = 14;
					totalBuy = perSqFt * (height * width);
					break;
				case '6':	// 4x6
					perSqFt = 13;
					totalBuy = perSqFt * (height * width);
					break;
				case '7':	// 4x7
					perSqFt = 12;
					totalBuy = perSqFt * (height * width);
					break;
				case '8':	// 4x8
					perSqFt = 11.5;
					totalBuy = perSqFt * (height * width);
					break;
				case '9':	// 4x9
					perSqFt = 11.5;
					totalBuy = perSqFt * (height * width);
					break;
				case '10':	// 4x10
					perSqFt = 11.5;
					totalBuy = perSqFt * (height * width);
					break;
			}
			break;
		case '5':
			perSqFt = 11.5;
			totalBuy = perSqFt * (height * width);
			break;
		case '6':
			perSqFt = 11.5;
			totalBuy = perSqFt * (height * width);
			break;
		case '7':
			perSqFt = 11.5;
			totalBuy = perSqFt * (height * width);
			break;
		case '8':
			perSqFt = 11.5;
			totalBuy = perSqFt * (height * width);
			break;
		case '9':
			perSqFt = 11.5;
			totalBuy = perSqFt * (height * width);
			break;
		case '10':
			perSqFt = 11.5;
			totalBuy = perSqFt * (height * width);
			break;
	}

	// Calculate how much people would save
	var save = totalBuy - totalMake;
	
	// Repopulate input fields with actual values calculated
//	document.frmCompare.selHeight.selected = height;
//	document.frmCompare.selWidth.selected = width;

	
	// Populate calculated fields
	document.frmCompare.txtMakeIt.value = '$'+ moneyFormat(totalMake);
	document.frmCompare.txtBuyIt.value = '$'+ moneyFormat(totalBuy);
	document.frmCompare.txtSave.value = '$'+ moneyFormat(save);
	
	return;
}
