function calculate()
{
var d1,m1,y1;
var sex1,datedd,datemm,dateyy;
var tday,tyear,tmon,str;

if(document.form1.sex.options[document.form1.sex.selectedIndex].value=='')
	{
		alert("Please select your gender");
		document.form1.sex.focus();
		return false;
	}

if(document.form1.days1.options[document.form1.days1.selectedIndex].value=='')
{
alert("Days cannot be left blank");
document.form1.days1.focus();
return false;
}
if(document.form1.months1.options[document.form1.months1.selectedIndex].value=='')
{
alert("Months cannot be left blank");
document.form1.months1.focus();
return false;
}
if(document.form1.years1.options[document.form1.years1.selectedIndex].value=='')
{
alert("Years cannot be left blank");
document.form1.years1.focus();
return false;
}
if(document.form1.fyf1.options[document.form1.fyf1.selectedIndex].value=='')
{
alert("Select Place of Birth");
document.form1.fyf1.focus();
return false;
}
if(document.form1.fyf2.options[document.form1.fyf2.selectedIndex].value=='')
{
alert("Select your tobacco exposure");
document.form1.fyf2.focus();
return false;
}
if(document.form1.fyf3.options[document.form1.fyf3.selectedIndex].value=='')
{
alert("Select your alcohol consumption");
document.form1.fyf3.focus();
return false;
}
if(document.form1.fyf4.options[document.form1.fyf4.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf4.focus();
return false;
}
if(document.form1.fyf5.options[document.form1.fyf5.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf5.focus();
return false;
}
if(document.form1.fyf6.options[document.form1.fyf6.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf6.focus();
return false;
}
if(document.form1.fyf7.options[document.form1.fyf7.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf7.focus();
return false;
}
if(document.form1.fyf8.options[document.form1.fyf8.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf8.focus();
return false;
}
if(document.form1.fyf9.options[document.form1.fyf9.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf9.focus();
return false;
}
if(document.form1.fyf10.options[document.form1.fyf10.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf10.focus();
return false;
}
if(document.form1.fyf11.options[document.form1.fyf11.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf11.focus();
return false;
}if(document.form1.fyf12.options[document.form1.fyf12.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf12.focus();
return false;
}if(document.form1.fyf13.options[document.form1.fyf13.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf13.focus();
return false;
}if(document.form1.fyf14.options[document.form1.fyf14.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf14.focus();
return false;
}if(document.form1.fyf15.options[document.form1.fyf15.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf15.focus();
return false;
}if(document.form1.fyf16.options[document.form1.fyf16.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf16.focus();
return false;
}if(document.form1.fyf17.options[document.form1.fyf17.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf17.focus();
return false;
}
if(document.form1.fyf18.options[document.form1.fyf18.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf18.focus();
return false;
}
if(document.form1.fyf19.options[document.form1.fyf19.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf19.focus();
return false;
}
if(document.form1.fyf20.options[document.form1.fyf20.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf20.focus();
return false;
}
if(document.form1.fyf21.options[document.form1.fyf21.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf21.focus();
return false;
}
if(document.form1.fyf22.options[document.form1.fyf22.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf22.focus();
return false;
}
if(document.form1.fyf23.options[document.form1.fyf23.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf23.focus();
return false;
}
if(document.form1.fyf24.options[document.form1.fyf24.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf24.focus();
return false;
}
if(document.form1.fyf25.options[document.form1.fyf25.selectedIndex].value=='')
{
alert("Select a option");
document.form1.fyf25.focus();
return false;
}

d1 = document.form1.days1.options[document.form1.days1.selectedIndex].value;
m1 = document.form1.months1.options[document.form1.months1.selectedIndex].value;
y1 = document.form1.years1.options[document.form1.years1.selectedIndex].value;


 var date1 = new Date();

 monthNow = date1.getMonth();
 monthNow = monthNow + 1;
 yearNow = date1.getFullYear();
 str = date1.toString();
 dateNow = str.substr(8,2);

 todate=yearNow+dateNow+monthNow;

    var yearDob = y1;
    var monthDob = m1;
    var dateDob = d1; 

var yearAge = yearNow - yearDob;


 if (monthNow >= monthDob)
        var monthAge = monthNow - monthDob;
    else {
        yearAge--;
        var monthAge = 12 + monthNow -monthDob;
    }



           if (dateNow >= dateDob)
           dateAge = dateNow - dateDob;
	   else
	   {
	   dateAge = 31 + eval(dateNow) - eval(dateDob);
           monthAge--;
             if (monthAge < 0) 
             {
             monthAge = 11;
             yearAge--; 
             }        
            }

var vsex=document.form1.sex.value;
var vfyf1=document.form1.fyf1.options[document.form1.fyf1.selectedIndex].value;
var vfyf2=document.form1.fyf2.options[document.form1.fyf2.selectedIndex].value;
var vfyf3=document.form1.fyf3.options[document.form1.fyf3.selectedIndex].value;
var vfyf4=document.form1.fyf4.options[document.form1.fyf4.selectedIndex].value;
var vfyf5=document.form1.fyf5.options[document.form1.fyf5.selectedIndex].value;
var vfyf6=document.form1.fyf6.options[document.form1.fyf6.selectedIndex].value;
var vfyf7=document.form1.fyf7.options[document.form1.fyf7.selectedIndex].value;
var vfyf8=document.form1.fyf8.options[document.form1.fyf8.selectedIndex].value;
var vfyf9=document.form1.fyf9.options[document.form1.fyf9.selectedIndex].value;
var vfyf10=document.form1.fyf10.options[document.form1.fyf10.selectedIndex].value;
var vfyf11=document.form1.fyf11.options[document.form1.fyf11.selectedIndex].value;
var vfyf12=document.form1.fyf12.options[document.form1.fyf12.selectedIndex].value;
var vfyf13=document.form1.fyf13.options[document.form1.fyf13.selectedIndex].value;
var vfyf14=document.form1.fyf14.options[document.form1.fyf14.selectedIndex].value;
var vfyf15=document.form1.fyf15.options[document.form1.fyf15.selectedIndex].value;
var vfyf16=document.form1.fyf16.options[document.form1.fyf16.selectedIndex].value;
var vfyf17=document.form1.fyf17.options[document.form1.fyf17.selectedIndex].value;
var vfyf18=document.form1.fyf18.options[document.form1.fyf18.selectedIndex].value;
var vfyf19=document.form1.fyf19.options[document.form1.fyf19.selectedIndex].value;
var vfyf20=document.form1.fyf20.options[document.form1.fyf20.selectedIndex].value;
var vfyf21=document.form1.fyf21.options[document.form1.fyf21.selectedIndex].value;
var vfyf22=document.form1.fyf22.options[document.form1.fyf22.selectedIndex].value;
var vfyf23=document.form1.fyf23.options[document.form1.fyf23.selectedIndex].value;
var vfyf24=document.form1.fyf24.options[document.form1.fyf24.selectedIndex].value;
var vfyf25=document.form1.fyf25.options[document.form1.fyf25.selectedIndex].value;

// total points 
var tot_pts=eval(vfyf2)+eval(vfyf3)+eval(vfyf4)+eval(vfyf5)+eval(vfyf6)+eval(vfyf7)+eval(vfyf8)+eval(vfyf9)+eval(vfyf10)+eval(vfyf11)+eval(vfyf12)+eval(vfyf13)+eval(vfyf14)+eval(vfyf15)+eval(vfyf16)+eval(vfyf17)+eval(vfyf18)+eval(vfyf19)+eval(vfyf20)+eval(vfyf21)+eval(vfyf22)+eval(vfyf23)+eval(vfyf24)+eval(vfyf25)+eval(vsex);

if (vsex="Female") 
{
tot_pts=eval(tot_pts) + 5;
}

// end of total points

var balance_to_live;
var expectedto_live;
if (yearAge < vfyf1)
{
expected_to_live=eval(vfyf1) - eval(yearAge);
}


if ((yearAge==vfyf1) && (tot_pts>0))
{
tot_pts=tot_pts * 0.50;
expected_to_live=eval(expected_to_live) + eval(tot_pts);
}

if ((yearAge>vfyf1) && (tot_pts>0))
{
tot_pts=tot_pts * 0.25;
expected_to_live=eval(expected_to_live) + eval(tot_pts);
}

if ((yearAge<vfyf1) && (tot_pts>0))
{
tot_pts=tot_pts * 1;
expected_to_live=eval(expected_to_live) + eval(tot_pts);
}


if ((yearAge==vfyf1) && (tot_pts<0))
{
tot_pts=tot_pts * 1.50;
expected_to_live=eval(expected_to_live) + eval(tot_pts);
}

if ((yearAge>vfyf1) && (tot_pts<0))
{
tot_pts=tot_pts * 1.25;
expected_to_live=eval(expected_to_live) + eval(tot_pts);
}

if ((yearAge<vfyf1) && (tot_pts<0))
{
tot_pts=tot_pts * 1;
expected_to_live=eval(expected_to_live) + eval(tot_pts);
}

if (yearAge > 120)
{
alert("Please Enter the Actual Date of Birth\n");
return false;
}

if (yearAge < 0)
{
alert("You are still not Born !!! \n");
alert("Do you wish to predict for your future baby \n");
return false;
}

var mox=monthAge;
if (mox==1) { mox="Jan"; } 
if (mox==2) { mox="Feb"; } 
if (mox==3) { mox="Mar"; } 
if (mox==4) { mox="Apr"; } 

if (mox==5) { mox="May"; } 
if (mox==6) { mox="Jun"; } 
if (mox==7) { mox="Jul"; } 
if (mox==8) { mox="Aug"; } 

if (mox==9)  { mox="Sep"; } 
if (mox==10) { mox="Oct"; } 
if (mox==11) { mox="Nov"; } 
if (mox==12) { mox="Dec"; } 

expected_to_live=eval(yearNow) + eval(expected_to_live);
expected_to_live=Math.round(expected_to_live,2);
live=mox+","+dateAge+","+expected_to_live+","+"12:00:00";
newwindow=window.open("time.jsp?id="+live,"my","top=150,left=150,width=488,height=198,buttons=no,scrollbars=no,location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no");     

return true;
}

