var errors, hddnVehicleId, edtVehicleReg, edtVehicleName, edtVehicleDesc, cbVehicleActive;
var module = baseRootURL + "vehicle/";

function registerVehicle(action)
{
	errors = false;
	validate_hddnVehicleId();
	validate_edtVehicleReg();
	validate_edtVehicleName();
	validate_edtVehicleDesc();
	validate_cbVehicleActive();
	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("hddnVehicleId") != null) data.hddnVehicleId = hddnVehicleId;
		data.edtVehicleReg = edtVehicleReg;
		data.edtVehicleName = edtVehicleName;
		data.edtVehicleDesc = edtVehicleDesc;
		data.cbVehicleActive = cbVehicleActive;
		callModule("vehicle/vehicle_val.php", data);
	}
}
function insertVehicle(){registerVehicle(0)}
function modifyVehicle(){registerVehicle(1)}

function validate_hddnVehicleId(){
	if (document.getElementById("hddnVehicleId") != null) hddnVehicleId=document.getElementById("hddnVehicleId").value;}
function validate_edtVehicleReg(){edtVehicleReg=validateRequiredText("edtVehicleReg", "This field is required.");}
function validate_edtVehicleName(){edtVehicleName=validateRequiredText("edtVehicleName", "This field is required.");}
function validate_edtVehicleDesc(){edtVehicleDesc=document.getElementById("edtVehicleDesc").value;}
function validate_cbVehicleActive(){cbVehicleActive = document.getElementById("cbVehicleActive").checked;}

function viewVehicle(id)
{
	var data = {}
	data.dummy = "";
	data.hddnVehicleId = id;
	data.action = 2;
	callModule("vehicle/vehicle_val.php", data);
}

function editVehicle(id)
{
	var data = {}
	data.dummy = "";
	data.hddnVehicleId = id;
	data.action = 3;
	callModule("vehicle/vehicle_val.php", data);
}

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