// JavaScript Document
function validdate(d,m,y)
{
	if ((m == 3 || m == 5 || m == 8 || m == 10)&&d>=31)
	{
		alert('April-June-Sep-Nov months cannot have 31 days'); 
		return false;
	} /////////////////////////DATE FOR APRIL, JUNE, SEP, NOV
	else
	{
		if(m==1)			///////////////////////FEBRUARY FOR LEAP AND NON LEAP YEAR
		{
			if((  (y % 4 == 0&&y % 100 != 0)||(y % 400 == 0) )&&d > 29 )
			{
				alert('Feb in Leap year can not have more than 29 days'); 
				return false;
			}					//alert('This leap february can not have date more than 29');
			else if(((y % 4 != 0||y % 100 == 0)&&(y % 400 != 0) )&&d > 28)
			{
				alert('February in Non Leap year cannot be more than 28 days!'); 
				return false;
			} //Non Leap year but date > 28
		}
	 }
	return true;
}

function daysInMon(year, mon)
{
	var days = 31;
    if (mon == 3 || mon == 5 || mon == 8 || mon == 10)
		days = 30;					//if Apr, Jun, Sep or Nov
    else
	{	
		if (mon == 1)
		{
			if( year % 4 != 0 )days = 28;										//odd year 1997
            else days = ( year % 100 == 0 && year % 400 != 0 ) ? 28 : 29;		//even but only 1800, 1900 ... not 1600
        }
     }
    return days;
}


var one_day = 1000*60*60*24;
function deductDays(noDays, ddate)
{
	var mindeduct;
	var sdate = new Date();
	mindeduct = noDays * one_day;
	sdate.setTime(ddate.getTime() - mindeduct);
	return sdate;
}

function addDays(noDays, rdate)
{	
	var mins;
	var pDate = new Date();
	mins = noDays * one_day;
	pDate.setTime(rdate.getTime() + mins);
	return pDate;
}
function addMonths(noMonths, mdate)
{		
	var minadd;
	var fdate = new Date();
	fdate.setTime(mdate.getTime());
	for (var i=1;i<=noMonths;i++)
	{		
		minadd = daysInMon(fdate.getYear(), fdate.getMonth()) * one_day;
		fdate.setTime(fdate.getTime() + minadd);
	}
	return fdate;
}

function dateDiff(bdate, edate)
{
	return Math.ceil((edate.getTime()-bdate.getTime())/one_day);
}


