function GetRadioValue(obj)
{
	for (i=0; i < obj.length; i++)
	{
		if (obj[i].checked)
			return obj[i].value;
	}
	return "-1";
}

function ValidateZip(thisForm)
{
	if  (!hasValue(thisForm.zipcode, "TEXT" ))
	{
		if  (!onError(thisForm.zipcode, "Error in zip field."))
		{
			return false;
		}
	}

	if  (!checkzip(thisForm.zipcode.value))
	{
		if  (!onError(thisForm.zipcode, "Error in zip field."))
		{
			return false;
		}
	}
	return true;
}

function  ValidateForm1(thisForm)
{
	if (thisForm.nrplans.value == 0)
	{
		if  (!onErrorNoFocus(thisForm.payment_plan_code, "There is no active payment plan."))
			return false;
	}
	else
	if (thisForm.nrplans.value > 1)
	{
		if  (!hasValue(thisForm.payment_plan_code, "RADIO" ))
			if  (!onErrorNoFocus(thisForm.payment_plan_code, "You must select a payment plan."))
				return false;
	}	
	else
	{
		if  (!hasValue(thisForm.payment_plan_code, "SINGLE_VALUE_RADIO" ))
			if  (!onErrorNoFocus(thisForm.payment_plan_code, "You must select a payment plan."))
				return false;
	}
	
	if  (!hasValue(thisForm.owner_full_name, "TEXT" ))
	{
		if  (!onError(thisForm.owner_full_name, "Please enter your name."))
		{
			return false;
		}
	}
	if  (!hasValue(thisForm.owner_phone_number, "TEXT" ))
	{
		if  (!onError(thisForm.owner_phone_number, "Error in phone number field."))
		{
			return false;
		}
	}
	
	if  (!checkphone(thisForm.owner_phone_number.value))
	{
		if  (!onError(thisForm.owner_phone_number, "Error in phone number field."))
		{
			return false;
		}
	}
	if  (hasValue(thisForm.owner_alternate_phone_number, "TEXT" ))
	{
		if  (!checkphone(thisForm.owner_alternate_phone_number.value))
		{
			if  (!onError(thisForm.owner_alternate_phone_number, "Error in alternate phone number field."))
			{
				return false;
			}
		}
	}
				
	if (GetRadioValue(thisForm.payment_plan_code) == "FS")
	{
		if  (!hasValue(thisForm.owner_email, "TEXT" ))
		{
			if  (!onError(thisForm.owner_email, "For the payment plan you have selected the contact email address is mandatory."))
			{
				return false;
			}
		}
	}
	
	if  (hasValue(thisForm.owner_email, "TEXT" ) || (GetRadioValue(thisForm.payment_plan_code) == "FS"))
	{
		if  (!checkemail(thisForm.owner_email.value))
		{
			return false;
		}
	}
		
	if  (!hasValue(thisForm.house_address, "TEXT" ))
	{
		if  (!onError(thisForm.house_address, "Please enter the address."))
		{
			return false;
		}
	}		
	
	if  (!hasValue(thisForm.zipcode, "TEXT" ))
	{
		if  (!onError(thisForm.zipcode, "Error in zip field."))
		{
			return false;
		}
	}

	if  (!checkzip(thisForm.zipcode.value))
	{
		if  (!onError(thisForm.zipcode, "Error in zip field."))
		{
			return false;
		}
	}

if (!(thisForm.house_for_sale.checked == true || thisForm.house_for_lease.checked == true))
{
		if  (!onError(thisForm.house_price, "You must choose at least one option (Sale or Lease)."))
		{
			return false;
		}
}
	
if (thisForm.house_for_sale.checked == true)
{	
	if  (!hasValue(thisForm.house_price, "TEXT" ))
	{
		if  (!onError(thisForm.house_price, "You must enter the sale price."))
		{
			return false;
		}
	}	
	if  (!checkinteger(thisForm.house_price.value))
	{
		if  (!onError(thisForm.house_price, "Input numbers only in sales price field."))
		{
			return false;
		}
	}
}		

if (thisForm.house_for_lease.checked == true)
{	
	if  (!hasValue(thisForm.house_lease_price, "TEXT" ))
	{
		if  (!onError(thisForm.house_lease_price, "You must enter the lease price."))
		{
			return false;
		}
	}	
		
	if  (!checkinteger(thisForm.house_lease_price.value))
	{
		if  (!onError(thisForm.house_lease_price, "Input numbers only in lease price field."))
		{
			return false;
		}
	}
}		

	if  (!hasValue(thisForm.owner_password, "TEXT" ))
	{
		if  (!onError(thisForm.owner_password, "Please enter a password."))
		{
			return false;
		}
	}		
	
	if  (!hasValue(thisForm.confirm_owner_password, "TEXT" ))
	{
		if  (!onError(thisForm.confirm_owner_password, "Please confirm the password."))
		{
			return false;
		}
	}		

	if (thisForm.confirm_owner_password.value != thisForm.owner_password.value)
	{
		if  (!onError(thisForm.confirm_owner_password, "The passwords does not match."))
		{
			return false;
		}
	}
	return true;
			
}

function  ValidateForm2(thisForm)
{
	if  (!hasValue(thisForm.house_year_built, "TEXT" ))
	{
		if  (!onError(thisForm.house_year_built, "Error in Age of House field: \n - Enter an integer value or 0 for 'unknown'."))
		{
			return false;
		}
	}	
	
	if  (!checkinteger(thisForm.house_year_built.value))
	{
		if  (!onError(thisForm.house_year_built, "Error in Age of House field: \n - Enter an integer value or 0 for 'unknown'."))
		{
			return false;
		}
		if  (!checkrange(thisForm.house_year_built.value, 0, 200))
		{
			if  (!onError(thisForm.house_year_built, "Please enter a value  between 0 and 200."))
			{
				return false;
			}
		}		
	}
	return true;
}

function  ValidateForm3(thisForm)
{
	return true;
}

function  ValidateForm4(thisForm)
{
	return true;
}