<!--

//This function checks if the start and end date entered by the user is not less than tomorrow.
function setdropDowns(MM,DD)
{
	if(getDates()==true)
	{
		endd.setFullYear(start.getFullYear(),start.getMonth()+parseInt(MM,10),start.getDate()+parseInt(DD,10)-1);
		setDates(start,endd,0);	//	!! Surprised !! 0 for non-initialization
		setperiods();
	}
}

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
			}
		}
	}
}

function questiondisplay(s)
{
	if(s=='USA')
	{
		document.form1.CountryforCoverage.value=4;
		document.getElementById("q11a").innerHTML='';
		document.getElementById("q11b").innerHTML='';
		document.getElementById("q11c").innerHTML='';
		document.form1.MailingAddress.value="AL";
		document.form1.Residence.value="AL";
	}
	else
	{
		document.form1.CountryforCoverage.value=1;
		document.getElementById("q11a").innerHTML='&nbsp;11. ';
		document.getElementById("q11b").innerHTML='If the traveler is already in USA, how long has the traveler been in USA <span class="smallFont">(Choose your latest entry to USA.)</span>';
		document.getElementById("q11c").innerHTML='<select name="USarrival" id="USarrival" onchange="priorCvgQuestion();"><option selected="selected" value="5">Not in USA yet</option><option value="6">Most recent US entry is within last 30 days</option><option value="0">Most recent US entry is within last 3 months</option><option value="1">Most recent US entry is within last 12 months</option><option value="2">Most recent US entry is within last 18 months</option><option value="3">Most recent US entry is within last 24 months</option><option value="4">Most recent US entry is more than 2 years ago</option></select>';
		document.form1.MailingAddress.value="2";
		document.form1.Residence.value="2";
	}
}

//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;
	}	
}  
//Input param - s- country code (USA, NON-USA)
function cmn_conditionalparameters()
{
	var a,s,x,d, cmn_msg;
	
	a=parseInt(document.form1.Age.value,10);
	s=parseInt(document.form1.spouseAge.value,10)?s!='':0;
	x=parseInt(document.form1.MaxPolicyLimit.value,10);
	
	if(x==75000) x=100000; 
	if(x==150000) x=250000;
	if(x==0) x=25000;
	cmn_msg = 'Please change your selection and then click "Get Quote"';
	
	d=parseInt(document.form1.Deductible.value,10);
	ct=document.form1.CountryofCitizenship.value;

	if ((a>80||s>80)&&((x >100000&&ct==1)||(x >50000&&ct==2)))
	{
		alert('For travelers who are 80 yrs and above, the maximum coverage amount has to be $25,000 or $50,000 or $100,000(US citizen and deductible $50).\n' + cmn_msg);
		 document.form1.MaxPolicyLimit.focus();
		 return false;
	}
	if ((a>70||s>70)&&((x >250000&&ct==1)||(x >100000&&ct==2)) )
	{
		alert('For travelers who are 70 yrs and above, the maximum coverage amount has to be $25,000, $50,000 or $100,000(Non-US citizen) or $250,000(US citizen).\n' + cmn_msg);
		document.form1.MaxPolicyLimit.focus(); 
		return false;
	}
	if ((a>80||s>80) && d==0 && x==50000)
	{
		alert('For all travelers who are 80 yrs and above requiring a $0 deductible, maximum policy coverage has to be $25,000.\n' + cmn_msg);
		document.form1.Deductible.focus(); 
		return false;	
	}
	if ( ((a>70&&a<80)||(s>70&&s<80)) && d==0 && x==25000)
	{
		alert('For all travelers between 70-79 yrs requiring a $0 deductible, maximum policy coverage has to be $50,000 or more.\n' + cmn_msg);
		document.form1.Deductible.focus();
		return false;
	}
	return true;
}

//-->
