/* author: aviveltz@yahoo.com */
/* Generated by AceHTML Freeware http://freeware.acehtml.com */
/* Creation date: 8/8/2005 */


//---------------------------------------------------
function isValidDate(dateStr) {
// Date validation function courtesty of 
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

// Checks for the following valid date formats:
// DD/MM/YYYY  DD-MM-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;
}
day = matchArray[1]; // parse date into variables
month = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("החודש חייב להיות בין  12 - 1");
return false;
}
if (day < 1 || day > 31) {
alert("היום חייב להיות בין  31 - 1");
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 convertDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
var matchArray = dateStr.match(datePat); // is the format ok?

// parse date into variables
day   = matchArray[1]; 
month = matchArray[3];
year  = matchArray[4];

return (month + "/" + day + "/" + year);
}

//---------------------------------------------------
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);
return (day + "/" + month + "/" + year);
}

//---------------------------------------------------
/*
function pregnancyCalc(pregform) {

// creates new date objects
menstrual = new Date(); 
duedate = new Date(); 
ovulation = new Date();
today = new Date();
posibleStart = new Date();
posibleEnd = new Date();
optimalStart = new Date();
optimalEnd = new Date();
cycle = 0, luteal = 0; // sets variables to invalid state ==> 0


cycle = 28;


luteal = 14;



if (pregform.calc[0].checked == true ) 
{
   if (isValidDate(pregform.menstrual.value))
   { // Validates menstual date 
      menstrualinput = new Date(convertDate(pregform.menstrual.value));
      menstrual.setTime(menstrualinput.getTime())

      duedate.setTime(menstrualinput.getTime() + (280*86400000));
      pregform.duedate.value = dispDate(duedate);

     // 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.ovulation.value = dispDate(ovulation);  
   }
   else {return false}
}

else  if ( pregform.calc[1].checked == true ) 
{
   if (isValidDate(pregform.ovulation.value))
   { // Validates date 
      ovulationinput = new Date(convertDate(pregform.ovulation.value));
      ovulation.setTime(ovulationinput.getTime());

      menstrual.setTime(ovulationinput.getTime() - (cycle*86400000) + (luteal*86400000));
      pregform.menstrual.value = dispDate(menstrual);	
	  
      duedate.setTime(ovulationinput.getTime() - (cycle*86400000) + (luteal*86400000) + (280*86400000));
      pregform.duedate.value = dispDate(duedate);	    
   }
   else {return false}   
}

else  if ( pregform.calc[2].checked == true ) 
{
   if (isValidDate(pregform.duedate.value))
   { // Validates date 
      duedateinput = new Date(convertDate(pregform.duedate.value));
      duedate.setTime(duedateinput.getTime())
	  
      menstrual.setTime(duedateinput.getTime() - (280*86400000));
      pregform.menstrual.value = dispDate(menstrual);	  

     // 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.ovulation.value = dispDate(ovulation);  	  
   }
   else {return false}   
}




// the '*86400000' is necessary because date objects track time
// in milliseconds;  86400000 milliseconds equals one day
posibleStart.setTime(duedate.getTime() - (91*86400000));
posibleEnd.setTime(duedate.getTime() - (55*86400000));
pregform.posible.value = dispDate(posibleEnd) + ' - ' + dispDate(posibleStart);

optimalStart.setTime(duedate.getTime() - (84*86400000));
optimalEnd.setTime(duedate.getTime() - (66*86400000));
pregform.optimal.value = dispDate(optimalEnd) + ' - ' + dispDate(optimalStart);


// 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
fetalage = weeks + " שבוע" + (weeks > 1 ? "ות" : "") + ", " + days + " ימים";
pregform.fetalage.value = fetalage;


var image = new Array()


image[0] =	'<?php echo $row[pic1]; ?>'
image[1] =	'2.jpg'
image[2] =	'3.jpg'
image[3] =	'4.jpg'
image[4] =	'5.jpg'
image[5] =	'6.jpg'
image[6] =	'7.jpg'
image[7] =	'<?php echo "fsdsasfs"; ?>'
image[8] =	'9.jpg'
image[9] =	'10.jpg'
image[10] =	'11.jpg'

pregform.image.value = image[weeks]

//Specify the fetal weight 
var fetalWeight = new Array()

fetalWeight[0]=	0
fetalWeight[1]=	0
fetalWeight[2]=	0
fetalWeight[3]=	0
fetalWeight[4]=	0
fetalWeight[5]=	0
fetalWeight[6]=	0
fetalWeight[7]=	0
fetalWeight[8]=	1
fetalWeight[9]=	3
fetalWeight[10]=5
fetalWeight[11]=12.5
fetalWeight[12]=20
fetalWeight[13]=40
fetalWeight[14]=60
fetalWeight[15]=90
fetalWeight[16]=120
fetalWeight[17]=170
fetalWeight[18]=220
fetalWeight[19]=275
fetalWeight[20]=330
fetalWeight[21]=395
fetalWeight[22]=460
fetalWeight[23]=545
fetalWeight[24]=650
fetalWeight[25]=750
fetalWeight[26]=850
fetalWeight[27]=975
fetalWeight[28]=1100
fetalWeight[29]=1260
fetalWeight[30]=1420
fetalWeight[31]=1585
fetalWeight[32]=1750
fetalWeight[33]=1915
fetalWeight[34]=2080
fetalWeight[35]=2250
fetalWeight[36]=2420
fetalWeight[37]=2660
fetalWeight[38]=2900
fetalWeight[39]=3075
fetalWeight[40]=3250
fetalWeight[41]=3420

pregform.fetalWeight.value = fetalWeight[weeks] + ' גרם '
//Specify the fetal length
var fetalLength =new Array()
fetalLength[0]=	0
fetalLength[1]=	0
fetalLength[2]=	0
fetalLength[3]=	0
fetalLength[4]=	0
fetalLength[5]=	0
fetalLength[6]=	1
fetalLength[7]=	2.5
fetalLength[8]=	4
fetalLength[9]=	5
fetalLength[10]=6
fetalLength[11]=7.5
fetalLength[12]=9
fetalLength[13]=11.5
fetalLength[14]=12
fetalLength[15]=14
fetalLength[16]=16
fetalLength[17]=18
fetalLength[18]=20
fetalLength[19]=22.5
fetalLength[20]=25
fetalLength[21]=26.5
fetalLength[22]=28
fetalLength[23]=29
fetalLength[24]=30
fetalLength[25]=31
fetalLength[26]=32
fetalLength[27]=33.5
fetalLength[28]=35
fetalLength[29]=36.5
fetalLength[30]=38
fetalLength[31]=39
fetalLength[32]=40
fetalLength[33]=41
fetalLength[34]=42
fetalLength[35]=43.5
fetalLength[36]=45
fetalLength[37]=46.5
fetalLength[38]=48
fetalLength[39]=49
fetalLength[40]=50
fetalLength[41]=51

pregform.fetalLength.value = fetalLength[weeks] + ' ס"מ '


return false; // form should never submit, returns false
}*/
//---------------------------------------------------