var countries=[['AF','Afghanistan'],['AL','Albania'],['DZ','Algeria'],['AD','Andorra'],['AO','Angola'],['AI','Anguilla'],['AG','Antigua and Barbuda'],['AR','Argentina'],['AM','Armenia'],['AW','Aruba'],['AU','Australia'],['AT','Austria'],['AZ','Azerbaijan'],['BS','Bahamas'],['BH','Bahrain'],['BD','Bangladesh'],['BB','Barbados'],['BY','Belarus'],['BE','Belgium'],['BZ','Belize'],['BJ','Benin(Rep.)'],['BM','Bermuda'],['BT','Bhutan'],['BO','Bolivia'],['BA','Bosnia Her.'],['BW','Botswana'],['BR','Brazil'],['BN','Brunei'],['BG','Bulgaria'],['BF','Burkina Faso'],['BI','Burundi'],['KH','Cambodia'],['CM','Cameroon'],['CA','Canada'],['CV','Cape Verde Islands'],['KY','Cayman Islands'],['CF','Central African Rep.'],['TD','Chad'],['CL','Chile'],['CN','China(Peoples Rep.)'],['CO','Colombia'],['KM','Comores Islands'],['CG','Congo(Brazzaville)'],['CD','Congo(Kinshasa)'],['CK','Cook Islands'],['CR','Costa Rica'],['CI','Cote d Ivoire'],['HR','Croatia'],['CU','Cuba'],['CY','Cyprus'],['CZ','Czech Rep.'],['DK','Denmark'],['DJ','Djibouti (Rep.)'],['DM','Dominica'],['DO','Dominican Rep.'],['EC','Ecuador'],['EG','Egypt (Arab Rep. of)'],['SV','El Salvador'],['GQ','Equatorial Guinea'],['ER','Eritrea'],['EE','Estonia'],['ET','Ethiopia'],['FK','Falkland Islands'],['FO','Faroe Islands'],['FJ','Fiji'],['FI','Finland'],['FR','France'],['GF','French Guiana'],['PF','French Polynesia'],['GP','French West Indies'],['MK','Fyrom'],['GA','Gabon'],['GM','Gambia'],['GE','Georgia'],['DE','Germany'],['GH','Ghana'],['GI','Gibraltar'],['GR','Greece'],['GL','Greenland'],['GD','Grenada'],['GU','Guam(Mariana Island)'],['GT','Guatemala'],['GN','Guinea (Rep. of)'],['GW','Guinea-Bissau'],['GY','Guyana'],['HT','Haiti'],['HN','Honduras'],['HK','Hong Kong (SAR), China'],['HU','Hungary'],['IS','Iceland'],['IN','India'],['ID','Indonesia'],['IR','Iran(Isl. Rep. of)'],['IQ','Iraq'],['IE','Ireland (Rep. of)'],['IL','Israel'],['IT','Italy'],['JM','Jamaica'],['JP','Japan'],['JO','Jordan'],['KZ','Kazakhstan'],['KE','Kenya'],['KI','Kiribati'],['KP','Korea(Peoples Rep.)'],['KR','Korea(Rep.)'],['KW','Kuwait'],['KG','Kyrgyzstan'],['LA','Laos'],['LV','Latvia'],['LB','Lebanon'],['LS','Lesotho'],['LR','Liberia'],['LY','Libya'],['LI','Liechtenstein'],['LT','Lithuania'],['LU','Luxembourg'],['MO','Macao (SAR), China'],['MG','Madagascar(Dem. Rep.)'],['MW','Malawi'],['MY','Malaysia'],['MV','Maldives'],['ML','Mali'],['MT','Malta'],['MH','Marshall Islands'],['MR','Mauritania'],['MU','Mauritius'],['YT','Mayotte'],['MX','Mexico'],['FM','Micronesia (Fed. St. of)'],['MD','Moldova(Rep. of)'],['MC','Monaco'],['MN','Mongolia'],['MS','Montserrat'],['MA','Morocco'],['MZ','Mozambique'],['MM','Myanmar'],['NA','Namibia'],['NR','Nauru'],['NP','Nepal'],['AN','Netherlands Antilles'],['NL','Netherlands'],['NC','New Caledonia'],['NZ','New Zealand'],['NI','Nicaragua'],['NE','Niger'],['NG','Nigeria'],['NU','Niue'],['NF','Norfolk Island'],['MP','Northern Mariana Isl.'],['NO','Norway'],['OM','Oman'],['PK','Pakistan'],['PW','Palau Islands'],['PA','Panama'],['PG','Papua New Guinea'],['PY','Paraguay'],['PE','Peru'],['PH','Philippines'],['PL','Poland'],['PT','Portugal'],['PR','Puerto Rico'],['QA','Qatar'],['RE','Reunion'],['RO','Romania'],['RU','Russian Federation'],['RW','Rwanda'],['AS','Samoa(American)'],['WS','Samoa'],['SM','San Marino'],['ST','Sao Tome & Principe'],['SA','Saudi Arabia'],['SN','Senegal'],['YU','Serbia & Montenegro'],['SC','Seychelles'],['SL','Sierra Leone'],['SG','Singapore'],['SK','Slovak Rep.'],['SI','Slovenia'],['SB','Solomon Islands'],['SO','Somalia'],['ZA','South Africa'],['ES','Spain'],['LK','Sri Lanka (Rep.)'],['KN','St.Kitts-Nevis'],['LC','St.Lucia'],['VC','St.Vincent & Grenadines'],['SD','Sudan'],['SR','Suriname'],['SZ','Swaziland'],['SE','Sweden'],['CH','Switzerland'],['SY','Syria'],['TW','Taiwan'],['TJ','Tajikistan'],['TZ','Tanzania(United Rep. of)'],['TH','Thailand'],['TL','Timor Leste'],['TG','Togo'],['TO','Tonga'],['TT','Trinidad & Tobago'],['TN','Tunisia'],['TR','Turkey'],['TM','Turkmenistan'],['TC','Turks & Caicos Isl.'],['TV','Tuvalu'],['US','U.S.A.'],['UG','Uganda'],['UA','Ukraine'],['AE','United Arab Emirates'],['GB','United Kingdom (GB)'],['UY','Uruguay'],['UZ','Uzbekistan'],['VU','Vanuatu'],['VA','Vatican City'],['VE','Venezuela'],['VN','Vietnam'],['VI','Virgin Islands (U.S.A.)'],['VG','Virgin Islands (British)'],['YE','Yemen Rep.'],['ZM','Zambia'],['ZW','Zimbabwe']];
var nationalities=[['00','Select country']].concat(countries);
var alienResidence=[['00','Select, if applicable']].concat(countries);
var departureCountry=[['00','Select country']].concat(countries);
var destinationCountries=[['00','Select country']].concat(countries);
var emChanged=false;
var popupWindow=null;

function submitVH(){
	f = document.vhForm
	if(isValid(f)){
		loc ="http://www.timaticweb.com/cgi-bin/tim_website_client.cgi?SpecData=1&HEALTH=VISA=&page=both"
		loc+="&NA="+f.NA.options[f.NA.selectedIndex].value+"&AR="+f.AR.options[f.AR.selectedIndex].value+
			"&EM="+f.EM.options[f.EM.selectedIndex].value
		loc+=f.hdnDest.value+f.hdnTrans.value+f.hdnVisi.value+"&user=AMADEB2C&subuser=QANTAS"
		if(popupWindow!=null){
		    popupWindow.close();
		}
		popupWindow=window.open(loc, null, 'width=660,height=500,resizable=yes,scrollbars=yes');
		popupWindow.focus();
	}
}

function isValid(f){
	if (f.NA.selectedIndex==-1 || f.NA.selectedIndex==0){
		alert('Please select your Nationality')
		return false}
	if (f.NA.selectedIndex==f.AR.selectedIndex){
		alert('"Nationality" and "Alien Resident of" cannot be the same country')
		return false}
	if (f.EM.selectedIndex==-1 || f.EM.selectedIndex==0){
		alert('Please select your Departure country')
		return false}
	if (f.DE.selectedIndex==-1 && f.TR.selectedIndex==-1){
		alert('Please select at least one Departure or Transit country')
		return false}
	return true
}


function clearForm(){
	f = document.vhForm;
	f.NA.selectedIndex=11;
	f.AR.selectedIndex=0;
	f.EM.selectedIndex=11;
	f.DE.selectedIndex=-1;
	f.TR.selectedIndex=-1;
	f.VT.selectedIndex=-1;
	setTypeVar();
}

function seeList(code,sel,hdn){
f = document.vhForm
fl = eval("f."+code)
errDE = "A maximum of 10 destination countries may be selected"
errTR = "A maximum of 10 transit countries may be selected"
errVT = "A maximum of 10 recently visited countries may be selected"
result =""
hdnVal="&"+code+"=00"
numSel=0
for (i=0;i<fl.length && numSel<=10;i++){
	if (fl.options[i].selected){
	    numSel++
		if (numSel==1){
			result=fl.options[i].text
			hdnVal='&'+fl.name+'='+fl.options[i].value
		}else{
			if(numSel>10){
				alert(eval("err"+code))
				result=""
				hdnVal="&"+code+"=00"
				fl.selectedIndex=null
				fl.options[0].selected=false
			}else{
				result +='\n'+fl.options[i].text
				hdnVal +='&'+fl.name+'='+fl.options[i].value
			}
		}
	}
}
eval("f."+sel+".value=result")
eval("f."+hdn+".value=hdnVal")
}

function setTypeVar(){
seeList("DE","selDest","hdnDest")
seeList("TR","selTrans","hdnTrans")
seeList("VT","selVisi","hdnVisi")
setEmbarkation()
}

function setEmbarkation(){
if(!emChanged){
	f.EM.selectedIndex = f.NA.selectedIndex}
}

function setEmChanged(){
	emChanged=true
}
