function addListeners_products() {

	
	// 1. Check if new or old product Description
	var productDescription = $('productDescription_name_old_id');
	addEvent(productDescription,'change', check_productDescription ,false);
	
	// 2. Add Unit Text to hidden input;
	var unit_id = $('unit_id');
	addEvent(unit_id,'change', check_unit ,false);
}


function check_productDescription() {

	var source = 'productDescription_name_old_id';
	var container = $('productDescription_name_new_container');
	var source_text = $('productDescription_name_old_text');

	var productDescription_id = $F(source);
	var productDescription_text = getAnOptionText(source);
	

	if (productDescription_id == 'createNew') {
		var new_prod = "<input name='productDescription_name_new' type='text' id='productDescription_name_new' value='Insert New Product Description Here' maxlength='200' />";
		container.innerHTML = new_prod;
		$('productDescription_name_new').focus();
		$('productDescription_name_new').select();
	} else {
		container.innerHTML = "";
		source_text.value = productDescription_text;
	}

}


function check_unit() {

	var source = 'unit_id';
	var source_text = $('unit_text');

	var unit_id = getAnOptionValue(source);
	var unit_text = getAnOptionText(source);
	

	if (unit_id == 0) {
		source_text.value = 'No Unit Selected';
	} else {
		source_text.value = unit_text;
	}

}



function add_modelCatNo() {

var target = 'items'; 
var model_id = getAnOptionValue('modelList_id');
var model_name = getAnOptionText('modelList_id');
var prodCatNumber = getATextBoxValue('prodCatNumber_name');

var obj = $(target);

// Add Checks Here For Model & Prod Cat Value
	// 0 = MODEL ID
	// 1 = Model Name
	// 2 = Product Category Number

if (model_id != 0) { 
	new_item = model_id + "$$$" + model_name + "$$$" + prodCatNumber;
	
	items = getATextBoxValue(target);
	
	items = (items == '') ? items = new_item : items = getATextBoxValue(target)  + "@@@" + new_item;

	obj.value = items;
	
	var source 			= escape(obj.value);
	var url				= 'add_swanName_modelCatNo_items.php';
	var target 			= $('items_listing');
	var params			= 'source=' + source;
	
	
	new Ajax.Updater(target, url,{ 
						method: 'post',
						parameters: params
					 });

} else {
	// do nothing.
	
} // End IF (model_id != 0) statement

	
} // end Function



function deleteItem(count, pathToUrl) {

	count = (count*1);
	var target = $('items_listing');
	var items = $('items');
	var itemsValue = items.value;
	var itemsArray = itemsValue.split('@@@');
	var new_itemsValue = '';
	
	
	for (var i=0; i < itemsArray.length; i++) {
		if (i == count) {
		
		} else {
			new_itemsValue += itemsArray[i];
			
			// Find out if current i is the second to the last. 
			// if so, do not print |||
			if (
				(itemsArray.length == (count+1)) && (i == (count-1)) ||
				(i == (itemsArray.length -1))
				) {
			} else {	
				new_itemsValue += '@@@';
			}
		}
	}
	
	items.value = new_itemsValue;
	
	/* list all items */
	var source 			= escape(items.value);
	var url				= pathToUrl;
	var params			= 'source=' + source;
	
	if (items.value != '') { // if items is NOT blank
		
			new Ajax.Updater(target, url,{ 
							method: 'post',
							parameters: params
						 });
	} else { // CLEAR items_listing
		target.innerHTML = '';
	}

}
