function validNumeric(val)
{
	if (String(parseInt(val)) != String(val))
		return false;	
	return true;
}

function validVisitorAge()
{
	if(document.form1.Age.value==''|| (!validNumeric(document.form1.Age.value))||
		document.form1.Age.value<1||document.form1.Age.value>99)
	{	
		alert('Visitor\'s Age is mandatory and it should be in numeric format in the range 1-99.');
		document.form1.Age.focus();
		return false;
	}
	return true;
}

function validSpouseAge()
{
	if(document.form1.spouseAge.value!=''&& (!validNumeric(document.form1.spouseAge.value)||
		document.form1.spouseAge.value<18||document.form1.spouseAge.value>99))
	{	
		alert('Spouse Age should be in numeric format in the range 18-99.');
		document.form1.spouseAge.focus();
		return false;
	}	
	return true;
}

function validStartDate(st, ref)
{
	if(getDates()==false||st < ref )
	{
		alert('Start Date should be valid and more than tommorrow\'s date.');
		document.form1.DepartureDay.focus(); 
		return false;
	}
	return true;
}

function validEndDate(ed, st)
{
	if(getDates()==false|| ed < st )
	{
		alert('End Date should be valid and more than Start Date as well as tommorrow\'s date.');
		document.form1.ReturnDay.focus(); 
		return false;
	}
	return true;
}

function validMonthsOfCoverage()
{
	if(document.form1.monthsOfCoverage.value==''||document.form1.monthsOfCoverage.value>12||
	   document.form1.monthsOfCoverage.value==12&&document.form1.daysOfCoverage.value>0||
	   document.form1.monthsOfCoverage.value==11&&document.form1.daysOfCoverage.value>30)
	{
		alert('Coverage period cannot be more than one year(12 months).'); 
		document.form1.ReturnDay.focus(); 
		return false;
	}
	return true;
}

function validDepChildrenAge()
{
	for(var i=0; i<6; i++)
	{
		if(document.getElementById("dependant"+i) != null)
		{
			if (document.getElementById("dependant"+i).value=='')
			{
				alert('Age of one or more dependant children is blank. Kindly enter.');
				return false;
			}
			if (!validNumeric(document.getElementById("dependant"+i).value))
			{
				alert('Dependendant children age has to be in the numeric format in the range 0-17');	
				return false;
			}
			if	(document.getElementById("dependant"+i).value < 0 ||document.getElementById("dependant"+i).value>18)
			{
				alert('Dependendant children age has to be in the range 0-17');	
				return false;
			}
		}
	}
	return true;
}

function validCoveragePeriod()
{
	var departureDate, daysCoverage, monthsCoverage, lDate, dDate;

	daysCoverage = document.form1.daysOfCoverage.value==""?0:parseInt(document.form1.daysOfCoverage.value,10);
	monthsCoverage = document.form1.monthsOfCoverage.value==""?0:parseInt(document.form1.monthsOfCoverage.value,10);

	departureDate = new Date();
	departureDate = addDays(1, departureDate);

	nextYear = addMonths(12, departureDate);
	dDate = addMonths(monthsCoverage,departureDate);
	lDate = addDays(daysCoverage,dDate);
	if (dateDiff(departureDate, nextYear) < dateDiff(departureDate, lDate))
	{		
		return false;
	}
	return true;
}
function cmn_conditionalparameters()
{
	var a,s,x,d,cmnmsg;
	a=document.form1.Age.value;
	s=document.form1.spouseAge.value;
	x=parseInt(document.form1.MaxPolicyLimit.value,10);
	d=parseInt(document.form1.Deductible.value,10);
	cmnmsg = 'Please change your selection and then click "Get Quote"';

	if ((a>80||s>80) && x >50000)
	{
		alert('For travelers who are 80 yrs and above, the maximum coverage amount has to be $25,000 or $50,000.\n'+ cmnmsg);
		document.form1.MaxPolicyLimit.focus(); 
		return false;
	}
	if ((a>70||s>70) && x >100000)
	{
		alert('For travelers who are 70 yrs and above, the maximum coverage amount has to be $25,000, $50,000 or $100,000.\n'+ cmnmsg);
		document.form1.MaxPolicyLimit.focus(); 
		return false;
	}
	if ((a>70||s>70)&& x!=50000 && d==0)
	{
		alert('For travelers who are 70 yrs and above requiring a $0 deductible, the maximum coverage amount has to be $50,000.\n'+ cmnmsg);
		document.form1.Deductible.focus(); 
		return false;	
	}
	if ((a<80||s<80) && d==0 && x==25000)
	{
		alert('For all travelers younger than 80 yrs requiring a $0 deductible, maximum policy coverage has to be greater than $25,000.\n'+ cmnmsg);
		document.form1.Deductible.focus(); 
		return false;
	}
	if ((a>=80||s>=80) && d==0 && x!=25000)
	{
		alert('For all travelers older than 80 yrs requiring a $0 deductible, maximum policy coverage has to be $25,000 or lower.\n'+ cmnmsg);
		document.form1.Deductible.focus(); 
		return false;	
	}
	return true;
}
