
/////////////////////////////////////////////
// e-mail-results.js
// Copyright 2006, 1995 Sustainable By Design
/////////////////////////////////////////////


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  EmailResults
	//
	/////////////////////////////////////////////////////////
	
		function EmailResults () {
		
			var f = document.theForm;

			var styleMenu = document.theForm['inputOverhangStyle'];
			
			var overhangStyle = styleMenu.options[styleMenu.selectedIndex].value;
			
		// ---------------------------------------------
		// compute outputs
		// ---------------------------------------------
 
 			if (CheckInputs ()) {
 			
 				Compute ();
 			}
 			
 			else {
 			
 				return false;
 			}
 			
		// ---------------------------------------------
		// get e-mail address
		// ---------------------------------------------
 
 			var eMail = Trim (f.eMail.value);

 			if (! Validate_Email_Address (eMail)) {
 			
 				alert ("Please enter the e-mail address to which you'd like the data to be sent, then click the SEND button. Enter a single address, with no spaces.");

				return false;
 			}

		// ---------------------------------------------
		// ensure printable output format
		// ---------------------------------------------
 
 			var outputFormat = f.inputLabels.options[f.inputLabels.selectedIndex].innerHTML;
 			
 			if (outputFormat == 'None') {
 			
 				alert ("The e-mail feature only works when the 'show values' input is not set to 'None'.  Please select a different value from that menu above, and try again.");

				return false;
 			}


		// =============================================
		// ---------------------------------------------
		// inputs
		// ---------------------------------------------
		// =============================================

			// ---------------------------------------------
			// section label
			// ---------------------------------------------
			
			var data = "\
==========\n\
INPUTS\n\
==========\n\n";

			// ---------------------------------------------
			// latitude
			// ---------------------------------------------
						
			var northSouth = f.inputNorthSouth.options[f.inputNorthSouth.selectedIndex].innerHTML;

			data += "latitude: " + f.inputLatitude.value + " deg. " + northSouth + "\n";
			
			// ---------------------------------------------
			// window height
			// ---------------------------------------------
			
			data += "window height: " + f.inputWindowHeight.value + "\n";

			// ---------------------------------------------
			// window faces
			// ---------------------------------------------
			
			var windowFaces = f.inputWindowOrientation.options[f.inputWindowOrientation.selectedIndex].innerHTML;

			data += "window faces: " + windowFaces + "\n";
			
			// ---------------------------------------------
			// horizontal overhang measurements
			// ---------------------------------------------

			if (overhangStyle == 'Horizontal') {

				// ---------------------------------------------
				// overhang spacing
				// ---------------------------------------------
				
				data += "overhang spacing: " + f.inputOverhangSpacing.value + "\n";
	
				// ---------------------------------------------
				// overhang depth
				// ---------------------------------------------
				
				data += "overhang depth: " + f.inputOverhangDepth.value + "\n";
			}

			// ---------------------------------------------
			// pitched overhang measurements
			// ---------------------------------------------

			else {

				// ---------------------------------------------
				// overhang spacing
				// ---------------------------------------------
				
				data += "overhang length: " + f.inputPitchedOverhangLength.value + "\n";

				// ---------------------------------------------
				// overhang pitch
				// ---------------------------------------------
				
				data += "overhang pitch: " + f.inputPitchedOverhangPitch.value + "\n";
	
				// ---------------------------------------------
				// space above window
				// ---------------------------------------------
				
				data += "space above window: " + f.inputPitchedOverhangHeight.value + "\n";
			}


		// =============================================
		// ---------------------------------------------
		// outputs
		// ---------------------------------------------
		// =============================================

			// ---------------------------------------------
			// section label
			// ---------------------------------------------
			
			data += "\
\n==========\n\
OUTPUTS\n\
==========\n\n";

		// ---------------------------------------------
		// output format
		// ---------------------------------------------

			data += "output displayed as: " + outputFormat + "\n";

		// ---------------------------------------------
		// if displaying data in spreadsheet format
		// ---------------------------------------------
 			
			if (f.spreadsheet.checked) {
			
				// header row
				
				data += "\nThe following data is tab-delimited, and can be copied and pasted into spreadsheets like Microsoft Excel:\n\n";
				
				for (hour = firstHour; hour <= lastHour; hour ++) {
				
					if (hour < 12) {
					
						displayHour = hour + ":00 am";
					}
					
					else {
					
						if (hour == 12) {
						
							displayHour = "12:00 noon";
						}
						
						else {
					
							displayHour = (hour - 12) + ":00 pm";
						}
					}
					
					data += "\t" + displayHour;
				}

				// data row for each month
					
				for (monthNum = 1; monthNum <= 12; monthNum ++) {
				
					monthName = months[monthNum - 1];
					
					data += "\n" + monthName;
					
					for (hour = firstHour; hour <= lastHour; hour ++) {
					
						var cellName = monthName + "_" + hour;
						
						cellData = GetDivContent (cellName);
						
						if (cellData == '&nbsp;') {
						
							cellData = '';
						}
						
						data += "\t" + cellData;
					}
				}
			}

		// ---------------------------------------------
		// if displaying data in readable format
		// ---------------------------------------------

			else {
			
				// data row for each month
					
				for (monthNum = 1; monthNum <= 12; monthNum ++) {
				
					monthName = months[monthNum - 1];
					
					data += "\n" + "----------------\n" + monthName + "\n----------------\n\n";
					
					for (hour = firstHour; hour <= lastHour; hour ++) {
						
						if (hour < 12) {
						
							displayHour = hour + ":00 am";
						}
						
						else {
						
							if (hour == 12) {
							
								displayHour = "12:00 n";
							}
							
							else {
						
								displayHour = (hour - 12) + ":00 pm";
							}
						}
						
						cellName = monthName + "_" + hour;
						
						cellData = GetDivContent (cellName);
						
						if (cellData == '&nbsp;') {
						
							cellData = '';
						}
						
						data += displayHour + ": " + cellData + "\n";
					}
				}
			}


		// ---------------------------------------------
		// create e-mail content
		// ---------------------------------------------

			var eMailSubject = "Overhang Annual Analysis data";

			var header = "\
-----------------------------------------\n\
Overhang Annual Analysis Results\n\
-----------------------------------------";

			var footer = Create_Email_Footer ('Overhang Annual Analysis', 'overhang_annual');

			var eMailBody = header + "\n\n" + data + "\n\n\n" + footer + "\n\n";

			var eMailData = eMail + "###" + eMailSubject + "###" + eMailBody;

			
		// ---------------------------------------------
		// send e-mail Ajax request
		// ---------------------------------------------

			Send_Email (eMailData);
		}
		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  AJAX_Handle_Response
	//
	/////////////////////////////////////////////////////////
	
		function AJAX_Handle_Response (response) {
		
			Send_Email_Feedback (response);
		}
 		
