function object(id)
{
	if(document.getElementById)//Netscap test
	{	
		if(document.forms[0].elements[id])
		{	
			return document.forms[0].elements[id];
		}

		if(document.getElementById(id))
		{
			return document.getElementById(id);
		}
	}
	if (document.all)//IE test
	{
		return document.all(id);
	}
	
}

function showResults(target)
{
	window.open("",target,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=500,height=600")
	return true;
}
		
function openHelpBox(relative_path,width,height)
{	
	//window.open(relative_path,"helpBox","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=noscroll,resizable=no,copyhistory=yes,width="+width+",height="+height+"");
	var helpBox=window.open(relative_path,"aHelpBox","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=noscroll,resizable=no,copyhistory=yes,width="+width+",height="+height+"");
	helpBox.moveTo(screen.availWidth/4-width/4,screen.availHeight/4-height/4);
	
	helpBox.focus();
}

function validate(form)
{
	
	if(form.nationality.value=="select"||form.nationality.value=="-----------------")
	{
		alert("Please select your nationality");
		form.nationality.focus();
		return false;
	}
	
	if(form.ageRange.value=="select")
	{
		alert("Please select your age range");
		form.ageRange.focus();
		return false;
	}
	
	if(form.englishAbility.value=="select")
	{
		alert("Please select your english ability");
		form.englishAbility.focus();
		return false;
	}
	
	if(form.occupation.value=="select")
	{
		alert("Please select your occupation");
		form.occupationCategory.focus();
		return false;
	}
	
	if(form.occupation.value!="select"&&(!form.yearsWorkYes.checked&&!form.yearsWorkNo.checked))
	{
		alert("Please select if you have been working in your chosen occupation for 3 out of the last 4 years");
		form.yearsWorkYes.focus();
		return false;
	}
	
	if(object("occupationInDemandRow").style.display=="block" && !form.jobOfferYes.checked && !form.jobOfferNo.checked)
	{
		alert("Please select if you have a job offer with an Australian company that employs more than ten full-time staff")
		form.jobOfferYes.focus();
		return false;
	}
	
	if(object("ITinfoCont").style.display=="block" && !form.ITExpYes.checked && !form.ITExpNo.checked)
	{
		alert("Please select if you have more than 12 months of experience in the above areas of computing")
		form.ITExpYes.focus();
		return false;
	}
	
	if(form.maritalStatus.value=="select")
	{
		alert("Please select your marital status");
		form.maritalStatus.focus();
		return false;
	}
	
	if(!form.studiedYes.checked && !form.studiedNo.checked)
	{
		alert("Please select if you successfully completed any full-time study in Australia")
		form.studiedYes.focus();
		return false;
	}
	
	if(object("studyInfo").style.display=="block" && !form.phd.checked && !form.otherQual.checked && !form.studyQualNone.checked)
	{
		alert("Please select which qualification you completed");
		form.phd.focus();
		return false;
	}
	
	if(!form.extraAtts1.checked && !form.extraAtts2.checked && !form.extraAtts3.checked && !form.extraAtts4.checked && !form.extraAtts5.checked)
	{
		alert("Please select which extra option applies to you");
		form.extraAtts1.focus();
		return false;
	}
	
	if(object("languagesRow1").style.display=="block" && form.extraAtts3.checked && form.language1.value=="select")
	{
		alert("Please select your accredited language");
		form.language1.focus();
		return false;
	}
	
	if(object("languagesRow2").style.display=="block" && form.extraAtts4.checked && form.language2.value=="select")
	{
		alert("Please select which language you have your overseas qualification for");
		form.language2.focus();
		return false;
	}
	
	if(!form.sponsorYes.checked && !form.sponsorNo.checked)
	{
		alert("Please select if you have a relative who is an Australian citizen or permanent resident and who is willing to sponsor you")
		form.sponsorYes.focus();
		return false;
	}
	
	if(object("sponsorDiv").style.display=="block")
	{
		if(form.sponsor_region.value=="select")
		{
			alert("Please select your sponsors location");
			form.sponsor_region.focus();
			return false;
		}
		
		if(form.relativesRelationshipToYou.value=="select")
		{
			alert("Please select you sponsors relationship to you");
			form.relativesRelationshipToYou.focus();
			return false;
		}
	}

	if(object("email").value=="" || object("email").value.indexOf("@") == -1)
	{
		alert("please enter a valid email address");
		form.email.focus();
		return false;
	}
	
	return true;//if all okay


}

function updateExtraAtts3()
{
	var selected = object("extraAtts3").checked;
	
	if(selected)
		object("languagesRow1").style.display = "block";
	else
		object("languagesRow1").style.display = "none";
}

function updateExtraAtts4()
{
	var selected = object("extraAtts4").checked;
	
	if(selected)
		object("languagesRow2").style.display = "block";
	else
		object("languagesRow2").style.display = "none";
}

function updateSponsorInfo()
{
	var yesSelected = object("instant_assess").sponsor[0].checked;

	if(yesSelected)
	{
		object("sponsorDiv").style.display = "block";
	}
	else
	{
		object("sponsorDiv").style.display = "none";
	}
}

function updateStudyInfo()
{
	var yesSelected = object("instant_assess").studied[0].checked;

	if(yesSelected)
		object("studyInfo").style.display = "block";
	else
		object("studyInfo").style.display = "none";
		

}		

function updatePartnerInfo()
{
	var selected = object("instant_assess").maritalStatus[object("instant_assess").maritalStatus.selectedIndex].innerHTML;
	
	if(selected == "Married" || selected == "De Facto")
	{
		if(selected == "De Facto")
			object("partnerMod").innerHTML = "partner";
		else
			object("partnerMod").innerHTML = "spouse";

		object("partnerInfo").style.display = "block";
	}
	else
	{
		object("partnerInfo").style.display = "none";
	}
}

function clearPartnerInfo()
{
	for(i=1; i<=4; i++)
		object("part"+i).checked = false;
}

function updateIndustries()
{
		var selected = object("occupationCategory").value;
		var numInIndustryList = object("occupationIndustry").length;
		var numOccupationList = object("occupation").length;
		
		//empty the lists
		
		object("occupationIndustry").length = 0;	
		object("occupation").length = 0;

		
		
		object("occupation").length++;
		
		object("occupation")[object("occupation").length-1].text="Please select";
		
		object("occupation")[object("occupation").length-1].value="select";
				
		
		
		object("occupationIndustry").length++;
		
		object("occupationIndustry")[object("occupation").length-1].text="Please select";
		
		object("occupationIndustry")[object("occupation").length-1].value="select";
			
		
		
		if (selected == "select")
		{		
			object("occupationIndustry").disabled = false;
		}
		else if(selected == 0)//Managers and Administrators
		{
			for(i=1; i<occupations[0].length; i++)
			{	
				object("occupation").length++;
				
				object("occupation")[i].text = occupations[0][i][0];
				
				object("occupation")[i].value = occupations[0][i][1];
			}
				
				object("occupation").length++;
				object("occupation")[i].text ="My occupation is not listed here";
			
				object("occupation")[i].value ="not listed";

				
				object("occupationIndustry").disabled = true;
		}
		else if (selected == 1)//Professionals
		{			
			for(i=1; i<=17; i++)
			{	
				object("occupationIndustry").length++;
				
				object("occupationIndustry")[i].text = occupations[i][0];
				
				object("occupationIndustry")[i].value = i;
			
			}
			object("occupationIndustry").disabled = false;
		}
		else if (selected == 2)//Associate Professionals
		{
			for(i=18; i<=24; i++)
			{	
				object("occupationIndustry").length++;
				
				object("occupationIndustry")[i-17].text = occupations[i][0];
				
				object("occupationIndustry")[i-17].value = i
			
			}
			object("occupationIndustry").disabled = false;
		}
		else if (selected == 3)//Tradesmen

		{
			for(i=25; i<=34; i++)
			{	
				object("occupationIndustry").length++;
				
				object("occupationIndustry")[i-24].text = occupations[i][0];
				
				object("occupationIndustry")[i-24].value = i;
			
			}
			object("occupationIndustry").disabled = false;
		}
}

function updateOccupations()
{
		var selected = object("occupationIndustry").value;
		
		object("occupation").length = 0;
		
		object("occupation").length++;
		
		object("occupation")[0].text = "Please select";
		object("occupation")[0].value = "select";
		
		if (selected != "select")
		
		{
			for(i=1; i<occupations[selected].length; i++)
			
			{
				
				object("occupation").length++;
				
				object("occupation")[i].text = occupations[selected][i][0];
				
				object("occupation")[i].value = occupations[selected][i][1];
			}
			
			object("occupation").length++;
			
			object("occupation")[i].text = "My occupation is not listed here";
			
			object("occupation")[i].value = "not listed";

		}

}

function updateOccupationInDemand()
{
	var selected = object("occupation")[object("occupation").selectedIndex].innerHTML;
	
	for(i=0; i<occupationsInDemand.length; i++)
	{	
		if(selected == occupationsInDemand[i])
		{
			object("occupationInDemandRow").style.display = "block";
			object("occupationInDemand").value="yes";
			break;
		}
		else
		{
			object("occupationInDemandRow").style.display = "none";
			object("occupationInDemand").value="no";
		}
	}
}

function updateYearsWork()
{
	var OccSelected = (object("occupation").value != "select")&&(object("occupation").value != "not listed");

	if(OccSelected)
	{	
		object("yearsWorkRow").style.display = "block";
	}
	else
	{
		object("yearsWorkRow").style.display = "none";
	}
}

function updateRecentWork()
{
	
	if(object("occupation").value == 60)
	{
		object("recentWorkCont").style.display = "block";
		object("recentWorkMonthsMod").innerHTML = "12";
		object("recentWorkYearsMod").innerHTML = "18 months";
	}
	else if(object("occupation").value == 40 || object("occupation").value == 50)
	{
		object("recentWorkCont").style.display = "block";
		object("recentWorkMonthsMod").innerHTML = "24 months";
		object("recentWorkYearsMod").innerHTML = "3 years";
	}
	else
	{
		object("recentWorkCont").style.display = "none";
	}
}

function updateITinfo()
{
	var selected = object("occupationIndustry")[object("occupationIndustry").selectedIndex].innerHTML;

	if(selected == "Information Technology" && object("occupation").value != "select" && object("occupation").value != "not listed")
		object("ITinfoCont").style.display = "block";
	else
		object("ITinfoCont").style.display = "none";
}

function updateITJobPts()
{
	//var selected = (object("instant_assess").ITExp[0].checked);
	var selected = (object("ITinfoCont").style.display=="block" && (object("instant_assess").ITCISSP.checked||object("instant_assess").ITSAP.checked||object("instant_assess").ITPeopleSoft.checked||object("instant_assess").ITJava.checked))
	if(selected)
		object("ITJobPts").value="15";
	else
		object("ITJobPts").value="0";
}

function updateAllOcc()
{
	
	object('occupationName').value=object("occupation")[object("occupation").selectedIndex].innerHTML;
	
	updateRecentWork()
	updateOccupationInDemand();
	updateYearsWork();
	updateITinfo();
	//updateITExp();
	updateITJobPts()
	
}

function updateAll()
{
	updateExtraAtts3();
	updateExtraAtts4();
	updateSponsorInfo();
	updateStudyInfo();
	updatePartnerInfo();
	//updateIndustries();
	//updateOccupations();
	updateAllOcc()
	
	object("main_container_form").style.display = "block";
	object("loading_div").style.display = "none";
}