Event.observe(window, 'load', init, false);

function init()
{
	//
}

// Validate inventory set name ID
function valInvNomId()
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=val&typ=inv_nom_id&inv_nom_id=' + escape($F('inv_nom_id'));
	
	// Validate inventory set name ID
	/*
	if ($F('inv_nom_id') == '')
	{
		alert('Please provide an Asset Group Name ID.');
		return(false);
	}
	*/
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			// Highlight
			$('inv_nom_id').style.color = '#FF0000';
		}
		else
		{
			// No highlight
			$('inv_nom_id').style.color = '#666666';
		}
	}
}

// Validate inventory set password
function valInvPwd()
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=val&typ=pwd&pwd=' + escape($F('pwd'));
	
	// Validate inventory set password
	/*
	if ($F('pwd') == '')
	{
		alert('Please provide an Asset Group Password.');
		return(false);
	}
	*/
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			// Highlight
			$('pwd').style.color = '#FF0000';
		}
		else
		{
			// No highlight
			$('pwd').style.color = '#666666';
		}
	}
}

/*
 * Remove inventory set
 */
function cmdRmInv(inv_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv&inv_id=' + escape(inv_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Asset group was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_row_' + inv_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory item
 */
function cmdRmInvItm(inv_id, inv_itm_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_itm&inv_id=' + escape(inv_id) + '&inv_itm_id=' + escape(inv_itm_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Asset item was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_itm_row_' + inv_id + '_' + inv_itm_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory item custom field
 */
function cmdRmInvItmFld(inv_id, inv_itm_fld_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_itm_fld&inv_id=' + escape(inv_id) + '&inv_itm_fld_id=' + escape(inv_itm_fld_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Asset item custom field was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_itm_fld_row_' + inv_id + '_' + inv_itm_fld_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory status
 */
function cmdRmInvSt(inv_id, inv_st_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_st&inv_id=' + escape(inv_id) + '&inv_st_id=' + escape(inv_st_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Status was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_st_row_' + inv_id + '_' + inv_st_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory category
 */
function cmdRmInvCat(inv_id, inv_cat_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_cat&inv_id=' + escape(inv_id) + '&inv_cat_id=' + escape(inv_cat_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Category was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_cat_row_' + inv_id + '_' + inv_cat_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory custodian
 */
function cmdRmInvUsr(inv_id, inv_usr_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_usr&inv_id=' + escape(inv_id) + '&inv_usr_id=' + escape(inv_usr_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Custodian was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_usr_row_' + inv_id + '_' + inv_usr_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory department
 */
function cmdRmInvDpt(inv_id, inv_dpt_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_dpt&inv_id=' + escape(inv_id) + '&inv_dpt_id=' + escape(inv_dpt_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Department was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_dpt_row_' + inv_id + '_' + inv_dpt_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory location
 */
function cmdRmInvLoc(inv_id, inv_loc_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_loc&inv_id=' + escape(inv_id) + '&inv_loc_id=' + escape(inv_loc_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Location was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_loc_row_' + inv_id + '_' + inv_loc_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory manufacturer
 */
function cmdRmInvMfg(inv_id, inv_mfg_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_mfg&inv_id=' + escape(inv_id) + '&inv_mfg_id=' + escape(inv_mfg_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Manufacturer was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_mfg_row_' + inv_id + '_' + inv_mfg_id, {duration: 0.5});
		}
	}
}

/*
 * Remove inventory vendor
 */
function cmdRmInvVen(inv_id, inv_ven_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_ven&inv_id=' + escape(inv_id) + '&inv_ven_id=' + escape(inv_ven_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Vendor was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_ven_row_' + inv_id + '_' + inv_ven_id, {duration: 0.5});
		}
	}
}

// Add/update inventory location building
function cmdInvLocBld(cmd, id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=' + cmd + '&typ=inv_loc_bld&inv_id=' + escape($F('ilb_' + cmd + '_inv_id_' + id)) + '&inv_loc_id=' + escape($F('ilb_' + cmd + '_inv_loc_id_' + id)) + '&inv_loc_bld_id=' + escape($F('ilb_' + cmd + '_inv_loc_bld_id_' + id)) + '&bld=' + escape($F('ilb_' + cmd + '_bld_' + id)) + '&dsc=' + escape($F('ilb_' + cmd + '_dsc_' + id));
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			// Add
			if (cmd == 'mk') 
			{
				alert('Building was not added.');
			}
			// Update
			else if (cmd == 'ch')
			{
				alert('Building was not updated.');
			}
			
			return(false);
		}
		else
		{
			// Hide form
			Effect.Fade('frm_' + cmd + '_inv_loc_bld_box_' + id, {duration: 0.0});
			
			// Add
			if (cmd == 'mk') 
			{
				// Generate listing
				$('inv_loc_bld_lst_' + $F('ilb_' + cmd + '_inv_loc_id_' + id)).innerHTML = result;
			}
			// Update
			else if (cmd == 'ch')
			{
				// Hide form
				Effect.Appear('inv_loc_bld_' + id, {duration: 0.5});
				
				// Update values
				$('inv_loc_bld_bld_' + id).innerHTML = $F('ilb_' + cmd + '_bld_' + id);
				$('inv_loc_bld_dsc_' + id).innerHTML = (($('inv_loc_bld_dsc_' + id).innerHTML == '') ? (' - ') : ('')) + $F('ilb_' + cmd + '_dsc_' + id);
			}
			
			// Clear form
			$('ilb_' + cmd + '_bld_' + id).value = '';
			$('ilb_' + cmd + '_dsc_' + id).value = '';
		}
	}
}

// Add/update inventory location building room
function cmdInvLocBldRm(cmd, id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=' + cmd + '&typ=inv_loc_bld_rm&inv_id=' + escape($F('ilbr_' + cmd + '_inv_id_' + id)) + '&inv_loc_id=' + escape($F('ilbr_' + cmd + '_inv_loc_id_' + id)) + '&inv_loc_bld_id=' + escape($F('ilbr_' + cmd + '_inv_loc_bld_id_' + id)) + '&inv_loc_bld_rm_id=' + escape(id) + '&rm=' + escape($F('ilbr_' + cmd + '_rm_' + id)) + '&dsc=' + escape($F('ilbr_' + cmd + '_dsc_' + id));
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			// Add
			if (cmd == 'mk') 
			{
				alert('Room was not added.');
			}
			// Update
			else if (cmd == 'ch')
			{
				alert('Room was not updated.');
			}
			
			return(false);
		}
		else
		{
			// Hide form
			Effect.Fade('frm_' + cmd + '_inv_loc_bld_rm_box_' + id, {duration: 0.0});
			
			// Add
			if (cmd == 'mk') 
			{
				// Generate listing
				$('inv_loc_bld_rm_lst_' + id).innerHTML = result;
			}
			// Update
			else if (cmd == 'ch')
			{
				// Hide form
				Effect.Appear('inv_loc_bld_rm_' + id, {duration: 0.5});
				
				// Update values
				$('inv_loc_bld_rm_rm_' + id).innerHTML = $F('ilbr_' + cmd + '_rm_' + id);
				$('inv_loc_bld_rm_dsc_' + id).innerHTML = (($('inv_loc_bld_rm_dsc_' + id).innerHTML == '') ? (' - ') : ('')) + $F('ilbr_' + cmd + '_dsc_' + id);
			}
			
			// Clear form
			$('ilbr_' + cmd + '_rm_' + id).value = '';
			$('ilbr_' + cmd + '_dsc_' + id).value = '';
		}
	}
}

/*
 * Remove inventory location building
 */
function cmdRmInvLocBld(inv_id, inv_loc_id, inv_loc_bld_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_loc_bld&inv_id=' + escape(inv_id) + '&inv_loc_id=' + escape(inv_loc_id) + '&inv_loc_bld_id=' + escape(inv_loc_bld_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Building was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_loc_bld_box_' + inv_loc_bld_id, {duration: 0.5});
		}
	}
}

// Add/update inventory location building room
function cmdRmInvLocBldRm(inv_id, inv_loc_id, inv_loc_bld_id, inv_loc_bld_rm_id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=rm&typ=inv_loc_bld_rm&inv_id=' + escape(inv_id) + '&inv_loc_id=' + escape(inv_loc_id) + '&inv_loc_bld_id=' + escape(inv_loc_bld_id) + '&inv_loc_bld_rm_id=' + escape(inv_loc_bld_rm_id);
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Room was not removed.');
			return(false);
		}
		else
		{
			// Hide row
			Effect.Fade('inv_loc_bld_rm_box_' + inv_loc_bld_rm_id, {duration: 0.5});
		}
	}
}

/*
 * Building inventory location listing
 */
function cmdInvLocLst(typ)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=lst&typ=' + escape(typ) + '&inv_id=' + escape($F('inv_id')) + '&inv_loc_id=' + escape($F('inv_loc_id')) + '&inv_loc_bld_id=' + escape($F('inv_loc_bld_id')) + '&inv_loc_bld_rm_id=' + escape($F('inv_loc_bld_rm_id'));
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Could not populate list.');
			return(false);
		}
		else
		{
			// Types
			if (typ == 'loc')
			{
				// Convert result string to object
				var inv_loc_obj = eval('(' + result + ')');
				
				var inv_loc_lst_len = $('inv_loc_id').length;
				var inv_loc_num = inv_loc_obj.inv_loc.length;
				
				// Clear ALL options
				$('inv_loc_id').options.length = 0;
				
				// Populate SELECT options
				for (i = 0; i <= (inv_loc_num - 1); i++)
				{
					$('inv_loc_id').options[i] = new Option(inv_loc_obj.inv_loc[i].loc, inv_loc_obj.inv_loc[i].inv_loc_id);
				}
			}
			else if (typ == 'bld')
			{
				// Convert result string to object
				var inv_loc_bld_obj = eval('(' + result + ')');
				
				var inv_loc_bld_lst_len = $('inv_loc_bld_id').length;
				var inv_loc_bld_num = inv_loc_bld_obj.inv_loc_bld.length;
				
				// Clear ALL options
				$('inv_loc_bld_id').options.length = 0;
				// Clear ALL options for rooms
				$('inv_loc_bld_rm_id').options.length = 0;
				
				// Populate SELECT options
				for (i = 0; i <= (inv_loc_bld_num - 1); i++)
				{
					$('inv_loc_bld_id').options[i] = new Option(inv_loc_bld_obj.inv_loc_bld[i].bld, inv_loc_bld_obj.inv_loc_bld[i].inv_loc_bld_id);
				}
				
				// Assign default value
				//$('inv_loc_bld_id').value = inv_loc_bld_id;
			}
			else if (typ == 'rm')
			{
				// Convert result string to object
				var inv_loc_bld_rm_obj = eval('(' + result + ')');
				
				var inv_loc_bld_rm_lst_len = $('inv_loc_bld_rm_id').length;
				var inv_loc_bld_rm_num = inv_loc_bld_rm_obj.inv_loc_bld_rm.length;
				
				// Clear ALL options
				$('inv_loc_bld_rm_id').options.length = 0;
				
				// Populate SELECT options
				for (i = 0; i <= (inv_loc_bld_rm_num - 1); i++)
				{
					$('inv_loc_bld_rm_id').options[i] = new Option(inv_loc_bld_rm_obj.inv_loc_bld_rm[i].rm, inv_loc_bld_rm_obj.inv_loc_bld_rm[i].inv_loc_bld_rm_id);
				}
				
				// Assign default value
				//$('inv_loc_bld_rm_id').value = inv_loc_bld_rm_id;
			}
		}
	}
}

/*
 * Add/update inventory vendor contact
 */
function cmdInvVenCtc(cmd, id)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=' + cmd + '&typ=inv_ven_ctc&inv_id=' + escape($F('ivc_' + cmd + '_inv_id_' + id)) + '&inv_ven_id=' + escape($F('ivc_' + cmd + '_inv_ven_id_' + id)) + '&inv_ven_ctc_id=' + escape($F('ivc_' + cmd + '_inv_ven_ctc_id_' + id)) + '&ctc=' + escape($F('ivc_' + cmd + '_ctc_' + id)) + '&dsc=' + escape($F('ivc_' + cmd + '_dsc_' + id)) + '&tel=' + escape($F('ivc_' + cmd + '_tel_' + id)) + '&tel_ext=' + escape($F('ivc_' + cmd + '_tel_ext_' + id)) + '&eml=' + escape($F('ivc_' + cmd + '_eml_' + id));
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			// Add
			if (cmd == 'mk') 
			{
				alert('Vendor contact was not added.');
			}
			// Update
			else if (cmd == 'ch')
			{
				alert('Vendor contact was not updated.');
			}
			
			return(false);
		}
		else
		{
			// Hide form
			Effect.Fade('frm_' + cmd + '_inv_ven_ctc_box_' + id, {duration: 0.0});
			
			// Add
			if (cmd == 'mk') 
			{
				// Generate listing
				$('inv_ven_ctc_lst_' + $F('ivc_' + cmd + '_inv_ven_id_' + id)).innerHTML = result;
			}
			// Update
			else if (cmd == 'ch')
			{
				// Hide form
				Effect.Appear('inv_ven_ctc_' + id, {duration: 0.5});
				
				// Update values
				$('inv_ven_ctc_ctc_' + id).innerHTML = $F('ivc_' + cmd + '_ctc_' + id);
				$('inv_ven_ctc_tel_' + id).innerHTML = $F('ivc_' + cmd + '_tel_' + id);
				$('inv_ven_ctc_tel_ext_' + id).innerHTML = $F('ivc_' + cmd + '_tel_ext_' + id);
				$('inv_ven_ctc_eml_' + id).innerHTML = $F('ivc_' + cmd + '_eml_' + id);
				$('inv_ven_ctc_dsc_' + id).innerHTML = $F('ivc_' + cmd + '_dsc_' + id);
			}
			
			// Clear form
			$('ivc_' + cmd + '_ctc_' + id).value = '';
			$('ivc_' + cmd + '_dsc_' + id).value = '';
			$('ivc_' + cmd + '_tel_' + id).value = '';
			$('ivc_' + cmd + '_tel_ext_' + id).value = '';
			$('ivc_' + cmd + '_eml_' + id).value = '';
		}
	}
}

/*
 * Building inventory vendor listing
 */
function cmdInvVenLst(typ)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=lst&typ=' + escape(typ) + '&inv_id=' + escape($F('inv_id')) + '&inv_ven_id=' + escape($F('inv_ven_id')) + '&inv_ven_ctc_id=' + escape($F('inv_ven_ctc_id'));
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('Could not populate list.');
			return(false);
		}
		else
		{
			// Types
			if (typ == 'ven')
			{
				// Convert result string to object
				var inv_ven_obj = eval('(' + result + ')');
				
				var inv_ven_lst_len = $('inv_ven_id').length;
				var inv_ven_num = inv_ven_obj.inv_ven.length;
				
				// Clear ALL options
				$('inv_ven_id').options.length = 0;
				
				// Populate SELECT options
				for (i = 0; i <= (inv_ven_num - 1); i++)
				{
					$('inv_ven_id').options[i] = new Option(inv_ven_obj.inv_ven[i].ven, inv_ven_obj.inv_ven[i].inv_ven_id);
				}
			}
			else if (typ == 'ctc')
			{
				// Convert result string to object
				var inv_ven_ctc_obj = eval('(' + result + ')');
				
				var inv_ven_ctc_lst_len = $('inv_ven_ctc_id').length;
				var inv_ven_ctc_num = inv_ven_ctc_obj.inv_ven_ctc.length;
				
				// Clear ALL options
				$('inv_ven_ctc_id').options.length = 0;
				
				// Populate SELECT options
				for (i = 0; i <= (inv_ven_ctc_num - 1); i++)
				{
					$('inv_ven_ctc_id').options[i] = new Option(inv_ven_ctc_obj.inv_ven_ctc[i].ctc, inv_ven_ctc_obj.inv_ven_ctc[i].inv_ven_ctc_id);
				}
				
				// Assign default value
				//$('inv_ven_ctc_id').value = inv_ven_ctc_id;
			}
		}
	}
}

/*
 * Add delegation rights
 */
function cmdMkInvDel(typ)
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=mk&typ=inv_del&inv_del_typ=' + typ + '&inv_id=' + $F('inv_id') + '&usr_id=' + $F('usr_id');
	
	if (isNaN(parseFloat($F('usr_id'))))
	{
		alert('Please select a user to delegate.');
		return(false);
	}
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		if (result == '0')
		{
			alert('An error occurred while delegating this user.');
		}
		else if (result != '0')
		{
			// Assign new option ID
			var inv_del_id = result;
			
			// Append new delegate to delegate type list
			$('inv_del_lst_' + typ).innerHTML = $('inv_del_lst_' + typ).innerHTML + '<span id="inv_del_id_' + inv_del_id + '">' + $('usr_id').options[$('usr_id').selectedIndex].text + '<br /></span>';
		}
		
		// Clear user search text field
		//$('q').value = '';
		
		return(false);
	}
}

/*
 * Add custom field option 
 */
function doInvItmFldOpt()
{
	var url = '/lib/inc/ajax/edz/mng_inv.php';
	var meth = 'post';
	var parm = 'cmd=mk&typ=inv_itm_fld_opt&inv_id=' + $F('inv_id') + '&inv_itm_fld_id=' + $F('inv_itm_fld_id') + '&inv_itm_fld_opt=' + escape($F('inv_itm_fld_opt'));
	
	// Set focus
	$('inv_itm_fld_opt').focus();
	
	// Validate option value
	if ($F('inv_itm_fld_opt') == '')
	{
		alert('Please provide a valid custom field option.');
		return(false);
	}
	
	// AJAX request call
	var myAjax = new Ajax.Request(
								  url,
								  {
										method: meth,
										parameters: parm,
										onComplete: showResponse
									}
								);
	
	// AJAX onComplete call
	function showResponse(request)
	{
		// Messages text block
		var result = request.responseText;
		
		// Display message text block
		//alert(result);
		
		// Validate option value
		if (result == 'ERR-NOT_FLD')
		{
			alert('Custom field not found. Cannot add option.');
		}
		else if (result == 'ERR-DUP_REC')
		{
			alert('The option you provided already exists.');
		}
		else if (result == 'ERR-NOT_LST')
		{
			alert('Field is not a list. Cannot add option.');
		}
		else if (result == '0')
		{
			alert('An error has occurred while adding this option.');
		}
		else if (result != '0')
		{
			// Assign new option ID
			var inv_itm_fld_opt_id = result;
			
			// Append new options in checkbox list
			$('inv_itm_fld_opt_lst').innerHTML = $('inv_itm_fld_opt_lst').innerHTML + '<span id="inv_itm_fld_opt_id_' + inv_itm_fld_opt_id + '">' + $F('inv_itm_fld_opt') + '<br /></span>';
			
		}
		
		// Clear options text field
		$('inv_itm_fld_opt').value = '';
		
		return(false);
	}
}