<!--

function showtextbox(n)
{
	hidetextbox();
	for(var i=0; i < n; i++)
	{
		document.getElementById("dtc"+i).innerHTML='<div class="formSmallFont">Age Child '+(i+1)+'</div><input size="2" name="dependant'+i+'" id="dependant'+i+'" onKeyPress="return numbersonly(event);" maxlength="2">';
	}
	restorevalues(n)
}

function restorevalues(d)
{
	//for(var i=0; i<d; i++)
	//	document.getElementById("dependant"+i).value = hidden[i+18]!=""?hidden[i+18]:"";
}

function hidetextbox()
{
	for(var i=0; i <= 5; i++)
		document.getElementById("dtc"+i).innerHTML='';
}

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 called on window onload
function iniForm()
{	
	setDates(stref,temp,1);
        document.form1.NumberOfChildren.value = 0;
	hidetextbox();
}

function resetform()
{
	document.form1.reset();
	temp.setFullYear(stref.getFullYear(),stref.getMonth()+1,stref.getDate()-1);
	setDates(stref,temp,1);
	questiondisplay('NONUSA');
	hidetextbox();
}

function validate()
{
	if (!validVisitorAge(document.form1))  return false;
 	if (!validSpouseAge(document.form1)) return false;
	if (!validStartDate(start, stref,document.form1)) return false;
	if (!validEndDate(endd, start,document.form1)) return false;
	if (!validMonthsOfCoverage(document.form1)) return false;
	if (!validDepChildrenAge()) return false;
	
	if(conditionalparameters())
	{
		document.form1.quote.disabled=true;
		document.form1.resetquote.disabled=true;
		if(document.form1.CountryofCitizenship.value == '1' && document.form1.CountryforCoverage.value == '1' && document.form1.Residence.value != 2)
			window.open('http://www.ztravelinsurance.com/buy/assurant-short-term-health-insurance/','_top');
		else
			document.form1.submit();
	}
}

//This function populates the contents of the tags q11a,b and c
//a - the question number on the form
//b - question to be asked to the user
//c - options from which the user can select the answer.

//Input param - s- country code (USA, NON-USA)
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='11. ';
		document.getElementById("q11b").innerHTML='If student is already in USA, how long has the student been in USA<div class="formSmallFont">Choose your latest entry to USA.</div>';
		document.getElementById("q11c").innerHTML='<select name="USarrival" size="1" onchange="priorCvgQuestion();">'+getUSArrivalHTML()+'</select>';
		document.form1.MailingAddress.value="2";
		document.form1.Residence.value="2";
	}
}

function arrivaldisplay(s)
{
	if(s.value=="4")
	{
		document.getElementById("q11a").innerHTML='';
		document.getElementById("q11b").innerHTML='';
		document.getElementById("q11c").innerHTML='';
	}
	else
	{
	        document.getElementById("q11a").innerHTML='11. ';
		document.getElementById("q11b").innerHTML='If student is already in USA, how long has the student been in USA<div class="formSmallFont">Choose your latest entry to USA.</div>';
		document.getElementById("q11c").innerHTML='<select name="USarrival" size="1" onchange="priorCvgQuestion();">'+getUSArrivalHTML()+'</select>';
	}
}

//This function displays the question for prior insurance coverage if the Non US citizen applicant/spouse's age > 65
//and seeks coverage in or including USA and arrived in the US less than 30 days ago.
function priorCvgQuestion()
{
	var age, sage, usarr, ctz, cvg;
	age = document.form1.Age.value;
	sage = document.form1.spouseAge.value;
	if (document.form1.USarrival)
		usarr = document.form1.USarrival.value;
	else
		usarr = -1;
	cvg = document.form1.CountryforCoverage.value;

	if ((age >=65 || sage >= 65) && usarr < 5 && (cvg != 4))
	{		
		var text = "<input type='radio' name='PriorCoverage' checked='checked' value='1'> Yes &nbsp; &nbsp";
		text += "<input type='radio' name='PriorCoverage' value='0'> No";
		document.getElementById("q12a").innerHTML="12.";
		document.getElementById("q12b").innerHTML= "Has the student/spouse aged 65 or more been covered by international travel insurance during the last 30 days?";
		document.getElementById("q12c").innerHTML= text;		
	}
	else
	{
		document.getElementById("q12a").innerHTML="";
		document.getElementById("q12b").innerHTML= "";
		document.getElementById("q12c").innerHTML= "";
	}
}

function 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);
	d=parseInt(document.form1.Deductible.value,10);
	
	if(x==0)x=25000;
	if(x==26000)x=60000;
	if(x==61000)x=75000; 
	if(x==76000)x=100000; 
	if(x==101000)x=499000; 	

	cmnmsg = 'Please change your selection and then click "Get Quote"';	
	ct=document.form1.CountryofCitizenship.value;

	/*if ((a>80||s>80)&&((x >100000&&ct==1)||(x >50000&&ct==2)))
	{
		alert('For students 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'+ cmnmsg);
		 document.form1.MaxPolicyLimit.focus();
		 return false;
	} */

	if ((a>79||s>79)&&(x >100000&&ct==1))
	{
		alert('For US citizens who are 80 yrs and above, the maximum coverage amount has to be $26,000 or $60,000 or $100,000 for a non-zero deductible; maximum coverage should be $25,000 or less for a $0 deductible.\n'+ cmnmsg);
		document.form1.MaxPolicyLimit.focus();
		return false;
	}

	if ((a>79||s>79)&&(x >75000&&ct==2))
	{
		alert('For Non US citizens who are 80 yrs and above, the maximum coverage has to be $26,000 or $60,000 or $75,000 for a non-zero deductible; maximum coverage should be $25,000 or less for a $0 deductible.\n'+ cmnmsg);
		 document.form1.MaxPolicyLimit.focus();
		 return false;
	}

	/*if ((a>70||s>70)&&((x >250000&&ct==1)||(x >100000&&ct==2)) )
	{
		alert('For students who are 70 yrs and above, the maximum coverage has to be $25,000, $50,000 or $100,000(Non-US citizen) or $250,000(US citizen).\n'+ cmnmsg);
		 document.form1.MaxPolicyLimit.focus(); 
		 return false;
	}*/
	if (((a>69 && a<80)||(s>69 && s<80))&& (x >1000000&&ct==1))
	{
		alert('For US citizens who are 70 yrs and above, the maximum coverage has to be $1,000,000 or less; For deductibles more than $1,000, maximum coverage has to be less than $500,000.\n'+ cmnmsg);
		 document.form1.MaxPolicyLimit.focus(); 
		 return false;
	}
	if (((a>69 && a<80)||(s>69 && s<80))&&(x >100000&&ct==2))
	{
		alert('For Non US citizens who are 70 yrs and above, the maximum coverage amount has to be $26,000, $60,000, $75,000 or $100,000.\n'+ cmnmsg);
		 document.form1.MaxPolicyLimit.focus(); 
		 return false;
	}
	if ((a>79||s>79) && d==0 && x>26000)
	{
		alert('For all students who are 80 yrs and above requiring a $0 deductible, maximum policy coverage has to be $25,000.\n'+ cmnmsg);
		 document.form1.Deductible.focus(); 
		 return false;	
	}
	if ((a>79||s>79) && d>2500 && x>26000)
	{
		alert('For all students who are 80 yrs and above requiring deductible above 2500, maximum policy coverage has to be $25,000.\n'+ cmnmsg);
		 document.form1.Deductible.focus(); 
		 return false;	
	}
	if ( ((a>69&&a<80)||(s>69&&s<80)) && d==0  && x==25000)
	{
		alert('For all students between 70-79 yrs requiring a $0 deductible, maximum policy coverage has to be $26,000 or more.\n'+ cmnmsg);
		document.form1.Deductible.focus();
		return false;
	} 
	if ( ((a>69&&a<80)||(s>69&&s<80)) && d>101 && x==25000)
	{
		alert('For all students between 70-79 yrs requiring deductible above 101, maximum policy coverage has to be $26,000 or more.\n'+ cmnmsg);
		document.form1.Deductible.focus();
		return false;
	} 	

	switch(x)
	{
		case 25000:
			if ((a<70 || s<70)&& d>101)
			{
				alert('For students younger than 70yrs, the deductible has to be $250 or less.\n'+ cmnmsg);
				document.form1.Deductible.focus(); 
				return false;	
			}
			break;
		case 60000:
			if ((a<80 || s<80)&& d>5000)
			{
				alert('For students younger than 80yrs, the deductible has to be $5000 or less.\n'+ cmnmsg);
				document.form1.Deductible.focus(); 
				return false;	
			}
			break;
		case 100000:
	  		if ((a<70 || s<70)&& d>5000)
			{
				alert('For students younger than 70yrs, the deductible has to be $5000 or less.\n'+ cmnmsg);
				document.form1.Deductible.focus(); 
				return false;	
			}
			break;

		case 499000:
			if ((a<70)&& d>5000)
			{
				alert('For students younger than 70yrs, the deductible has to be $5000 or less.\n'+ cmnmsg);
				document.form1.Deductible.focus(); 
				return false;	
			}	
			break;	
		case 500000:	  	
			if ((a<70) && d > 5000)
			{
				alert('For all students younger than 70 yrs, the deductible has to be $5000 or less\n'+ cmnmsg);
				document.form1.Deductible.focus(); 
				return false;	
			}
			break;	
	}
	return true;
}


//-->
