
/*TO DO
WWV timing in IE!!! -> AJAX remote scripting using perl-cgi xml
realtime solar flux activity -> Planck black body radiation from Wikipedia
UTC klok
clickable images logo
qsl.net backup

WWV after nT: recent history + short-term forecast

coronal holes + long-term forecast from http://www.solen.info/solar/

active desktop

a INDEX.  A 3-hourly "equivalent amplitude" index of local geomagnetic
          activity; "a" is related to the 3-hourly K INDEX according to
          the following scale:
 
          K    0    1    2    3    4    5    6    7    8    9
          a    0    3    7   15   27   48   80  140  240  400


A INDEX.  A daily index of geomagnetic activity derived as the average of
          the eight 3-hourly a indices.

*/
/////////////////////////////////////////////////////////////////////////////

// CH (SOHO or SXI) image loader

var CH_source="SOHO";

function SOHOsrc(aDate) {
	return "http://www.spaceweather.com/images" + year(aDate) + "/" + dd(aDate) + monthltr[month(aDate)] + yy(aDate) + "/coronalhole_soho_163.gif";
}

function SXIsrc(aDate) {
	return "http://www.spaceweather.com/images" + year(aDate) + "/" + dd(aDate) + monthltr[month(aDate)] + yy(aDate) + "/coronalhole_sxi.gif";
}

function CHerrorHandler(evt) {
  if(CH_source=="SOHO") {CH_source="SXI";}
	else if(CH_source=="SXI") {CH_source="SOHO_direct";}
	else if(CH_source=="SOHO_direct") {minus1day(CH_date); CH_source="SOHO";}
  loadCHimage();
}

function loadCHimage() {
  document.CH_image.onerror = CHerrorHandler;
  if(CH_source=="SOHO") {document.CH_image.src = SOHOsrc(CH_date);}
  else if(CH_source=="SXI") {document.CH_image.src = SXIsrc(CH_date);}
  else if(CH_source=="SOHO_direct") {document.CH_image.src = "http://umbra.nascom.nasa.gov/eit/images/latest_eit_284_thumbnail.gif";}
}

function enlargeCH()  {
  if(CH_source=="SOHO" || CH_source=="SOHO_direct") {
		enlargePic('SOHO Extreme ultraviolet Imaging Telescope Fe XV 284&Aring;', 'http://umbra.nascom.nasa.gov/eit/images/latest_eit_284.gif', 512, 512);
		}
/*
  else if(CH_source=="SXI") {
		enlargePic('GOES Solar X-ray Imager', 'http://www.sec.noaa.gov/sxi/current_sxi_4MKcorona.png', 576, 512);
		}
*/
// temporary link, waiting for GOES13 file !!!
  else if(CH_source=="SXI") {
		enlargePic('SOHO Extreme ultraviolet Imaging Telescope Fe XV 284&Aring;', 'http://umbra.nascom.nasa.gov/eit/images/latest_eit_284.gif', 512, 512);
		}
}

function writeCHlink()  {
  if(CH_source=="SOHO") {
		var CH_link="http://umbra.nascom.nasa.gov/eit/eit_full_res.html";
		var CH_link_text="SOHO";
		}
  else if(CH_source=="SXI") {
		CH_link="http://www.sec.noaa.gov/sxi/"; CH_link_text="SXI";
		}
}


// X-Ray Activity loader

function loadXrayActivity() {
  var now = new Date();
  document.xray_activity.src = "http://www.n3kl.org/sun/images/status.gif?" + now.getTime();
}


// WWV loaders

function loadWWVbroadcast() {
  var now = new Date();
  document.getElementById('wwv_iframe').src = "http://www.swpc.noaa.gov/ftpdir/latest/wwv.txt?" + now.getTime();
}


function updateWWVvalues(solar_flux, a_index, k_index) {
  document.getElementById('solar_geo_form').SF.value = solar_flux;
  document.getElementById('solar_geo_form').A.value = a_index;
  document.getElementById('solar_geo_form').K.value = k_index;
  loadGeoMagActivity(k_index);
}

function loadGeoMagActivity(k_index) {
  if(k_index < 4) {document.geomag_activity.src = "solar/geom-q.gif";}
  else if(k_index == 4) {document.geomag_activity.src = "solar/geom-u.gif";}
  else if(k_index > 4) {document.geomag_activity.src = "solar/geom-s.gif";}
  else {document.geomag_activity.src = "../transparent_dot.gif";}
}


// D-Region Absorbtion loader

function loadDregionAbsorb() {
  var now = new Date();
  document.dregion_absorb.src = "http://www.swpc.noaa.gov/dregion/dregion.gif?" + now.getTime();
}


// Solar Wind loader

function loadSolarWind() {
  var now = new Date();
  document.solarwind.src = "http://www.swpc.noaa.gov/SWN/sw_dials.gif?" + now.getTime();
}


// Aurora loader

function loadAuroras() {
  var now = new Date();
  document.aurora_north.src = "http://www.swpc.noaa.gov/pmap/gif/pmapNst.gif?" + now.getTime();
  document.aurora_south.src = "http://www.swpc.noaa.gov/pmap/gif/pmapSst.gif?" + now.getTime();
}


// MDI image loader

function MDIsrc(aDate) {return "http://www.solen.info/solar/images/AR_CH_" + year(aDate) + mm(aDate) + dd(aDate) + ".jpg";}

function MDIerrorHandler(evt) {
  minus1day(MDI_date);
  loadMDIimage();}

function loadMDIimage() {
  document.MDI_image.onerror = MDIerrorHandler;
  document.MDI_image.src = MDIsrc(MDI_date);
}


// Image load countdown counters

function minCounters() {
  var now = new Date();
  var minutes = now.getMinutes();
  var seconds = now.getSeconds();

  //minute counter updates
  var min2ReloadSWA = 4-mod(minutes,5);
  if (min2ReloadSWA === 0) {min2ReloadSWA = 5;}
  document.getElementById('solar_geo_form').min2reloadSW.value = min2ReloadSWA;
  document.getElementById('solar_geo_form').min2reloadA.value = min2ReloadSWA;

  var min2ReloadWWV = 70-minutes;
  if (minutes <= 9) {min2ReloadWWV = 10-minutes;}
  document.getElementById('solar_geo_form').min2reloadSFAK.value = min2ReloadWWV;
  document.getElementById('solar_geo_form').min2reloadWWVdata.value = min2ReloadWWV;

  //reload actions
  loadDregionAbsorb();
  if(mod(minutes,5)==4) {loadSolarWind(); loadAuroras();}
  if(minutes == 10) {callToServer(); loadWWVbroadcast(); loadXrayActivity();}
  one_minute_wait = window.setTimeout('minCounters()',(60-seconds)*1000);
}
