var errors, hddnCategoryId, edtCategoryName;
var module = baseRootURL + "category/";


function registerCategory(action)
{
	errors = false;
	validate_hddnCategoryId();
	validate_edtCategoryName();
	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("hddnCategoryId") != null) data.hddnCategoryId = hddnCategoryId;
		data.edtCategoryName = edtCategoryName;
		callModule("category/category_val.php", data);
	}
}

function insertCategory(){registerCategory(0)}

function modifyCategory(){registerCategory(1)}

function validate_hddnCategoryId(){if (document.getElementById("hddnCategoryId") != null) hddnCategoryId=document.getElementById("hddnCategoryId").value;}
function validate_edtCategoryName(){edtCategoryName=validateRequiredText("edtCategoryName", "This field is required.");}

function viewCategory(id)
{
	var data = {}
	data.dummy = "";
	data.hddnCategoryId = id;
	data.action = 2;
	callModule("category/category_val.php", data);
}

function editCategory(id)
{
	var data = {}
	data.dummy = "";
	data.hddnCategoryId = id;
	data.action = 3;
	callModule("category/category_val.php", data);
}

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