//used in AR_app1_3 (appform_step3.php)

function TAMax( ta, countspan, maxlength ) {
 if (ta.value.length > maxlength){
 	ta.value = ta.value.substring( 0, maxlength );
  	ta.blur();
  	ta.focus();
  	return false;
 	}
 else {
  	countspan.innerHTML = maxlength - ta.value.length;
 	}
}
  /*************************************************************/
function toggle_it(itemID){
      // Toggle visibility between none and inline
      if ((document.getElementById(itemID).style.display == 'none'))
      {
        document.getElementById(itemID).style.display = 'inline';
      } else {
        document.getElementById(itemID).style.display = 'none';
      }
  }
  /*************************************************************/
function chk_appform_step1()
{
	var msg="";
	
	dc = document.appform_step1;
		
	if(dc.save_appln.value==0)//bye pass the form validations.. just save it for future use
	{
		
		if(dc.a1_firstname.value.length==0)
			msg+="First Names\n";
	
		if(dc.a1_lastname.value.length==0)
			msg+="Last Name\n";
			
		if(dc.a1_dob.value.length==0)
			msg+="Date of Birth\n";
			
		if(dc.a1_gender.value.length==0)
			msg+="Gender\n";
			
		if(dc.a1_country_birth.value.length==0)
			msg+="Country of Birth\n";
	
		if((!dc.a1_residency[0].checked && !dc.a1_residency[1].checked && !dc.a1_residency[2].checked && !dc.a1_residency[3].checked) || (dc.a1_residency[3].checked && dc.a1_residency_years.value.length==0))
			msg+="Residency Status\n";
	
			
		if(dc.a1_marital.value.length==0)
			msg+="Marital Status\n";
			
		if(dc.a1_dependents.value.length==0)
			msg+="No. of Dependents\n";
			
		if(dc.a1_dependents_under10.value.length==0)
			msg+="No. under 10yrs\n";
			
		if(dc.a1_current_address.value.length==0)
			msg+="Current Address\n";
			
		if(dc.a1_current_suburb.value.length==0)
			msg+="Suburb\n";
	
		if(dc.a1_current_state.value.length==0)
			msg+="State\n";
	
		if(dc.a1_current_postcode.value.length==0)
			msg+="Postcode\n";
	/*
		if(dc.a1_hm_ph_1.value.length==0 || dc.a1_hm_ph_2.value.length==0 || dc.a1_hm_ph_3.value.length==0)
			msg+="Phone\n";
	*/
		if(dc.a1_email.value.length==0)
			msg+="Email\n";
		else 	
		{
			if(dc.a1_email_Verify.value.length==0)
				msg+="Verify Email Required\n";
			
			if(dc.a1_email_Verify.value != dc.a1_email.value)
				msg+="Please retype email address\n";
			else if(!chk_email(dc.a1_email))
			{
				msg+="Invalid email address\n";
			}			
		}
		
	
		if(dc.a1_relative_name.value.length==0)
			msg+="Full Name\n";

	} //end bye pass
	
	msg="";//280208
	if(msg.length > 0)
	{
		msg = "Response Required\n============\n"+msg;
		alert(msg);
		return false;
	}	
	else
		return true;
}


  /*************************************************************/
function chk_appform_step2()
{
	var msg="";
	
	dc = document.appform_step2;
		
	if(dc.save_appln.value==0)//bye pass the form validations.. just save it for future use
	{
		
		if(dc.a1_occupation.value.length==0)
			msg+="Occupation\n";
	
		if(dc.a1_employ_type.value.length==0)
			msg+="Employment Type\n";
			
		if(dc.a1_employer.value.length==0)
			msg+="Employer\n";
			
		if(dc.a1_employ_period_yr.value.length==0)
			msg+="Period\n";
			
		if(dc.a1_employ_income.value.length==0)
			msg+="Gross Monthly Employment Income\n";
			
		if(dc.a1_net_income.value.length==0)
			msg+="Net (in hand) Income\n";
	
		if(!dc.a1_netincome_week_month[0].checked && !dc.a1_netincome_week_month[1].checked)
			msg+="Weekly / Monthly\n";
			
		if(dc.a1_centrelink_income.value.length==0)
			msg+="Gross Monthly C/Link Child Support Income\n";
			
		if(dc.a1_pension_income.value.length==0)
			msg+="Gross Monthly Pension/Disability Support\n";
			
		if(dc.a1_other_income.value.length==0)
			msg+="Gross Monthly Other Income\n";
			
		if(dc.a1_rental_income.value.length==0)
			msg+="Gross Monthly Rental Income\n";
			

	} //end bye pass


	msg="";
	
	if(msg.length > 0)
	{
		msg = "Response Required\n============\n"+msg;
		alert(msg);
		return false;
	}	
	else
		return true;
}


function chk_appform_step3()
{
	var msg="";
	
	dc = document.appform_step3;

	if(dc.save_appln.value==0)//bye pass the form validations.. just save it for future use
	{

	} //end bye pass
	
	if(msg.length > 0)
	{
		msg = "Response Required\n============\n"+msg;
		alert(msg);
		return false;
	}	
	else
		return true;
	
}

function chk_appform_step4()
{
	var msg="";
	
	dc = document.appform_step4;

	if(dc.save_appln.value==0)//bye pass the form validations.. just save it for future use
	{
	
		//radio button a1_property_loan_type and a1_fhog needs to be validated
	
		if(!dc.a1_property_loan_type[0].checked && !dc.a1_property_loan_type[1].checked)
			msg+="Property Loan type\n";
	
		if(!dc.a1_fhog[0].checked && !dc.a1_fhog[1].checked && !dc.a1_fhog[2].checked)
			msg+="I qualify for the First Home Owners Grant (FHOG)\n";
	
		if(dc.a1_which_state.value.length==0)
			msg+="In which State would you like your property?\n";
	
		if(dc.a1_pref_suburb1.value.length==0)
			msg+="Suburb 1\n";
	
		if(dc.a1_pref_postcode1.value.length==0)
			msg+="Postcode 1\n";
	
		if(dc.a1_pref_price.value.length==0)
			msg+="Price not exceeding\n";
	
		if(!dc.a1_declaration.checked)
			msg+="Declaration by applicant\n";
			
	} //end bye pass

	msg="";
	
	if(msg.length > 0)
	{
		msg = "Response Required\n============\n"+msg;
		alert(msg);
		return false;
	}	
	else
		return true;
	
}




function chk_email(fldname)
{

	var bool=true;

	email = fldname.value;

	var len = email.length;              

	if(len<5){
		bool=false;
	}	else	{

	var index1 = email.indexOf('@');

	var subind = email.substring(0,index1);

	var indlen = subind.length;

	var index2 = email.indexOf('.');

	var subind1=email.substring(indlen+1,index2);

	var indlen1 = subind1.length;

	var index3 = email.indexOf(' ');

	var subind3=email.substring(index2+1,len)

	var indlen2 = subind3.length;

	if((index1!= -1)&&(index2!= -1)&&(index3==-1))

	{	

		if((indlen!=0)&&(indlen1!=0)&&(indlen2!=0))

		{

		} 

        else

		{

		}

	}

	else

	{

			bool=false;

	}		

	} // end of else if len<5



	return(bool);



}


function show_selected_menu(obj,val)
{

  var len=obj.options.length

  for(var i=0;i<len;i++)
  {
    if(obj.options[i].value==val)
     {
       obj.selectedIndex=i;
     }
  } 
}

function set_form_field(form_name, field_name, field_value)
{
	str="document."+form_name + "." + field_name + ".value='" + field_value+"'";
	eval(str);
}

function chk_signup()
{
	var msg="";

	dc = document.signup_frm;
	
	if(dc.username.value.length<=5)
		msg+="Username\n";
		
	if(dc.password.value.length<=5)
		msg+="Error: Your password must be at least 6 characters\n";
	else if(dc.password.value != dc.confirm_password.value)
		msg+="Error: Passwords do not match\n";


	if(msg.length > 0)
	{
		msg = "Response Required\n============\n"+msg;
		alert(msg);
		return false;
	}	
	else
		return true;
	

}

function chk_admin_list()
{
	if(document.admin_frm.admin_id.value > 0)
		return true;
	else
	{
		alert("Please Select");
		return false;
	}
}

function validate_admin()
{
	var msg="";
	
//	alert("hi");
	
	dc=document.admin_frm;
	
	if(dc.admin_name.value.length==0)
		msg+="Enter Name\n";

	if(dc.user_name.value.length==0)
		msg+="Enter Username\n";

	if(dc.user_pass.value.length==0)
		msg+="Enter Password\n";
		
	if(msg.length > 0)
	{
		//msg = "Response Required\n============\n"+msg;
		alert(msg);
		return false;
	}	
	else
		return true;

}

function confirm_on_del(val)
{

	if(val.length==0)
	val = "Are you sure?";
	
		if(confirm(val))
			return true;
		else
			return false;
}

function alert_delete(val1,val2,val3)
{

if(confirm_on_del(''))
{
str=val2+"&id="+val1+"&type="+val3;
//alert(str);
window.location.href=str;

}

}

function close_window()
{	
	window.close();
}
