<!--

//This function checks if the start and end date entered by the user is not less than tomorrow.
function testdropdown()
{
	if(getDates()==true)
	{
		if(start < stref)
		{
			document.form1.DepartureDay.focus();
			alert('Start Date cannot be less than tommorrow.'); 
			return false;
		}
	 	if(endd < stref)
		{
			document.form1.ReturnDay.focus();
			alert('Start or End Date cannot be less than tommorrow.');
			return false;
		}
	}
	return true;
}


function Difference(lastDay)
{
	YY = MM = DD = 0; 
	var lastDaySize=lastDay==false?0:1;
	if(testdropdown()==true)
	{
		temp.setFullYear(endd.getFullYear(),endd.getMonth(),endd.getDate()+lastDaySize);
		var sd=start.getDate(),sm=start.getMonth(),sy=start.getFullYear(),ed=temp.getDate(),em=temp.getMonth(),ey=temp.getFullYear();	
		if(ey==sy)
		{
			if(em==sm) 
				DD=ed-sd;		// Same Year and same Month and  end-date is more the start :: if end-date is less than start then alert !
			else
			{
				if(ed >= sd)
				{
					MM=em-sm; DD=ed-sd;
				}				// Same Year and different-greater Month and end-date is more
				else
				{
					MM=em-sm-1;
					//DD=daysInMon(sy,sm)-sd+ed;
					DD=daysInMon(ey,(em-1))-sd+ed;
				}	// Same Year and diff Month and end-date is less
			}
		}
		else
		{
			if(em>sm)
			{
				YY=ey-sy;
				if(ed >= sd)
				{
					MM=em-sm+YY*12;	
					DD=ed-sd;
				}			// Different Year, different-greater Month and end-date is more
				else
				{
					MM=em-sm+YY*12-1; 
					//DD=daysInMon(sy,sm)-sd+ed;
					DD=daysInMon(ey,(em-1))-sd+ed;
				}// Different Year, different-greater Month and end-date is less
			  
			}
			else
			{
				YY=ey-sy-1;
				if(ed >= sd)
				{
					MM=12-sm+em+YY*12;
					DD=ed-sd;
				}			// Different Year, different-lesser Month and end-date is more
				else
				{
					MM=12-sm+em+YY*12-1; 
					//DD=daysInMon(sy,sm)-sd+ed;
					DD=daysInMon(ey,(em-1))-sd+ed;
				}	// Different Year, different-lesser Month and end-date is less
			}
		}
	}
}

//This functions sets the number of days and months in the textboxes monthsOfCoverage and daysOfCoverage
//depending on the month and days selected in the start date, end date combo box
function setperiods()				// Nothing returns
{
		Difference(false);
		DD++;
	
		if(DD==endd.getDate()&&endd.getDate()==daysInMon(endd.getFullYear(),endd.getMonth()))
		{MM++;DD=0;}//any 1st-->any last date
		else if(start.getDate()==endd.getDate()+1)
		{MM++;DD=0;}
		else if(start.getMonth()!=endd.getMonth()&&DD>daysInMon(endd.getFullYear(),endd.getMonth()))
		{MM++;DD=0;}
		
		if(start.getDate()==31&&endd.getDate()!=31)
		{
			if(endd.getDate()==daysInMon(endd.getFullYear(),endd.getMonth()))
			{DD=1;}//endd is last date as 28, 29, 30
			else if(DD==daysInMon(endd.getFullYear(),endd.getMonth()))
			{MM++;DD=0;}		//DD is more than daysInMonth(endd)
		}

		if(MM>=0 && DD>=0)
		{		
			if(MM>12||MM==11&&DD>30||MM==12&&DD>0)
			{
				alert('Coverage period cannot be more than one year(12 months).'); 
				document.form1.ReturnDay.focus();
			}
		
			document.form1.monthsOfCoverage.value=MM;
			document.form1.daysOfCoverage.value=DD; 
		}
}

//function called on window onload
//This function sets the start and the end date from the departure date and return date
//entered by the user
function getDates()
{
	var frmdd,frmmm,frmyy,todd,tomm,toyy;

	frmdd=document.form1.DepartureDay[document.form1.DepartureDay.selectedIndex].value;
	frmmm=document.form1.DepartureMonth[document.form1.DepartureMonth.selectedIndex].value-1;
	frmyy=document.form1.DepartureYear[document.form1.DepartureYear.selectedIndex].value;
	todd=document.form1.ReturnDay[document.form1.ReturnDay.selectedIndex].value;
	tomm=document.form1.ReturnMonth[document.form1.ReturnMonth.selectedIndex].value-1;
	toyy=document.form1.ReturnYear[document.form1.ReturnYear.selectedIndex].value;
	//alert('Start--'+start.getDate()+':'+start.getMonth()+':'+start.getFullYear()+'\nEnd--'+endd.getDate()+':'+endd.getMonth()+':'+endd.getFullYear());
	if(validdate(frmdd,frmmm,frmyy)==false)
		return false;
	else
	{start.setFullYear(frmyy,frmmm,frmdd);}
	if(validdate(todd,tomm,toyy)==false)
		return false;
	else
	{endd.setFullYear(toyy,tomm,todd);}
	 return true;
} //end of function

//This function sets the departure date and return date from the start and the end date.
//s - start date
//e - end date
//ini - 1 if called from the iniForm function and 0 otherwise
function setDates(s,e,ini)
{
	document.form1.DepartureYear.value=s.getFullYear();
	document.form1.DepartureMonth.value=s.getMonth()+1;
	document.form1.DepartureDay.value=s.getDate();
	document.form1.ReturnYear.value=e.getFullYear();
	document.form1.ReturnMonth.value=e.getMonth()+1;
	document.form1.ReturnDay.value=e.getDate();
	if(ini==1)
	{
		document.form1.monthsOfCoverage.value = 1;
		document.form1.daysOfCoverage.value = 0;
	}	
}  


//-->
