function DoValidation ()
{
	var oForm = document.forms[0];

	if (oForm.property_province.value.length < 2 )
	{
		hideErrors();
		document.getElementById("provinceError").style.display = "inline";
		return false;
	}

    if (oForm.property_suburb.value.length < 2 )
	{
		hideErrors();
		document.getElementById("suburbError").style.display = "inline";
		return false;
	}
	
	if (oForm.property_office.value.length < 1) 
	{
		hideErrors();
		document.getElementById("officeError").style.display = "inline";
		return false;
	}

    if (oForm.property_bedrooms.value.length < 1)
	{
		hideErrors();
		document.getElementById("bedroomsError").style.display = "inline";
		return false;
	}

    if (oForm.property_bathrooms.value.length < 1)
	{
		hideErrors();
		document.getElementById("bathroomsError").style.display = "inline";
		return false;
	}
	
	if (oForm.client_name.value.length < 2 )
	{
		hideErrors();
		document.getElementById("nameError").style.display = "inline";
		return false;
	}
	
	if (oForm.client_email.value.length < 2) 
	{
		hideErrors();
		document.getElementById("emailError").style.display = "inline";
		return false;
	}
	
	if (oForm.sec_number.value!=oForm.correct_code.value)
	{
		hideErrors();
		document.getElementById("codeError").style.display = "inline";
		return false;
	}

	oForm.submit();
}

function hideErrors()
{
	document.getElementById("provinceError").style.display = "none";
    document.getElementById("suburbError").style.display = "none";
    document.getElementById("officeError").style.display = "none";
	document.getElementById("bedroomsError").style.display = "none";
    document.getElementById("bathroomsError").style.display = "none";
	document.getElementById("nameError").style.display = "none";
	document.getElementById("emailError").style.display = "none";
	document.getElementById("codeError").style.display = "none";
}

function loadSellingData(provinceid)
{
	var param = '';
	switch(true)
	{
		case provinceid != "0":
			param += "ProvinceID="+provinceid;
		break;
	}
	
	$('property_office').options.length = 0;
	
	new Ajax.Request('/index.php',
     {
      	onSuccess : function(response) 
		{
			var option_count = 0;
			var Offices = $H(eval("("+response.responseText+")"));
			
			Offices.each(function(office)
		    {
				if(office.value.officetype.toLowerCase() == "office" && office.value.email.length > 0)
				{
					$('property_office').options[option_count] = new Option(office.value.suburb +" - ("+office.value.name+")",office.value.officeid+":"+office.value.suburb +" - ("+office.value.name+"):"+office.value.email);
			    	option_count++;
				}
    	
		    });
			$('property_office').disabled = false;
	    },
		onFailure : function(response)
		{
		    alert("Error occurred while loading data, please try again.")
		},
		parameters : "page=sellingoffer&content=main&json=yes&"+param
	});
}