var errors, hddnAreaId, edtAreaName;
var module = baseRootURL + "area/";

function registerArea(action)
{
	errors = false;
	validate_hddnAreaId();
	validate_edtAreaName();
	validate_selAreaId();
	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("hddnAreaId") != null) data.hddnAreaId = hddnAreaId;
		data.edtAreaName = edtAreaName;
		callModule("area/area_val.php", data);
	}
}
function insertArea(){registerArea(0)}
function modifyArea(){registerArea(1)}

function validate_hddnAreaId(){
	if (document.getElementById("hddnAreaId") != null) hddnAreaId=document.getElementById("hddnAreaId").value;}
function validate_edtAreaName(){edtAreaName=validateRequiredText("edtAreaName", "This field is required.");}
function validate_selAreaId(){selAreaId=validateRequiredSelection("selAreaId", "Please make a valid selection.");}

function viewArea(id)
{
	var data = {}
	data.dummy = "";
	data.hddnAreaId = id;
	data.action = 2;
	callModule("area/area_val.php", data);
}

function editArea(id)
{
	var data = {}
	data.dummy = "";
	data.hddnAreaId = id;
	data.action = 3;
	callModule("area/area_val.php", data);
}

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

function setAreaName()
{
	"use strict"; 
	var sel = document.getElementById('selAreaId');
	document.getElementById('edtAreaName').value = sel.options[sel.selectedIndex].innerHTML;
}