1.0; daychange = true; } if (hour < 0) { hour += 24; julianday -= 1.0; daychange = true; } var timeStr = hour + ":"; if (minute < 10) // i.e. only one digit timeStr += "0" + minute; else timeStr += minute; if (daychange) return timeStr + " " + calcDayFromJD(julianday); return timeStr; } //***********************************************************************///* Name: calcSun *///* Type: Main Function called by form controls *///* Purpose: calculate time of sunrise and sunset for the entered date *///* and location. In the special cases near earth's poles, *///* the date of nearest sunrise and set are reported. *///* Arguments: *///* riseSetForm : for displaying results *///* latLongForm : for reading latitude and longitude data *///* index : daylight saving yes/no select *///* index2 : city select index *///* Return value: *///* none *///* (fills riseSetForm text fields with results of calculations) *///***********************************************************************/ function calcSun(riseSetForm, latLongForm, index, index2) { if(index2 != 0) { setLatLong(latLongForm, index2); } var latitude = getLatitude(latLongForm); var longitude = getLongitude(latLongForm); var indexRS = riseSetForm.mos.selectedIndex if (isValidInput(riseSetForm, indexRS, latLongForm)) { if((latitude >= -90) && (latitude < -89.8)) { alert("Todas as latitudes entre 89.8 e 90 S\n serao corrigidas para -89.8."); latLongForm["latDeg"].value = -89.8; latitude = -89.8; } if ((latitude <= 90) && (latitude > 89.8)) { alert("Todas as latitudes entre 89.8 e 90 N\n serao corrigidas para 89.8."); latLongForm["latDeg"].value = 89.8; latitude = 89.8; } //***** Calculate the time of sunrise //*********************************************************************///**************** NEW STUFF ****** January, 2001 ****************//*********************************************************************/ var JD = (calcJD(parseFloat(riseSetForm["year"].value), indexRS + 1, parseFloat(riseSetForm["day"].value))); var dow = calcDayOfWeek(JD); var doy = calcDayOfYear(indexRS + 1, parseFloat(riseSetForm["day"].value), isLeapYear(riseSetForm["year"].value)); var T = calcTimeJulianCent(JD); //var L0 = calcGeomMeanLongSun(T); //var M = calcGeomMeanAnomalySun(T); //var e = calcEccentricityEarthOrbit(T); //var C = calcSunEqOfCenter(T); //var O = calcSunTrueLong(T); //var v = calcSunTrueAnomaly(T); //var R = calcSunRadVector(T); //var lambda = calcSunApparentLong(T); //var epsilon0 = calcMeanObliquityOfEcliptic(T); //var epsilon = calcObliquityCorrection(T); var alpha = calcSunRtAscension(T); var theta = calcSunDeclination(T); var Etime = calcEquationOfTime(T); //riseSetForm["dbug"].value = doy;//*********************************************************************/ var eqTime = Etime; var solarDec = theta; riseSetForm["eqTime"].value = (Math.floor(100*eqTime))/100; riseSetForm["solarDec"].value = (Math.floor(100*(solarDec)))/100; // Calculate sunrise for this date // if no sunrise is found, set flag nosunrise var nosunrise = false; var riseTimeGMT = calcSunriseUTC(JD, latitude, longitude); if (!isNumber(riseTimeGMT)) { nosunrise = true; } // Calculate sunset for this date // if no sunset is found, set flag nosunset var nosunset = false; var setTimeGMT = calcSunsetUTC(JD, latitude, longitude); if (!isNumber(setTimeGMT)) { nosunset = true; } var daySavings = YesNo[index].value; // = 0 (no) or 60 (yes) var zone = latLongForm["hrsToGMT"].value; if(zone > 12 || zone < -12.5) { alert("O ajuste deve estar entre -12.5 e 12. \n Assumimos 0."); zone = "0"; latLongForm["hrsToGMT"].value = zone; } if (!nosunrise) // Sunrise was found { var riseTimeLST = riseTimeGMT - (60 * zone) + daySavings; // in minutes var riseStr = timeStringShortAMPM(riseTimeLST, JD); var utcRiseStr = timeStringDate(riseTimeGMT, JD); riseSetForm["sunrise"].value = riseStr; riseSetForm["utcsunrise"].value = utcRiseStr; } if (!nosunset) // Sunset was found { var setTimeLST = setTimeGMT - (60 * zone) + daySavings; var setStr = timeStringShortAMPM(setTimeLST, JD); var utcSetStr = timeStringDate(setTimeGMT, JD); riseSetForm["sunset"].value = setStr; riseSetForm["utcsunset"].value = utcSetStr; } //