var errors, hddnAddressId, hddnClientId, hddnAddressTypeId, hddnCountryId, hddnPostId, edtAddressStreet, edtAddressSuburb, edtAddressCity, edtAddressCounty, edtAddressPostalCode, edtAddressLng, edtAddressLat;
var module = baseRootURL + "address/";

function registerAddress(action)
{
	errors = false;
	validate_hddnAddressId();
	validate_hddnClientId();
	validate_hddnAddressTypeId();
	validate_hddnCountryId();
	validate_hddnPostId();
	validate_edtAddressStreet();
	validate_edtAddressSuburb();
	validate_edtAddressCity();
	validate_edtAddressCounty();
	validate_edtAddressPostalCode();
	validate_edtAddressLng();
	validate_edtAddressLat();
	if (!errors)
	{
		var data = {};
		data.dummy = ""; //we seem to get errors from the first value, so always add a dummy value first.
		data.action = action;
		if (document.getElementById("hddnAddressId") != null) data.hddnAddressId = hddnAddressId;
		data.hddnClientId = hddnClientId;
		data.hddnAddressTypeId = hddnAddressTypeId;
		data.hddnCountryId = hddnCountryId;
		data.hddnPostId = hddnPostId;
		data.edtAddressStreet = edtAddressStreet;
		data.edtAddressSuburb = edtAddressSuburb;
		data.edtAddressCity = edtAddressCity;
		data.edtAddressCounty = edtAddressCounty;
		data.edtAddressPostalCode = edtAddressPostalCode;
		data.edtAddressLng = edtAddressLng;
		data.edtAddressLat = edtAddressLat;
		callModule("address/address_val.php", data);
	}
}
function insertAddress(){registerAddress(0)}
function modifyAddress(){registerAddress(1)}

function validate_hddnAddressId(){
	if (document.getElementById("hddnAddressId") != null) hddnAddressId=document.getElementById("hddnAddressId").value;}
function validate_hddnClientId(){
	if (document.getElementById("hddnClientId") != null) hddnClientId=document.getElementById("hddnClientId").value;}
function validate_hddnAddressTypeId(){
	if (document.getElementById("hddnAddressTypeId") != null) hddnAddressTypeId=document.getElementById("hddnAddressTypeId").value;}
function validate_hddnCountryId(){
	if (document.getElementById("hddnCountryId") != null) hddnCountryId=document.getElementById("hddnCountryId").value;}
function validate_hddnPostId(){
	if (document.getElementById("hddnPostId") != null) hddnPostId=document.getElementById("hddnPostId").value;}
function validate_edtAddressStreet(){edtAddressStreet=validateRequiredText("edtAddressStreet", "Address Street is required.");}
function validate_edtAddressSuburb(){edtAddressSuburb=validateRequiredText("edtAddressSuburb", "Address Suburb is required.");}
function validate_edtAddressCity(){edtAddressCity=validateRequiredText("edtAddressCity", "Address City is required.");}
function validate_edtAddressCounty(){edtAddressCounty=validateRequiredText("edtAddressCounty", "Address County is required.");}
function validate_edtAddressPostalCode(){edtAddressPostalCode=validateRequiredText("edtAddressPostalCode", "Address Postal Code is required.");}
function validate_edtAddressLng(){edtAddressLng=validateRequiredText("edtAddressLng", "Address Lng is required.");}
function validate_edtAddressLat(){edtAddressLat=validateRequiredText("edtAddressLat", "Address Lat is required.");}

function viewAddress(id)
{
	var data = {}
	data.dummy = "";
	data.hddnAddressId = id;
	data.action = 2;
	callModule("address/address_val.php", data);
}

function editAddress(id)
{
	var data = {}
	data.dummy = "";
	data.hddnAddressId = id;
	data.action = 3;
	callModule("address/address_val.php", data);
}

function deleteAddress(id, desc)
{
	if (confirm("Are you sure you want to delete "+desc+" and all associated records?"))
	{
		var data = {}
		data.dummy = "";
		data.hddnAddressId = id;
		data.action = 4;
		callModule("address/address_val.php", data);
	}
}


