var errors, hddnLegalId, edtLegalName, txtLegalText, cbLegalActive;
var module = baseRootURL + "legal/";



function registerLegal(action)
{
	errors = false;
	validate_hddnLegalId();
	validate_edtLegalName();
	nicEditors.findEditor('txtLegalText').saveContent();
	validate_txtLegalText();
	validate_cbLegalActive();
	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("hddnLegalId") != null) data.hddnLegalId = hddnLegalId;
		data.edtLegalName = edtLegalName;
		data.txtLegalText = txtLegalText;
		data.cbLegalActive = cbLegalActive;
		callModule("legal/legal_val.php", data);
	}
}

function insertLegal(){registerLegal(0)}

function modifyLegal(){registerLegal(1)}

function validate_hddnLegalId(){if (document.getElementById("hddnLegalId") != null) hddnLegalId=document.getElementById("hddnLegalId").value;}
function validate_edtLegalName(){edtLegalName=validateRequiredText("edtLegalName", "This field is required.");}
function validate_txtLegalText(){txtLegalText=validateTextArea("txtLegalText", "Field is required.", true);}
function validate_cbLegalActive(){cbLegalActive = document.getElementById("cbLegalActive").checked;}

function viewLegal(id)
{
	var data = {}
	data.dummy = "";
	data.hddnLegalId = id;
	data.action = 2;
	callModule("legal/legal_val.php", data);
}

function editLegal(id)
{
	var data = {}
	data.dummy = "";
	data.hddnLegalId = id;
	data.action = 3;
	callModule("legal/legal_val.php", data);
}

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