<!--
/*
  AstroCalc -- adopted from the:
  
   "Astro Utilities Electronic Book -- 
   Astronomical Algorithms for the Practicing Amateur Astronomer"
   http://www.pietro.org/Astro_Util/astro_comp_AU.htm
   (copyright 1999,2000 Pietro Carboni)
  

   copyright 2000 Pietro Carboni
*/
// Script Accessible?
function bAstroLibAlive()
{
  return true;
}

// Normalizes Value to within a range of 0 to Max 
function Normalize
(
  Value, // value to round
  Max    // max value to roll over
)
{
  return (-Max*Math.floor(Value/Max))+Value;
}

// Julian Day Count for Year 2000
var JD2000 = 2451545;

// Converts JD to Julian Centuries since J2000.0
function JCJ2000
(
 nJD  // Julian Day Count
)
{
  return (nJD - JD2000)/36525;
}


var JD1970Const = 2440587.5;  // Julian Day Count on 1970 Jan 1.
var nMilliPerDay = (1000*60*60*24);  // Milliseconds per day
// Returns Julian Day Count 
function Date2JD
(
  DtObj // Date Object
)
{// Add 1970 Day Count to Day Count Since
 return JD1970Const +(DtObj.valueOf()/nMilliPerDay);
}

// Constants for Greenwich/Local Mean Sidereal Time (GMST & LMST) functions
var GMST_A = 280.46061837;
var GMST_B = 360.98564736629;
var GMST_C = 0.000387933;
var GMST_D = 38710000;

// Convert fractional Julian Day Count to GMST (degrees)
function JD2GMST
(
  nJD // Julian Day Count
)
{
  return Normalize(
       (GMST_A + GMST_B*(nJD-JD2000)+GMST_C*Math.pow(JCJ2000(nJD),2))-Math.pow(JCJ2000(nJD),3)/GMST_D, 
                  360);
}

// Convert fractional Julian Day Count to LMST (degrees)
function JD2LMST
(
  nJD,   // Julian Day Count
  fLongWest // West Longitude as a float
)
{
  return Normalize((JD2GMST(nJD) - fLongWest),360);
}

// Constants for Degree to Time Conversion
var SecsPerHour = 60*60;

// Convert Degrees of Arc to Time Units (Right Ascension)
function Deg2TimeArray
(
  fDeg,       // degrees 
  fArHrMnSc  // array object to hold Hr:Mn:Sec
)
{
 // Restate in rounded seconds to avoid getting "60" in the seconds place
 var fTimeSc = Math.round((Normalize(fDeg, 360)/15)*SecsPerHour); // Round Seconds
 // Seconds of Time
 fArHrMnSc[2] = fTimeSc%60;
 // Minutes of Time
 fArHrMnSc[1] = ((fTimeSc - fArHrMnSc[2])/60)%60;  
 // Hours of Time (Result should be integer!)
 fArHrMnSc[0] = (fTimeSc - fArHrMnSc[2] - fArHrMnSc[1]*60)/SecsPerHour;
 
}

// -->
