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


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

		// ---------------------------------------------
		// 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;
 			}
 			
		// =============================================
		// ---------------------------------------------
		// inputs
		// ---------------------------------------------
		// =============================================

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

			// ---------------------------------------------
			// longitude
			// ---------------------------------------------
			
			var eastWest = f.inputEastWest.options[f.inputEastWest.selectedIndex].value;
			
			data += "longitude: " + f.inputLongitude.value + " " + eastWest + "\n";

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

			data += "latitude: " + f.inputLatitude.value + " " + northSouth + "\n";
			
			// ---------------------------------------------
			// date
			// ---------------------------------------------
			
			var month = f.inputMonth.options[f.inputMonth.selectedIndex].value;

			var date = f.inputDate.options[f.inputDate.selectedIndex].value;

			var year = f.inputYear.options[f.inputYear.selectedIndex].value;
			
			data += "date: " + month + ". " + date + ", " + year + "\n";
			
			// ---------------------------------------------
			// time
			// ---------------------------------------------
			
			var amPM = f.inputAMPM.options[f.inputAMPM.selectedIndex].value;
			
			if (f.inputTime.value == '') { amPM = ''; }

			data += "time: " + f.inputTime.value + " " + amPM + "\n";

			// ---------------------------------------------
			// time basis
			// ---------------------------------------------
			
			var timeFormat = f.inputTimeFormat.options[f.inputTimeFormat.selectedIndex].innerHTML;
			
			data += "time basis: " + timeFormat + "\n";

			// ---------------------------------------------
			// time zone
			// ---------------------------------------------
			
			var timeZone = f.inputTimeZone.options[f.inputTimeZone.selectedIndex].innerHTML;
			
			data += "time zone: " + timeZone + "\n";
			
			// ---------------------------------------------
			// daylight saving time
			// ---------------------------------------------
			
			var daylightSaving = f.inputDaylight.options[f.inputDaylight.selectedIndex].innerHTML;
			
			data += "daylight saving time: " + daylightSaving + "\n";

			// ---------------------------------------------
			// elevation
			// ---------------------------------------------
			
			var elevationUnits = f.inputFeetMeters.options[f.inputFeetMeters.selectedIndex].innerHTML;
			
			if (f.inputElevation.value == '') { elevationUnits = ''; }

			data += "elevation: " + f.inputElevation.value + " " + elevationUnits + "\n";

			// ---------------------------------------------
			// zero azimuth
			// ---------------------------------------------
			
			var inputZeroAzimuth = f.inputZeroAzimuth.options[f.inputZeroAzimuth.selectedIndex].innerHTML;
			
			data += "zero azimuth: " + inputZeroAzimuth + "\n";


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

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

			// ---------------------------------------------
			// altitude angle
			// ---------------------------------------------
			
			data += "altitude angle: " + f.outputAltitude.value + "\n";

			// ---------------------------------------------
			// azimuth angle
			// ---------------------------------------------
			
			data += "azimuth angle: " + f.outputAzimuth.value + "\n";

			// ---------------------------------------------
			// declination
			// ---------------------------------------------
			
			data += "solar declination: " + f.outputDeclination.value + "\n";

			// ---------------------------------------------
			// EOT
			// ---------------------------------------------
			
			data += "equation of time: " + f.outputEOT.value + "\n";

			// ---------------------------------------------
			// clock time
			// ---------------------------------------------
			
			data += "clock time: " + f.outputClockTime.value + "\n";

			// ---------------------------------------------
			// solar time
			// ---------------------------------------------
			
			data += "solar time: " + f.outputLSOT.value + "\n";

			// ---------------------------------------------
			// hour angle
			// ---------------------------------------------
			
			data += "hour angle: " + f.outputHourAngle.value + "\n";

			// ---------------------------------------------
			// sunrise
			// ---------------------------------------------
			
			data += "time of sunrise: " + f.outputSunrise.value + "\n";

			// ---------------------------------------------
			// sunset
			// ---------------------------------------------
			
			data += "time of sunset: " + f.outputSunset.value;


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

			var eMailSubject = "SunAngle data";

			var header = "\
-----------------------------------------\n\
SunAngle Results\n\
-----------------------------------------";

			var footer = Create_Email_Footer ('SunAngle', 'sunangle');

			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);
		}
 		
