// sunangle.js
var showedLongitudeMeridianWarning = false;
//console.log("调试");
// 检查输入功能//
function CheckInputs () {
var error = false;
var error_message = "注意!下面的输入必须予以纠正,才可以计算出太阳的角度:\n\n";
var f = document.theForm;
var inputLatitude = f.inputLatitude.value;
var inputLongitude = f.inputLongitude.value;
var inputTime = f.inputTime.value;
var inputElevation = f.inputElevation.value;
//纬度
var latitudeOkay = false;
if (inputLatitude.search ("^[0-9]+[dD][0-9]+[mM][0-9]+[sS]$") > -1) { latitudeOkay = true; }
else { if ((inputLatitude >= 0 ) && (inputLatitude <= 90)) { latitudeOkay = true; } }
if (! latitudeOkay) {
error_message = error_message + "* T纬度必须介于0到90度之间\n";
error = true;
}
// 经度
var longitudeOkay = false;
if (inputLongitude.search ("^[0-9]+[dD][0-9]+[mM][0-9]+[sS]$") > -1) { longitudeOkay = true; }
else { if ((inputLongitude >= 0 ) && (inputLongitude <= 360)) { longitudeOkay = true; } }
if (! longitudeOkay) {
error_message = error_message + "* 经度必须介于0到360度之间\n";
error = true;
}
//海拔
if ((inputElevation != '') && (inputElevation.search ("[^0-9]") > -1)) {
error_message = error_message + "* 高程仅包含数字\n";
error = true;
}
// 时间
if ((inputTime != '') && (inputTime.search ("^[0-9]+:?[0-9][0-9]$") < 0)) {
error_message = error_message + "* 时间必须是XX:XX或XXXX格式,如12点10分,填12:10或1210 \n";
error = true;
}
//警报/返回
if (error == true) { alert (error_message); }
return (! error);
}
///
// 主函数计算//
///
function compute () {
if (CheckInputs ()) {
var f = document.theForm;
//常量
var degreesToRadians = 3.1416 / 180.0000;
var radiansToDegrees = 180.0000 / 3.1416;
var degreeMinutesToDecimal = 1.0000 / 60.0000;
var degreeSecondsToDecimal = 1.0000 / 3600.0000;
// 检索输入的值
var inputLongitude = f.inputLongitude.value;
var inputEastWest = f.inputEastWest.options[f.inputEastWest.selectedIndex].text;
var inputLatitude = f.inputLatitude.value;
var inputNorthSouth = f.inputNorthSouth.options[f.inputNorthSouth.selectedIndex].text;
var inputElevation = f.inputElevation.value;
//var inputFeetMeters = f.inputFeetMeters.options[f.inputFeetMeters.selectedIndex].text;
var inputMonth = f.inputMonth.options[f.inputMonth.selectedIndex].text;
var inputDate = f.inputDate.options[f.inputDate.selectedIndex].text - 0;
var inputYear = f.inputYear.options[f.inputYear.selectedIndex].text - 0;
var inputTime = f.inputTime.value;
var inputAMPM = f.inputAMPM.options[f.inputAMPM.selectedIndex].text;
var inputTimeFormat = f.inputTimeFormat.options[f.inputTimeFormat.selectedIndex].text;
var inputTimeZone = f.inputTimeZone.options[f.inputTimeZone.selectedIndex].value - 0;
var inputZeroAzimuth = f.inputZeroAzimuth.options[f.inputZeroAzimuth.selectedIndex].value - 0;
if (inputLongitude.indexOf("d") != -1) {
degMarker = inputLongitude.indexOf("d");
minMarker = inputLongitude.indexOf("m");
secMarker = inputLongitude.indexOf("s");
longitudeDeg = inputLongitude.substr(0,degMarker) - 0;
longitudeMin = inputLongitude.substr(degMarker+1,minMarker-degMarker-1) - 0;
longitudeSec = inputLongitude.substr(minMarker+1,secMarker-minMarker-1) - 0;
inputLongitude = longitudeDeg + (longitudeMin * degreeMinutesToDecimal) + (longitudeSec * degreeSecondsToDecimal);
}
else { inputLongitude -= 0; }
if (inputLatitude.indexOf("d") != -1) {
degMarker = inputLatitude.indexOf("d");
minMarker = inputLatitude.indexOf("m");
secMarker = inputLatitude.indexOf("s");
LatitudeDeg = inputLatitude.substr(0,degMarker) - 0;
LatitudeMin = inputLatitude.substr(degMarker+1,minMarker-degMarker-1) - 0;
LatitudeSec = inputLatitude.substr(minMarker+1,secMarker-minMarker-1) - 0;
inputLatitude = LatitudeDeg + (LatitudeMin * degreeMinutesToDecimal) + (LatitudeSec * degreeSecondsToDecimal);
}
else { inputLatitude -= 0; }
//检查输入值的有效性
var validInputTime = true;
// 避免由于纬度或经度数学错误 = 0
if ((inputLatitude == 0) && (f.inputLatitude.value.length > 0)) { inputLatitude = 0.000000001; }
if ((inputLongitude == 0) && (f.inputLongitude.value.length > 0)) { inputLongitude =