<?php
// sun_information.php
// RJM Programming
// January, 2018
// Thanks to http://php.net/manual/en/function.date-sun-info.php
//
// Sun declination calculation rules below via https://sciencing.com/calculate-suns-declination-6904335.html (thanks) ...
//
// Determine how many days have passed since January 1st. For example, the number of days between January 1st and February 14th is 44.
// Add ten to the number of days passed. Write this number down. Following the example, adding 10 to 44 gives 54.
// Divide 360 by the number of days in the year. Every year has 365 days except leap years. Write this number down. From the example, 360 divided by 365 = 0.9863.
// Multiply the number from Step 2 (the approximate number of days that have passed since the winter solstice) by the amount from Step 3 (the degree of rotation per day). Write down the result. From the example, 54 times .9863 equals 53.2603.
// Find the cosine of the result from Step 4. Multiply it by -23.44, the tilt of the Earth's axis in degrees. The result is the solar declination in degrees for that day of the year. From the example, the cosine of 53.2603 is 0.5982; multiply it by -23.44 to get -14.02 degrees.

function helpforothers($elevation, $xxlat, $xxlong, $transit_time) {
  global $latd, $latm, $lats, $longd, $longm, $longs, $sun_declination, $preres, $tzis, $dateis;
  $latpos=" latitude North ";
  $longpos=" longitude East ";
  if (strpos(("" . $xxlat), "-") !== false) $latpos=" latitude South ";
  if (strpos(("" . $xxlong), "-") !== false) $longpos=" longitude West ";
  $pinfo=" ";
  $ppbits=explode("for: ", $preres);
  if (sizeof($ppbits) > 1) {
    $pinfo=" " . explode("<",$ppbits[1])[0] . " ";
  }
  
  $xzd=(($xxlat - $sun_declination));
  $zd=explode(".",("" . $xzd))[0];
  $zm=floor(($xzd - $zd) * 60.0);
  $zs=(($xzd - $zd) * 3600.0) - ($zm * 60.0);
  
  $blurb=" <h2>Position of the Sun</h2><p>On " . $dateis . " UTC" . $pinfo . "Transit Time: " . $transit_time . $latpos . $longpos . "<td class=r>" . str_replace("-","",$zd) . "&deg;" . $zm . "'&nbsp;</td>" . "<td class=r>" . str_replace("-","",$zd) . "&deg;" . $zm . "'&nbsp;</td>" . "<td class=r>" . str_replace("-","",$latd) . "&deg;" . $latm . "'&nbsp;</td>" . "<td class=r>" . str_replace("-","",$longd) . "&deg;" . $longm . "'&nbsp;</td>";
  
  if (file_exists("PHP/SunAngle/sun_angle_now_at.php")) {
    file_put_contents("PHP/SunAngle/sun_angle_data.txt", $blurb);
  } else if (file_exists("SunAngle/sun_angle_now_at.php")) {
    file_put_contents("SunAngle/sun_angle_data.txt", $blurb);
  } else if (file_exists("PHP/SunAngle/sun_angle_now_at.php")) {
    file_put_contents("PHP/SunAngle/sun_angle_data.txt", $blurb);
  } else if (file_exists("sun_angle_now_at.php")) {
    file_put_contents("sun_angle_data.txt", $blurb);
  } 
  //echo $blurb;  
}

function oururldecodeget($what) {
  global $latis, $longis, $latd, $latm, $lats, $longd, $longm, $longs;
  if (isset($_GET[$what])) {
    if ($what == "latitude") {
    $latd=explode(".",urldecode($_GET['latitude']))[0];
    $latm=floor((urldecode($_GET['latitude']) - $latd) * 60.0);
    $lats=((urldecode($_GET['latitude']) - $latd) * 3600.0) - ($latm * 60.0);
    }
    if ($what == "longitude") {
    $longd=explode(".",urldecode($_GET['longitude']))[0];
    $longm=floor((urldecode($_GET['longitude']) - $longd) * 60.0);
    $longs=((urldecode($_GET['longitude']) - $longd) * 3600.0) - ($longm * 60.0);
    }
    return urldecode($_GET[$what]);
  }
  if ($what == "latitude" && isset($_GET['latd'])) {
    $latd=explode(" ",urldecode($_GET['latd']))[0];
    $latm=0.00;
    $lats=0.00;
    if (isset($_GET['latm'])) $latm=urldecode($_GET['latm']);
    if (isset($_GET['lats'])) $lats=urldecode($_GET['lats']);
    $latis=$latd + ($latm / 60.0) + ($lats / 3600.0);
    return $latd + ($latm / 60.0) + ($lats / 3600.0);
  }
  if ($what == "place" && isset($_GET['latd'])) {
    if (strpos(urldecode($_GET['latd']), " ") !== false) {
      return str_replace(explode(" ", urldecode($_GET['latd']))[0] . " ","",urldecode($_GET['latd']));
    }
  }
  if ($what == "longitude" && isset($_GET['longd'])) {
    $longd=urldecode($_GET['longd']);
    $longm=0.00;
    $longs=0.00;
    if (isset($_GET['longm'])) $longm=urldecode($_GET['longm']);
    if (isset($_GET['longs'])) $longs=urldecode($_GET['longs']);
    $longis=$longd + ($longm / 60.0) + ($longs / 3600.0);
    return $longd + ($longm / 60.0) + ($longs / 3600.0);
  } else if ($what == "longitude" && isset($_GET['latd'])) {
    $longd=0.00;
    $longm=0.00;
    $longs=0.00;
    return 0.0000;
  }
  return "";
}

function oururldecodepost($what) {
  global $latis, $longis, $latd, $latm, $lats, $longd, $longm, $longs;
  if (isset($_POST[$what])) {
    if ($what == "latitude") {
    $latd=explode(".",urldecode($_POST['latitude']))[0];
    $latm=floor((urldecode($_POST['latitude']) - $latd) * 60.0);
    $lats=((urldecode($_POST['latitude']) - $latd) * 3600.0) - ($latm * 60.0);
    }
    if ($what == "longitude") {
    $longd=explode(".",urldecode($_POST['longitude']))[0];
    $longm=floor((urldecode($_POST['longitude']) - $longd) * 60.0);
    $longs=((urldecode($_POST['longitude']) - $longd) * 3600.0) - ($longm * 60.0);
    }
    return urldecode($_POST[$what]);
  }
  if ($what == "place" && isset($_POST['latd'])) {
    if (strpos(urldecode($_POST['latd']), " ") !== false) {
      return str_replace(explode(" ", urldecode($_POST['latd']))[0] . " ","",urldecode($_POST['latd']));
    }
  }
  if ($what == "latitude" && isset($_POST['latd'])) {
    $latd=explode(" ",urldecode($_POST['latd']))[0];
    $latm=0.00;
    $lats=0.00;
    if (isset($_POST['latm'])) $latm=urldecode($_POST['latm']);
    if (isset($_POST['lats'])) $lats=urldecode($_POST['lats']);
    $latis=$latd + ($latm / 60.0) + ($lats / 3600.0);
    return $latd + ($latm / 60.0) + ($lats / 3600.0);
  }
  if ($what == "longitude" && isset($_POST['longd'])) {
    $longd=urldecode($_POST['longd']);
    $longm=0.00;
    $longs=0.00;
    if (isset($_POST['longm'])) $longm=urldecode($_POST['longm']);
    if (isset($_POST['longs'])) $longs=urldecode($_POST['longs']);
    $longis=$longd + ($longm / 60.0) + ($longs / 3600.0);
    return $longd + ($longm / 60.0) + ($longs / 3600.0);
  } else if ($what == "longitude" && isset($_POST['latd'])) {
    $longd=0.00;
    $longm=0.00;
    $longs=0.00;
    return 0.0000;
  }
  return "";
}

function ourissetpost($what) {
  if (isset($_POST[$what])) return true;
  if (($what == "latitude" || $what == "place") && isset($_POST['latd'])) {
    if ($what == "place" && strpos(urldecode($_POST['latd']), " ") === false) return false;
    return true;
  }
  if ($what == "longitude" && isset($_POST['longd'])) return true;
  if ($what == "longitude" && isset($_POST['latd'])) return true;
  return false;
}

function ourissetget($what) {
  if (isset($_GET[$what])) return true;
  if (($what == "latitude" || $what == "place") && isset($_GET['latd'])) {
    if ($what == "place" && strpos(urldecode($_GET['latd']), " ") === false) return false;
    return true;
  }
  if ($what == "longitude" && isset($_GET['longd'])) return true;
  if ($what == "longitude" && isset($_GET['latd'])) return true;
  return false;
}

function mb($din) {
  $rdin=$din;
  $rdin=str_replace("-01-", "-January-", $rdin);
  $rdin=str_replace("-02-", "-February-", $rdin);
  $rdin=str_replace("-03-", "-March-", $rdin);
  $rdin=str_replace("-04-", "-April-", $rdin);
  $rdin=str_replace("-05-", "-May-", $rdin);
  $rdin=str_replace("-06-", "-June-", $rdin);
  $rdin=str_replace("-07-", "-July-", $rdin);
  $rdin=str_replace("-08-", "-August-", $rdin);
  $rdin=str_replace("-09-", "-September-", $rdin);
  $rdin=str_replace("-10-", "-October-", $rdin);
  $rdin=str_replace("-11-", "-November-", $rdin);
  $rdin=str_replace("-12-", "-December-", $rdin);
  return $rdin;
}

function zp($dis) {
  global $yyyy, $mnthis, $dythis, $dmol;
  $ddis=explode("-", $dis);
  if (sizeof($ddis) != 3) return $dis;
  $yyyy=$ddis[0];
  $mnthis=$ddis[1];
  $dythis=$ddis[2];
  if (strlen($ddis[1]) == 1 && strlen($ddis[2]) == 1) {
    $dmol=$ddis[0] . "-0" . $ddis[1] . "-0" . $ddis[2];
    return $dmol;
  } else if (strlen($ddis[1]) == 1) {
    $dmol=$ddis[0] . "-0" . $ddis[1] . "-" . $ddis[2];
    return $dmol;
  } else if (strlen($ddis[2]) == 1) {
    $dmol=$ddis[0] . "-" . $ddis[1] . "-0" . $ddis[2];
    return $dmol;
  }
  $dmol=$dis;
  return $dis;
}

function sun_declination($indate) {
  global $sun_declination;
  $lday=0;
  $ayear=explode("-", $indate)[0];
  $amonth=explode("-", $indate)[1];
  $adate=explode("-", $indate)[2];
  if (($ayear % 4) == 0) $lday=1;
  $sar=[0, 31, (59 + $lday), (80 + $lday), (120 + $lday), (151 + $lday), (181 + $lday), (212 + $lday), (243 + $lday), (273 + $lday), (304 + $lday), (334 + $lday)]; 
  $hmdhp=$sar[-1 + $amonth] - 1 + $adate + 10;
  $dts=(360.0 / (365 + $lday));
  $hdm=($hmdhp * $dts);
  $sun_declination=0.0 - (23.44 * cos($hdm * pi() / 180.0));
  return $sun_declination;
}

$results="";
$vis="";
$sun_declination=0.00;
$dmol="";
$ttspanfix="";

$yyyy = "yyyy";
$mnthis = "mnthis";
$dythis = "dythis";
$dateis = "2006-12-12";
$gdatenow="";
$pdatenow="";
$latis = "0.000000"; // 31.7667;
$longis = "0.000000"; //35.2333;
$tzis="GMT";
$sundecis=0.0;
$refresh="";
$resextra="";
$preres="";
$diagram="";
$ilat="0";

$latd="0";
$latm="0";
$lats="0";

$longd="0";
$longm="0";
$longs="0";

if (ourissetget('place')) {
$preres=" <input type=hidden value='" . oururldecodeget('place') . "' name=place></input> ";
} else if (ourissetpost('place')) {
$preres=" <input type=hidden value='" . oururldecodepost('place') . "' name=place></input> ";
}

if (isset($_GET['timezone'])) {
$tzis=urldecode($_GET['timezone']);
} else if (isset($_POST['timezone'])) {
$tzis=urldecode($_POST['timezone']);
} else if (ourissetget('latitude')) {
$refresh=" document.getElementById('isubmit').click(); ";
$resextra=$preres;
if (strpos($_SERVER['HTTP_REFERER'], "sun_angle_now") !== false || (!isset($_GET['mv']) && !isset($_POST['mv']))) {
  $resextra.=" <input type=hidden value=y name=beingcalled></input> ";
} else {
  $refresh="";
}
if (!isset($_GET['dmdates'])) $gdatenow=zp(date("Y-m-d"));
} else if (ourissetpost('latitude')) {
$refresh=" document.getElementById('isubmit').click(); ";
$resextra=$preres;
if (strpos($_SERVER['HTTP_REFERER'], "sun_angle_now") !== false || (!isset($_GET['mv']) && !isset($_POST['mv']))) {
  $resextra.=" <input type=hidden value=y name=beingcalled></input> ";
} else {
  $refresh="";
}
if (!isset($_POST['dmdates'])) $pdatenow=zp(date("Y-m-d"));
}

if (ourissetget('place')) {
$preres="&nbsp;&nbsp;&nbsp;  <span id=nnnspan> for: " . oururldecodeget('place') . "  </span><br>";
} else if (ourissetpost('place')) {
$preres="&nbsp;&nbsp;&nbsp;  <span id=nnnspan> for: " . oururldecodepost('place') . "  </span><br>";
}

date_default_timezone_set($tzis);

if (!isset($_GET['dmdates']) && !isset($_POST['dmdates']) && (ourissetget('latitude') || ourissetpost('latitude'))) {
  $vis=" style='display:none;'";
  //$diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah" . $ilat . "' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '></div>";
} else if (isset($_GET['beingcalled']) || isset($_POST['beingcalled'])) {
  $vis=" style='display:none;'";
  //$diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah" . $ilat . "' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '></div>";
}

if (isset($_GET['dmdates']) || $gdatenow != "") {
  if ($gdatenow != "") {
  $dateis=$gdatenow;
  } else {
  $dateis=zp(urldecode($_GET['dmdates']));
  }
  if (str_replace("now","",$dateis) == "") {
    $dateis=zp(date("Y-m-d"));
  }
  if (ourissetget('latitude') && ourissetget('longitude')) {
   $latis=oururldecodeget('latitude');
   $ilat=round($latis);
   
   
if (!isset($_GET['dmdates']) && !isset($_POST['dmdates']) && (ourissetget('latitude') || ourissetpost('latitude'))) {
  //$vis=" style='display:none;'";
  $diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '><div id='mydodah" . $ilat . "' style='height:100px; width: 100px;'><h2 class='skyandground' style='color: yellow;' id='myh2'>----&gt;<br>----&gt;<br>----&gt;</h2></div></div>";
} else if (isset($_GET['beingcalled']) || isset($_POST['beingcalled'])) {
  //$vis=" style='display:none;'";
  $diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '><div id='mydodah" . $ilat . "' style='height:100px; width: 100px;'><h2 class='skyandground' style='color: yellow;' id='myh2'>----&gt;<br>----&gt;<br>----&gt;</h2></div></div>";
} else {
  $diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '><div id='mydodah" . $ilat . "' style='height:100px; width: 100px;'><h2 class='skyandground' style='color: yellow;' id='myh2'>----&gt;<br>----&gt;<br>----&gt;</h2></div></div>";
}
   $sunaltis=(90.0 + $latis - sun_declination($dateis)); // thanks to http://www.pveducation.org/pvcdrom/properties-of-sunlight/elevation-angle
   if ($sunaltis > 90.0) $sunaltis=(180.0 - $sunaltis);
   $longis=oururldecodeget('longitude');
   $sun_info = date_sun_info(strtotime($dateis), $latis, $longis);
   $results.="<br>";
   foreach ($sun_info as $key => $val) {
    if ($key == "sunrise") {
     $results.=$preres . "&nbsp;&nbsp;&nbsp;   at (latitude, longitude): ($latis, $longis)  <br>&nbsp;&nbsp;&nbsp;   on: " . mb($dateis) . "  <br>&nbsp;&nbsp;&nbsp;   $key: " . date("H:i:s", $val) . " " . $tzis . "<br>";
    } else if ($key == "transit") {
     if (!isset($_GET['nowrite']) && !isset($_POST['nowrite'])) helpforothers($sunaltis, $latis, $longis, (date("H:i:s", $val) . " " . $tzis));
     $ttspanfix="  if (parent.document) { if (parent.document.getElementById('ttspan')) { parent.document.getElementById('ttspan').innerHTML='" . date("H:i:s", $val) . " " . $tzis . "';  }  }   ";
     $results.="&nbsp;&nbsp;&nbsp;   <a onclick=dhdf(); style=cursor:pointer;text-decoration:underline; title=Menu>" . $key . "</a>: " . date("H:i:s", $val) . " " . $tzis . " when sun is elevated at " . $sunaltis . " degrees" . $diagram . "<br>";
    } else {
     $results.="&nbsp;&nbsp;&nbsp;   $key: " . date("H:i:s", $val) . " " . $tzis . "<br>";
    }
   }
   $results.="<br>";
  }
  $yyyy=explode("-", $dateis)[0];
  $mnthis=(-1 + explode("-", $dateis)[1]);
  $dythis=explode("-", $dateis)[2];
} else if (isset($_POST['dmdates']) || $pdatenow != "") {
  if ($pdatenow != "") {
  $dateis=$pdatenow;
  } else {
  $dateis=zp(urldecode($_POST['dmdates']));
  }
  if (str_replace("now","",$dateis) == "") {
    $dateis=zp(date("Y-m-d"));
  }
  if (ourissetpost('latitude') && ourissetpost('longitude')) {
   $latis=oururldecodepost('latitude');
   $ilat=round($latis);
if (!isset($_GET['dmdates']) && !isset($_POST['dmdates']) && (ourissetget('latitude') || ourissetpost('latitude'))) {
  //$vis=" style='display:none;'";
  $diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '><div id='mydodah" . $ilat . "' style='height:100px; width: 100px;'><h2 class='skyandground' style='color: yellow;' id='myh2'>----&gt;<br>----&gt;<br>----&gt;</h2></div></div>";
} else if (isset($_GET['beingcalled']) || isset($_POST['beingcalled'])) {
  //$vis=" style='display:none;'";
  $diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '><div id='mydodah" . $ilat . "' style='height:100px; width: 100px;'><h2 class='skyandground' style='color: yellow;' id='myh2'>----&gt;<br>----&gt;<br>----&gt;</h2></div></div>";
} else {
  $diagram="<br><div class='skyandground' id='sandg' style='background-color: orange; display: block;'></div><div id='mydodah' style='background-color: ochre; display: block; height:100px; width: 100px; border-bottom: 5px solid green; '><div id='mydodah" . $ilat . "' style='height:100px; width: 100px;'><h2 class='skyandground' style='color: yellow;' id='myh2'>----&gt;<br>----&gt;<br>----&gt;</h2></div></div>";
}
   $sunaltis=(90.0 + $latis - sun_declination($dateis)); // thanks to http://www.pveducation.org/pvcdrom/properties-of-sunlight/elevation-angle
   if ($sunaltis > 90.0) $sunaltis=(180.0 - $sunaltis);
   $longis=oururldecodepost('longitude');
   $sun_info = date_sun_info(strtotime($dateis), $latis, $longis);
   $results.="<br>";
   foreach ($sun_info as $key => $val) {
    if ($key == "sunrise") {
     $results.=$preres . "&nbsp;&nbsp;&nbsp;   at (latitude, longitude): ($latis, $longis)  <br>&nbsp;&nbsp;&nbsp;   on: " . mb($dateis) . "  <br>&nbsp;&nbsp;&nbsp;   $key: " . date("H:i:s", $val) . " " . $tzis . "<br>";
    } else if ($key == "transit") {
     if (!isset($_GET['nowrite']) && !isset($_POST['nowrite'])) helpforothers($sunaltis, $latis, $longis, (date("H:i:s", $val) . " " . $tzis));
     $ttspanfix="  if (parent.document) { if (parent.document.getElementById('ttspan')) { parent.document.getElementById('ttspan').innerHTML='" . date("H:i:s", $val) . " " . $tzis . "';  }  }   ";
     $results.="&nbsp;&nbsp;&nbsp;   <a onclick=dhdf(); style=cursor:pointer;text-decoration:underline; title=Menu>" . $key . "</a>: " . date("H:i:s", $val) . " " . $tzis . " when sun is elevated at " . $sunaltis . " degrees" . $diagram . "<br>";
    } else {
     $results.="&nbsp;&nbsp;&nbsp;   $key: " . date("H:i:s", $val) . " " . $tzis . "<br>";
    }
   }
   $results.="<br>";
  }
  $yyyy=explode("-", $dateis)[0];
  $mnthis=(-1 + explode("-", $dateis)[1]);
  $dythis=explode("-", $dateis)[2];
}

echo "<!doctype><html><head>
      <title>Sun Information - RJM Programming - January, 2018 ... Thanks to http://php.net/manual/en/function.date-sun-info.php</title>
      <scrip" . "t type='text/javascript'>
           var today=new Date(); 
           var yyyy = today.getFullYear();
           var mnthis = today.getMonth();
           var dythis = today.getDate();
           var selc = 0;
           var geolocation = null;

function errorHandler(err) {
  if (err.code == 1) {
    if (1 == 2) alert('Access is denied');
  }

}

function showLocation( position ) {
  document.getElementById('latitude').value = '' + position.coords.latitude;
  document.getElementById('longitude').value = '' + position.coords.longitude;
}

function getLocation() {
  if (selc == 0) {
   selc=1;
   geolocation = navigator.geolocation;
   geolocation.getCurrentPosition(showLocation, errorHandler, {maximumAge: 75000});
  }
}
           function ol() { 
           if (parent.document) {
           if (parent.document.getElementById('nnspan')) {
           if (document.getElementById('nnnspan')) {
           if (document.getElementById('nnnspan').innerHTML.length > 0 && parent.document.getElementById('nnspan').innerHTML.length == 0) {
           document.getElementById('nnnspan').innerHTML='';
           } else if (document.getElementById('nnnspan').innerHTML.length > 0 && parent.document.getElementById('nnspan').innerHTML.length > 0) {
           if (document.getElementById('nnnspan').innerHTML.trim() != parent.document.getElementById('nnspan').innerHTML.trim()) {
           parent.document.getElementById('nnspan').innerHTML=document.getElementById('nnnspan').innerHTML;
           }           
           }
           }
           }
           }
           " . $ttspanfix . "
           var tzis='' + Intl.DateTimeFormat().resolvedOptions().timeZone;   /" . "/ Thanks to https://stackoverflow.com/questions/22618056/javascript-timezone-information-how-to-get-america-los-angeles-or-equivalent/22625076#22625076 
           if (tzis != '') {
             document.getElementById('timezone').value=tzis;
             " . $refresh . "
           }
           document.getElementById('myform').action=document.URL.split('#')[0].split('?')[0];
           var dprefix='0', mprefix='0', i, months=['','January','February','March','April','May','June','July','August','September','October','November','December'];
           for (i=eval('' + yyyy) + 1; i>(eval('' + yyyy) - 100); i--) {
             if (i == " . $yyyy . ") {
             document.getElementById('dmdates').value='' + i;
             document.getElementById('syears').innerHTML+='<option value=' + i + ' selected>' + i + '</option>';
             } else {
             document.getElementById('syears').innerHTML+='<option value=' + i + '>' + i + '</option>';
             }
           } 
           for (i=1; i<=12; i++) {
             if (eval(-1 + i) == " . $mnthis . ") {
             document.getElementById('dmdates').value+='-' + mprefix + i;
             document.getElementById('smonths').innerHTML+='<option value=' + mprefix + i + ' selected>' + months[i] + '</option>';
             } else {
             document.getElementById('smonths').innerHTML+='<option value=' + mprefix + i + '>' + months[i] + '</option>';
             }
             if (i == 9) mprefix='';
           }
           for (i=1; i<=31; i++) {
             if (i == " . $dythis . ") {
             document.getElementById('dmdates').value+='-' + mprefix + i;
             document.getElementById('sdays').innerHTML+='<option value=' + dprefix + i + ' selected>' + dprefix + i + '</option>';
             } else {
             document.getElementById('sdays').innerHTML+='<option value=' + dprefix + i + '>' + dprefix + i + '</option>';
             }
             if (i == 9) dprefix='';
           }
           getLocation();
        }
        function dc(sois) {
           if (sois.value != '') {
           var paro=null, lastc=sois.id.slice(-1);
           if (sois.id.indexOf('year') != -1) {
             paro=document.getElementById(sois.id.replace('s','dm').replace('year','date'));
             if (paro.value == '') {
               if (document.getElementById(sois.id.replace('year' + lastc,'month' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('year' + lastc,'month' + lastc)).value='01';
               }
               if (document.getElementById(sois.id.replace('year' + lastc,'day' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('year' + lastc,'day' + lastc)).value='01';
               }
             }
             paro.value=sois.value + '-' + document.getElementById(sois.id.replace('year' + lastc,'month' + lastc)).value + '-' + document.getElementById(sois.id.replace('year' + lastc,'day' + lastc)).value;
           } else if (sois.id.indexOf('month') != -1) {
             paro=document.getElementById(sois.id.replace('s','dm').replace('month','date'));
             if (paro.value == '') {
               if (document.getElementById(sois.id.replace('month' + lastc,'day' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('month' + lastc,'day' + lastc)).value='01';
               }
               if (document.getElementById(sois.id.replace('month' + lastc,'year' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('month' + lastc,'year' + lastc)).value='' + yyyy;
               }
             }
             paro.value=document.getElementById(sois.id.replace('month' + lastc,'year' + lastc)).value + '-' + sois.value + '-' + document.getElementById(sois.id.replace('month' + lastc,'day' + lastc)).value;
           } else if (sois.id.indexOf('day') != -1) {
             paro=document.getElementById(sois.id.replace('s','dm').replace('day','date'));
             if (paro.value == '') {
               if (document.getElementById(sois.id.replace('day' + lastc,'month' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('day' + lastc,'month' + lastc)).value='01';
               }
               if (document.getElementById(sois.id.replace('day' + lastc,'year' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('day' + lastc,'year' + lastc)).value='' + yyyy;
               }
             }
             paro.value=document.getElementById(sois.id.replace('day' + lastc,'year' + lastc)).value + '-' + document.getElementById(sois.id.replace('day' + lastc,'month' + lastc)).value + '-' + sois.value;
           }
           }
        }
        function checkthings() {
           return true;
        }
        function dhdf() {
          document.getElementById('dhead').style.display='block';
          document.getElementById('dfoot').style.display='block';
        }
        window.onload=ol;
 </scri" . "pt>
<style>
 .skyandground { 
 height: 70px; 
 width: 70px; 
 -moz-border-radius: 35px; 
 border-radius: 35px; 
 margin-left: 25px;
 } 
 #mydodah" . $ilat . "
 { 
 transform: rotate(" . (90 - $ilat) . "deg); 
 -ms-transform: rotate(" . (90 - $ilat) . "deg); 
 -webkit-transform: rotate(" . (90 - $ilat) . "deg); 
 } 
</style>
</head>
<body> 
<div id=dhead" . $vis . ">
<h1>Sun Information</h1>
<h3>RJM Programming <a onclick=\"location.href=document.URL.split('#')[0].split('?')[0];\" title=Start>-</a> January, 2018 ... Thanks to <a target=_blank title='http://php.net/manual/en/function.date-sun-info.php' href='http://php.net/manual/en/function.date-sun-info.php'>http://php.net/manual/en/function.date-sun-info.php</a></h3>
</div><div id=results style='border:10px solid pink;'>" . $results . "</div>
<div id=dfoot" . $vis . ">
<form style='padding: 5px 5px 5px 5px;border:3px solid green;background-color:lightgray;' id=myform onsubmit='return checkthings();' action=./sun_information.php method=POST>
Date: <input type=hidden name=dmdates id=dmdates value='" . $dmol . "'></input><select style=display:inline-flex; onchange=dc(this); id=syears><option value=''></option></select><select style=display:inline-flex; onchange=dc(this); id=smonths><option value=''></option></select><select style=display:inline-flex; onchange=dc(this); id=sdays><option value=''></option></select>  Timezone: <input type=text id=timezone name=timezone value='" . $tzis . "'></input>  Latitude: <input name='latitude' id='latitude' type='number' step='0.000000000001' value='" . $latis . "' min='-90.000000000000' max='90.000000000000'></input>  Longitude: <input name='longitude' id='longitude' type='number' step='0.000000000001' value='" . $longis . "' min='-180.000000000000' max='180.000000000000'></input><br><br>
" . $resextra . "<input id=isubmit type=submit value='Sun Information' style='background-color:yellow;'></input>
</div></body></html>";
?>
