// validation of top form - search by property code
function validateTopForm(form)
{
	var myfields = new Array(form.propertycode)
	var mynames = new Array("Property ID")
	
	var errorFound01=false;
	var msg01="Please fill in or select a value for the following fields :\n\n";
	
	for (var i=0; i < myfields.length; i++)
	{
		
		if (myfields[i].value == "")
		{
			errorFound01=true;
			msg01=msg01 + mynames[i] + "\n";
		}
	}
	
	if(errorFound01)
	{
		alert(msg01);
		return false;
	}
	else
	{
		return true;
	}
}

// validation of bottom form - search by suburb, postcode .... search key
// this form validation is used to 'Commercial' search, which does not have search critiria of 'Bedrooms'
function validateBottomForm(form)
{
	var errorFound01=false;
	var msg01="The following errors occurred:\n\n";
	
	
	//validate post code
	var input_postcode=form.postcode.value;
	var postcodeFilter=/^[0-9]{3,4}$/i
	if(input_postcode != ''){
		if (!postcodeFilter.test(input_postcode))
		{
			errorFound01 = true;
			msg01 += "Invalid Post Code.\n";
		}
	}
	
	//validate price range
	var input_pricefrom = form.pricefrom.value;
	var input_priceto = form.priceto.value;
	if((input_pricefrom == '' && input_priceto != '') || (input_pricefrom != '' && input_priceto == '')){
		errorFound01=true;
		msg01 += "Please select both Price Range Min and Max, or select none of them.\n";
	} else if((input_pricefrom != '' && input_priceto != '') && (parseInt(input_pricefrom) > parseInt(input_priceto))){
		errorFound01=true;
		msg01 += "Price Range Min must be less than Price Range Max.\n";
	}
	
	//validate floor area range
	var input_floorareafrom = form.floorareafrom.value;
	var input_floorareato = form.floorareato.value;
	if((input_floorareafrom == '' && input_floorareato != '') || (input_floorareafrom != '' && input_floorareato == '')){
		errorFound01=true;
		msg01 += "Please select both Floor Area Min and Max, or select none of them.\n";
	} else if((input_floorareafrom != '' && input_floorareato != '') && (parseInt(input_floorareafrom) > parseInt(input_floorareato))){
		errorFound01=true;
		msg01 += "Floor Area Min must be less than Price Range Max.\n";
	}
	
		
	if(errorFound01)
	{
		alert(msg01);
		return false;
	}
	else
	{
		return true;
	}
}




