//=========================================================
//
// Define certain solar constants
//
//=========================================================
	solar_constant = 1366
	solar_attenuation_factor = .18
	SolarRiseSetElev = 0.8333 // Elevation at which upper limb of sun crosses horizon; corrected for solar disc size and refraction, sign reversed
	SolarFirstLastLightElev = 6// Elevation at which nautical light begins/ends, sign reversed

//=========================================================
//
// Define certain mathematical constants
//
//=========================================================
	deg2Rad = Math.PI / 180
	rad2Deg = 1 / (Math.PI / 180)
	PI_2 = 2.0 * Math.PI

//=========================================================
//
// Convert radians to degree angle
//
//=========================================================

function radToDeg(angleRad) 
	{
		return (180.0 * angleRad / Math.PI);
	}

//=========================================================
//
// Convert degree angle to radians
//
//=========================================================

	function degToRad(angleDeg) 
	{
		return (Math.PI * angleDeg / 180.0);
	}



//=========================================================
//
// Define certain unit-of-measure tags
//
//=========================================================
	if (TempUnit == '°F') {AltTempUnit = '°C'} else {AltTempUnit = '°F'}
	if (WindUnit == 'mph') {AltWindUnit = 'km/hr'} else {AltWindUnit = 'mph'}
//	if (BaroUnit == 'mb' || BaroUnit == 'hPa') {BaroUnit= 'hPa', AltBaroUnit = 'in Hg'} else {BaroUnit = 'in Hg', AltBaroUnit = 'hPa'}
//	if (PrecipUnit == 'in') {AltPrecipUnit = 'mm', PrecipUnit = 'in'} else {AltPrecipUnit = 'in'}
	if (BaroUnit == 'mb' || BaroUnit == 'hPa') {BaroUnit= ' hPa', AltBaroUnit = '” Hg'} else {BaroUnit = '” Hg', AltBaroUnit = ' hPa'}
	if (PrecipUnit == 'in') {AltPrecipUnit = ' mm', PrecipUnit = '”'} else {PrecipUnit = " mm", AltPrecipUnit = '”'}


//=========================================================
//
// Names for Months
//
//=========================================================
	MonthName = new Array(13)
	MonthName[1]  = "January"
	MonthName[2]  = "February"
	MonthName[3]  = "March"
	MonthName[4]  = "April"
	MonthName[5]  = "May"
	MonthName[6]  = "June"
	MonthName[7]  = "July"
	MonthName[8]  = "August"
	MonthName[9]  = "September"
	MonthName[10] = "October"
	MonthName[11] = "November"
	MonthName[12] = "December"

//=========================================================
//
// Names for Full moons
//
//=========================================================
	FullName = new Array(13)
	FullName[1]  = "Wolf Moon"
	FullName[2]  = "Ice Moon"
	FullName[3]  = "Storm Moon"
	FullName[4]  = "Growing Moon"
	FullName[5]  = "Hare Moon"
	FullName[6]  = "Mead Moon"
	FullName[7]  = "Hay Moon"
	FullName[8]  = "Corn Moon"
	FullName[9]  = "Harvest Moon"
	FullName[10] = "Hunter\'s Moon"
	FullName[11] = "Snow Moon"
	FullName[12] = "Winter Moon"
	
//=========================================================
//
// Number of days in each Month
//
//=========================================================
	DaysInMonth = new Array(13)
	DaysInMonth[1]  = 31
	DaysInMonth[2]  = 28
	DaysInMonth[3]  = 31
	DaysInMonth[4]  = 30
	DaysInMonth[5]  = 31
	DaysInMonth[6]  = 30
	DaysInMonth[7]  = 31
	DaysInMonth[8]  = 31
	DaysInMonth[9]  = 30
	DaysInMonth[10] = 31
	DaysInMonth[11] = 30
	DaysInMonth[12] = 31
	
//=========================================================
//
// Names for days of week
//
//=========================================================
	DayOfWeekName = new Array(8)
	DayOfWeekName[1] = "Monday"
	DayOfWeekName[2] = "Tuesday"
	DayOfWeekName[3] = "Wednesday"
	DayOfWeekName[4] = "Thursday"
	DayOfWeekName[5] = "Friday"
	DayOfWeekName[6] = "Saturday"
	DayOfWeekName[7] = "Sunday"
	

//=========================================================
//
// Truncates numeric value to specified number of decimal places, with rounding
//
//=========================================================
function setDecimal(value, places)
	{if (value < 0) {sign = "–"} else {sign = ""}
	value = Math.abs(value)
	factor = Math.pow(10, places)
	valInt = Math.round(value * factor)
	if (places == 0 && valInt == 0) {sign = ""}
	if (places == 0) {return sign + valInt}
	valStr = valInt.toString(10)
	len = valStr.length
	radix = len - places - 1
	radShift = 0
	if (radix < 0) {radShift = -radix, radix = 0}
	for (i = 0; i < radShift; i++) {valStr = "0" + valStr}
	intStr = valStr.substring(0, radix + 1)
	decStr = valStr.substring(radix + 1, len + radShift)
	valStr = sign + intStr + "." + decStr
	return valStr}
		
       
//=========================================================
//
// Adds leading zero(s)
//
//=========================================================

function PadDigits(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    } 

//=========================================================
//
// Adds leading space(s)
//
//=========================================================

function PadSpaces(n, totalSpaces) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalSpaces > n.length) 
        { 
            for (i=0; i < (totalSpaces-n.length); i++) 
            { 
                pd += ' '; 
            } 
        } 
        return pd + n.toString(); 
    } 
//=========================================================
//
// Extracts fractional value of a number
//
//=========================================================	 

function frac(X) 
	{X = X - Math.floor(X)
	if (X < 0) X = X + 1.0
	return X}

