<div class="calculator_table">
<select id="calc-month">
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<select id="calc-day"></select>
<select id="calc-year"></select>
<p align="center"><button onclick="calculate();return false;">Calculate</button></p>
<div id="results"></div>
</div>
<script>
window.onload = function()
{
var npw = new Date();
var g = npw.getFullYear();
var m = npw.getMonth();
var da = npw.getDate();
for (var y = 2014; y < 2050; y++ )
{
document.getElementById('calc-year').innerHTML += '<option value="'+y+'">' + y +'</option>';
}
for (var d = 1; d <= 31; d++ )
{
document.getElementById('calc-day').innerHTML += '<option value="'+d+'">' + d +'</option>';
}
document.getElementById('calc-year').value=g;
document.getElementById('calc-month').value=m;
document.getElementById('calc-day').value=da;
}
function calculate()
{
var monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var day = Number(document.getElementById('calc-day').value);
var month = Number(document.getElementById('calc-month').value);
var year = Number(document.getElementById('calc-year').value);
var nextday = day + 280;
var initial = new Date(Date.UTC( year, month, day, 0, 0, 0));
var predicted = new Date(Date.UTC( year, month, nextday, 0, 0, 0));
var conc = new Date(Date.UTC( year, month, day+14, 0, 0, 0));
var now = new Date();
var formated = monthNames[predicted.getMonth()] + ' ' + predicted.getDate() + ', ' + predicted.getFullYear();
var leftDays = ( predicted.getTime() - now.getTime() ) / (24*3600*1000);
var currentWeeks = (now.getTime() - initial.getTime()) / (7*24*3600*1000);
var conceptionDate = monthNames[conc.getMonth()] + ' ' + conc.getDate() + ', ' + conc.getFullYear();
document.getElementById('results').innerHTML = '<p>Your estimated due date is ' + formated + '</p><p>Your Conception Date: '+conceptionDate+'</p><p>Days left to your date: '+ parseInt(leftDays) +'</p><p>Weeks of pregnancy: '+ Math.round(currentWeeks) +'</p>';
}
</script>