Наверно это:
Code
<script language="JavaScript">
<!-- Begin
function isValidDate(dateStr) {
// Date validation function courtesty of
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
// Checks for the following valid date formats:
// MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Дата введена в неправильном формате. Надо: месяц/день/год. Год - четырёхзначное число.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Значение месяца должно находиться в пределах от 1 до 12!");
return false;
}
if (day < 1 || day > 31) {
alert("Значение дня может быть от 1 до 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("В месяце "+month+" не может быть 31 дня!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("В феврале " + year + " года " + " не может быть " + day + " дней!");
return false;
}
}
return true;
}
function dispDate(dateObj) {
month = dateObj.getMonth()+1;
month = (month < 10) ? "0" + month : month;
day = dateObj.getDate();
day = (day < 10) ? "0" + day : day;
year = dateObj.getYear();
if (year < 2000) year += 1900;
return (month + "/" + day + "/" + year);
}
function pregnancyCalc(pregform) {
menstrual = new Date(); // creates new date objects
ovulation = new Date();
duedate = new Date();
today = new Date();
cycle = 0, luteal = 0; // sets variables to invalid state ==> 0
if (isValidDate(pregform.menstrual.value)) { // Validates menstual date
menstrualinput = new Date(pregform.menstrual.value);
menstrual.setTime(menstrualinput.getTime())
}
else return false; // otherwise exits
cycle = (pregform.cycle.value == "" ? 28 : pregform.cycle.value); // defaults to 28
// validates cycle range, from 22 to 45
if (pregform.cycle.value != "" && (pregform.cycle.value < 22 || pregform.cycle.value > 45)) {
alert("Продолжительность Вашего цикла либо слишком мала, либо слишком велика \n"
+ "для того, чтобы получить точный результат! Мы попробуем подсчитать даты, исходя из тех данных, что Вы ввели, но, что называется - без гарантии.");
}
luteal = (pregform.luteal.value == "" ? 14 : pregform.luteal.value); // defaults to 14
// validates luteal range, from 9 to 16
if (pregform.luteal.value != "" && (pregform.luteal.value < 9 || pregform.luteal.value > 16)) {
alert("Продолжительность лютеиновой фазы Вашего цикла либо слишком мала,\n"
+ "либо слишком велика для того, чтобы получить точный результат! Мы попробуем\n"
+ "подсчитать даты, исходя из тех данных, что Вы ввели, но, что называется -\n"
+ "без гарантии.");
}
// sets ovulation date to menstrual date + cycle days - luteal days
// the '*86400000' is necessary because date objects track time
// in milliseconds; 86400000 milliseconds equals one day
ovulation.setTime(menstrual.getTime() + (cycle*86400000) - (luteal*86400000));
pregform.conception.value = dispDate(ovulation);
// sets due date to ovulation date plus 266 days
duedate.setTime(ovulation.getTime() + 266*86400000);
pregform.duedate.value = dispDate(duedate);
// sets fetal age to 14 + 266 (pregnancy time) - time left
var fetalage = 14 + 266 - ((duedate - today) / 86400000);
weeks = parseInt(fetalage / 7); // sets weeks to whole number of weeks
days = Math.floor(fetalage % 7); // sets days to the whole number remainder
// fetal age message, automatically includes 's' on week and day if necessary
fetalage = weeks + " нед." + ", " + days + " дн.";
pregform.fetalage.value = fetalage;
return false; // form should never submit, returns false
}
// End -->
</script>
<form onsubmit="return pregnancyCalc(this);">
<table style="border-collapse: collapse;" width="600" bgcolor="#ffffff" bordercolor="#111111" cellpadding="0" cellspacing="0">
<tbody><tr><td width="615">
<p style="margin: 12px 5px 12px 10px; line-height: 120%; text-indent: 0pt; word-spacing: 0pt;" align="left"><br>
Начало последних месячных (<b>месяц</b>/день/год):
<input name="menstrual" value="" size="10" maxlength="10" type="text"> (например,
<b>12</b>/26/2001)
<br>
<br>
Средняя продолжительность цикла (дни): <input name="cycle" value="" size="3" maxlength="3" type="text">
(от 22 до 45, по умолчанию = 28)
<br>
<br>
Средняя продолжительность лютеиновой <input name="luteal" value="" size="3" maxlength="3" type="text">
(от 9 до 16, по умолчанию = 14)
<br>
фазы (<u>от овуляции до начала месячных</u>)*:<br>
</p>
<hr>
<p style="margin: 0pt; word-spacing: 0pt; line-height: 120%; text-indent: 0pt;" align="center">*
- <i>в грубом приближении - "цикл пополам", т.е среднюю
продолжительность цикла делим пополам. Более
точно можно определить с помощью измерения
базальной температуры</i></p>
<div align="center">
<hr>
<p style="margin: 0pt; word-spacing: 0pt; line-height: 120%; text-indent: 0pt;"> </p>
</div>
<div style="width: 602px; height: 122px;" align="center">
<div align="center">
<center>
</center><table width="485" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="349">
</td>
<td valign="middle" width="122" align="center">
<p style="text-indent: 0pt; margin-bottom: 18px;" align="center"><font color="#0000ff"><input value="Подсчитать!" style="color: rgb(128, 128, 0); font-weight: bold;" type="submit"></font>
</p></td>
</tr>
<tr>
<td width="349">
<p style="text-indent: 0pt; margin-left: 4px; margin-right: 4px; margin-bottom: 12px;">Предполагаемая дата
зачатия(<u>месяц</u>/день/год): </p></td>
<td valign="top" width="122" align="center">
<p align="left"><input name="conception" value="" size="16" type="text">
</p></td>
</tr>
<tr>
<td width="349">
<p style="text-indent: 0pt; margin-left: 4px; margin-right: 4px; margin-bottom: 12px;">Предполагаемая дата
родов(<u>месяц</u>/день/год): </p></td>
<td valign="top" width="122" align="center">
<input name="duedate" size="16" style="float: left;">
</td>
</tr>
<tr>
<td width="349">
<p style="text-indent: 0pt; margin-left: 4px; margin-right: 4px; margin-bottom: 12px;">Срок беременности (на
сегодняшний день):</p></td>
<td valign="top" width="122" align="center">
<input name="fetalage" size="16" style="float: left;">
</td>
</tr>
</tbody></table>