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 ValidateCity(thisForm)
{
	if  (!hasValue(thisForm.city_name, "TEXT" ))
	{
		if  (!onError(thisForm.city_name, "Error in city 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  (!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  (!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, "Error in sale price field."))
		{
			return false;
		}
	}	
	if  (!checkprice(thisForm.house_price.value))
	{
		if  (!onError(thisForm.house_price, "Error in sale price field."))
		{
			return false;
		}
	}
}		

if (thisForm.house_for_lease.checked == true)
{	
	if  (!hasValue(thisForm.house_lease_price, "TEXT" ))
	{
		if  (!onError(thisForm.house_lease_price, "Error in lease price field."))
		{
			return false;
		}
	}	
		
	if  (!checkprice(thisForm.house_lease_price.value))
	{
		if  (!onError(thisForm.house_lease_price, "Error 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;
			}
		}		
	}
	
	if  (!hasValue(thisForm.real_estate_taxes, "TEXT" ))
	{
		if  (!onError(thisForm.real_estate_taxes, "Error in real estate taxes field: \n - Enter an integer value."))
		{
			return false;
		}
	}	
	if  (!checkinteger(thisForm.real_estate_taxes.value))
	{
		if  (!onError(thisForm.real_estate_taxes, "Error in real estate taxes field."))
		{
			return false;
		}
	}	
	
	return ValidateOpenHouseInfo(thisForm);
}


function ValidateOpenHouseInfo(thisForm)
{

/*
	if  (hasValue(thisForm.open_house1, "SINGLE_VALUE_CHECKBOX" ))
		{
			if  (!hasValue(thisForm.StartDate1, "TEXT" ))
			{
				if  (!onError(thisForm.StartDate1, "Error in Open House 1 date field: \n - You must select a date."))
				{
					return false;
				}
			}
			
			if (!ValidateCalendarDate(thisForm.StartDate1.value))
			{
				if  (!onError(thisForm.StartDate1, "Error in Open House 1 date field: \n - Invalid date."))
				{
					return false;
				}
			}
	
			var startTime = thisForm.StartAMPM1.selectedIndex * 1000 + thisForm.StartHour1.selectedIndex * 10 +  thisForm.StartMin1.selectedIndex;
			var endTime = thisForm.EndAMPM1.selectedIndex * 1000 + thisForm.EndHour1.selectedIndex * 10 +  thisForm.EndMin1.selectedIndex;		
			
			if (startTime >= endTime)
				if  (!onError(thisForm.StartMin1, "Error in Open House 1 time fields: \n - Start time must be greater than end time"))
				{
					return false;
				}
		}
		
	if  (hasValue(thisForm.open_house2, "SINGLE_VALUE_CHECKBOX" ))
		{
			if  (!hasValue(thisForm.StartDate2, "TEXT" ))
			{
				if  (!onError(thisForm.StartDate2, "Error in Open House 2 date field: \n - You must select a date."))
				{
					return false;
				}
			}
			
			if (!ValidateCalendarDate(thisForm.StartDate2.value))
			{
				if  (!onError(thisForm.StartDate2, "Error in Open House 2 date field: \n - Invalid date."))
				{
					return false;
				}
			}
	
			var startTime = thisForm.StartAMPM2.selectedIndex * 1000 + thisForm.StartHour2.selectedIndex * 10 +  thisForm.StartMin2.selectedIndex;
			var endTime = thisForm.EndAMPM2.selectedIndex * 1000 + thisForm.EndHour2.selectedIndex * 10 +  thisForm.EndMin2.selectedIndex;		
			
			if (startTime >= endTime)
				if  (!onError(thisForm.StartMin2, "Error in Open House 2 time fields: \n - Start time must be greater than end time"))
				{
					return false;
				}
		}
*/

	if  (hasValue(thisForm.open_house1, "SINGLE_VALUE_CHECKBOX" ))
		{
			if  (!hasValue(thisForm.StartDate1, "TEXT" ))
			{
				if  (!onError(thisForm.StartDate1, "Error in Open House 1 date field: \n - You must select a date."))
				{
					return false;
				}
			}
			
			if (!ValidateCalendarDate(thisForm.StartDate1.value))
			{
				if  (!onError(thisForm.StartDate1, "Error in Open House 1 date field: \n - Invalid date."))
				{
					return false;
				}
			}
			

			if (thisForm.EndAMPM1.selectedIndex == 0 && thisForm.EndHour1.selectedIndex == 11 && thisForm.EndMin1.selectedIndex > 0)
			{
				if  (!onError(thisForm.EndAMPM1, "Error in Open House 1 End time field: \n - You cannot pass midnight"))
					{
						return false;
					}
			}
	
			var tmpTime = 0;
			
			tmpRef = (thisForm.StartAMPM1.selectedIndex == 1 && thisForm.StartHour1.selectedIndex == 11) ? 0 : ((thisForm.StartAMPM1.selectedIndex == 0 && thisForm.StartHour1.selectedIndex == 11) ? 1000 : thisForm.StartAMPM1.selectedIndex * 1000);
			var startTime = tmpRef + thisForm.StartHour1.selectedIndex * 10 +  thisForm.StartMin1.selectedIndex;
			
			tmpRef = (thisForm.EndAMPM1.selectedIndex == 1 && thisForm.EndHour1.selectedIndex == 11) ? 0 : ((thisForm.EndAMPM1.selectedIndex == 0 && thisForm.EndHour1.selectedIndex == 11) ? 1000 : thisForm.EndAMPM1.selectedIndex * 1000);
			var endTime = tmpRef + thisForm.EndHour1.selectedIndex * 10 +  thisForm.EndMin1.selectedIndex;		

			//var startTime = thisForm.StartAMPM1.selectedIndex * 1000 + thisForm.StartHour1.selectedIndex * 10 +  thisForm.StartMin1.selectedIndex;
			//var endTime = thisForm.EndAMPM1.selectedIndex * 1000 + thisForm.EndHour1.selectedIndex * 10 +  thisForm.EndMin1.selectedIndex;		

			if (startTime >= endTime)
				if  (!onError(thisForm.StartMin1, "Error in Open House 1 time fields: \n - Start time must be greater than end time"))
				{
					return false;
				}
		}
		
	if  (hasValue(thisForm.open_house2, "SINGLE_VALUE_CHECKBOX" ))
		{
			if  (!hasValue(thisForm.StartDate2, "TEXT" ))
			{
				if  (!onError(thisForm.StartDate2, "Error in Open House 2 date field: \n - You must select a date."))
				{
					return false;
				}
			}
			
			if (!ValidateCalendarDate(thisForm.StartDate2.value))
			{
				if  (!onError(thisForm.StartDate2, "Error in Open House 2 date field: \n - Invalid date."))
				{
					return false;
				}
			}

			if (thisForm.EndAMPM2.selectedIndex == 0 && thisForm.EndHour2.selectedIndex == 11 && thisForm.EndMin2.selectedIndex > 0)
			{
				if  (!onError(thisForm.EndAMPM2, "Error in Open House 2 End time field: \n - You cannot pass midnight"))
					{
						return false;
					}
			}
	
			var tmpTime = 0;
			
			tmpRef = (thisForm.StartAMPM2.selectedIndex == 1 && thisForm.StartHour2.selectedIndex == 11) ? 0 : ((thisForm.StartAMPM2.selectedIndex == 0 && thisForm.StartHour2.selectedIndex == 1) ? 1000 : thisForm.StartAMPM2.selectedIndex * 1000);
			var startTime = tmpRef + thisForm.StartHour2.selectedIndex * 20 +  thisForm.StartMin2.selectedIndex;
			
			tmpRef = (thisForm.EndAMPM2.selectedIndex == 1 && thisForm.EndHour2.selectedIndex == 11) ? 0 : ((thisForm.EndAMPM2.selectedIndex == 0 && thisForm.EndHour2.selectedIndex == 1) ? 1000 : thisForm.EndAMPM2.selectedIndex * 1000);
			var endTime = tmpRef + thisForm.EndHour2.selectedIndex * 20 +  thisForm.EndMin2.selectedIndex;		
	
			//var startTime = thisForm.StartAMPM2.selectedIndex * 1000 + thisForm.StartHour2.selectedIndex * 10 +  thisForm.StartMin2.selectedIndex;
			//var endTime = thisForm.EndAMPM2.selectedIndex * 1000 + thisForm.EndHour2.selectedIndex * 10 +  thisForm.EndMin2.selectedIndex;		
			
			if (startTime >= endTime)
				if  (!onError(thisForm.StartMin2, "Error in Open House 2 time fields: \n - Start time must be greater than end time"))
				{
					return false;
				}
		}		
		return true;
}


function  ValidateForm3(thisForm)
{
	return true;
}

function  ValidateForm4(thisForm)
{
	return true;
}

