var errors, hddnPostId, edtSuburbName, edtBoxCode, edtStrCode, edtRegionName;
var module = baseRootURL + "postal_data/";

function registerPostal_data(action)
{
	errors = false;
	validate_hddnPostId();
	validate_edtSuburbName();
	validate_edtBoxCode();
	validate_edtStrCode();
	validate_edtRegionName();
	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("hddnPostId") != null) data.hddnPostId = hddnPostId;
		data.edtSuburbName = edtSuburbName;
		data.edtBoxCode = edtBoxCode;
		data.edtStrCode = edtStrCode;
		data.edtRegionName = edtRegionName;
		callModule("postal_data/postal_data_val.php", data);
	}
}
function insertPostal_data(){registerPostal_data(0)}
function modifyPostal_data(){registerPostal_data(1)}

function validate_hddnPostId(){
	if (document.getElementById("hddnPostId") != null) hddnPostId=document.getElementById("hddnPostId").value;}
function validate_edtSuburbName(){edtSuburbName=validateRequiredText("edtSuburbName", "Suburb Name is required.");}
function validate_edtBoxCode(){edtBoxCode=validateRequiredText("edtBoxCode", "Box Code is required.");}
function validate_edtStrCode(){edtStrCode=validateRequiredText("edtStrCode", "Str Code is required.");}
function validate_edtRegionName(){edtRegionName=validateRequiredText("edtRegionName", "Region Name is required.");}

function viewPostal_data(id)
{
	var data = {}
	data.dummy = "";
	data.hddnPostId = id;
	data.action = 2;
	callModule("postal_data/postal_data_val.php", data);
}

function editPostal_data(id)
{
	var data = {}
	data.dummy = "";
	data.hddnPostId = id;
	data.action = 3;
	callModule("postal_data/postal_data_val.php", data);
}

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


function setSuburbName()
{
	"use strict"; 
	var sel = document.getElementById('selPostId');
	document.getElementById('edtSuburbName').value = sel.options[sel.selectedIndex].innerHTML;
}