var Join25="";
function checkBlank()
{
	formObj = document.form1;
	var day;
	var month;
	var year;
	if (document.form1.name.value=="")
	{
		alert("Please Enter Pensioner Name");
		document.form1.name.focus();
		return false;
	}
	
	if ((document.form1.bdate.value=="") || (document.form1.bmonth.value=="") || (document.form1.byear.value==""))
	{
		alert("Please Enter Date of Birth");
		if(document.form1.bdate.value=="")
			document.form1.bdate.focus();
		else if(document.form1.bmonth.value=="")
				document.form1.bmonth.focus();
		else
			document.form1.byear.focus();		
		return false;		
	}	
	else
		{
				day=formObj.bdate.value;  month=formObj.bmonth.value;  year=formObj.byear.value;				
						
				 if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30))
				 {
				  alert("Date of Birth : " + day + " is not a valid day for month " + month);
				  formObj.bdate.focus();
				  return(false);
				 } 
				
				 if (month == 2)
				 {
				  //---- check for leap year -----
				  if ((day > 28) && (year%4 != 0)) 
				  {
				   alert("Date of Birth : " + day + " is not a valid day for month " + month  + " of year " + year);
				   formObj.bdate.focus();      
				   return(false);
				  }
				
				  if ((day > 29) && (year%4 == 0)) 
				  {
				    alert("Date of Birth : " + day + " is not a valid day for month " + month + " of year " + year);
				    formObj.bdate.focus();
				    return(false);
				  }
				
			 }
		}	 

	if ((document.form1.jdate.value=="") || (document.form1.jmonth.value=="") || (document.form1.jyear.value==""))
	{
		alert("Please Enter Date of Joining");
		if(document.form1.jdate.value=="")
			document.form1.jdate.focus();
		else if(document.form1.jmonth.value=="")
				document.form1.jmonth.focus();
		else
			document.form1.jyear.focus();		
		return false;
	}	
	else
		{
				day=formObj.jdate.value;  month=formObj.jmonth.value; year=formObj.jyear.value;

						
				 if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30))
				 {
				  alert("Date of Joining : " + day + " is not a valid day for month " + month);
				  formObj.jdate.focus();
				  return(false);
				 } 
				
				 if (month == 2)
				 {
				  //---- check for leap year -----
				  if ((day > 28) && (year%4 != 0)) 
				  {
				   alert("Date of Joining: " + day + " is not a valid day for month " + month  + " of year " + year);
				   formObj.jdate.focus();      
				   return(false);
				  }
				
				  if ((day > 29) && (year%4 == 0)) 
				  {
				    alert("Date of Joining: " + day + " is not a valid day for month " + month + " of year " + year);
				    formObj.jdate.focus();
				    return(false);
				  }
				
			 }
		}	 


	yDate=document.form1.jdate.value;
	yMonth=document.form1.jmonth.value;
	yYear=document.form1.jyear.value;
	yYear= 25 + eval(yYear);
	
	yYear_retire= 55 + eval(document.form1.byear.value);
	
	if (yYear > yYear_retire){
		Join25="N.A.";
		window.td_image.background="bg_without25.jpg";
		document.form2.Year25.style.visibility="hidden";
		window.link_detail25.style.visibility="hidden";}
	else {
		Join25 = yDate + "/" + yMonth + "/" + yYear ;

		window.td_image.background="bg.jpg";
		document.form2.Year25.style.visibility="visible";
		window.link_detail25.style.visibility="visible";}
	
	cDate();

}

function openDetail(add)
{
leftVal = screen.width / 2 - 150;
topVal = screen.height / 2 - 42;
aa=window.open(add, "PERSONALISED_SCHEDULE_OF_EVENTS","width=500, height=286,toolbar=0,left="+leftVal+",top="+topVal+",location=0,directories=0,status=0,menubar=0,scrollbars=1,resizeable=0");
aa.document.bgColor="#CCCCCC";
aa.focus();
}

function cDate()
{

	if (document.form1.bdate.value!="")
	{
	//alert(document.form1.bmonth.value)
	if (document.form1.bmonth.value!="")
	{
		//alert("2")
	if (document.form1.byear.value!="")
	{
		//alert("3")
	yDate=document.form1.bdate.value;
	yMonth=document.form1.bmonth.value;
	yYear=document.form1.byear.value;
	document.rPrint.name.value=document.form1.pre.value + " " + document.form1.name.value;
	yYear= 60 + eval(yYear);
	actDate = yMonth + "/" + yDate + "/" + yYear ;
	

	newDOR=new Date(actDate);

	
	if (eval(newDOR.getDate())==1)
	{
	
	newDOR=newDOR.setDate(newDOR.getDate() - 1)
	newDOR=new Date(newDOR)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form1.dor.value= dor60;
	alert(dor60);
	document.rPrint.dor.value=document.form1.dor.value;
	}
	else
	{
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();

		three1=31; three0=30; feb=28;
		m=eval(newDOR.getMonth() + 1)
		y=newDOR.getFullYear()
		
		if(m==2)
		{
			if ((y%4)==0)
			{
			 feb=29;
             actDate = m + "/" + feb + "/" + y ;
			newDOR= new Date(actDate)
			dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
		 	document.form1.dor.value= dor60;
			document.rPrint.dor.value=document.form1.dor.value;
			dor60 = (eval(newDOR.getMonth()) + 1) + "/" +  newDOR.getDate() + "/" + newDOR.getFullYear();
			newDOR= new Date(dor60)
			}
			else
			{		
			feb=28;
            actDate = m + "/" + feb + "/" + y ;
			newDOR= new Date(actDate)
			dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
		 	document.form1.dor.value= dor60;
			document.rPrint.dor.value=document.form1.dor.value;
			dor60 = (eval(newDOR.getMonth()) + 1) + "/" +  newDOR.getDate() + "/" + newDOR.getFullYear();
			newDOR= new Date(dor60)
			}
		}
		else
		{
			if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
			{
			actDate = m + "/" + three1 + "/" + y ;
				newDOR= new Date(actDate)
				dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
				document.form1.dor.value= dor60;
				document.rPrint.dor.value=document.form1.dor.value;
				dor60 = (eval(newDOR.getMonth()) + 1) + "/" +  newDOR.getDate() + "/" + newDOR.getFullYear();
				newDOR= new Date(dor60)
			}
			else
			{
			actDate = m + "/" + three0 + "/" + y ;
				newDOR= new Date(actDate)
				dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
				document.form1.dor.value= dor60;
				document.rPrint.dor.value=document.form1.dor.value;
				dor60 = (eval(newDOR.getMonth()) + 1) + "/" +  newDOR.getDate() + "/" + newDOR.getFullYear();
				newDOR= new Date(dor60)
			}
											
		}
	
	}		
		

	document.form2.Year25.value=Join25;

	
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + (eval(newDOR.getFullYear()) - 5);
	document.form2.Year5.value=dor60;
	
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + (eval(newDOR.getFullYear()) - 2);
	document.form2.Year3.value=dor60;
	
	newMonth=(eval(newDOR.setMonth(newDOR.getMonth()-10)))
	newDOR=new Date(newMonth)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form2.Month10.value=dor60;
	
	newDOR= new Date(actDate)
	newMonth=(eval(newDOR.setMonth(newDOR.getMonth()-8)))
	newDOR=new Date(newMonth)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form2.Month8.value=dor60;
	
	newDOR= new Date(actDate)
	newMonth=(eval(newDOR.setMonth(newDOR.getMonth()-6)))
	newDOR=new Date(newMonth)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form2.Month6.value=dor60;
	
	newDOR= new Date(actDate)
	newMonth=(eval(newDOR.setMonth(newDOR.getMonth()-3)))
	newDOR=new Date(newMonth)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form2.Month3.value=dor60;
	
	newDOR= new Date(actDate)
	newMonth=(eval(newDOR.setMonth(newDOR.getMonth()-2)))
	newDOR=new Date(newMonth)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form2.Month2.value=dor60;
	
	newDOR= new Date(actDate)
	newMonth=(eval(newDOR.setMonth(newDOR.getMonth()-1)))
	newDOR=new Date(newMonth)
	dor60= newDOR.getDate() + "/" + (eval(newDOR.getMonth()) + 1) + "/" + newDOR.getFullYear();
	document.form2.Month1.value=dor60;
	}
	}
	}
}

function openWindow()
{
leftVal = screen.width / 2 - 402;
topVal = screen.height / 2 - 290;
aa=window.open("report.htm", "PERSONALISED_SCHEDULE_OF_EVENTS","width=790, height=450,toolbar=0,left="+leftVal+",top="+topVal+",location=0,directories=0,status=1,menubar=1,scrollbars=1");
aa.focus();
}

function reportValues()
{
alert("Please set your page size to A4 and it will require 7 sheets.")
document.report1.name.value=window.opener.document.form1.pre.value + " " + window.opener.document.form1.name.value;
document.report1.dor.value=window.opener.document.form1.dor.value;
document.detail.Year5.value=window.opener.document.form2.Year5.value;
document.detail.Year2.value=window.opener.document.form2.Year3.value;
document.detail.Month10.value=window.opener.document.form2.Month10.value;
document.detail.Month8.value=window.opener.document.form2.Month8.value;
document.detail.Month8a.value=window.opener.document.form2.Month8.value;
document.detail.Month6.value=window.opener.document.form2.Month6.value;
document.detail.Month3.value=window.opener.document.form2.Month3.value;
//document.detail.Month2.value=window.opener.document.form2.Month2.value;
//document.detail.Month1.value=window.opener.document.form2.Month1.value;
}