// JavaScript Document
function frmrequest()
{
	var Field= Array();
	var FieldName= Array();
	
	
	Field[0]=document.contact.first_name.value;
	Field[1]=document.contact.family_name.value;
	Field[2]=document.contact.phone.value;
	Field[3]=document.contact.email.value;
  Field[4]=document.contact.sImageCheck.value;
	

	FieldName[0]="First Name ";
	FieldName[1]="Family Name ";
	FieldName[2]="Phone ";
	FieldName[3]="Email ";
  FieldName[4]="Code ";
	
	
	var msg="";
	var bval = true;
	
	for(i=0; i<5; i++)
	{
		if(Field[i]=="" || Field[i]==null)
		{
			//alert("Please fill " + FieldName[i] + " field.");
			msg = msg + "Please Fill:"
			msg = msg + "\n" + FieldName[i] + "Field";
			alert(msg);
			bval = false;
			break;

		}
	}
	
	

	if(bval)
	{
		bval=emailCheck();
	}
	
	if(bval)
	{
		if(isNaN(Field[2]))
		{
			bval = false;
			alert("Invalid Phone Number");
		}
	}
	
	
	if(bval){
		bval = checkBoxesCheck('visa_info_checkbox','Please select at least ONE Visa Information');
	}
	
	return bval;
}
	
function checkBoxesCheck(parentId,message){
	var chkBoxesParentObj = document.getElementById(parentId);
	if(chkBoxesParentObj != null || chkBoxesParentObj != 'undefined'){
		var inputArray = chkBoxesParentObj.getElementsByTagName('input');
		var i = 0;
		for(i = 0;i < inputArray.length;i++){
			if(inputArray[i].type == 'checkbox' && inputArray[i].checked){
				return true;
			}
		}
	}
	alert(message);
	return false;
}

function emailCheck() 
  	{
  	  		var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/
  	        var matchArray;	
  	  		var emailStr1 =document.contact.email.value;	
			
  	  	
  	  		
					matchArray = emailStr1.match(emailPat);
					if (matchArray == null) 
					
					{
						alert("Please Enter Valid Email Address"); 
						document.contact.email.focus;
						return false;
					}	
					else 
					return true;
	  	
    }
	
	
	//BUSINESS VISA FORM CHECK
	
	
	function frmrequest1()
	{
		var Field= Array();
		var FieldName= Array();
		
		
		Field[0]=document.business.first_name.value;
		Field[1]=document.business.last_name.value;
		Field[2]=document.business.business_email.value;
		Field[3]=document.getElementById('b_day').options[document.getElementById('b_day').options.selectedIndex].value;
		Field[4]=document.getElementById('b_month').options[document.getElementById('b_month').options.selectedIndex].value;
		Field[5]=document.getElementById('b_year').options[document.getElementById('b_year').options.selectedIndex].value;
		Field[6]=document.getElementById('language_ability').options[document.getElementById('language_ability').options.selectedIndex].value;
		Field[7]=document.getElementById('marital_status').options[document.getElementById('marital_status').options.selectedIndex].value;
		
	
		FieldName[0]="First Name ";
		FieldName[1]="Last Name ";
		FieldName[2]="Email ";
		FieldName[3]="Day ";
		FieldName[4]="Month ";
		FieldName[5]="Year ";
		FieldName[6]="English Language Ability ";
		FieldName[7]="Marital Status ";
		
		
		
		var msg="";
		var bval = true;
		
		for(i=0; i<8; i++)
		{
			if(Field[i]=="" || Field[i]==null)
			{
				//alert("Please fill " + FieldName[i] + " field.");
				msg = msg + "Please Fill:"
				msg = msg + "\n" + FieldName[i] + "Field";
				alert(msg);
				bval = false;
				break;
	
			}
		}
		
		
	
		if(bval)
		{
			bval=businessemailCheck();
		}
		
		
		
		
		if(bval){
			bval = checkBoxesRadio('business_radio','Please Specify Your Business Category');
		}
		
		return bval;
	}
		
	function checkBoxesRadio(parentId,message){
		var chkBoxesParentObj = document.getElementById(parentId);
		if(chkBoxesParentObj != null || chkBoxesParentObj != 'undefined'){
			var inputArray = chkBoxesParentObj.getElementsByTagName('input');
			var i = 0;
			for(i = 0;i < inputArray.length;i++){
				if(inputArray[i].type == 'radio' && inputArray[i].checked){
					return true;
				}
			}
		}
		alert(message);
		return false;
	}
	
	function businessemailCheck() 
		{
				var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/
				var matchArray;	
				var emailStr1 =document.business.business_email.value;	
				
			
				
						matchArray = emailStr1.match(emailPat);
						if (matchArray == null) 
						
						{
							alert("Please Enter Valid Email Address"); 
							document.business.business_email.focus;
							return false;
						}	
						else 
						return true;
			
		}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//SKILL VISA FROM CHECK
	
	
	function CheckForm(){
	var Field= Array();
	var FieldName= Array();
	
	Field[0]=document.frmSkilled.FirstName;
	Field[1]=document.frmSkilled.LastName;
	Field[2]=document.frmSkilled.Email;
	Field[3]=document.frmSkilled.ConfirmEmail;
	Field[4]=document.frmSkilled.ddlDay;
	Field[5]=document.frmSkilled.ddlMonth;
	Field[6]=document.frmSkilled.ddlYear;
	Field[7]=document.frmSkilled.ddlCitizenship;
	Field[8]=document.frmSkilled.ddlEnglishAbility;
	Field[9]=document.frmSkilled.ddlIndustry;
	Field[10]=document.frmSkilled.ddlMarital;
	Field[11]=document.frmSkilled.Children;
	Field[12]=document.frmSkilled.Studies;
	Field[13]=document.frmSkilled.Sponsor;
	
	FieldName[0]="First Name";
	FieldName[1]="Last Name";
	FieldName[2]="Email";
	FieldName[3]="Re-type Email";
	FieldName[4]="Date of birth";
	FieldName[5]="Month of birth";
	FieldName[6]="Year of birth";
	FieldName[7]="Country of citizenship";
	FieldName[8]="English language ability";
	FieldName[9]="Industry you work in";
	FieldName[10]="Marital Status";
	FieldName[11]="Children";
	FieldName[12]="Completed any studies in Australia";
	FieldName[13]="Sponsor";
	//alert(Field[0]);
	if(!CheckRadioBoxes(document.frmSkilled, 'Title')){
		alert("Please select your Title");
		return false;
	}
	for(i=0; i<11; i++){
		if(Field[i].value==""){
			alert(FieldName[i] + " cannot be blank.");
			Field[i].focus();
			return false;
		}
	}
	
	if(!CheckRadioBoxes(document.frmSkilled, 'Children')){
		alert("Please specify if you have any children.");
		return false;
	}
	
	if(!CheckRadioBoxes(document.frmSkilled, 'Studies')){
		alert("Please specify if you have successfully completed any studies in Australia.");
		return false;
	}
	
	if(!CheckRadioBoxes(document.frmSkilled, 'Sponsor')){
		alert("Please specify if anybody is willing to sponsor you.");
		return false;
	}
	if(!skilledemailCheck()){
		return false;
	}
	return true;
}

function CheckRadioBoxes(objForm, CtrlName){
	var checkVal=false;
	for(var i=0;i<objForm.elements.length;i++){
		var e=objForm.elements[i];
		var eType=e.type;
		var eName=e.name;
		var eValue=e.value;
		
		if(eType=='radio'){
			if(eName==CtrlName){
				if(e.checked){
					checkVal=true;
					break;
				}
			}
		}
	}
	return checkVal;
}
function skilledemailCheck() 
{
	var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/
	var matchArray;	
	var emailStr1 =document.frmSkilled.Email.value;	
	
	matchArray = emailStr1.match(emailPat);
	if (matchArray == null){
		alert("Please Enter Valid Email Address"); 
		document.frmSkilled.Email.focus;
		return false;
	}else{
		return true;
	}
}
function changeResidense(){
	document.frmSkilled.ddlResidence.value=document.frmSkilled.ddlCitizenship.value;
}
	
	
	
	//FOR Parent Visa Assessment Page
	
	function frmrequest2()
	{
		var Field= Array();
		var FieldName= Array();
		
		
		Field[0]=document.parent.FirstName.value;
		Field[1]=document.parent.LastName.value;
		Field[2]=document.parent.Email.value;
		Field[3]=document.getElementById('ddlDay').options[document.getElementById('ddlDay').options.selectedIndex].value;
		Field[4]=document.getElementById('ddlMonth').options[document.getElementById('ddlMonth').options.selectedIndex].value;
		Field[5]=document.getElementById('ddlYear').options[document.getElementById('ddlYear').options.selectedIndex].value;
		Field[6]=document.getElementById('parentGender').options[document.getElementById('parentGender').options.selectedIndex].value;
		Field[7]=document.getElementById('marital_status').options[document.getElementById('marital_status').options.selectedIndex].value;
		Field[8]=document.getElementById('numChildren').options[document.getElementById('numChildren').options.selectedIndex].value;
		Field[9]=document.getElementById('numChildrenInOz').options[document.getElementById('numChildrenInOz').options.selectedIndex].value;
		Field[10]=document.getElementById('childWillingToSponsorDescription').options[document.getElementById('childWillingToSponsorDescription').options.selectedIndex].value;
		Field[11]=document.getElementById('childWillingToSponsorYearsInOz').options[document.getElementById('childWillingToSponsorYearsInOz').options.selectedIndex].value;
		Field[12]=document.parent.VerifyEmail.value;
		
		
	
		FieldName[0]="First Name ";
		FieldName[1]="Last Name ";
		FieldName[2]="Email ";
		FieldName[3]="Please specify your date of birth Day ";
		FieldName[4]="Please specify your date of birth Month ";
		FieldName[5]="Please specify your date of birth Year ";
		FieldName[6]="Please specify your gender ";
		FieldName[7]="Please indicate your marital status ";
		FieldName[8]="How many children do you have? ";
		FieldName[9]="How many children are currently living in Australia? ";
		FieldName[10]="Which statement best describes your sponsoring child?  ";
		FieldName[11]="How long has your sponsoring child lived in Australia? ";
		FieldName[12]="Retype your correct email address ";
		
		
		
		var msg="";
		var bval = true;
		
		for(i=0; i<13; i++)
		{
			if(Field[i]=="" || Field[i]==null)
			{
				//alert("Please fill " + FieldName[i] + " field.");
				msg = msg + "Please Fill:"
				msg = msg + "\n"  + FieldName[i] + "Field";
				alert(msg);
				bval = false;
				break;
	
			}
		}
		
		
	
		if(bval)
		{
			bval=ParentmailCheck();
		}
		if(bval && Field[2] != Field[12]) 
		{
			bval = false;
			alert("Retype your correct email address");
		}
		return bval;
	}
	
	function ParentmailCheck() 
		{
				var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/
				var matchArray;	
				var emailStr1 =document.parent.Email.value;	
				
			
				
						matchArray = emailStr1.match(emailPat);
						if (matchArray == null) 
						
						{
							alert("Please Enter Valid Email Address"); 
							document.parent.Email.focus;
							return false;
						}	
						else 
						return true;
			
		}
		
		
		//FOR PARTNER Visa Assessment Page
	
	function frmrequest3()
	{
		var Field= Array();
		var FieldName= Array();
		
		
		Field[0]=document.partner.FirstName.value;
		Field[1]=document.partner.LastName.value;
		Field[2]=document.partner.Email.value;
		Field[3]=document.getElementById('ddlDay').options[document.getElementById('ddlDay').options.selectedIndex].value;
		Field[4]=document.getElementById('ddlMonth').options[document.getElementById('ddlMonth').options.selectedIndex].value;
		Field[5]=document.getElementById('ddlYear').options[document.getElementById('ddlYear').options.selectedIndex].value;
		Field[6]=document.getElementById('partnerGender').options[document.getElementById('partnerGender').options.selectedIndex].value;
		Field[7]=document.getElementById('partnerDescription').options[document.getElementById('partnerDescription').options.selectedIndex].value;
		Field[8]=document.getElementById('relationshipToPartner').options[document.getElementById('relationshipToPartner').options.selectedIndex].value;
		Field[9]=document.getElementById('durationInRelationship').options[document.getElementById('durationInRelationship').options.selectedIndex].value;
		Field[10]=document.getElementById('durationLivingTogether').options[document.getElementById('durationLivingTogether').options.selectedIndex].value;
		
		
		
	
		FieldName[0]="First Name ";
		FieldName[1]="Last Name ";
		FieldName[2]="Email ";
		FieldName[3]="Please specify your date of birth Day ";
		FieldName[4]="Please specify your date of birth Month ";
		FieldName[5]="Please specify your date of birth Year ";
		FieldName[6]="Please specify your gender ";
		FieldName[7]="Which of the following statements best describes your partner? ";
		FieldName[8]="What is your relationship to your partner? ";
		FieldName[9]="Please specify the total duration of your relationship: ";
		FieldName[10]="Of that time, how long have you lived together?  ";
		
		
		
		
		var msg="";
		var bval = true;
		
		for(i=0; i<11; i++)
		{
			if(Field[i]=="" || Field[i]==null)
			{
				//alert("Please fill " + FieldName[i] + " field.");
				msg = msg + "Please Fill:"
				msg = msg + "\n"  + FieldName[i] + "Field";
				alert(msg);
				bval = false;
				break;
	
			}
		}
		
		
	
		if(bval)
		{
			bval=partnermailCheck();
		}
		
		return bval;
	}
	
	function partnermailCheck() 
		{
				var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/
				var matchArray;	
				var emailStr1 =document.partner.Email.value;	
				
			
				
						matchArray = emailStr1.match(emailPat);
						if (matchArray == null) 
						
						{
							alert("Please Enter Valid Email Address"); 
							document.partner.Email.focus;
							return false;
						}	
						else 
						return true;
			
		}
	
	
	
	
	//Student Check Form
	
	function CheckFormStudent(){
	var Field= Array();
	var FieldName= Array();
	
	Field[0]=document.frmStudent.studentFirstName;
	Field[1]=document.frmStudent.studentLastName;
	Field[2]=document.frmStudent.studentEmail;
	Field[3]=document.frmStudent.studentddlDay;
	Field[4]=document.frmStudent.studentddlMonth;
	Field[5]=document.frmStudent.studentddlYear;
	Field[6]=document.frmStudent.studentddlCitizenship;
	Field[7]=document.frmStudent.studentddlResidence;
	Field[8]=document.frmStudent.studentStudy;
	Field[9]=document.frmStudent.studentShortstudy;
	Field[10]=document.frmStudent.studentCourse;
	
	
	FieldName[0]="First Name";
	FieldName[1]="Last Name";
	FieldName[2]="Email";
	FieldName[3]="Date of birth";
	FieldName[4]="Month of birth";
	FieldName[5]="Year of birth";
	FieldName[6]="Country of citizenship";
	FieldName[7]="Residence Addres";
	FieldName[8]="What would you like to study ";
	FieldName[9]="Short description of the course ";
	FieldName[10]="Length of course";
	//alert(Field[0]);
	if(!CheckRadioBoxes(document.frmStudent, 'studentTitle')){
		alert("Please select your Title");
		return false;
	}
	for(i=0; i<11; i++){
		if(Field[i].value==""){
			alert(FieldName[i] + " cannot be blank.");
			Field[i].focus();
			return false;
		}
	}
	
	if(!CheckRadioBoxes(document.frmStudent, 'studentExpenses')){
		alert("Please specify Student's other personal expenses.");
		return false;
	}
	
	if(!CheckRadioBoxes(document.frmStudent, 'studentCitizenship')){
		alert("Please specify you lived outside your country of citizenship.");
		return false;
	}
	
	if(!CheckRadioBoxes(document.frmStudent, 'studentFamily')){
		alert("Please specify accompanied by any family members.");
		return false;
	}
	
	if(!CheckRadioBoxes(document.frmStudent, 'studentMedical')){
		alert("Please specify you got any medical condition.");
		return false;
	}
	
	if(!CheckRadioBoxes(document.frmStudent, 'studentCriminal')){
		alert("Please specify you have a criminal record.");
		return false;
	}
	if(!studentemailCheck()){
		return false;
	}
	return true;
}

function CheckRadioBoxes(objForm, CtrlName){
	var checkVal=false;
	for(var i=0;i<objForm.elements.length;i++){
		var e=objForm.elements[i];
		var eType=e.type;
		var eName=e.name;
		var eValue=e.value;
		
		if(eType=='radio'){
			if(eName==CtrlName){
				if(e.checked){
					checkVal=true;
					break;
				}
			}
		}
	}
	return checkVal;
}
function studentemailCheck() 
{
	var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/
	var matchArray;	
	var emailStr1 =document.frmStudent.Email.value;	
	
	matchArray = emailStr1.match(emailPat);
	if (matchArray == null){
		alert("Please Enter Valid Email Address"); 
		document.frmStudent.Email.focus;
		return false;
	}else{
		return true;
	}
}
function changeResidense(){
	document.frmStudent.ddlResidence.value=document.frmStudent.ddlCitizenship.value;
}
	
	
	
	
	
	
	