<MvCOMMENT>
|
| Miva Merchant v4.x
|
| This file and the source codes contained herein are the property 
| of Miva Corporation.  Use of this file is restricted to the specific 
| terms and conditions in the License Agreement associated with this 
| file.  Distribution of this file or portions of this file for uses
| not covered by the License Agreement is not allowed without a written 
| agreement signed by an officer of Miva Corporation.
| 
| Copyright 1998-2001 Miva Corporation.  All rights reserved.
| http://www.miva.com/
|
| dBase III Database Layer
| $Source: /home/cvs/merchant/Merchant/lib/db.mv,v $
|
| Prefix         : MER-DTB-
| Next Error Code: 407  
| Next Text ID   : 188  
|
</MvCOMMENT>

<MvCOMMENT>
|
| BasketList/Baskets
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_BasketList" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_BasketList_Open }">
		<MvOPEN NAME = "BasketList"	
				DATABASE = "{ g._DB_Store_Directory $ 'basklist.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'blst_ses.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00001', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketList_Open" VALUE = 1>
			<MvFILTER NAME = "BasketList" FILTER = "{ NOT BasketList.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_FindSession" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.basket_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00001">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00002', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.basket_id" VALUE = "{ BasketList.d.basket_id }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.basket_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() }">
		<MvGO NAME = "BasketList" ROW = "top">
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "BasketList" ROWS = 1>
	<MvIF EXPR = "{ BasketList.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketLastUpdate_Update_LastUpdate" PARAMETERS = "session_id, lastupdate" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketLastUpdate() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketLastUpdate" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketLastUpdate.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00002">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket Last Update '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00003', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "BasketLastUpdate.d.lastupdate" VALUE = "{ l.lastupdate }">
			<MvUPDATE NAME = "BasketLastUpdate">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Insert" PARAMETERS = "session_id, lastupdate" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.basket_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_BasketLastUpdate() }">
		<MvASSIGN NAME = "BasketList.d.session_id" 	VALUE = "{ l.session_id }">
		<MvASSIGN NAME = "BasketList.d.cust_id" 	VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.basket_id" 	VALUE = "{ StoreKey_Generate( 'Baskets' ) }">

		<MvASSIGN NAME = "BasketList.d.order_id" 	VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.order_proc" 	VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.ship_fname" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_lname" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_email" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_comp" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_phone" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_fax" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_addr" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_city" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_state" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_zip" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.ship_cntry" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_fname" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_lname" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_email" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_comp" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_phone" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_fax" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_addr" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_city" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_state" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_zip" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.bill_cntry" 	VALUE = "">

		<MvASSIGN NAME = "BasketList.d.tax" 		VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.shipping" 	VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.ship_id" 	VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.ship_data" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.pay_id" 		VALUE = 0>
		<MvASSIGN NAME = "BasketList.d.pay_data" 	VALUE = "">
		<MvASSIGN NAME = "BasketList.d.total" 		VALUE = 0>

		<MvADD NAME = "BasketList">
		
		<MvASSIGN NAME = "BasketLastUpdate.d.session_id" 	VALUE = "{ l.session_id }">
		<MvASSIGN NAME = "BasketLastUpdate.d.lastupdate" 	VALUE = "{ l.lastupdate }">

		<MvADD NAME = "BasketLastUpdate">
		
		<MvDO FILE = "{ g.Module_Feature_STA }" NAME = "l.ok" VALUE = "{ Stats_Add_Visits( ) }">

		<MvIF EXPR = "{ g.Features:Affiliates:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ Affiliate_Insert_SessionID( l.session_id ) }">
		</MvIF>

		<MvASSIGN NAME = "l.basket_id" VALUE = "{ BasketList.d.basket_id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.basket_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_BasketLastUpdate" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_BasketLastUpdate_Open }">
		<MvOPEN NAME = "BasketLastUpdate"	
				DATABASE = "{ g._DB_Store_Directory $ 'basklupd.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'blup_ses.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00001', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketLastUpdate_Open" VALUE = 1>
			<MvFILTER NAME = "BasketLastUpdate" FILTER = "{ NOT BasketLastUpdate.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketLastUpdate_FindSession" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.lastupdate" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketLastUpdate() }">
		<MvFIND NAME = "BasketLastUpdate" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketLastUpdate.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00185">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket Last Update '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00401', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "lastupdate" VALUE = "{ BasketLastUpdate.d.lastupdate }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ lastupdate }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_Baskets" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Baskets_Open }">
		<MvOPEN NAME = "Baskets"
				DATABASE = "{ g._DB_Store_Directory $ 'baskets.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'bsk_id.mvx, ' $ g._DB_Store_Directory $ 'bsk_line.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00004', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Baskets_Open" VALUE = 1>
			<MvFILTER NAME = "Baskets" FILTER = "{ NOT Baskets.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_BasketOptions" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	
	<MvIF EXPR = "{ NOT g._DB_Store_BasketOptions_Open }">		
		<MvOPEN NAME = "BasketOptions"
				DATABASE = "{ g._DB_Store_Directory $ 'baskopts.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'bopt_ln.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00005', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketOptions_Open" VALUE = 1>
			<MvFILTER NAME = "BasketOptions" FILTER = "{ NOT BasketOptions.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_BasketCharges" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	
	<MvIF EXPR = "{ NOT g._DB_Store_BasketCharges_Open }">		
		<MvOPEN NAME = "BasketCharges"
				DATABASE = "{ g._DB_Store_Directory $ 'baskchrg.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'bchg_bid.mvx, ' $ 
							 g._DB_Store_Directory $ 'bchg_typ.mvx, ' $
							 g._DB_Store_Directory $ 'bchg_mod.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00341', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketCharges_Open" VALUE = 1>
			<MvFILTER NAME = "BasketCharges" FILTER = "{ NOT BasketCharges.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Free_Order" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00003">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00006', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ BasketList.d.order_id }">
				<MvASSIGN NAME = "Orphans.d.type" VALUE = "Orders">
				<MvASSIGN NAME = "Orphans.d.value" VALUE = "{ BasketList.d.order_id }">
				
				<MvADD NAME = "Orphans">
			</MvIF>
			
			<MvASSIGN NAME = "BasketList.d.order_id" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.cust_id" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.rate" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.discount" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.markup" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.order_proc" VALUE = 0>

			<MvASSIGN NAME = "BasketList.d.ship_fname" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_lname" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_email" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_comp" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_phone" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_fax" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_addr" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_city" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_state" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_zip" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.ship_cntry" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_fname" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_lname" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_email" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_comp" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_phone" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_fax" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_addr" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_city" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_state" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_zip" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.bill_cntry" VALUE = "">

			<MvASSIGN NAME = "BasketList.d.tax" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.shipping" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.ship_id" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.ship_data" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.pay_id" VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.pay_data" VALUE = "">
			<MvASSIGN NAME = "BasketList.d.total" VALUE = 0>

			<MvUPDATE NAME = "BasketList">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Save_Order_Info" PARAMETERS = "session_id, ship_fname, ship_lname, ship_email, ship_comp, ship_phone,
															  ship_fax, ship_addr, ship_city, ship_state, ship_zip, ship_cntry,
															  bill_fname, bill_lname, bill_email, bill_comp, bill_phone, bill_fax,
															  bill_addr, bill_city, bill_state, bill_zip, bill_cntry"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00004">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00007', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ ( BasketList.d.order_id EQ 0 ) OR
					( BasketList.d.order_id AND BasketList.d.order_proc ) }">
				<MvASSIGN NAME = "BasketList.d.order_id" VALUE = "{ StoreKey_Generate( 'Orders' ) }">
			</MvIF>

			<MvASSIGN NAME = "BasketList.d.order_proc" VALUE = 0>

			<MvASSIGN NAME = "BasketList.d.ship_fname" VALUE = "{ l.ship_fname }">
			<MvASSIGN NAME = "BasketList.d.ship_lname" VALUE = "{ l.ship_lname }">
			<MvASSIGN NAME = "BasketList.d.ship_email" VALUE = "{ l.ship_email }">
			<MvASSIGN NAME = "BasketList.d.ship_comp"  VALUE = "{ l.ship_comp }">
			<MvASSIGN NAME = "BasketList.d.ship_phone" VALUE = "{ l.ship_phone }">
			<MvASSIGN NAME = "BasketList.d.ship_fax"   VALUE = "{ l.ship_fax }">
			<MvASSIGN NAME = "BasketList.d.ship_addr"  VALUE = "{ l.ship_addr }">
			<MvASSIGN NAME = "BasketList.d.ship_city"  VALUE = "{ l.ship_city }">
			<MvASSIGN NAME = "BasketList.d.ship_state" VALUE = "{ l.ship_state }">
			<MvASSIGN NAME = "BasketList.d.ship_zip"   VALUE = "{ l.ship_zip }">
			<MvASSIGN NAME = "BasketList.d.ship_cntry" VALUE = "{ l.ship_cntry }">
			<MvASSIGN NAME = "BasketList.d.bill_fname" VALUE = "{ l.bill_fname }">
			<MvASSIGN NAME = "BasketList.d.bill_lname" VALUE = "{ l.bill_lname }">
			<MvASSIGN NAME = "BasketList.d.bill_email" VALUE = "{ l.bill_email }">
			<MvASSIGN NAME = "BasketList.d.bill_comp"  VALUE = "{ l.bill_comp }">
			<MvASSIGN NAME = "BasketList.d.bill_phone" VALUE = "{ l.bill_phone }">
			<MvASSIGN NAME = "BasketList.d.bill_fax"   VALUE = "{ l.bill_fax }">
			<MvASSIGN NAME = "BasketList.d.bill_addr"  VALUE = "{ l.bill_addr }">
			<MvASSIGN NAME = "BasketList.d.bill_city"  VALUE = "{ l.bill_city }">
			<MvASSIGN NAME = "BasketList.d.bill_state" VALUE = "{ l.bill_state }">
			<MvASSIGN NAME = "BasketList.d.bill_zip"   VALUE = "{ l.bill_zip }">
			<MvASSIGN NAME = "BasketList.d.bill_cntry" VALUE = "{ l.bill_cntry }">

			<MvASSIGN NAME = "BasketList.d.tax" 	   VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.shipping"   VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.ship_id"    VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.ship_data"  VALUE = "">
			<MvASSIGN NAME = "BasketList.d.pay_id"     VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.pay_data"   VALUE = "">
			<MvASSIGN NAME = "BasketList.d.total"      VALUE = 0>

			<MvUPDATE NAME = "BasketList">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Update_Tax" PARAMETERS = "session_id, tax" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00005">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00008', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "BasketList.d.tax" VALUE = "{ l.tax ROUND 2 }">
			<MvUPDATE NAME = "BasketList">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Update_Shipping" PARAMETERS = "session_id, shipping, ship_id, ship_data" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00006">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00009', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "BasketList.d.shipping"  VALUE = "{ l.shipping ROUND 2 }">
			<MvASSIGN NAME = "BasketList.d.ship_id"   VALUE = "{ l.ship_id }">
			<MvASSIGN NAME = "BasketList.d.ship_data" VALUE = "{ l.ship_data }">

			<MvUPDATE NAME = "BasketList">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Update_Payment" PARAMETERS = "session_id, pay_id, pay_data" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00007">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00010', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "BasketList.d.pay_id"   VALUE = "{ l.pay_id }">
			<MvASSIGN NAME = "BasketList.d.pay_data" VALUE = "{ l.pay_data }">

			<MvUPDATE NAME = "BasketList">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Update_Customer" PARAMETERS = "session_id, cust_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00008">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00011', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "BasketList.d.cust_id" VALUE = "{ l.cust_id }">
			<MvUPDATE NAME = "BasketList">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_MakeDirty" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00008">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00360', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ BasketList.d.order_id AND ( NOT BasketList.d.order_proc ) }">
				<MvASSIGN NAME = "Orphans.d.type"  VALUE = "Orders">
				<MvASSIGN NAME = "Orphans.d.value" VALUE = "{ BasketList.d.order_id }">
				
				<MvADD NAME = "Orphans">
			</MvIF>
			<MvASSIGN NAME = "BasketList.d.order_id" VALUE = "">
			<MvUPDATE NAME = "BasketList">
		</MvIF>
		<MvIF EXPR = "{ g.Features:Upsale:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.deleted" VALUE = "{ Upsell_Delete_UpsellProductInBasket() }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Delete" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ BasketList.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00009">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00012', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">
				<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
					<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
					<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
						<MvDELETE NAME = "BasketOptions">
						<MvSKIP NAME = "BasketOptions" ROWS = 1>
					</MvWHILE>

					<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity ) }">
					</MvIF>
					<MvIF EXPR = "{ l.ok }">
						<MvDELETE NAME = "Baskets">
					</MvIF>
					<MvSKIP NAME = "Baskets" ROWS = 1>
				</MvWHILE>

				<MvDELETE NAME = "BasketList">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ g.Features:Affiliates:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ Bask_Delete( l.session_id ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Insert" PARAMETERS = "basket_id, product_id, code, name, price, weight, taxable, upsold, quantity" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.line_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Baskets() }">
		<MvASSIGN NAME = "Baskets.d.id" 		VALUE = "{ l.basket_id }">
		<MvASSIGN NAME = "Baskets.d.line_id" 	VALUE = "{ StoreKey_Generate( 'BasketLines' ) }">
		<MvASSIGN NAME = "Baskets.d.product_id" VALUE = "{ l.product_id }">
		<MvASSIGN NAME = "Baskets.d.code" 		VALUE = "{ l.code }">
		<MvASSIGN NAME = "Baskets.d.name" 		VALUE = "{ l.name }">
		<MvASSIGN NAME = "Baskets.d.price" 		VALUE = "{ l.price }">
		<MvASSIGN NAME = "Baskets.d.weight" 	VALUE = "{ l.weight }">
		<MvASSIGN NAME = "Baskets.d.taxable" 	VALUE = "{ l.taxable }">
		<MvASSIGN NAME = "Baskets.d.upsold" 	VALUE = "{ l.upsold }">
		<MvASSIGN NAME = "Baskets.d.quantity" 	VALUE = "{ l.quantity }">

		<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity * -1 ) }">
		</MvIF>

		<MvADD NAME = "Baskets">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ Baskets.d.line_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Update_Quantity" PARAMETERS = "line_id, quantity" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_line.mvx' }">

		<MvFIND NAME = "Baskets" VALUE = "{ l.line_id }" EXACT>
		<MvIF EXPR = "{ Baskets.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00010">
				<MvLOCALIZED-TOKEN NAME = "line_id" VALUE = "{ encodeentities( l.line_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket Line '%line_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00013', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity - l.quantity ) }">
			</MvIF>
			<MvASSIGN NAME = "Baskets.d.quantity" VALUE = "{ l.quantity }">
			<MvUPDATE NAME = "Baskets">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Delete_Line" PARAMETERS = "line_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "BasketOptions" VALUE = "{ l.line_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ l.line_id ) }">
			<MvDELETE NAME = "BasketOptions">
			<MvSKIP NAME = "BasketOptions" ROWS = 1>
		</MvWHILE>

		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_line.mvx' }">
		<MvFIND NAME = "Baskets" VALUE = "{ l.line_id }" EXACT>
		<MvIF EXPR = "{ NOT Baskets.d.EOF }">
			<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity ) }">
			</MvIF>
			<MvIF EXPR = "{ l.ok }">
				<MvDELETE NAME = "Baskets">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Delete_AllLines" PARAMETERS = "basket_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvFIND NAME = "Baskets" VALUE = "{ l.basket_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ l.basket_id ) }">
			<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
				<MvDELETE NAME = "BasketOptions">
				<MvSKIP NAME = "BasketOptions" ROWS = 1>
			</MvWHILE>

			<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity ) }">
			</MvIF>
			<MvIF EXPR = "{ l.ok }">
				<MvDELETE NAME = "Baskets">
			</MvIF>
			<MvSKIP NAME = "Baskets" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderCharges_Delete" PARAMETERS = "basket_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_OrderCharges() }">

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "OrderCharges" INDEX = "{ g._DB_Store_Directory $ 'ochg_oid.mvx' }">
		<MvFIND NAME = "OrderCharges" VALUE = "{ l.basket_id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT OrderCharges.d.EOF ) AND ( l.basket_id EQ OrderCharges.d.order_id ) }">
			<MvDELETE NAME = "OrderCharges">
			<MvSKIP NAME = "OrderCharges" ROWS = 1>
		</MvWHILE>	
	</MvIF>
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharges_Delete_Type" PARAMETERS = "basket_id, type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketCharges() }">

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "BasketCharges" INDEX = "{ g._DB_Store_Directory $ 'bchg_typ.mvx' }">
		<MvFIND NAME = "BasketCharges" VALUE = "{ l.basket_id $ ':' $ l.type $ ':'}">
		<MvWHILE EXPR = "{ ( NOT BasketCharges.d.EOF ) AND ( l.basket_id EQ BasketCharges.d.basket_id ) AND ( l.type EQ BasketCharges.d.type ) }">
			<MvDELETE NAME = "BasketCharges">
			<MvSKIP NAME = "BasketCharges" ROWS = 1>
		</MvWHILE>	
	</MvIF>
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Quantity" PARAMETERS = "session_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.quantity" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_Baskets() }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>	
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">

			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvIF EXPR = "{ Baskets.d.product_id EQ l.product_id }">
					<MvASSIGN NAME = "l.quantity" VALUE = "{ l.quantity + Baskets.d.quantity }">
				</MvIF>

				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.quantity }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_TotalQuantity" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.quantity" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_Baskets() }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>	
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">

			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvASSIGN NAME = "l.quantity" VALUE = "{ l.quantity + Baskets.d.quantity }">

				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.quantity }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Find_Line" PARAMETERS = "line_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Baskets() }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_line.mvx' }">

		<MvFIND NAME = "Baskets" VALUE = "{ l.line_id }" EXACT>
		<MvIF EXPR = "{ NOT Baskets.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00011">
				<MvLOCALIZED-TOKEN NAME = "line_id" VALUE = "{ encodeentities( l.line_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket Line '%line_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00014', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_FindFirst_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Baskets() }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvFIND NAME = "Baskets" VALUE = "{ l.id $ ':' }">
		<MvIF EXPR = "{ NOT Baskets.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_FindNext_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">	
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Baskets" ROWS = 1>
	<MvIF EXPR = "{ ( Baskets.d.EOF ) OR ( Baskets.d.id NE l.id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.found }">		
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Total" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.total" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_Baskets() AND _DB_Store_Open_BasketOptions() AND _DB_Store_Open_BasketCharges() }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvASSIGN NAME = "l.total" VALUE = "{ l.total + ( Baskets.d.price * Baskets.d.quantity ) }">

				<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
					<MvASSIGN NAME = "l.total" VALUE = "{ l.total + ( BasketOptions.d.price * Baskets.d.quantity ) }">
		
					<MvSKIP NAME = "BasketOptions" ROWS = 1>
				</MvWHILE>

				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>
		</MvIF>

		<MvIF EXPR = "{ g.Features:Affiliates:Enabled }">
			<MvASSIGN NAME = "g.Affiliate_Basket_Total" VALUE = "0">

			<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateOptions() }">
			<MvIF EXPR = "{ l.ok AND AffiliateOptions.d.pct_slt EQ 'S' }">
				<MvASSIGN NAME = "g.Affiliate_Basket_Total" VALUE = "{ l.total }">
			</MvIF>
		</MvIF>		

		<MvPRIMARY NAME = "BasketCharges" INDEX = "{ g._DB_Store_Directory $ 'bchg_bid.mvx' }">

		<MvFIND NAME = "BasketCharges" VALUE = "{ BasketList.d.basket_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT BasketCharges.d.EOF ) AND ( BasketCharges.d.basket_id EQ BasketList.d.basket_id ) }">

			<MvASSIGN NAME = "l.total" VALUE = "{ l.total +  BasketCharges.d.amount }">
			<MvSKIP NAME = "BasketCharges" ROWS = 1>
		</MvWHILE>
		
		<MvASSIGN NAME = "l.total" VALUE = "{ l.total + BasketList.d.tax }">
		<MvASSIGN NAME = "l.total" VALUE = "{ ( l.total + BasketList.d.shipping ) ROUND 2 }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.total }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_SubTotal" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.total" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_Baskets() AND _DB_Store_Open_BasketOptions() }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvASSIGN NAME = "l.total" VALUE = "{ l.total + ( Baskets.d.price * Baskets.d.quantity ) }">

				<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
					<MvASSIGN NAME = "l.total" VALUE = "{ l.total + ( BasketOptions.d.price * Baskets.d.quantity ) }">
		
					<MvSKIP NAME = "BasketOptions" ROWS = 1>
				</MvWHILE>

				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>
		</MvIF>

	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.total }">
</MvFUNCTION>

<MvFUNCTION NAME = "Basket_Weight" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.total_weight" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_Baskets() AND _DB_Store_Open_BasketOptions() AND _DB_Store_Open_BasketCharges() }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvASSIGN NAME = "l.total_weight" VALUE = "{ l.total_weight + ( Baskets.d.weight * Baskets.d.quantity ) }">
				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.total_weight }">
</MvFUNCTION>

<MvCOMMENT>
|
| Categories
|
</MvCOMMENT>

<MvFUNCTION NAME = "_Category_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._Category_Word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._Category_Word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._Category_Word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT Categories.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND ( ( g._Category_Word[' $ l.pos $ '] CIN Categories.d.code ) OR
																  ( g._Category_Word[' $ l.pos $ '] CIN Categories.d.name ) )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_Categories" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Categories_Open }">
		<MvOPEN NAME = "Categories" 
				DATABASE = "{ g._DB_Store_Directory $ 'cats.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'cat_id.mvx, ' $ 
							 g._DB_Store_Directory $ 'cat_code.mvx, ' $ 
							 g._DB_Store_Directory $ 'cat_prnt.mvx, ' $
							 g._DB_Store_Directory $ 'cat_ord.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00015', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = 1>
			<MvFILTER NAME = "Categories" FILTER = "{ NOT Categories.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Insert" PARAMETERS = "parent_id, code, name, active" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.category_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvASSIGN NAME = "Categories.d.id" VALUE = "{ StoreKey_Generate( 'Categories' ) }">
		<MvASSIGN NAME = "Categories.d.parent_id" VALUE = "{ l.parent_id }">
		<MvASSIGN NAME = "Categories.d.agrpcount" VALUE = 0>
		<MvASSIGN NAME = "Categories.d.order" VALUE = "{ Categories.d.id }">
		<MvASSIGN NAME = "Categories.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
		<MvASSIGN NAME = "Categories.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "Categories.d.active" VALUE = "{ l.active }">

		<MvADD NAME = "Categories">

		<MvASSIGN NAME = "l.category_id" VALUE = "{ Categories.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.category_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Update" PARAMETERS = "id, parent_id, code, name, active" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
		<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>

		<MvIF EXPR = "{ Categories.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00012">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00016', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Categories.d.parent_id" VALUE = "{ l.parent_id }">
			<MvASSIGN NAME = "Categories.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
			<MvASSIGN NAME = "Categories.d.name" VALUE = "{ l.name }">
			<MvASSIGN NAME = "Categories.d.active" VALUE = "{ l.active }">
			
			<MvUPDATE NAME = "Categories">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Update_Order" PARAMETERS = "id, order" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
		<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>

		<MvIF EXPR = "{ Categories.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00013">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00017', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Categories.d.order" VALUE = "{ l.order }">
			<MvUPDATE NAME = "Categories">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_CategoryXProduct() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_prnt.mvx' }">
			<MvFIND NAME = "Categories" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ NOT Categories.d.EOF }">
				<MvASSIGN NAME = "Categories.d.parent_id" VALUE = 0>
				<MvUPDATE NAME = "Categories">

				<MvFIND NAME = "Categories" VALUE = "{ l.id $ ':' }">
			</MvWHILE>

			<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }">
			<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) }"> 
				<MvIF EXPR = "{ ( CategoryXProduct.d.cat_id EQ l.id ) }">
					<MvASSIGN NAME = "l.product_id" VALUE = "{ CategoryXProduct.d.product_id }">
					<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
					<MvIF EXPR = "{ l.ok }">
						<MvASSIGN NAME = "l.found" VALUE = "{ Product_Find_ID( l.product_id ) }">

						<MvIF EXPR = "{ l.found }">
							<MvASSIGN NAME = "Products.d.catcount" VALUE = "{ ( Products.d.catcount - 1 ) }">
							<MvUPDATE NAME = "Products">
						</MvIF>
					</MvIF>					
					<MvDELETE NAME = "CategoryXProduct">
				</MvIF>
				<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.id $ ':' }">
			</MvWHILE>

			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
			<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>

			<MvIF EXPR = "{ Categories.d.EOF }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00014">
					<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00018', l.error ) }">
			<MvELSE>
				<MvDELETE NAME = "Categories">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AvailabilityGroup_Category_Delete_AvailabilityGroupXCategory( l.id ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }">
		<MvGO NAME = "Categories" ROW = "top">

		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindLast" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }">
		<MvGO NAME = "Categories" ROW = "bottom">

		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindNext_CategoryOrder" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvASSIGN NAME = "l.found" VaLUE = "{ Category_Find_Code( l.code ) }">
		<MvIF EXPR = "{ l.found }">
			<MvASSIGN NAME = "l.order" VaLUE = "{ Categories.d.order }">
			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }">
			<MvFIND NAME = "Categories" VALUE = "{ padl( l.order, 10, '0' ) }">

			<MvIF EXPR = "{ NOT Categories.d.EOF }">
				<MvSKIP NAME = "Categories" ROWS = 1>
				<MvIF EXPR = "{ NOT Categories.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>
				</MvIF>
			<MvELSE>
				<MvASSIGN NAME = "l.found" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindPrev_CategoryOrder" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvASSIGN NAME = "l.found" VaLUE = "{ Category_Find_Code( l.code ) }">
		<MvIF EXPR = "{ l.found }">
			<MvASSIGN NAME = "l.order" VaLUE = "{ Categories.d.order }">
			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }">
			<MvFIND NAME = "Categories" VALUE = "{ padl( l.order, 10, '0' ) }">

			<MvIF EXPR = "{ NOT Categories.d.EOF }">
				<MvSKIP NAME = "Categories" ROWS = -1>
				<MvIF EXPR = "{ NOT Categories.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>
				</MvIF>
			<MvELSE>
				<MvASSIGN NAME = "l.found" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindFirst_Offset" PARAMETERS = "offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvGO NAME = "Categories" ROW = "top">
		<MvSKIP NAME = "Categories" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "Categories" ROWS = 1>
	<MvIF EXPR = "{ Categories.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
		<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>

		<MvIF EXPR = "{ Categories.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00015">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00019', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_Find_Name" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = "0">

	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
		<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ ( NOT Categories.d.EOF ) AND ( Categories.d.active ) }">
			<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
				<MvASSIGN NAME = "l.found" VALUE = "{ Categories.d.name }">
			<MvELSE>
				<MvIF EXPR = "{ l.cust_id }">
					<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXCategory() }">
						<MvIF EXPR = "{ l.ok }">					
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, l.id }">
						</MvIF>
					<MvELSE>
						<MvASSIGN NAME = "l.found" VALUE = "{ Categories.d.name }">
					</MvIF>
					
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ NOT l.found }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00016">
			<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00020', l.error ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_Find_ID" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
		<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ ( NOT Categories.d.EOF ) AND ( Categories.d.active ) }">
			<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvIF EXPR = "{ l.cust_id }">
					<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXCategory() }">
						<MvIF EXPR = "{ l.ok }">					
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, l.id ) }">
						</MvIF>
					<MvELSE>
						<MvASSIGN NAME = "l.found" VALUE = 1>
					</MvIF>
					
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ NOT l.found }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00016">
			<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00020', l.error ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Find_Code" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.category_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_code.mvx' }">
		<MvFIND NAME = "Categories" VALUE = "{ toupper( l.code ) }" EXACT>

		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.category_id" VALUE = "{ Categories.d.id }">
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00017">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00021', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.category_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_Find_Code" PARAMETERS = "cust_id, code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.category_id" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_code.mvx' }">

		<MvFIND NAME = "Categories" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ ( NOT Categories.d.EOF ) AND ( Categories.d.active ) }">
			<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
				<MvASSIGN NAME = "l.category_id" VALUE = "{ Categories.d.id }">
			<MvELSE>
				<MvIF EXPR = "{ l.cust_id }">
					<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXCategory() }">
						<MvIF EXPR = "{ l.ok }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, Categories.d.id ) }">
						</MvIF>
					<MvELSE>
						<MvASSIGN NAME = "l.found" VALUE = 1>
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ NOT l.found }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00018">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00022', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.category_id" VALUE = "{ Categories.d.id }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.category_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindFirst_Parent" PARAMETERS = "parent_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_prnt.mvx' }">

		<MvFIND NAME = "Categories" VALUE = "{ l.parent_id $ ':' }">
		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindID_Parent" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">

		<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_prnt.mvx' }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindNext_Parent" PARAMETERS = "parent_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Categories" ROWS = 1>
	<MvIF EXPR = "{ ( Categories.d.EOF ) OR ( Categories.d.parent_id NE l.parent_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_FindFirst_Parent" PARAMETERS = "cust_id, parent_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_prnt.mvx' }">

		<MvFIND NAME = "Categories" VALUE = "{ l.parent_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT Categories.d.EOF ) AND ( Categories.d.parent_id EQ l.parent_id ) }">
			<MvIF EXPR = "{ Categories.d.active }">
				<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
					<MvWHILESTOP>
				<MvELSE>
					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND g.Features:Customers:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXCategory() }">
							<MvIF EXPR = "{ l.ok }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, Categories.d.id ) }">
							<MvELSE>
								<MvASSIGN NAME = "l.found" VALUE = 1>
							</MvIF>
							<MvIF EXPR = "{ l.found }">
								<MvWHILESTOP>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
			<MvSKIP NAME = "Categories" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_FindID_Parent" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">

	<MvFIND NAME = "Categories" VALUE = "{ l.id }" EXACT>
	<MvIF EXPR = "{ ( NOT Categories.d.EOF ) AND ( Categories.d.active ) }">
		<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvIF EXPR = "{ l.cust_id }">
				<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
					<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, l.id ) }">
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 1>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ NOT l.found }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00019">
			<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%id%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00023', l.error ) }">
	</MvIF>

	<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_prnt.mvx' }">
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_FindNext_Parent" PARAMETERS = "cust_id, parent_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "Categories" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Categories.d.EOF ) }"> 
		<MvIF EXPR = "{ ( Categories.d.parent_id EQ l.parent_id ) }">
			<MvIF EXPR = "{ Categories.d.active }">
				<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
					<MvWHILESTOP>
				<MvELSE>
					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, Categories.d.id ) }">
						<MvELSE>
							<MvASSIGN NAME = "l.found" VALUE = 1>
						</MvIF>
						<MvIF EXPR = "{ l.found }">
							<MvWHILESTOP>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
		<MvSKIP NAME = "Categories" ROWS = 1>
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_FindFirst_Product" PARAMETERS = "cust_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() AND
					_DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_prod.mvx' }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.product_id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.product_id EQ l.product_id ) }">
			<MvFIND NAME = "Categories" VALUE = "{ CategoryXProduct.d.cat_id }" EXACT>
			<MvIF EXPR = "{ NOT Categories.d.EOF }">
				<MvIF EXPR = "{ Categories.d.active }">
					<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
						<MvASSIGN NAME = "l.found" VALUE = 1>
						<MvWHILESTOP>
					<MvELSE>
						<MvIF EXPR = "{ l.cust_id }">
							<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND g.Features:Customers:Enabled }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXCategory() }">
								<MvIF EXPR = "{ l.ok }">
									<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, Categories.d.id ) }">
								</MvIF>
							<MvELSE>
								<MvASSIGN NAME = "l.found" VALUE = 1>
							</MvIF>

							<MvIF EXPR = "{ l.found }">
								<MvWHILESTOP>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>

			<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>
<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Category_FindNext_Product" PARAMETERS = "cust_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.product_id EQ l.product_id ) }">
		<MvFIND NAME = "Categories" VALUE = "{ CategoryXProduct.d.cat_id }" EXACT>
		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvIF EXPR = "{ Categories.d.active }">
				<MvIF EXPR = "{ Categories.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
					<MvWHILESTOP>
				<MvELSE>
					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND g.Features:Customers:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory( l.cust_id, Categories.d.id ) }">
						<MvELSE>
							<MvASSIGN NAME = "l.found" VALUE = 1>
						</MvIF>
	
						<MvIF EXPR = "{ l.found }">
							<MvWHILESTOP>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
	</MvWHILE>
	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Product_FindOffset_Unassigned" PARAMETERS = "cat_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_Products() AND _DB_Store_Open_CategoryXProduct() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cprd.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Products.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' $ Products.d.id }" EXACT>
			<MvIF EXPR = "{ CategoryXProduct.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Products" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Product_FindNext_Unassigned" PARAMETERS = "cat_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Products.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' $ Products.d.id }" EXACT>
		<MvIF EXPR = "{ CategoryXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Products" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Product_FindOffset_Assigned" PARAMETERS = "cat_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_Products() AND _DB_Store_Open_CategoryXProduct() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' }">
		<MvSKIP NAME = "CategoryXProduct" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Product_FindNext_Assigned" PARAMETERS = "cat_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "CategoryXProduct" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvIF EXPR = "{ _DB_Store_Open_Categories() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Category_Filter( l.search ) }">
		<MvFILTER NAME = "Categories" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Categories" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Categories" ROWS = 1>
	<MvIF EXPR = "{ NOT Categories.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Categories" FILTER = "{ NOT Categories.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Category_Sort" PARAMETERS = "sort_field, ascending" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
	<MvIF EXPR = "{ l.ok }">
		<MvIF EXPR = "{ l.ascending }">
			<MvASSIGN NAME = "l.flags" VALUE = "nounique, ascending, string">
		<MvELSE>
			<MvASSIGN NAME = "l.flags" VALUE = "nounique, descending, string">
		</MvIF>

		<MvIF EXPR = "{ l.sort_field EQ 'code' }">
			<MvMAKEINDEX 	NAME = "Categories"
							INDEXFILE = "{ g._DB_Store_Directory $ 'catsort.mvx' }"
							EXPR = "{ toupper( Categories.d.code ) }"
							FLAGS = "{ l.flags }">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00328', MvMAKEINDEX_Error ) }">
			</MvIF>
		<MvELSE>
			<MvIF EXPR = "{ l.sort_field EQ 'name' }">
				<MvMAKEINDEX 	NAME = "Categories"
								INDEXFILE = "{ g._DB_Store_Directory $ 'catsort.mvx' }"
								EXPR = "{ toupper( Categories.d.name ) }"
								FLAGS = "{ l.flags }">
				<MvIF EXPR = "{ MvMAKEINDEX_Error }">
					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00337', MvMAKEINDEX_Error ) }">
				</MvIF>
			<MvELSE>
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00020">
					<MvLOCALIZED-TOKEN NAME = "sort_field" VALUE = "{ encodeentities( l.sort_field ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Invalid category sort field '%sort_field%'</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00320', l.error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'catsort.mvx' }">
			<MvASSIGN NAME = "l.counter" VALUE = "1">
			<MvGO NAME = "Categories" ROW = "top">
			<MvWHILE EXPR = "{ NOT Categories.d.EOF }">
				<MvASSIGN NAME = "Categories.d.order" VALUE = "{ l.counter }">
				<MvUPDATE NAME = "Categories">
				
				<MvASSIGN NAME = "l.counter" VALUE = "{ l.counter + 1 }">
				<MvSKIP NAME = "Categories" ROWS = "1">
			</MvWHILE>
			
			<MvCLOSE NAME = "Categories">
			<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = "0">
			
			<MvIF EXPR = "{ NOT fdelete( g._DB_Store_Directory $ 'catsort.mvx' ) }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00021">
					<MvLOCALIZED-TOKEN NAME = "file" VALUE = "{ encodeentities( g._DB_Store_Directory $ 'catsort.mvx' ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Unable to delete file '%file%'</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00321', l.error ) }">
			</MvIF>
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| StoreKeys
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_StoreKeys" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_StoreKeys_Open }">
		<MvOPEN NAME = "StoreKeys" 
				DATABASE = "{ g._DB_Store_Directory $ 'storekey.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'storekey.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00024', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_StoreKeys_Open" VALUE = 1>
			<MvFILTER NAME = "StoreKeys" FILTER = "{ NOT StoreKeys.d.deleted }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvOPEN NAME = "Orphans"
					DATABASE = "{ g._DB_Store_Directory $ 'orphans.dbf' }"
					INDEXES = "{ g._DB_Store_Directory $ 'orphans.mvx' }">
			<MvIF EXPR = "{ MvOPEN_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00025', MvOPEN_Error ) }">
			<MvELSE>
				<MvASSIGN NAME = "g._DB_Store_Orphans_Open" VALUE = 1>
				<MvFILTER NAME = "Orphans" FILTER = "{ NOT Orphans.d.deleted }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreKey_Insert" PARAMETERS = "type, start" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "StoreKeys" VALUE = "{ l.type }" EXACT>
		<MvIF EXPR = "{ StoreKeys.d.EOF }">
			<MvASSIGN NAME = "StoreKeys.d.type" VALUE = "{ l.type }">
			<MvASSIGN NAME = "StoreKeys.d.maxvalue" VALUE = "{ l.start - 1 }">
	
			<MvADD NAME = "StoreKeys">
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00022">
				<MvLOCALIZED-TOKEN NAME = "type" VALUE = "{ encodeentities( l.type ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">StoreKey '%type%' already exists</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00342', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreKey_Delete" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "StoreKeys" VALUE = "{ l.type }" EXACT>
		<MvIF EXPR = "{ NOT StoreKeys.d.EOF }">
			<MvDELETE NAME = "StoreKeys">
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreKey_Generate" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.key" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_StoreKeys() }">
		<MvLOCKFILE FILE = "{ g._DB_Store_Directory $ 'storekey.dbf' }">
			<MvFIND NAME = "Orphans" VALUE = "{ l.type $ ':' }">
			<MvIF EXPR = "{ NOT Orphans.d.EOF }">
				<MvASSIGN NAME = "l.key" VALUE = "{ Orphans.d.value }">
				<MvDELETE NAME = "Orphans">
			<MvELSE>
				<MvFIND NAME = "StoreKeys" VALUE = "{ l.type }" EXACT>
				<MvIF EXPR = "{ NOT StoreKeys.d.EOF }">
					<MvASSIGN NAME = "StoreKeys.d.maxvalue" VALUE = "{ StoreKeys.d.maxvalue + 1 }">
					<MvUPDATE NAME = "StoreKeys">

					<MvASSIGN NAME = "l.key" VALUE = "{ StoreKeys.d.maxvalue }">
				</MvIF>
			</MvIF>
		</MvLOCKFILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.key }">
</MvFUNCTION>

<MvFUNCTION NAME = "OpenDataFiles" PARAMETERS = "version" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvOPEN NAME = "Domain" 
				DATABASE = "{ g.MerchantPath $ 'domain.dbf' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00026', MvOPEN_Error ) }">
		<MvELSE>
			<MvIF EXPR = "{ l.version AND ( Domain.d.version NE l.version ) }">
				<MvASSIGN NAME = "g.Version_Mismatch" VALUE = 1>

				<MvIF EXPR = "{ Domain.d.version LT l.version }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00023">
						<MvLOCALIZED-TOKEN NAME = "version" VALUE = "{ encodeentities( l.version ) }">
						<MvLOCALIZED-TOKEN NAME = "domain_version" VALUE = "{ encodeentities( Domain.d.version ) }">

						<MvLOCALIZED-TEXT LANGUAGE = "en-US">
						Database version mismatch.  Expected %version%, found %domain_version%.
						Please run the Miva Merchant Upgrade script.							
						</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00027', l.error ) }">
				<MvELSE>
					<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00024">
						<MvLOCALIZED-TOKEN NAME = "version" VALUE = "{ encodeentities( l.version ) }">
						<MvLOCALIZED-TOKEN NAME = "domain_version" VALUE = "{ encodeentities( Domain.d.version ) }">

						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Database version mismatch.  Expected %version%, found %domain_version%.</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00028', l.error ) }">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvOPEN NAME = "Stores" 
				DATABASE = "{ g.MerchantPath $ 'stores.dbf' }" 
				INDEXES = "{ g.MerchantPath $ 'str_id.mvx, ' $ 
							 g.MerchantPath $ 'str_code.mvx, ' $ 
							 g.MerchantPath $ 'str_lic.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00029', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "Stores" FILTER = "{ NOT Stores.d.deleted }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "g._DB_Modules_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Keys_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Users_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_UserXStore_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Privileges_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_AdminSessions_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Countries_Open" VALUE = 0>
	</MvIF>
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "CloseDataFiles" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvIF EXPR = "{ g._DB_Countries_Open }">
		<MvCLOSE NAME = "Countries">
		<MvASSIGN NAME = "g._DB_Countries_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_AdminSessions_Open }">
		<MvCLOSE NAME = "AdminSessions">
		<MvASSIGN NAME = "g._DB_AdminSessions_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Privileges_Open }">
		<MvCLOSE NAME = "Privileges">
		<MvASSIGN NAME = "g._DB_Privileges_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_UserXStore_Open }">
		<MvCLOSE NAME = "UserXStore">
		<MvASSIGN NAME = "g._DB_UserXStore_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Users_Open }">
		<MvCLOSE NAME = "Users">
		<MvASSIGN NAME = "g._DB_Users_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Keys_Open }">
		<MvCLOSE NAME = "Keys">
		<MvASSIGN NAME = "g._DB_Keys_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Modules_Open }">
		<MvCLOSE NAME = "Modules">	
		<MvASSIGN NAME = "g._DB_Modules_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_StandardFields_Open }">
		<MvCLOSE NAME = "StandardFields">	
		<MvASSIGN NAME = "g._DB_StandardFields_Open" VALUE = 0>
	</MvIF>

	<MvCLOSE NAME = "Stores">
	<MvCLOSE NAME = "Domain">

	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvFUNCTION NAME = "DeleteDataFiles" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = "{ CloseDataFiles() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'domain.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'stores.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'stores.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'str_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'str_code.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'str_lic.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'keys.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'keys.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'modules.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'mod_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'mod_code.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'mod_type.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'users.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'usr_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'usr_name.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'usrxstor.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'uxs_stor.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'uxs_user.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'privs.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'prv_priv.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'prv_name.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'admsess.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'ads_sess.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'country.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'cntry_a.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'cntry_n.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'cntry_i.mvx' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'install.log' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath $ 'language.dat' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( g.MerchantPath ) }">
		
		<MvDO FILE = "{ g.Module_Feature_STP_DB }" NAME = "l.ok" VALUE = "{ STP_DeleteDataFiles() }">
		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.ok" VALUE = "{ NOT_DeleteDataFiles() }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Keys
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Open_Keys" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Keys_Open }">
		<MvOPEN NAME = "Keys"
				DATABASE = "{ g.MerchantPath $ 'keys.dbf' }"
				INDEXES = "{ g.MerchantPath $ 'keys.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00030', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Keys_Open" VALUE = "1">
			<MvFILTER NAME = "Keys" FILTER = "{ NOT( Keys.d.deleted ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>
	
<MvFUNCTION NAME = "Key_Insert" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Keys() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "Keys.d.type" VALUE = "{ l.type }">
		<MvASSIGN NAME = "Keys.d.maxvalue" VALUE = "0">

		<MvADD NAME = "Keys">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Key_Generate" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.key" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Keys() }">
		<MvLOCKFILE FILE = "{ g.MerchantPath $ 'keys.dbf' }">
			<MvFIND NAME = "Keys" VALUE = "{ l.type }" EXACT>
			<MvIF EXPR = "{ NOT Keys.d.EOF }">
				<MvASSIGN NAME = "Keys.d.maxvalue" VALUE = "{ Keys.d.maxvalue + 1 }">
				<MvUPDATE NAME = "Keys">

				<MvASSIGN NAME = "l.key" VALUE = "{ Keys.d.maxvalue }">
			</MvIF>
		</MvLOCKFILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.key }">
</MvFUNCTION>

<MvFUNCTION NAME = "Key_Delete" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Keys() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "Keys" VALUE = "{ l.type }" EXACT>
		<MvIF EXPR = "{ Keys.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00025">
				<MvLOCALIZED-TOKEN NAME = "type" VALUE = "{ encodeentities( l.type ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Key '%type%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00031', 'Key \'' $ l.type $ '\' not found' ) }">
		<MvELSE>
			<MvDELETE NAME = "Keys">
			<MvPACK NAME = "Keys">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Modules
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Open_Modules" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Modules_Open }">
		<MvOPEN NAME = "Modules"
				DATABASE = "{ g.MerchantPath $ 'modules.dbf' }"
				INDEXES = "{ g.MerchantPath $ 'mod_id.mvx, ' $
				             g.MerchantPath $ 'mod_code.mvx, ' $
							 g.MerchantPath $ 'mod_type.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00032', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Modules_Open" VALUE = 1>
			<MvFILTER NAME = "Modules" FILTER = "{ NOT Modules.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Insert" PARAMETERS = "type, code, name, provider, version, module, active" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.id" VALUE = 0>

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "Modules.d.id" VALUE = "{ Key_Generate( 'Modules' ) }">
		<MvASSIGN NAME = "Modules.d.type" VALUE = "{ l.type }">
		<MvASSIGN NAME = "Modules.d.code" VALUE = "{ l.code }">
		<MvASSIGN NAME = "Modules.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "Modules.d.provider" VALUE = "{ l.provider }">
		<MvASSIGN NAME = "Modules.d.version" VALUE = "{ l.version }">
		<MvASSIGN NAME = "Modules.d.module" VALUE = "{ l.module }">
		<MvASSIGN NAME = "Modules.d.refcount" VALUE = 0>
		<MvASSIGN NAME = "Modules.d.active" VALUE = "{ l.active }">

		<MvADD NAME = "Modules">

		<MvASSIGN NAME = "l.id" VALUE = "{ Modules.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Increment_ReferenceCount" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00026">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00033', l.error ) }">
		<MvELSE>
			<MvLOCKFILE FILE = "{ g.MerchantPath $ 'modules.dbf' }">
				<MvASSIGN NAME = "Modules.d.refcount" VALUE = "{ Modules.d.refcount + 1 }">
				<MvUPDATE NAME = "Modules">
			</MvLOCKFILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Decrement_ReferenceCount" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00027">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00034', l.error ) }">
		<MvELSE>
			<MvLOCKFILE FILE = "{ g.MerchantPath $ 'modules.dbf' }">
				<MvIF EXPR = "{ Modules.d.refcount GT 0 }">
					<MvASSIGN NAME = "Modules.d.refcount" VALUE = "{ Modules.d.refcount - 1 }">
					<MvUPDATE NAME = "Modules">
				</MvIF>
			</MvLOCKFILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Update" PARAMETERS = "id, code, name, provider, version, module, active" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00028">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00035', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Modules.d.code" VALUE = "{ l.code }">
			<MvASSIGN NAME = "Modules.d.name" VALUE = "{ l.name }">
			<MvASSIGN NAME = "Modules.d.provider" VALUE = "{ l.provider }">
			<MvASSIGN NAME = "Modules.d.version" VALUE = "{ l.version }">
			<MvASSIGN NAME = "Modules.d.module" VALUE = "{ l.module }">
			<MvASSIGN NAME = "Modules.d.active" VALUE = "{ l.active }">

			<MvUPDATE NAME = "Modules">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00029">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00036', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Modules.d.refcount GT 0 }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00030">
					<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.id ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' is in use by one or more stores</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00037', l.error ) }">
			<MvELSE>
				<MvDELETE NAME = "Modules">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00031">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00038', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Modules.d.active }"> 
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00186">
					<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( modules.d.code ) }">
					<MvLOCALIZED-TOKEN NAME = "name" VALUE = "{ modules.d.name }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%code%' (%name%) has been deactivated.</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00402', l.error ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Find_Code" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_code.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.code }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00032">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00039', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Modules.d.active }">
				<MvASSIGN NAME = "l.id" VALUE = "{ Modules.d.id }">
			<MvELSE>
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00187">
					<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
					<MvLOCALIZED-TOKEN NAME = "name" VALUE = "{ modules.d.name }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%code%' (%name%) has been deactivated.</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00403', l.error ) }">

			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvGO NAME = "Modules" ROW = "top">
		<MvWHILE EXPR = "{ (NOT Modules.d.EOF) AND (NOT l.found) }">
			<MvIF EXPR = "{ Modules.d.active }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvSKIP NAME = "Modules" ROWS = 1>
			</MvIF>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "Modules" ROWS = 1>
	<MvWHILE EXPR = "{ (NOT Modules.d.EOF) AND (NOT l.found) }">
		<MvIF EXPR = "{ Modules.d.active }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvSKIP NAME = "Modules" ROWS = 1>
		</MvIF>
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindFirst_Type" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_type.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.type }" EXACT>
		<MvWHILE EXPR = "{ (NOT Modules.d.EOF) AND (NOT l.found) AND (Modules.d.type EQ l.type) }">
			<MvIF EXPR = "{ Modules.d.active }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvSKIP NAME = "Modules" ROWS = 1>
			</MvIF>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindNext_Type" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_type.mvx' }">
	<MvSKIP NAME = "Modules" ROWS = 1>
	<MvWHILE EXPR = "{ (NOT Modules.d.EOF) AND (NOT l.found) AND (Modules.d.type EQ l.type) }">
		<MvIF EXPR = "{ Modules.d.active }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvSKIP NAME = "Modules" ROWS = 1>
		</MvIF>
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindFirst_Type_Admin" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_type.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.type }" EXACT>
		<MvIF EXPR = "{ (NOT Modules.d.EOF) AND (Modules.d.type EQ l.type) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindNext_Type_Admin" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_type.mvx' }">
	<MvSKIP NAME = "Modules" ROWS = 1>
	<MvIF EXPR = "{ (NOT Modules.d.EOF) AND (Modules.d.type EQ l.type) }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindFirst_Admin" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvGO NAME = "Modules" ROW = "top">
		<MvIF EXPR = "{ NOT Modules.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_FindNext_Admin" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Modules" ROWS = 1>
	<MvIF EXPR = "{ Modules.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Find_Code_Admin" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_code.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.code }" EXACT>
		<MvIF EXPR = "{ NOT Modules.d.EOF }">
			<MvASSIGN NAME = "l.id" VALUE = "{ Modules.d.id }">
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00032">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00039', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Module_Find_ID_Admin" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Modules() }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">
		<MvFIND NAME = "Modules" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Modules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00031">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00038', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = "1">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>



<MvCOMMENT>
|
| Domain
|
</MvCOMMENT>

<MvFUNCTION NAME = "Domain_Update" PARAMETERS = "name, license, version, owner, email, company, address, city,
											     state, zip, country, phone, fax, mm_url, mm_surl, admin_surl, 
											     image_root, base_url, base_surl, mod_root, mod_sroot, 
											     admexp, mailhost, mailmeth, mail_angl, ui_id, lo_time, li_trys, img_ext" 
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	
	<MvASSIGN NAME = "Domain.d.name" VALUE = "{ l.name }">
	<MvASSIGN NAME = "Domain.d.license" VALUE = "{ l.license }">
	<MvASSIGN NAME = "Domain.d.version" VALUE = "{ l.version }">
	<MvASSIGN NAME = "Domain.d.owner" VALUE = "{ l.owner }">
	<MvASSIGN NAME = "Domain.d.email" VALUE = "{ l.email }">
	<MvASSIGN NAME = "Domain.d.company" VALUE = "{ l.company }">
	<MvASSIGN NAME = "Domain.d.address" VALUE = "{ l.address }">
	<MvASSIGN NAME = "Domain.d.city" VALUE = "{ l.city }">
	<MvASSIGN NAME = "Domain.d.state" VALUE = "{ l.state }">
	<MvASSIGN NAME = "Domain.d.zip" VALUE = "{ l.zip }">
	<MvASSIGN NAME = "Domain.d.country" VALUE = "{ l.country }">
	<MvASSIGN NAME = "Domain.d.phone" VALUE = "{ l.phone }">
	<MvASSIGN NAME = "Domain.d.fax" VALUE = "{ l.fax }">
	<MvASSIGN NAME = "Domain.d.mm_url" VALUE = "{ l.mm_url }">
	<MvASSIGN NAME = "Domain.d.mm_surl" VALUE = "{ l.mm_surl }">
	<MvASSIGN NAME = "Domain.d.admin_surl" VALUE = "{ l.admin_surl }">
	<MvASSIGN NAME = "Domain.d.image_root" VALUE = "{ l.image_root }">
	<MvASSIGN NAME = "Domain.d.base_url" VALUE = "{ l.base_url }">
	<MvASSIGN NAME = "Domain.d.base_surl" VALUE = "{ l.base_surl }">
	<MvASSIGN NAME = "Domain.d.mod_root" VALUE = "{ l.mod_root }">
	<MvASSIGN NAME = "Domain.d.mod_sroot" VALUE = "{ l.mod_sroot }">
	<MvASSIGN NAME = "Domain.d.admexp" VALUE = "{ l.admexp }">
	<MvASSIGN NAME = "Domain.d.mailhost" VALUE = "{ l.mailhost }">
	<MvASSIGN NAME = "Domain.d.mailmeth" VALUE = "{ l.mailmeth }">
	<MvASSIGN NAME = "Domain.d.mail_angl" VALUE = "{ l.mail_angl }">
	<MvASSIGN NAME = "Domain.d.ui_id" VALUE = "{ l.ui_id }">
	<MvASSIGN NAME = "Domain.d.lo_time"	VALUE = "{ l.lo_time }">
	<MvASSIGN NAME = "Domain.d.li_trys"	VALUE = "{ l.li_trys }">
	<MvASSIGN NAME = "Domain.d.img_ext" VALUE = "{ l.img_ext }">

	<MvUPDATE NAME = "Domain">

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Domain_Update_AdminDisabling" PARAMETERS = "d_set, d_mod, d_pay, d_ship, d_ful, d_usr, d_log, d_sys, d_utl, d_maxstores" 
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	
	<MvASSIGN NAME = "Domain.d.d_set" VALUE = "{ l.d_set }">
	<MvASSIGN NAME = "Domain.d.d_mod" VALUE = "{ l.d_mod }">
	<MvASSIGN NAME = "Domain.d.d_pay" VALUE = "{ l.d_pay }">
	<MvASSIGN NAME = "Domain.d.d_ship" VALUE = "{ l.d_ship }">
	<MvASSIGN NAME = "Domain.d.d_ful" VALUE = "{ l.d_ful }">
	<MvASSIGN NAME = "Domain.d.d_usr" VALUE = "{ l.d_usr }">
	<MvASSIGN NAME = "Domain.d.d_log" VALUE = "{ l.d_log }">	
	<MvASSIGN NAME = "Domain.d.d_sys" VALUE = "{ l.d_sys }">
	<MvASSIGN NAME = "Domain.d.d_utl" VALUE = "{ l.d_utl }">
	<MvASSIGN NAME = "Domain.d.maxstores" VALUE = "{ l.d_maxstores }">

	<MvUPDATE NAME = "Domain">

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>


<MvCOMMENT>
|
| Users
|
</MvCOMMENT>

<MvFUNCTION NAME = "_User_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._user_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._user_word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._user_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT Users.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND ( g._user_word[' $ l.pos $ '] CIN Users.d.name )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Open_Users" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Users_Open }">
		<MvOPEN NAME = "Users" 
				DATABASE = "{ g.MerchantPath $ 'users.dbf' }" 
				INDEXES = "{ g.MerchantPath $ 'usr_id.mvx, ' $ g.MerchantPath $ 'usr_name.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00040', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Users_Open" VALUE = 1>
			<MvFILTER NAME = "Users" FILTER = "{ NOT Users.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Insert" PARAMETERS = "parent_id, page_len, name, password, admin, create, smod, t_fails, c_fails, lo_date" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.user_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvASSIGN NAME = "Users.d.id" VALUE = "{ Key_Generate( 'Users' ) }">
		<MvASSIGN NAME = "Users.d.parent_id" VALUE = "{ l.parent_id }">
		<MvASSIGN NAME = "Users.d.page_len" VALUE = "{ page_len }">
		<MvASSIGN NAME = "Users.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "Users.d.password" VALUE = "{ l.password CRYPT ( s.dyn_time_t SUBSTR '8, 2' ) }">
		<MvASSIGN NAME = "Users.d.admin" VALUE = "{ l.admin }">
		<MvASSIGN NAME = "Users.d.create" VALUE = "{ l.create }">
		<MvASSIGN NAME = "Users.d.smod" VALUE = "{ l.smod }">
		<MvASSIGN NAME = "Users.d.t_fails" VALUE = "{ l.t_fails }">
		<MvASSIGN NAME = "Users.d.c_fails" VALUE = "{ l.c_fails }">
		<MvASSIGN NAME = "Users.d.lo_date" VALUE = "{ l.lo_date }">
		
		<MvADD NAME = "Users">
		<MvASSIGN NAME = "l.user_id" VALUE = "{ Users.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.user_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Update" PARAMETERS = "id, parent_id, page_len, name, password, admin, create, t_fails, c_fails, lo_date, switch" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Users() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">
		<MvFIND NAME = "Users" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Users.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00033">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00041', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Users.d.parent_id" VALUE = "{ l.parent_id }">
			<MvASSIGN NAME = "Users.d.page_len" VALUE = "{ l.page_len }">
			<MvASSIGN NAME = "Users.d.name" VALUE = "{ l.name }">
		
			<MvIF EXPR = "{ l.password }">
				<MvASSIGN NAME = "Users.d.password" VALUE = "{ l.password CRYPT ( s.dyn_time_t SUBSTR '8, 2' ) }">
			</MvIF>

			<MvASSIGN NAME = "Users.d.admin" VALUE = "{ l.admin }">
			<MvASSIGN NAME = "Users.d.create" VALUE = "{ l.create }">
			<MvASSIGN NAME = "Users.d.t_fails" VALUE = "{ l.t_fails }">
			<MvASSIGN NAME = "Users.d.c_fails" VALUE = "{ l.c_fails }">
			<MvASSIGN NAME = "Users.d.lo_date" VALUE = "{ l.lo_date }">
			<MvASSIGN NAME = "Users.d.smod" VALUE = "{ l.switch }">

			<MvUPDATE NAME = "Users">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Users() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Delete_User( l.id ) }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.find_store" VALUE = "{ Store_FindFirst() }">
		<MvWHILE EXPR = "{ l.find_store }">
			<MvASSIGN NAME = "l.open_store" VALUE = "{ Store_Open( Stores.d.code ) }">
			<MvIF EXPR = "{ l.open_store }">
				<MvASSIGN NAME = "l.delete" VALUE = "{ UserXGroup_Delete_User( l.id ) }">
			</MvIF>
			
			<MvASSIGN NAME = "l.find_store" VALUE = "{ Store_FindNext() }">
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">
		<MvFIND NAME = "Users" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Users.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00034">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00042', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "Users">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Is_Admin" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.admin" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">
		<MvFIND NAME = "Users" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Users.d.EOF }">
			<MvASSIGN NAME = "l.admin" VALUE = "{ Users.d.admin }">
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.admin }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Is_Manager" PARAMETERS = "user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.manager" VALUE = 0>

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvFIND NAME = "UserXStore" VALUE = "{ l.user_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT UserXStore.d.EOF ) AND ( UserXStore.d.user_id EQ l.user_id ) }">
			<MvIF EXPR = "{ UserXStore.d.manager }">
				<MvASSIGN NAME = "l.manager" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvSKIP NAME = "UserXStore" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.manager }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Count_Admin" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.count" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">
		<MvGO NAME = "Users" ROW = "top">
		<MvWHILE EXPR = "{ NOT Users.d.EOF }">
			<MvIF EXPR = "{ Users.d.admin }">
				<MvASSIGN NAME = "l.count" VALUE = "{ l.count + 1 }">
			</MvIF>

			<MvSKIP NAME = "Users" ROWS = 1>
		</MvWHILE>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.count }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">
		<MvFIND NAME = "Users" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Users.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00035">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00043', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_Find_Name" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.user_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_name.mvx' }">
		<MvFIND NAME = "Users" VALUE = "{ toupper( l.name ) }" EXACT>
		<MvIF EXPR = "{ Users.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00036">
				<MvLOCALIZED-TOKEN NAME = "name" VALUE = "{ encodeentities( l.name ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%name%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00044', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.user_id" VALUE = "{ Users.d.id }">
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.user_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_name.mvx' }">
		<MvGO NAME = "Users" ROW = "top">

		<MvIF EXPR = "{ NOT Users.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_FindFirst_Offset" PARAMETERS = "offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">

		<MvGO NAME = "Users" ROW = "top">
		<MvSKIP NAME = "Users" ROWS = "{ l.offset }">

		<MvIF EXPR = "{ NOT Users.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "Users" ROWS = 1>
	<MvIF EXPR = "{ Users.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "User_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Open_Users() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _User_Filter( l.search ) }">
		<MvFILTER NAME = "Users" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Users" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT Users.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "User_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Users" ROWS = 1>
	<MvIF EXPR = "{ NOT Users.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Users" FILTER = "{ NOT Users.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvCOMMENT>
|
| Stores
|
</MvCOMMENT>

<MvFUNCTION NAME = "Store_Open" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = "{ Store_Close( l.code ) }">

	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_code.mvx' }">
	<MvFIND NAME = "Stores" VALUE = "{ substring( toupper( l.code ), 1, 50 ) }" EXACT>

	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00037">
			<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store '%code%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>
		
		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00045', l.error ) }">
	<MvELSE>
		<MvASSIGN NAME = "g._DB_Store_Directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">
		<MvASSIGN NAME = "g._DB_Store_StoreKeys_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Orphans_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_States_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_CategoryXProduct_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_RelatedProduct_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Attributes_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Options_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_BasketList_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_BasketLastUpdate_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Baskets_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_BasketOptions_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Orders_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_OrderItems_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_OrderOptions_Open" VALUE = 0>
		<MvASSIGN NAME = "g._DB_Store_Batches_Open" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Close" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ g._DB_Store_StoreKeys_Open }">
		<MvCLOSE NAME = "StoreKeys">
		<MvASSIGN NAME = "g._DB_Store_StoreKeys_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Orphans_Open }">
		<MvCLOSE NAME = "Orphans">
		<MvASSIGN NAME = "g._DB_Store_Orphans_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Groups_Open }">
		<MvCLOSE NAME = "Groups">
		<MvASSIGN NAME = "g._DB_Store_Groups_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_GroupPrivileges_Open }">
		<MvCLOSE NAME = "GroupPrivileges">
		<MvASSIGN NAME = "g._DB_Store_GroupPrivileges_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_UserXGroup_Open }">
		<MvCLOSE NAME = "UserXGroup">
		<MvASSIGN NAME = "g._DB_Store_UserXGroup_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_States_Open }">
		<MvCLOSE NAME = "States">
		<MvASSIGN NAME = "g._DB_Store_States_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_StoreCountries_Open }">
		<MvCLOSE NAME = "StoreCountries">
		<MvASSIGN NAME = "g._DB_StoreCountries_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Categories_Open }">
		<MvCLOSE NAME = "Categories">
		<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_CategoryXProduct_Open }">
		<MvCLOSE NAME = "CategoryXProduct">
		<MvASSIGN NAME = "g._DB_Store_CategoryXProduct_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Products_Open }">
		<MvCLOSE NAME = "Products">
		<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Attributes_Open }">
		<MvCLOSE NAME = "Attributes">
		<MvASSIGN NAME = "g._DB_Store_Attributes_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AttributeTemplates_Open }">
		<MvCLOSE NAME = "AttributeTemplates">
		<MvASSIGN NAME = "g._DB_Store_AttributeTemplates_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Options_Open }">
		<MvCLOSE NAME = "Options">
		<MvASSIGN NAME = "g._DB_Store_Options_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_BasketList_Open }">
		<MvCLOSE NAME = "BasketList">
		<MvASSIGN NAME = "g._DB_Store_BasketList_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_BasketLastUpdate_Open }">
		<MvCLOSE NAME = "BasketLastUpdate">
		<MvASSIGN NAME = "g._DB_Store_BasketLastUpdate_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Baskets_Open }">
		<MvCLOSE NAME = "Baskets">
		<MvASSIGN NAME = "g._DB_Store_Baskets_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Basket_Charges_Open }">
		<MvCLOSE NAME = "BasketCharges">
		<MvASSIGN NAME = "g._DB_Store_Basket_Charges_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_BasketOptions_Open }">
		<MvCLOSE NAME = "BasketOptions">
		<MvASSIGN NAME = "g._DB_Store_BasketOptions_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_StoreModules_Open }">
		<MvCLOSE NAME = "StoreModules">
		<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Orders_Open }">
		<MvCLOSE NAME = "Orders">
		<MvASSIGN NAME = "g._DB_Store_Orders_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_OrderItems_Open }">
		<MvCLOSE NAME = "OrderItems">
		<MvASSIGN NAME = "g._DB_Store_OrderItems_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_OrderOptions_Open }">
		<MvCLOSE NAME = "OrderOptions">
		<MvASSIGN NAME = "g._DB_Store_OrderOptions_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Order_Charges_Open }">
		<MvCLOSE NAME = "OrderCharges">
		<MvASSIGN NAME = "g._DB_Store_Order_Charges_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_Batches_Open }">
		<MvCLOSE NAME = "Batches">
		<MvASSIGN NAME = "g._DB_Store_Batches_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_StandardFields_Open }">
		<MvCLOSE NAME = "StandardFields">
		<MvASSIGN NAME = "g._DB_Store_StandardFields_Open" VALUE = 0>
	</MvIF>
	
	<MvIF EXPR = "{ g._DB_StoreNotes_Open }">
		<MvCLOSE NAME = "StoreNotes">
		<MvASSIGN NAME = "g._DB_StoreNotes_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g.Features:Affiliates:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ AFF_Store_Close() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:AttributeTemplates:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ ATT_Store_Close() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:Customers:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ CUS_Store_Close() }">

		<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AGR_Store_Close() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:PriceGroups:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_PGR_DB }" NAME = "l.ok" VALUE = "{ PGR_Store_Close() }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.ok" VALUE = "{ INV_Store_Close() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:RelatedProducts:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_RPD_DB }" NAME = "l.ok" VALUE = "{ RPD_Store_Close() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:Upsale:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ USL_Store_Close() }">
	</MvIF>

	<MvDO FILE = "{ g.Module_Feature_STP_DB }" NAME = "l.ok" VALUE = "{ STP_Store_Close() }">

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Update" PARAMETERS = "id, manager_id, code, license, name, owner, email, company, address, city, state, zip, country, phone, fax, wtunits, baskexp, pgrp_ovlp, ui_id, currncy_id, tax_id, m_mode, m_no_new, m_warn, m_msg, omin_quant, omin_price, omin_all, omin_msg" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_id.mvx' }">
	<MvFIND NAME = "Stores" VALUE = "{ l.id }" EXACT>
	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00038">
			<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store '%id%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00046', l.error ) }">
	<MvELSE>
		<MvASSIGN NAME = "g._DB_Store_Directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">

		<MvASSIGN NAME = "l.oldmanager_id" VALUE = "{ Stores.d.manager_id }">

		<MvASSIGN NAME = "Stores.d.manager_id" VALUE = "{ l.manager_id }">
		<MvASSIGN NAME = "Stores.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
		<MvASSIGN NAME = "Stores.d.license" VALUE = "{ l.license }">
		<MvASSIGN NAME = "Stores.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "Stores.d.owner" VALUE = "{ l.owner }">
		<MvASSIGN NAME = "Stores.d.email" VALUE = "{ l.email }">
		<MvASSIGN NAME = "Stores.d.company" VALUE = "{ l.company }">
		<MvASSIGN NAME = "Stores.d.address" VALUE = "{ l.address }">
		<MvASSIGN NAME = "Stores.d.city" VALUE = "{ l.city }">
		<MvASSIGN NAME = "Stores.d.state" VALUE = "{ l.state }">
		<MvASSIGN NAME = "Stores.d.zip" VALUE = "{ l.zip }">
		<MvASSIGN NAME = "Stores.d.country" VALUE = "{ l.country }">
		<MvASSIGN NAME = "Stores.d.phone" VALUE = "{ l.phone }">
		<MvASSIGN NAME = "Stores.d.fax" VALUE = "{ l.fax }">
		<MvASSIGN NAME = "Stores.d.wtunits" VALUE = "{ l.wtunits }">
		<MvASSIGN NAME = "Stores.d.baskexp" VALUE = "{ l.baskexp }">
		<MvASSIGN NAME = "Stores.d.pgrp_ovlp" VALUE = "{ l.pgrp_ovlp }">
		
		<MvASSIGN NAME = "l.oldui_id" VALUE = "{ Stores.d.ui_id }">
		<MvASSIGN NAME = "l.oldcurrncy_id" VALUE = "{ Stores.d.currncy_id }">
		<MvASSIGN NAME = "l.oldtax_id" VALUE = "{ Stores.d.tax_id }">
		
		<MvASSIGN NAME = "Stores.d.ui_id" VALUE = "{ l.ui_id }">
		<MvASSIGN NAME = "Stores.d.currncy_id" VALUE = "{ l.currncy_id }">
		<MvASSIGN NAME = "Stores.d.tax_id" VALUE = "{ l.tax_id }">
		<MvASSIGN NAME = "Stores.d.mnt_time" VALUE = "{ l.m_mode }">		
		<MvASSIGN NAME = "Stores.d.mnt_no_new" VALUE = "{ l.m_no_new }">		
		<MvASSIGN NAME = "Stores.d.mnt_warn" VALUE = "{ l.m_warn }">		
		<MvASSIGN NAME = "Stores.d.mnt_close" VALUE = "{ l.m_msg }">	
		<MvASSIGN NAME = "Stores.d.omin_quant" VALUE = "{ l.omin_quant }">	
		<MvASSIGN NAME = "Stores.d.omin_price" VALUE = "{ l.omin_price }">	
		<MvASSIGN NAME = "Stores.d.omin_all" VALUE = "{ l.omin_all }">	
		<MvASSIGN NAME = "Stores.d.omin_msg" VALUE = "{ l.omin_msg }">	
			
		<MvUPDATE NAME = "Stores">
		<MvIF EXPR = "{ l.manager_id NE l.oldmanager_id }">
			<MvIF EXPR = "{ l.oldmanager_id }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Set_Manager( Stores.d.id, l.oldmanager_id, 0 ) }">
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Set_Manager( Stores.d.id, l.manager_id, 1 ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ui_id NE l.oldui_id }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Delete( l.oldui_id ) }">
			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Insert( l.ui_id, 'UI' ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.currncy_id NE l.oldcurrncy_id }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Delete( l.oldcurrncy_id ) }">
			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Insert( l.currncy_id, 'CURRENCY' ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.tax_id NE l.oldtax_id }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Delete( l.oldtax_id ) }">
			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Insert( l.tax_id, 'TAX' ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Delete" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_code.mvx' }">
	<MvFIND NAME = "Stores" VALUE = "{ toupper( l.code ) }" EXACT>
	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00039">
			<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store '%code%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00047', l.error ) }">
	<MvELSE>
		<MvASSIGN NAME = "g._DB_Store_Directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvGO NAME = "StoreModules" ROW = "top">
		<MvWHILE EXPR = "{ l.ok AND ( NOT StoreModules.d.EOF ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ Module_Decrement_ReferenceCount( StoreModules.d.module_id ) }">
			<MvSKIP NAME = "StoreModules" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Delete_Store( Stores.d.id ) }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCLOSE NAME = "StoreModules">
		<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 0>

		<MvASSIGN NAME = "l.directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'attr.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'attr.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'atr_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'atr_code.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'atr_prod.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'afileml.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'afilmng.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'atr_at_p.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'atr_at_i.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'afilopt.dbt' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'basklist.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'blst_ses.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'baskets.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bsk_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bsk_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'baskopts.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bopt_ln.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'batches.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bch_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bch_clsd.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'baskchrg.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bchg_bid.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bchg_typ.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'bchg_mod.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'baskopts.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'basklupd.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'blup_ses.mvx' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cats.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cat_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cat_code.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cat_prnt.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cat_ord.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'catxprod.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cxp_cat.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cxp_prod.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'cxp_cprd.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'customers.dat' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'groups.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'grp_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'grp_name.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'grppriv.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'grppriv.mvx' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'orphans.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'orphans.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'opts.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'opts.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'opt_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'opt_code.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'opt_attr.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'orders.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ord_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ord_btch.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ord_prcd.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'orditems.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oit_ord.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ordopts.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ordrchrg.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ochg_oid.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ochg_typ.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ochg_mod.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'ordopts.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'orders.dat' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'products.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'products.dbt' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prd_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prd_ord.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prd_ccnt.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prd_gcnt.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prd_code.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prd_pgct.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prdsta_p.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prdsta_c.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prdsta.dbf' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'storekey.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'storekey.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'std_fld.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'str_cty.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'str_cty.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'str_ctyn.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'str_ctyi.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'stats.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'stasks.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'stsk_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'states.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'states.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'storemod.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'smd_id.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'smd_type.mvx' ) }">

		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'usrxgrp.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'uxg_user.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'uxg_grp.mvx' ) }">
		
		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.ok" VALUE = "{ NOT_DeleteStoreData( l.directory ) }">

		<MvIF EXPR = "{ g.Features:Affiliates:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ AFF_Store_Delete( l.directory ) }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:AttributeTemplates:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ ATT_Store_Delete() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:Customers:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ CUS_Store_Delete() }">
			<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND l.ok }">
				<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AGR_Store_Delete() }">
			</MvIF>

			<MvIF EXPR = "{ g.Features:PriceGroups:Enabled AND l.ok }">
				<MvDO FILE = "{ g.Module_Feature_PGR_DB }" NAME = "l.ok" VALUE = "{ PGR_Store_Delete() }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.ok" VALUE = "{ INV_Store_Delete() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:RelatedProducts:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_RPD_DB }" NAME = "l.ok" VALUE = "{ RPD_Store_Delete() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:Upsale:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ USL_Store_Delete() }">
		</MvIF>
		
		<MvDO FILE = "{ g.Module_Feature_STP_DB }" NAME = "l.ok" VALUE = "{ STP_Store_Delete() }">
		
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory ) }">
		<MvDELETE NAME = "Stores">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_id.mvx' }">
	<MvFIND NAME = "Stores" VALUE = "{ l.id }" EXACT>

	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00040">
			<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store '%id%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.found" VALUE = "{ Error( 'MER-DTB-00048', l.error ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_code.mvx' }">
	<MvGO NAME = "Stores" ROW = "top">

	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "Stores" ROWS = 1>
	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_FindFirst_User" PARAMETERS = "user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_UserXStore() }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvFIND NAME = "UserXStore" VALUE = "{ l.user_id $ ':' }">
		<MvIF EXPR = "{ NOT UserXStore.d.EOF }">
			<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_id.mvx' }">
			<MvFIND NAME = "Stores" VALUE = "{ UserXStore.d.store_id }" EXACT>
			<MvIF EXPR = "{ NOT Stores.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_FindNext_User" PARAMETERS = "user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "UserXStore" ROWS = 1>
	<MvIF EXPR = "{ ( UserXStore.d.EOF ) OR ( UserXStore.d.user_id NE l.user_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvELSE>
		<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_id.mvx' }">
		<MvFIND NAME = "Stores" VALUE = "{ UserXStore.d.store_id }" EXACT>
		<MvIF EXPR = "{ Stores.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Find_Code" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_code.mvx' }">
	<MvFIND NAME = "Stores" VALUE = "{ toupper( l.code ) }" EXACT>

	<MvIF EXPR = "{ Stores.d.EOF }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00041">
			<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store '%code%' not found</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.found" VALUE = "{ Error( 'MER-DTB-00049', l.error ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Count" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.count" VALUE = 0>

	<MvGO NAME = "Stores" ROW = "top">
	<MvWHILE EXPR = "{ NOT Stores.d.EOF }">
		<MvASSIGN NAME = "l.count" VALUE = "{ l.count + 1 }">
		<MvSKIP NAME = "Stores" ROWS = 1>
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.count }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_License_In_Use" PARAMETERS = "license" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.inuse" VALUE = 0>

	<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_lic.mvx' }">
	<MvFIND NAME = "Stores" VALUE = "{ l.license }" EXACT>
	<MvIF EXPR = "{ NOT Stores.d.EOF }">
		<MvASSIGN NAME = "l.inuse" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.inuse }">
</MvFUNCTION>

<MvCOMMENT>
|
| AdminSessions
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Open_AdminSessions" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_AdminSessions_Open }">
		<MvOPEN NAME = "AdminSessions" 
				DATABASE = "{ g.Merchantpath $ 'admsess.dbf' }" 
				INDEXES = "{ g.MerchantPath $ 'ads_sess.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00050', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_AdminSessions_Open" VALUE = 1>
			<MvFILTER NAME = "AdminSessions" FILTER = "{ NOT AdminSessions.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AdminSession_Insert" PARAMETERS = "session_id, user_id, lastupdate" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_AdminSessions() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "AdminSessions.d.session_id" VALUE = "{ l.session_id }">
		<MvASSIGN NAME = "AdminSessions.d.user_id" VALUE = "{ l.user_id }">
		<MvASSIGN NAME = "AdminSessions.d.lastupdate" VALUE = "{ l.lastupdate }">

		<MvADD NAME = "AdminSessions">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AdminSession_Update" PARAMETERS = "session_id, user_id, lastupdate" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_AdminSessions() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "AdminSessions" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ AdminSessions.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00042">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Administration Session '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00051', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "AdminSessions.d.user_id" VALUE = "{ l.user_id }">
			<MvASSIGN NAME = "AdminSessions.d.lastupdate" VALUE = "{ l.lastupdate }">

			<MvUPDATE NAME = "AdminSessions">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AdminSession_Delete" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_AdminSessions() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "AdminSessions" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ AdminSessions.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00043">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Administration Session '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00052', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "AdminSessions">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AdminSession_Find_Session" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_AdminSessions() }">
		<MvFIND NAME = "AdminSessions" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ NOT AdminSessions.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00044">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Administration Session '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00053', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Countries
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Open_Countries" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Countries_Open }">
		<MvOPEN NAME = "Countries" 
				DATABASE = "{ g.MerchantPath $ 'country.dbf' }"
				INDEXES = "{ g.MerchantPath $ 'cntry_i.mvx, ' $ g.MerchantPath $ 'cntry_a.mvx, ' $ g.MerchantPath $ 'cntry_n.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00054', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Countries_Open" VALUE = 1>
			<MvFILTER NAME = "Countries" FILTER = "{ NOT Countries.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Country_Insert" PARAMETERS = "id, name, alpha, numeric" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Countries() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "Countries.d.id" VALUE = "{ l.id }">
		<MvASSIGN NAME = "Countries.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "Countries.d.alpha" VALUE = "{ l.alpha }">
		<MvASSIGN NAME = "Countries.d.numeric" VALUE = "{ l.numeric }">

		<MvADD NAME = "Countries">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Country_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Countries() }">
		<MvPRIMARY NAME = "Countries" INDEX = "{ g.MerchantPath $ 'cntry_n.mvx' }">

		<MvGO NAME = "Countries" ROW = "top">
		<MvIF EXPR = "{ NOT Countries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Country_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Countries() }">
		<MvSKIP NAME = "Countries" ROWS = 1>
		<MvIF EXPR = "{ NOT Countries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Country_Find_Alpha" PARAMETERS = "alpha" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Countries() }">
		<MvPRIMARY NAME = "Countries" INDEX = "{ g.MerchantPath $ 'cntry_a.mvx' }">
			
		<MvFIND NAME = "Countries" VALUE = "{ l.alpha }" EXACT>
		<MvIF EXPR = "{ NOT Countries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00045">
				<MvLOCALIZED-TOKEN NAME = "alpha" VALUE = "{ encodeentities( l.alpha ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Country '%alpha%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00335', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Store Countries
|
</MvCOMMENT>

<MvFUNCTION NAME = "_Country_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._country_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._country_word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._country_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT Countries.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND ( 
				( g._country_word[' $ l.pos $ '] CIN Countries.d.alpha ) OR
				( g._country_word[' $ l.pos $ '] CIN Countries.d.name ) )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Open_StoreCountries" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_StoreCountries_Open }">
		<MvOPEN NAME = "StoreCountries" 
				DATABASE = "{ g._DB_Store_Directory $ 'str_cty.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'str_cty.mvx, ' $ g._DB_Store_Directory $ 'str_ctyn.mvx, ' $ g._DB_Store_Directory $ 'str_ctyi.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00362', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_StoreCountries_Open" VALUE = 1>
			<MvFILTER NAME = "StoreCountries" FILTER = "{ NOT StoreCountries.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Insert" PARAMETERS = "id, name, alpha, numeric" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_StoreCountries() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "StoreCountries.d.id" VALUE = "{ l.id }">
		<MvASSIGN NAME = "StoreCountries.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "StoreCountries.d.alpha" VALUE = "{ l.alpha }">
		<MvASSIGN NAME = "StoreCountries.d.numeric" VALUE = "{ l.numeric }">

		<MvADD NAME = "StoreCountries">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_FindFirst_Alpha" PARAMETERS = "" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Open_StoreCountries() }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_ctyn.mvx' }">
		<MvGO NAME = "StoreCountries" ROW = "top">
		<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_FindNext_Alpha" PARAMETERS = "" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "StoreCountries" ROWS = 1>
	<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Find_Alpha" PARAMETERS = "alpha" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_StoreCountries() }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_cty.mvx' }">
			
		<MvFIND NAME = "StoreCountries" VALUE = "{ l.alpha }" EXACT>
		<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00045">
				<MvLOCALIZED-TOKEN NAME = "alpha" VALUE = "{ encodeentities( l.alpha ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Country '%alpha%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00363', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Open_StoreCountries() }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_ctyi.mvx' }">
		<MvFIND NAME = "StoreCountries" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00045">
				<MvLOCALIZED-TOKEN NAME = "alpha" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Country '%alpha%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00364', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_StoreCountries() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_ctyi.mvx' }">

		<MvFIND NAME = "StoreCountries" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ StoreCountries.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00119">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Country '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00365', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ l.ok }">
				<MvDELETE NAME = "StoreCountries">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Country_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Open_Countries() }">
		<MvPRIMARY NAME = "Countries" INDEX = "{ g.MerchantPath $ 'cntry_n.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Country_Filter( l.search ) }">
		<MvFILTER NAME = "Countries" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Countries" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT Countries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Country_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Countries" ROWS = 1>
	<MvIF EXPR = "{ NOT Countries.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Countries" FILTER = "{ NOT Countries.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Country_FindOffset_Unassigned" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Open_StoreCountries() AND _DB_Open_Countries() }">
		<MvPRIMARY NAME = "Countries" INDEX = "{ g.MerchantPath $ 'cntry_n.mvx' }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_ctyi.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Country_Filter( l.search ) }">
		<MvFILTER NAME = "Countries" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Countries" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Countries.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "StoreCountries" VALUE = "{ Countries.d.id }" EXACT>
			<MvIF EXPR = "{ StoreCountries.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Countries" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Country_FindNext_Unassigned" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Countries" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Countries.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "StoreCountries" VALUE = "{ Countries.d.id }" EXACT>
		<MvIF EXPR = "{ StoreCountries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Countries" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Countries" FILTER = "{ NOT Countries.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Country_FindOffset_Assigned" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Open_Countries() AND _DB_Open_StoreCountries() }">
		<MvPRIMARY NAME = "Countries" INDEX = "{ g.MerchantPath $ 'cntry_n.mvx' }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_ctyi.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Country_Filter( l.search ) }">
		<MvFILTER NAME = "Countries" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "StoreCountries" VALUE = "{ Countries.d.id }" EXACT>
		<MvSKIP NAME = "Countries" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT Countries.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "StoreCountries" VALUE = "{ Countries.d.id }" EXACT>
			<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Countries" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Country_FindNext_Assigned" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Countries" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT Countries.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "StoreCountries" VALUE = "{ Countries.d.id }" EXACT>
		<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Countries" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Countries" FILTER = "{ NOT Countries.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "StoreCountry_Find" PARAMETERS = "store_id, count_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Open_StoreCountries() }">
		<MvPRIMARY NAME = "StoreCountries" INDEX = "{ g._DB_Store_Directory $ 'str_ctyi.mvx' }">

		<MvFIND NAME = "StoreCountries" VALUE = "{ l.store_id $ ':' $ padl( l.count_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT StoreCountries.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| States
|
</MvCOMMENT>

<MvFUNCTION NAME = "_State_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._state_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._state_word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._state_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT States.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND ( ( g._state_word[' $ l.pos $ '] CIN States.d.code ) OR
																  ( g._state_word[' $ l.pos $ '] CIN States.d.name ) )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_States" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_States_Open }">
		<MvOPEN NAME = "States" 
				DATABASE = "{ g._DB_Store_Directory $ 'states.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'states.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00055', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_States_Open" VALUE = 1>
			<MvFILTER NAME = "States" FILTER = "{ NOT States.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_Insert" PARAMETERS = "code, name" STANDARDOUTPUTLEVEL = "">

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_States() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "States.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
		<MvASSIGN NAME = "States.d.name" VALUE = "{ l.name }">

		<MvADD NAME = "States">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_Update" PARAMETERS = "code, newcode, name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_States() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "States" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ States.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00046">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">State '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00056', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "States.d.code" VALUE = "{ l.newcode }">
			<MvASSIGN NAME = "States.d.name" VALUE = "{ l.name }">
			<MvUPDATE NAME = "States">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_Delete" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_States() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "States" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ States.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00047">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">State '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00057', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "States">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_Find_Code" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_States() }">
		<MvFIND NAME = "States" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ NOT States.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_Empty" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.empty" VALUE = 1>

	<MvIF EXPR = "{ _DB_Store_Open_States() }">
		<MvGO NAME = "States" ROW = "top">
		<MvWHILE EXPR = "{ l.empty AND ( NOT States.d.EOF ) }">
			<MvIF EXPR = "{ len( States.d.code ) }">
				<MvASSIGN NAME = "l.empty" VALUE = 0>
			</MvIF>

			<MvSKIP NAME = "States" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.empty }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_States() }">
		<MvGO NAME = "States" ROW = "top">
		<MvIF EXPR = "{ NOT States.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_FindFirst_Offset" PARAMETERS = "offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_States() }">
		<MvGO NAME = "States" ROW = "top">
		<MvSKIP NAME = "States" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT States.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "States" ROWS = 1>
	<MvIF EXPR = "{ States.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "State_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_States() }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ _State_Filter( l.search ) }">
		<MvFILTER NAME = "States" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "States" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT States.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "State_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "States" ROWS = 1>
	<MvIF EXPR = "{ NOT States.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "States" FILTER = "{ NOT States.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>


<MvCOMMENT>
|
| CategoryXProduct
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_CategoryXProduct" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_CategoryXProduct_Open }">
		<MvOPEN NAME = "CategoryXProduct"
				DATABASE = "{ g._DB_Store_Directory $ 'catxprod.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'cxp_cat.mvx, ' $ g._DB_Store_Directory $ 'cxp_prod.mvx, ' $ g._DB_Store_Directory $ 'cxp_cprd.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00058', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_CategoryXProduct_Open" VALUE = 1>
			<MvFILTER NAME = "CategoryXProduct" FILTER = "{ NOT CategoryXProduct.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "CategoryXProduct_Insert" PARAMETERS = "cat_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_CategoryXProduct() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cprd.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' $ l.product_id }" EXACT>
		<MvIF EXPR = "{ NOT CategoryXProduct.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00048">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' is already in category '%cat_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00059', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
				<MvFIND NAME = "Products" VALUE = "{ l.product_id }" EXACT>
				<MvIF EXPR = "{ Products.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00049">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00060', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "Products.d.catcount" VALUE = "{ Products.d.catcount + 1 }">
					<MvUPDATE NAME = "Products">

					<MvASSIGN NAME = "CategoryXProduct.d.cat_id" VALUE = "{ l.cat_id }">
					<MvASSIGN NAME = "CategoryXProduct.d.product_id" VALUE = "{ l.product_id }">
					<MvASSIGN NAME = "CategoryXProduct.d.order" VALUE = "{ l.product_id }">

					<MvADD NAME = "CategoryXProduct">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "CategoryXProduct_Update_Order" PARAMETERS = "cat_id, product_id, order" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cprd.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' $ l.product_id }" EXACT>
		<MvIF EXPR = "{ CategoryXProduct.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00050">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' is not in category '%cat_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00061', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "CategoryXProduct.d.order" VALUE = "{ l.order }">
			<MvUPDATE NAME = "CategoryXProduct">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "CategoryXProduct_Find" PARAMETERS = "cat_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cprd.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' $ l.product_id }" EXACT>
		<MvIF EXPR = "{ NOT CategoryXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "CategoryXProduct_Delete" PARAMETERS = "cat_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ l.product_id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00051">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00062', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_CategoryXProduct() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cprd.mvx' }">
				<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' $ l.product_id }" EXACT>
				<MvIF EXPR = "{ CategoryXProduct.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00052">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
						<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">

						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' is not in category '%cat_id%'</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00063', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "Products.d.catcount" VALUE = "{ Products.d.catcount - 1 }">
					<MvUPDATE NAME = "Products">

					<MvDELETE NAME = "CategoryXProduct">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "CategoryXProduct_Sort" PARAMETERS = "category_id, sort_field, ascending" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "1">
	
	<MvIF EXPR = "{ l.ascending }">
		<MvASSIGN NAME = "l.flags" VALUE = "nounique, ascending, string">
	<MvELSE>
		<MvASSIGN NAME = "l.flags" VALUE = "nounique, descending, string">
	</MvIF>
	
	<MvIF EXPR = "{ ( l.sort_field NE 'code' ) AND ( l.sort_field NE 'name' ) }">
		<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00053">
			<MvLOCALIZED-TOKEN NAME = "sort_field" VALUE = "{ encodeentities( l.sort_field ) }">
			<MvLOCALIZED-TEXT LANGUAGE = "en-US">Invalid CategoryXProduct sort field '%sort_field%'</MvLOCALIZED-TEXT>
		</MvLOCALIZED>

		<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00325', l.error ) }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">	
		<MvCREATE 	NAME = "CxPSort"
					DATABASE = "{ g._DB_Store_Directory $ 'cxpsort.dbf' }"
					FIELDS = "product_id	NUMBER,
							  sort_fld		CHAR( 100 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00323', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.cxpsort_open" VALUE = "1">
			<MvASSIGN NAME = "l.delete_dbf" VALUE = 1>
		</MvIF>
	</MvIF>
	
	<MvIF EXPR = "{ l.ok }">
		<MvMAKEINDEX 	NAME = "CxPSort"
						INDEXFILE = "{ g._DB_Store_Directory $ 'cxpsort.mvx' }"
						EXPR = "{ toupper( CxPSort.d.sort_fld ) }"
						FLAGS = "{ l.flags }">
		<MvIF EXPR = "{ MvMAKEINDEX_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00324', MvMAKEINDEX_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.delete_mvx" VALUE = 1>
		</MvIF>
	</MvIF>
	
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.found" VALUE = "{ Product_FindFirst_Category( l.category_id ) }">
		<MvWHILE EXPR = "{ l.found }">
			<MvASSIGN NAME = "CxPSort.d.product_id" VALUE = "{ Products.d.id }">

			<MvIF EXPR = "{ l.sort_field EQ 'code' }">
				<MvASSIGN NAME = "CxPSort.d.sort_fld" VALUE = "{ Products.d.code }">
			<MvELSE>
				<MvIF EXPR = "{ l.sort_field EQ 'name' }">
					<MvASSIGN NAME = "CxPSort.d.sort_fld" VALUE = "{ Products.d.name }">
				</MvIF>
			</MvIF>

			<MvADD NAME = "CxPSort">

			<MvASSIGN NAME = "l.found" VALUE = "{ Product_FindNext_Category( l.category_id ) }">
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.counter" VALUE = "1">
		<MvGO NAME = "CxPSort" ROW = "top">
		<MvWHILE EXPR = "{ NOT CxPSort.d.EOF }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ CategoryXProduct_Update_Order( l.category_id, CxPSort.d.product_id, l.counter ) }">
			<MvIF EXPR = "{ NOT l.ok }">
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.counter" VALUE = "{ l.counter + 1 }">
			<MvSKIP NAME = "CxPSort" ROWS = "1">
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.cxpsort_open }">
		<MvCLOSE NAME = "CxPSort">
	</MvIF>

	<MvIF EXPR = "{ l.delete_dbf }">
		<MvIF EXPR = "{ NOT fdelete( g._DB_Store_Directory $ 'cxpsort.dbf' ) }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00054">
				<MvLOCALIZED-TOKEN NAME = "file" VALUE = "{ encodeentities( g._DB_Store_Directory $ 'cxpsort.dbf' ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Error deleting file '%file%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00329', l.error ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.delete_mvx }">
		<MvIF EXPR = "{ NOT fdelete( g._DB_Store_Directory $ 'cxpsort.mvx' ) }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00055">
				<MvLOCALIZED-TOKEN NAME = "file" VALUE = "{ encodeentities( g._DB_Store_Directory $ 'cxpsort.mvx' ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Error deleting file '%file%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00338', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Products
|
</MvCOMMENT>

<MvFUNCTION NAME = "_Product_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._product_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._product_word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._product_word" INDEX ="{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT Products.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND (
			( g._product_word[' $ l.pos $ '] CIN Products.d.code ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.name ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.thumbnail ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.image ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.price ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.cost ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.desc ) OR
			( g._product_word[' $ l.pos $ '] CIN Products.d.weight ) )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_Products" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Products_Open }">
		<MvOPEN NAME = "Products" 
				DATABASE = "{ g._DB_Store_Directory $ 'products.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'prd_id.mvx, ' $
						     g._DB_Store_Directory $ 'prd_ord.mvx, ' $
						     g._DB_Store_Directory $ 'prd_ccnt.mvx, ' $
							 g._DB_Store_Directory $ 'prd_gcnt.mvx, ' $
							 g._DB_Store_Directory $ 'prd_pgct.mvx, ' $
							 g._DB_Store_Directory $ 'prd_code.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00064', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = 1>
			<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Products" ROWS = 1>

	<MvIF EXPR = "{ NOT Products.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Insert" PARAMETERS = "code, name, thumbnail, image, price, cost, desc, weight, taxable, active" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.product_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvASSIGN NAME = "Products.d.id" VALUE = "{ StoreKey_Generate( 'Products' ) }">
		<MvASSIGN NAME = "Products.d.catcount" VALUE = 0>
		<MvASSIGN NAME = "Products.d.agrpcount" VALUE = 0>
		<MvASSIGN NAME = "Products.d.pgrpcount" VALUE = 0>
		<MvASSIGN NAME = "Products.d.order" VALUE = "{ Products.d.id }">
		<MvASSIGN NAME = "Products.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
		<MvASSIGN NAME = "Products.d.name" VALUE = "{ l.name }">
		<MvASSIGN NAME = "Products.d.thumbnail" VALUE = "{ l.thumbnail }">
		<MvASSIGN NAME = "Products.d.image" VALUE = "{ l.image }">
		<MvASSIGN NAME = "Products.d.price" VALUE = "{ l.price }">
		<MvASSIGN NAME = "Products.d.cost" VALUE = "{ l.cost }">
		<MvASSIGN NAME = "Products.d.desc" VALUE = "{ l.desc }">
		<MvASSIGN NAME = "Products.d.weight" VALUE = "{ l.weight }">
		<MvASSIGN NAME = "Products.d.taxable" VALUE = "{ l.taxable }">
		<MvASSIGN NAME = "Products.d.active" VALUE = "{ l.active }">

		<MvADD NAME = "Products">
	
		<MvASSIGN NAME = "l.product_id" VALUE = "{ Products.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.product_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Update" PARAMETERS = "id, code, name, thumbnail, image, price, cost, desc, weight, taxable, active" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvFIND NAME = "Products" VALUE = "{ l.id }" EXACT>

		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00056">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00065', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Products.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
			<MvASSIGN NAME = "Products.d.name" VALUE = "{ l.name }">
			<MvASSIGN NAME = "Products.d.thumbnail" VALUE = "{ l.thumbnail }">
			<MvASSIGN NAME = "Products.d.image" VALUE = "{ l.image }">
			<MvASSIGN NAME = "Products.d.price" VALUE = "{ l.price }">
			<MvASSIGN NAME = "Products.d.cost" VALUE = "{ l.cost }">
			<MvASSIGN NAME = "Products.d.desc" VALUE = "{ l.desc }">
			<MvASSIGN NAME = "Products.d.weight" VALUE = "{ l.weight }">
			<MvASSIGN NAME = "Products.d.taxable" VALUE = "{ l.taxable }">
			<MvASSIGN NAME = "Products.d.active" VALUE = "{ l.active }">
			
			<MvUPDATE NAME = "Products">
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Update_Order" PARAMETERS = "id, order" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvFIND NAME = "Products" VALUE = "{ l.id }" EXACT>

		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00057">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00066', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Products.d.order" VALUE = "{ l.order }">
			<MvUPDATE NAME = "Products">
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvIF EXPR = "{ g.Features:Upsale:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.deleted" VALUE = "{ Upsell_Delete( l.id ) }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.deleted" VALUE = "{ INV_InventoryProductSettings_Delete(l.id) }">		
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_CategoryXProduct() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_prod.mvx' }">
			<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.id }" EXACT>

			<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.product_id EQ l.id ) }">
				<MvDELETE NAME = "CategoryXProduct">
				<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
			</MvWHILE>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ g.Features:Customers:Enabled }">
		<MvIF EXPR = "{ l.ok }">
			<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AvailabilityGroupXProduct_Delete_Product( l.id ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvIF EXPR = "{ g.Features:PriceGroups:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_PGR_DB }" NAME = "l.ok" VALUE = "{ PriceGroupXProduct_Delete_Product( l.id ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ l.id }" EXACT>

			<MvIF EXPR = "{ Products.d.EOF }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00058">
					<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00067', l.error ) }">
			<MvELSE>
				<MvDELETE NAME = "Products">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvIF EXPR = "{ g.Features:RelatedProducts:Enabled }">
			<MvDO FILE = "{ g.Module_Feature_RPD_DB }" NAME = "l.ok" VALUE = "{ Product_Delete_RelatedProduct( l.id ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ Product_Delete_Attributes( l.id ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Delete_Attributes" PARAMETERS = "id">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Attributes() }">

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Options() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_prod.mvx' }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_attr.mvx' }">

		<MvFIND NAME = "Attributes" VALUE = "{ l.id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT Attributes.d.EOF ) AND ( Attributes.d.product_id EQ l.id ) }">
			<MvIF EXPR = "{ Attributes.d.type EQ 'template' }">
				<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Decrement_ReferenceCount( Attributes.d.attemp_id ) }">
			</MvIF>

			<MvFIND NAME = "Options" VALUE = "{ Attributes.d.id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Options.d.EOF ) AND ( Options.d.attr_id EQ Attributes.d.id ) }">
				<MvDELETE NAME = "Options">
				<MvSKIP NAME = "Options" ROWS = 1>
			</MvWHILE>

			<MvDELETE NAME = "Attributes">

			<MvSKIP NAME = "Attributes" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_Offset" PARAMETERS = "offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">

		<MvGO NAME = "Products" ROW = "top">
		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">

		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
		<MvGO NAME = "Products" ROW = "top">

		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindLast" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
		<MvGO NAME = "Products" ROW = "bottom">

		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "Products" ROWS = 1>
	<MvIF EXPR = "{ Products.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">

	<MvASSIGN NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
	<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">
	<MvSKIP NAME = "Products" ROWS = "{ l.offset }">

	<MvIF EXPR = "{ NOT Products.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>
	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindOffset_Uncategorized" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ccnt.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "Products" VALUE = "0:">
		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">

		<MvIF EXPR = "{ ( NOT Products.d.EOF ) AND ( Products.d.catcount EQ 0 ) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_Uncategorized" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvIF EXPR = "{ ( NOT Products.d.EOF ) AND ( Products.d.catcount EQ 0 ) }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindFirst_Offset" PARAMETERS = "cust_id, offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">

		<MvGO NAME = "Products" ROW = "top">
		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ NOT Products.d.EOF }">

			<MvIF EXPR = "{ Products.d.active }">
				<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
					<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
				<MvELSE>
					<MvASSIGN NAME = "l.show_product" VALUE = "1">
				</MvIF>
				<MvIF EXPR = "{ l.show_product }">
					<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
						<MvASSIGN NAME = "l.found" VALUE = 1>
						<MvWHILESTOP>
					<MvELSE>
						<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
							<MvIF EXPR = "{ l.cust_id }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct() }">
								<MvIF EXPR = "{ l.ok }">
									<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
									<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">

									<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
								</MvIF>
							</MvIF>
						<MvELSE>
							<MvASSIGN NAME = "l.found" VALUE = 1>
						</MvIF>
						<MvIF EXPR = "{ l.found }">
							<MvWHILESTOP>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Products" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindFirst" PARAMETERS = "cust_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
		<MvGO NAME = "Products" ROW = "top">

		<MvWHILE EXPR = "{ NOT Products.d.EOF }">
			<MvIF EXPR = "{ Products.d.active }">		
				<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
					<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
				<MvELSE>
					<MvASSIGN NAME = "l.show_product" VALUE = "1">
				</MvIF>
			
				<MvIF EXPR = "{ l.show_product }">
			
					<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
						<MvASSIGN NAME = "l.found" VALUE = 1>
						<MvWHILESTOP>
					<MvELSE>
						<MvIF EXPR = "{ l.cust_id }">
							<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct() }">
								<MvIF EXPR = "{ l.ok }">
									<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
									<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
									<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
								</MvIF>
							<MvELSE>
								<MvASSIGN NAME = "l.found" VALUE = 1>
							</MvIF>

							<MvIF EXPR = "{ l.found }">
								<MvWHILESTOP>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
			
			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Products" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindNext" PARAMETERS = "cust_id, offset"
		    STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	
	<MvSKIP NAME = "Products" ROWS = 1>

	<MvWHILE EXPR = "{ NOT Products.d.EOF }">
		<MvIF EXPR = "{ Products.d.active }">
			<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
			<MvELSE>
				<MvASSIGN NAME = "l.show_product" VALUE = "1">
			</MvIF>
			<MvIF EXPR = "{ l.show_product }">
				<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
					<MvWHILESTOP>
				<MvELSE>
					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
						<MvELSE>
							<MvASSIGN NAME = "l.found" VALUE = 1>
						</MvIF>

						<MvIF EXPR = "{ l.found }">
							<MvWHILESTOP>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Products" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_Code_NonExact" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_code.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ toupper( l.code ) }">
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_Code_NonExact" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvASSIGN NAME = "l.directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0', ) $ '/' }">
	<MvPRIMARY NAME = "Products" INDEX = "{ l.directory $ 'prd_code.mvx' }">

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvIF EXPR = "{ Products.d.EOF OR ( ( toupper( l.code ) IN toupper( Products.d.code ) ) NE 1 ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindOffset_Words" PARAMETERS = "words, offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _Product_Filter( l.words ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_Words" PARAMETERS = "words" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvIF EXPR = "{ Products.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindOffset_Words" PARAMETERS = "cust_id, offset, words" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
	
		<MvASSIGN NAME = "l.filter" VALUE = "{ _Product_Filter( l.words ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ NOT Products.d.EOF }">
			<MvIF EXPR = "{ Products.d.active }">
				<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
					<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
				<MvELSE>
					<MvASSIGN NAME = "l.show_product" VALUE = "1">
				</MvIF>
				<MvIF EXPR = "{ l.show_product }">
					<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
						<MvASSIGN NAME = "l.found" VALUE = 1>
						<MvWHILESTOP>
					<MvELSE>
						<MvIF EXPR = "{ l.cust_id }">
							<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct()}">
								<MvIF EXPR = "{ l.ok }">
									<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
									<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
									<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
								</MvIF>
							<MvELSE>
								<MvASSIGN NAME = "l.found" VALUE = 1>
							</MvIF>

							<MvIF EXPR = "{ l.found }">
								<MvWHILESTOP>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Products" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindNext_Words" PARAMETERS = "cust_id, offset, words"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Products" ROWS = 1>

	<MvWHILE EXPR = "{ NOT Products.d.EOF }">
		<MvIF EXPR = "{ Products.d.active }">
			<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
			<MvELSE>
				<MvASSIGN NAME = "l.show_product" VALUE = "1">
			</MvIF>
			<MvIF EXPR = "{ l.show_product }">
				<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
					<MvWHILESTOP>
				<MvELSE>
					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
						<MvELSE>
							<MvASSIGN NAME = "l.found" VALUE = 1>
						</MvIF>

						<MvIF EXPR = "{ l.found }">
							<MvWHILESTOP>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
		
		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Products" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ Products.d.EOF }">
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00059">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00068', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Runtime_Product_Find_ID" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = "{ Customer_Product_Find_ID( l.cust_id, l.id ) }">

	<mvcomment>
		<MvASSIGN NAME = "l.found" VALUE = "{ Runtime_Product_Find_ID( l.id ) }">
bon
	</mvcomment>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "NOCustomers_Product_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products()  }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvFIND NAME = "Products" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00060">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00069', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Products.d.active }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_Find_ID" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00060">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00069', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Products.d.active }">
				<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct() }">
							<MvIF EXPR = "{ l.ok }">
								<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
								<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
							</MvIF>
						<MvELSE>
							<MvASSIGN NAME = "l.ok" VALUE = 1>
						</MvIF>
					</MvIF>

					<MvIF EXPR = "{ NOT l.found }">
						<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00061">
							<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
							<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%id%' not found</MvLOCALIZED-TEXT>
						</MvLOCALIZED>

						<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00070', l.error ) }">
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Find_Code" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.product_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_code.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00062">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00370', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.product_id" VALUE = "{ Products.d.id }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.product_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_Find_Code" PARAMETERS = "cust_id, code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.product_id" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_code.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00063">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00072', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Products.d.active }">
				<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
					<MvASSIGN NAME = "l.product_id" VALUE = "{ Products.d.id }">
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>

					<MvIF EXPR = "{ l.cust_id }">
						<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
							<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct() }">
							<MvIF EXPR = "{ l.ok }">
								<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
								<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
							</MvIF>
						<MvELSE>
							<MvASSIGN NAME = "l.found" VALUE = 1>
						</MvIF>
					</MvIF>

					<MvIF EXPR = "{ l.found }">
						<MvASSIGN NAME = "l.product_id" VALUE = "{ Products.d.id }">
					<MvELSE>
						<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00064">
							<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
							<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%code%' not found</MvLOCALIZED-TEXT>
						</MvLOCALIZED>

						<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00073', l.error ) }">
					</MvIF>
				</MvIF>
			<MvELSE>
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00160">
					<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%code%' not found</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.product_id" VALUE = "{ Error( 'MER-DTB-00371', l.error ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.product_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindOffset_Category" PARAMETERS = "offset, cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() AND _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' }">
		<MvSKIP NAME = "CategoryXProduct" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindOffset_Category" PARAMETERS = "cust_id, offset, cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() AND
				    _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' }">
		<MvSKIP NAME = "CategoryXProduct" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) }">
			<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvIF EXPR = "{ Products.d.active }">
					<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
					<MvELSE>
						<MvASSIGN NAME = "l.show_product" VALUE = "1">
					</MvIF>
					<MvIF EXPR = "{ l.show_product }">

						<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
							<MvASSIGN NAME = "l.found" VALUE = 1>
							<MvWHILESTOP>
						<MvELSE>
							<MvIF EXPR = "{ l.cust_id }">
								<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">

									<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct() }">
									<MvIF EXPR = "{ l.ok }">
										<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
										<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
										<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
									</MvIF>
								<MvELSE>
									<MvASSIGN NAME = "l.found" VALUE = 1>
								</MvIF>

								<MvIF EXPR = "{ l.found }">
									<MvWHILESTOP>
								</MvIF>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindFirst_Category" PARAMETERS = "cust_id, cat_id"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.offset" VALUE = 1>

	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() AND _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) }">
			<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvIF EXPR = "{ Products.d.active }">
					<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
					<MvELSE>
						<MvASSIGN NAME = "l.show_product" VALUE = "1">
					</MvIF>
					<MvIF EXPR = "{ l.show_product }">

						<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
							<MvASSIGN NAME = "l.found" VALUE = 1>
							<MvWHILESTOP>
						<MvELSE>
							<MvIF EXPR = "{ l.cust_id }">
								<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
									<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() AND _DB_Store_Open_AvailabilityGroupXProduct() }">
									<MvIF EXPR = "{ l.ok }">
										<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
										<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
										<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
									</MvIF>
								<MvELSE>
									<MvASSIGN NAME = "l.found" VALUE = 1>
								</MvIF>

								<MvIF EXPR = "{ l.found }">
									<MvWHILESTOP>
								</MvIF>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
		
			<MvASSIGN NAME = "l.offset" VALUE = "{ l.offset + 1 }">
			<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.offset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Customer_Product_FindNext_Category" PARAMETERS = "cust_id, offset, cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

	<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) }">
		<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.show_product" VALUE = "{ INV_ShowProduct( Products.d.id ) }">
			<MvELSE>
				<MvASSIGN NAME = "l.show_product" VALUE = "1">
			</MvIF>
			<MvIF EXPR = "{ l.show_product }">
				<MvIF EXPR = "{ Products.d.active }">
					<MvIF EXPR = "{ Products.d.agrpcount EQ 0 }">
						<MvASSIGN NAME = "l.found" VALUE = 1>
						<MvWHILESTOP>
					<MvELSE>
						<MvIF EXPR = "{ l.cust_id }">
							<MvIF EXPR = "{ g.Features:Customers:Enabled AND g.Features:AvailabilityGroups:Enabled }">
								<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.found" VALUE = "{ AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct( l.cust_id, Products.d.id ) }">
							<MvELSE>
								<MvASSIGN NAME = "l.found" VALUE = 1>
							</MvIF>

							<MvIF EXPR = "{ l.found }">
								<MvWHILESTOP>
							</MvIF>
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_Category" PARAMETERS = "cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_CategoryXProduct() AND _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "CategoryXProduct" INDEX = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }">

		<MvFIND NAME = "CategoryXProduct" VALUE = "{ l.cat_id $ ':' }">
		<MvIF EXPR = "{ ( NOT CategoryXProduct.d.EOF ) AND ( CategoryXProduct.d.cat_id EQ l.cat_id ) }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_Category" PARAMETERS = "cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "CategoryXProduct" ROWS = 1>
	<MvIF EXPR = "{ ( CategoryXProduct.d.EOF ) OR ( CategoryXProduct.d.cat_id NE l.cat_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvELSE>
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ CategoryXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_CategoryCount" PARAMETERS = "catcount" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ccnt.mvx' }">
		
		<MvFIND NAME = "Products" VALUE = "{ l.catcount $ ':' }">
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_CategoryCount" PARAMETERS = "catcount" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvIF EXPR = "{ Products.d.EOF OR ( Products.d.catcount NE l.catcount ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_ProductOrder" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvASSIGN NAME = "l.found" VaLUE = "{ Product_Find_Code( l.code ) }">
		<MvIF EXPR = "{ l.found }">
			<MvASSIGN NAME = "l.order" VaLUE = "{ Products.d.order }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ padl( l.order, 10, '0' ) }">

			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvSKIP NAME = "Products" ROWS = 1>
				<MvIF EXPR = "{ NOT Products.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>
				</MvIF>
			<MvELSE>
				<MvASSIGN NAME = "l.found" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindPrev_ProductOrder" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Products() }">
		<MvASSIGN NAME = "l.found" VaLUE = "{ Product_Find_Code( l.code ) }">
		<MvIF EXPR = "{ l.found }">
			<MvASSIGN NAME = "l.order" VaLUE = "{ Products.d.order }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ padl( l.order, 10, '0' ) }">

			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvSKIP NAME = "Products" ROWS = -1>
				<MvIF EXPR = "{ NOT Products.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>
				</MvIF>
			<MvELSE>
				<MvASSIGN NAME = "l.found" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_Sort" PARAMETERS = "sort_field, ascending" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvIF EXPR = "{ l.ascending }">
			<MvASSIGN NAME = "l.flags" VALUE = "nounique, ascending, string">
		<MvELSE>
			<MvASSIGN NAME = "l.flags" VALUE = "nounique, descending, string">
		</MvIF>
		
		<MvIF EXPR = "{ l.sort_field EQ 'code' }">
			<MvMAKEINDEX 	NAME = "Products"
							INDEXFILE = "{ g._DB_Store_Directory $ 'prodsort.mvx' }"
							EXPR = "{ toupper( Products.d.code ) }"
							FLAGS = "{ l.flags }">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00327', MvMAKEINDEX_Error ) }">
			</MvIF>
		<MvELSE>
			<MvIF EXPR = "{ l.sort_field EQ 'name' }">
				<MvMAKEINDEX 	NAME = "Products"
								INDEXFILE = "{ g._DB_Store_Directory $ 'prodsort.mvx' }"
								EXPR = "{ toupper( Products.d.name ) }"
								FLAGS = "{ l.flags }">
				<MvIF EXPR = "{ MvMAKEINDEX_Error }">
					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00332', MvMAKEINDEX_Error ) }">
				</MvIF>
			<MvELSE>
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00065">
					<MvLOCALIZED-TOKEN NAME = "sort_field" VALUE = "{ encodeentities( l.sort_field ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Invalid Product sort field '%sort_field%'</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00319', l.error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
		</MvIF>
		
		<MvIF EXPR = "{ l.ok }">	
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prodsort.mvx' }">
			<MvASSIGN NAME = "l.counter" VALUE = "1">
			<MvGO NAME = "Products" ROW = "top">
			<MvWHILE EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "Products.d.order" VALUE = "{ l.counter }">
				<MvUPDATE NAME = "Products">
				
				<MvASSIGN NAME = "l.counter" VALUE = "{ l.counter + 1 }">
				<MvSKIP NAME = "Products" ROWS = "1">
			</MvWHILE>

			<MvCLOSE NAME = "Products">
			<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = "0">
			
			<MvIF EXPR = "{ NOT fdelete( g._DB_Store_Directory $ 'prodsort.mvx' ) }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00066">
					<MvLOCALIZED-TOKEN NAME = "file" VALUE = "{ encodeentities( g._DB_Store_Directory $ 'prodsort.mvx' ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Unable to delete file '%file%'</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00322', l.error ) }">
			</MvIF>
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Attributes
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_Attributes" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Attributes_Open }">
		<MvOPEN NAME = "Attributes" 
				DATABASE = "{ g._DB_Store_Directory $ 'attr.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'atr_id.mvx, ' $ g._DB_Store_Directory $ 'atr_code.mvx, ' $ g._DB_Store_Directory $ 'atr_prod.mvx, '  $ g._DB_Store_Directory $ 'atr_at_p.mvx, ' $ g._DB_Store_Directory $ 'atr_at_i.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00074', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Attributes_Open" VALUE = 1>
			<MvFILTER NAME = "Attributes" FILTER = "{ NOT Attributes.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_Insert" PARAMETERS = "product_id, code, type, template, prompt, price, cost, required, image" STANDARDOUTPUTLEVEL = "">

	<MvASSIGN NAME = "l.attribute_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Attributes() }">
		<MvASSIGN NAME = "Attributes.d.id" VALUE = "{ StoreKey_Generate( 'Attributes' ) }">
		<MvASSIGN NAME = "Attributes.d.product_id" VALUE = "{ l.product_id }">
		<MvASSIGN NAME = "Attributes.d.default_id" VALUE = 0>
		<MvASSIGN NAME = "Attributes.d.order" VALUE = "{ Attributes.d.id }">
		<MvASSIGN NAME = "Attributes.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
		<MvASSIGN NAME = "Attributes.d.type" VALUE = "{ l.type }">
		<MvASSIGN NAME = "Attributes.d.attemp_id" VALUE = "{ l.template }">
		<MvASSIGN NAME = "Attributes.d.prompt" VALUE = "{ l.prompt }">
		<MvASSIGN NAME = "Attributes.d.price" VALUE = "{ l.price }">
		<MvASSIGN NAME = "Attributes.d.cost" VALUE = "{ l.cost }">
		<MvASSIGN NAME = "Attributes.d.required" VALUE = "{ l.required }">
		<MvASSIGN NAME = "Attributes.d.image" VALUE = "{ l.image }">

		<MvADD NAME = "Attributes">

		<MvASSIGN NAME = "l.attribute_id" VALUE = "{ Attributes.d.id }">
		
		<MvIF EXPR = "{ Attributes.d.type EQ 'template' }">
			<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Increment_ReferenceCount( Attributes.d.attemp_id ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.attribute_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_Update" PARAMETERS = "id, default_id, code, type, template, prompt, price, cost, required, image" STANDARDOUTPUTLEVEL = "">

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Attributes() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_id.mvx' }">

		<MvFIND NAME = "Attributes" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Attributes.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00067">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Attribute '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00075', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.save_type" VALUE = "{ Attributes.d.type }">
			<MvASSIGN NAME = "l.save_attemp_id" VALUE = "{ Attributes.d.attemp_id }">
		
		
			<MvASSIGN NAME = "Attributes.d.default_id" VALUE = "{ l.default_id }">
			<MvASSIGN NAME = "Attributes.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
			<MvASSIGN NAME = "Attributes.d.type" VALUE = "{ l.type }">
			<MvASSIGN NAME = "Attributes.d.attemp_id" VALUE = "{ l.template }">
			<MvASSIGN NAME = "Attributes.d.prompt" VALUE = "{ l.prompt }">
			<MvASSIGN NAME = "Attributes.d.price" VALUE = "{ l.price }">
			<MvASSIGN NAME = "Attributes.d.cost" VALUE = "{ l.cost }">
			<MvASSIGN NAME = "Attributes.d.required" VALUE = "{ l.required }">
			<MvASSIGN NAME = "Attributes.d.image" VALUE = "{ l.image }">
			<MvUPDATE NAME = "Attributes">
			
			<MvIF EXPR = "{ ( Attributes.d.type EQ 'template' ) AND ( l.save_type EQ 'template' ) }">
				<MvIF EXPR = "{ ( Attributes.d.attemp_id NE l.save_attemp_id ) }">
					<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Increment_ReferenceCount( Attributes.d.attemp_id ) }">
					<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Decrement_ReferenceCount( l.save_attemp_id ) }">
				</MvIF>
			<MvELSE>
				<MvIF EXPR = "{ Attributes.d.type EQ 'template' }">
					<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Increment_ReferenceCount( Attributes.d.attemp_id ) }">
				</MvIF>
				<MvIF EXPR = "{ l.save_type EQ 'template' }">
					<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Decrement_ReferenceCount( l.save_attemp_id ) }">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_Update_Order" PARAMETERS = "id, order" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Attributes() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_id.mvx' }">

		<MvFIND NAME = "Attributes" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Attributes.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00068">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Attribute '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00076', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Attributes.d.order" VALUE = "{ l.order }">

			<MvUPDATE NAME = "Attributes">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Attributes() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Options() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_id.mvx' }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_attr.mvx' }">

		<MvFIND NAME = "Attributes" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Attributes.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00069">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Attribute '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00077', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Attributes.d.type EQ 'template' }">
				<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ AttributeTemplate_Decrement_ReferenceCount( Attributes.d.attemp_id ) }">
			</MvIF>

		
			<MvFIND NAME = "Options" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Options.d.EOF ) AND ( Options.d.attr_id EQ l.id ) }">
				<MvDELETE NAME = "Options">
				<MvSKIP NAME = "Options" ROWS = 1>
			</MvWHILE>

			<MvDELETE NAME = "Attributes">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Attributes() }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_id.mvx' }">
		
		<MvFIND NAME = "Attributes" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Attributes.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00070">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Attribute '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00078', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_Find_Code" PARAMETERS = "product_id, code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.attribute_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Attributes() }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_code.mvx' }">

		<MvFIND NAME = "Attributes" VALUE = "{ l.product_id $ ':' $ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ Attributes.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00071">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Attribute '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00079', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.attribute_id" VALUE = "{ Attributes.d.id }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.attribute_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_FindFirst_Product" PARAMETERS = "product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Attributes() }">
		<MvPRIMARY NAME = "Attributes" INDEX = "{ g._DB_Store_Directory $ 'atr_prod.mvx' }">

		<MvFIND NAME = "Attributes" VALUE = "{ l.product_id $ ':' }">
		<MvIF EXPR = "{ NOT Attributes.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.found }">		
</MvFUNCTION>

<MvFUNCTION NAME = "Attribute_FindNext_Product" PARAMETERS = "product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Attributes" ROWS = 1>
	<MvIF EXPR = "{ ( Attributes.d.EOF ) OR ( Attributes.d.product_id NE l.product_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>


<MvCOMMENT>
|
| Options
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_Options" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Options_Open }">
		<MvOPEN NAME = "Options" 
				DATABASE = "{ g._DB_Store_Directory $ 'opts.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'opt_id.mvx, ' $ g._DB_Store_Directory $ 'opt_code.mvx, ' $ g._DB_Store_Directory $ 'opt_attr.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00080', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Options_Open" VALUE = 1>
			<MvFILTER NAME = "Options" FILTER = "{ NOT Options.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_Insert" PARAMETERS = "attr_id, code, prompt, price, cost, image" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.option_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Options() }">
		<MvASSIGN NAME = "Options.d.id" VALUE = "{ StoreKey_Generate( 'Options' ) }">
		<MvASSIGN NAME = "Options.d.attr_id" VALUE = "{ l.attr_id }">
		<MvASSIGN NAME = "Options.d.order" VALUE = "{ Options.d.id }">
		<MvASSIGN NAME = "Options.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
		<MvASSIGN NAME = "Options.d.prompt" VALUE = "{ l.prompt }">
		<MvASSIGN NAME = "Options.d.price" VALUE = "{ l.price }">
		<MvASSIGN NAME = "Options.d.cost" VALUE = "{ l.cost }">
		<MvASSIGN NAME = "Options.d.image" VALUE = "{ l.image }">

		<MvADD NAME = "Options">

		<MvASSIGN NAME = "l.option_id" VALUE = "{ Options.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.option_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_Update" PARAMETERS = "id, code, prompt, price, cost, image" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Options() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_id.mvx' }">

		<MvFIND NAME = "Options" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Options.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00072">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Option '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00081', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Options.d.code" VALUE = "{ ltrim( rtrim( l.code ) ) }">
			<MvASSIGN NAME = "Options.d.prompt" VALUE = "{ l.prompt }">
			<MvASSIGN NAME = "Options.d.price" VALUE = "{ l.price }">
			<MvASSIGN NAME = "Options.d.cost" VALUE = "{ l.cost }">
			<MvASSIGN NAME = "Options.d.image" VALUE = "{ l.image }">

			<MvUPDATE NAME = "Options">
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_Update_Order" PARAMETERS = "id, order" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Options() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_id.mvx' }">
		
		<MvFIND NAME = "Options" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Options.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00073">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Option '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00082', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Options.d.order" VALUE = "{ l.order }">
			<MvUPDATE NAME = "Options">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Options() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_id.mvx' }">
		
		<MvFIND NAME = "Options" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Options.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00074">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Option '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00083', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "Options">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Options() }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_id.mvx' }">
		
		<MvFIND NAME = "Options" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Options.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00075">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Option '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00084', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_Find_Code" PARAMETERS = "attr_id, code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.option_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Options() }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_code.mvx' }">
		
		<MvFIND NAME = "Options" VALUE = "{ l.attr_id $ ':' $ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ Options.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00076">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Option '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00085', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.option_id" VALUE = "{ Options.d.id }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.option_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_FindFirst_Attribute" PARAMETERS = "attr_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Options() }">
		<MvPRIMARY NAME = "Options" INDEX = "{ g._DB_Store_Directory $ 'opt_attr.mvx' }">
		<MvFIND NAME = "Options" VALUE = "{ l.attr_id $ ':' }">
		<MvIF EXPR = "{ NOT Options.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Option_FindNext_Attribute" PARAMETERS = "attr_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "Options" ROWS = 1>
	<MvIF EXPR = "{ ( Options.d.EOF ) OR ( Options.d.attr_id NE l.attr_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| BasketOptions
|
</MvCOMMENT>

<MvFUNCTION NAME = "BasketOption_Insert" PARAMETERS = "line_id, attr_id, attr_code, option_id, opt_code, data, price" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "BasketOptions.d.line_id" VALUE = "{ l.line_id }">
		<MvASSIGN NAME = "BasketOptions.d.attr_id" VALUE = "{ l.attr_id }">
		<MvASSIGN NAME = "BasketOptions.d.attr_code" VALUE = "{ l.attr_code }">
		<MvASSIGN NAME = "BasketOptions.d.option_id" VALUE = "{ l.option_id }">
		<MvASSIGN NAME = "BasketOptions.d.opt_code" VALUE = "{ l.opt_code }">
		<MvIF EXPR = "{ len( l.data ) GT 254 }">
			<MvASSIGN NAME = "BasketOptions.d.data" VALUE = "">
			<MvASSIGN NAME = "BasketOptions.d.data_long" VALUE = "{ l.data }">
		<MvELSE>
			<MvASSIGN NAME = "BasketOptions.d.data" VALUE = "{ l.data }">
			<MvASSIGN NAME = "BasketOptions.d.data_long" VALUE = "">
		</MvIF>
		<MvASSIGN NAME = "BasketOptions.d.price" VALUE = "{ l.price }">
		
		<MvADD NAME = "BasketOptions">
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">	
</MvFUNCTION>

<MvFUNCTION NAME = "BasketOption_FindFirst_Line" PARAMETERS = "line_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketOptions() }">
		<MvFIND NAME = "BasketOptions" VALUE = "{ l.line_id $ ':' }">
		<MvIF EXPR = "{ NOT BasketOptions.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketOption_FindNext_Line" PARAMETERS = "line_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "BasketOptions" ROWS = 1>
	<MvIF EXPR = "{ ( BasketOptions.d.EOF ) OR ( BasketOptions.d.line_id NE l.line_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| BasketCharges
|
</MvCOMMENT>

<MvFUNCTION NAME = "BasketCharge_Insert" PARAMETERS = "basket_id, module_id, type, desc, amount, disp_amt, tax_exempt" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketCharges() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "BasketCharges.d.basket_id" VALUE = "{ l.basket_id }">
		<MvASSIGN NAME = "BasketCharges.d.charge_id" VALUE = "{ StoreKey_Generate( 'BasketCharges' ) }">
		<MvASSIGN NAME = "BasketCharges.d.module_id" VALUE = "{ l.module_id }">
		<MvASSIGN NAME = "BasketCharges.d.type" VALUE = "{ l.type }">
		<MvASSIGN NAME = "BasketCharges.d.desc" VALUE = "{ l.desc }">
		<MvASSIGN NAME = "BasketCharges.d.amount" VALUE = "{ l.amount ROUND 3}">
		<MvASSIGN NAME = "BasketCharges.d.disp_amt" VALUE = "{ l.disp_amt ROUND 3}">
		<MvASSIGN NAME = "BasketCharges.d.tax_exempt" VALUE = "{ l.tax_exempt }">
		
		<MvADD NAME = "BasketCharges">
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">	
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_FindFirst_Charge" PARAMETERS = "basket_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketCharges() }">
		<MvFIND NAME = "BasketCharges" VALUE = "{ l.basket_id $ ':' }">
		<MvIF EXPR = "{ NOT BasketCharges.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_FindNext_Charge" PARAMETERS = "basket_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "BasketCharges" ROWS = 1>
	<MvIF EXPR = "{ ( BasketCharges.d.EOF ) OR ( BasketCharges.d.basket_id NE l.basket_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_FindFirst_Type" PARAMETERS = "basket_id, type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketCharges() }">
		<MvPRIMARY NAME = "BasketCharges" INDEX = "{ g._DB_Store_Directory $ 'bchg_typ.mvx' }">
		<MvFIND NAME = "BasketCharges" VALUE = "{ l.basket_id $ ':' $ l.type $ ':'}">
		<MvIF EXPR = "{ ( NOT BasketCharges.d.EOF ) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_FindNext_Type" PARAMETERS = "basket_id, type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "BasketCharges" ROWS = 1>
	<MvIF EXPR = "{ ( BasketCharges.d.EOF ) OR ( BasketCharges.d.basket_id NE l.basket_id ) OR ( BasketCharges.d.type NE l.type ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_FindFirst_Module" PARAMETERS = "basket_id, module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketCharges() }">
		<MvPRIMARY NAME = "BasketCharges" INDEX = "{ g._DB_Store_Directory $ 'bchg_mod.mvx' }">
		<MvFIND NAME = "BasketCharges" VALUE = "{ l.basket_id $ ':' $ l.module_id $ ':' }">
		<MvIF EXPR = "{ ( NOT BasketCharges.d.EOF ) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_FindNext_Module" PARAMETERS = "basket_id, module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "BasketCharges" ROWS = 1>
	<MvIF EXPR = "{ ( BasketCharges.d.EOF ) OR ( BasketCharges.d.basket_id NE l.basket_id ) OR ( BasketCharges.d.type NE l.type ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketCharge_DeleteAll_Module" PARAMETERS = "basket_id, module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketCharges() }">
		<MvPRIMARY NAME = "BasketCharges" INDEX = "{ g._DB_Store_Directory $ 'bchg_mod.mvx' }">
		
		<MvFIND NAME = "BasketCharges" VALUE = "{ l.basket_id $ ':' $ l.module_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT BasketCharges.d.EOF ) AND 
						   ( BasketCharges.d.basket_id EQ l.basket_id ) AND
						   ( BasketCharges.d.module_id EQ l.module_id ) }">
			<MvDELETE NAME = "BasketCharges">
			<MvSKIP NAME = "BasketCharges" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| StoreModules
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_StoreModules" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_StoreModules_Open }">
		<MvOPEN NAME = "StoreModules"
				DATABASE = "{ g._DB_Store_Directory $ 'storemod.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'smd_id.mvx, ' $ g._DB_Store_Directory $ 'smd_type.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00094', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 1>
			<MvFILTER NAME = "StoreModules" FILTER = "{ NOT StoreModules.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Insert" PARAMETERS = "module_id, type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvLOCKFILE FILE = "{ g._DB_Store_Directory $ 'storemod.dbf' }">
			<MvASSIGN NAME = "StoreModules.d.module_id" VALUE = "{ l.module_id }">
			<MvASSIGN NAME = "StoreModules.d.type" VALUE = "{ l.type }">
			<MvASSIGN NAME = "StoreModules.d.refcount" VALUE = 0>

			<MvADD NAME = "StoreModules">

			<MvASSIGN NAME = "l.ok" VALUE = "{ Module_Increment_ReferenceCount( l.module_id ) }">
		</MvLOCKFILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Increment_ReferenceCount" PARAMETERS = "module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">

		<MvFIND NAME = "StoreModules" VALUE = "{ l.module_id }" EXACT>
		<MvIF EXPR = "{ StoreModules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00083">
				<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( l.module_id ) }">
				<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( Stores.d.id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' is not installed in store '%store_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00095', l.error ) }">
		<MvELSE>
			<MvLOCKFILE FILE = "{ g._DB_Store_Directory $ 'storemod.dbf' }">
				<MvASSIGN NAME = "StoreModules.d.refcount" VALUE = "{ StoreModules.d.refcount + 1 }">
				<MvUPDATE NAME = "StoreModules">
			</MvLOCKFILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Decrement_ReferenceCount" PARAMETERS = "module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">

		<MvFIND NAME = "StoreModules" VALUE = "{ l.module_id }" EXACT>
		<MvIF EXPR = "{ StoreModules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00084">
				<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( l.module_id ) }">
				<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( Stores.d.id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' is not installed in store '%store_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00096', l.error ) }">
		<MvELSE>
			<MvLOCKFILE FILE = "{ g._DB_Store_Directory $ 'storemod.dbf' }">
				<MvIF EXPR = "{ StoreModules.d.refcount GT 0 }">
					<MvASSIGN NAME = "StoreModules.d.refcount" VALUE = "{ StoreModules.d.refcount - 1 }">
					<MvUPDATE NAME = "StoreModules">
				</MvIF>
			</MvLOCKFILE>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Delete" PARAMETERS = "module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">

		<MvFIND NAME = "StoreModules" VALUE = "{ l.module_id }" EXACT>
		<MvIF EXPR = "{ StoreModules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00085">
				<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( l.module_id ) }">
				<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( Stores.d.id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' is not installed in store '%store_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00097', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ StoreModules.d.refcount GT 0 }">
				<MvASSIGN NAME = "l.found" VALUE = "{ Module_Find_ID_Admin( Store_Modules.d.id ) }">
				<MvIF EXPR = "{ l.found AND Modules.d.active }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00086">
						<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( l.module_id ) }">
						<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( Stores.d.id ) }">

						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' is in use by one or more orders in store '%store_id%'</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00098', l.error ) }">
				</MvIF>
			</MvIF>
			<MvIf EXPR = "{ l.ok }">
				<MvDELETE NAME = "StoreModules">
				<MvASSIGN NAME = "l.ok" VALUE = "{ Module_Decrement_ReferenceCount( l.module_id ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Installed" PARAMETERS = "module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.installed" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_StoreModules() }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">
		<MvFIND NAME = "StoreModules" VALUE = "{ l.module_id }" EXACT>
		<MvIF EXPR = "{ NOT StoreModules.d.EOF }">
			<MvASSIGN NAME = "l.installed" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.installed }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Find_ID" PARAMETERS = "module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">

		<MvFIND NAME = "StoreModules" VALUE = "{ l.module_id }" EXACT>
		<MvIF EXPR = "{ StoreModules.d.EOF OR (NOT Modules.d.active) }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00087">
				<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( l.module_id ) }">
				<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( Stores.d.id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' is not installed in store '%store_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00099', l.error ) }">
		<MvELSE>
			<MvFIND NAME = "Modules" VALUE = "{ StoreModules.d.module_id }" EXACT>
			<MvIF EXPR = "{ Modules.d.EOF }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00088">
					<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( StoreModules.d.module_id ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' not found</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00100', l.error ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_Find_ID_Admin" PARAMETERS = "module_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">

		<MvFIND NAME = "StoreModules" VALUE = "{ l.module_id }" EXACT>
		<MvIF EXPR = "{ StoreModules.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00087">
				<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( l.module_id ) }">
				<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( Stores.d.id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' is not installed in store '%store_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00099', l.error ) }">
		<MvELSE>
			<MvFIND NAME = "Modules" VALUE = "{ StoreModules.d.module_id }" EXACT>
			<MvIF EXPR = "{ Modules.d.EOF }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00088">
					<MvLOCALIZED-TOKEN NAME = "module_id" VALUE = "{ encodeentities( StoreModules.d.module_id ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Module '%module_id%' not found</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00100', l.error ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_StoreModules() AND _DB_Open_Modules() }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_id.mvx' }">
		<MvGO NAME = "StoreModules" ROW = "top">
		<MvWHILE EXPR = "{ ( NOT StoreModules.d.EOF ) AND ( NOT l.found ) }"> 
			<MvFIND NAME = "Modules" VALUE = "{ StoreModules.d.module_id }" EXACT>
			<MvIF EXPR = "{ (NOT Modules.d.EOF) AND (Modules.d.active) }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvSKIP NAME = "StoreModules" ROWS = "1">
			</MvIF>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_StoreModules() AND _DB_Open_Modules() }">
		<MvSKIP NAME = "StoreModules" ROWS = 1>
		<MvWHILE EXPR = "{ ( NOT StoreModules.d.EOF ) AND ( NOT l.found ) }"> 
			<MvFIND NAME = "Modules" VALUE = "{ StoreModules.d.module_id }" EXACT>
			<MvIF EXPR = "{ (NOT Modules.d.EOF) AND (Modules.d.active) }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvSKIP NAME = "StoreModules" ROWS = "1">
			</MvIF>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_FindFirst_Type" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_StoreModules() AND _DB_Open_Modules() }">
		<MvPRIMARY NAME = "StoreModules" INDEX = "{ g._DB_Store_Directory $ 'smd_type.mvx' }">
		<MvPRIMARY NAME = "Modules" INDEX = "{ g.MerchantPath $ 'mod_id.mvx' }">

		<MvFIND NAME = "StoreModules" VALUE = "{ l.type }" EXACT>
		<MvWHILE EXPR = "{ ( NOT StoreModules.d.EOF ) AND ( NOT l.found ) AND ( StoreModules.d.type EQ l.type ) }"> 
			<MvFIND NAME = "Modules" VALUE = "{ StoreModules.d.module_id }" EXACT>
			<MvIF EXPR = "{ (NOT Modules.d.EOF) AND (Modules.d.active) }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvELSE>
				<MvSKIP NAME = "StoreModules" ROWS = "1">
			</MvIF>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "StoreModule_FindNext_Type" PARAMETERS = "type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "StoreModules" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT StoreModules.d.EOF ) AND ( NOT l.found ) }"> 
		<MvFIND NAME = "Modules" VALUE = "{ StoreModules.d.module_id }" EXACT>
		<MvIF EXPR = "{ (NOT Modules.d.EOF) AND (Modules.d.active) AND ( StoreModules.d.type EQ l.type ) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvSKIP NAME = "StoreModules" ROWS = "1">
		</MvIF>
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Orders
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_Orders" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Orders_Open }">
		<MvOPEN NAME = "Orders"
				DATABASE = "{ g._DB_Store_Directory $ 'orders.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'ord_id.mvx, ' $ g._DB_Store_Directory $ 'ord_btch.mvx, ' $ g._DB_Store_Directory $ 'ord_prcd.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00101', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Orders_Open" VALUE = 1>
			<MvFILTER NAME = "Orders" FILTER = "{ NOT Orders.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_OrderItems" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_OrderItems_Open }">
		<MvOPEN NAME = "OrderItems"
				DATABASE = "{ g._DB_Store_Directory $ 'orditems.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'oit_ord.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00102', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_OrderItems_Open" VALUE = 1>
			<MvFILTER NAME = "OrderItems" FILTER = "{ NOT OrderItems.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_OrderOptions" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_OrderOptions_Open }">
		<MvOPEN NAME = "OrderOptions"
				DATABASE = "{ g._DB_Store_Directory $ 'ordopts.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'oop_line.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00103', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_OrderOptions_Open" VALUE = 1>
			<MvFILTER NAME = "OrderOptions" FILTER = "{ NOT OrderOptions.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_OrderCharges" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	
	<MvIF EXPR = "{ NOT g._DB_Store_OrderCharges_Open }">		
		<MvOPEN NAME = "OrderCharges"
				DATABASE = "{ g._DB_Store_Directory $ 'ordrchrg.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'ochg_oid.mvx, ' $
							 g._DB_Store_Directory $ 'ochg_typ.mvx, ' $
							 g._DB_Store_Directory $ 'ochg_mod.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00340', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_OrderCharges_Open" VALUE = 1>
			<MvFILTER NAME = "OrderCharges" FILTER = "{ NOT OrderCharges.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_Batches" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Batches_Open }">
		<MvOPEN NAME = "Batches"
				DATABASE = "{ g._DB_Store_Directory $ 'batches.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'bch_id.mvx, ' $ g._DB_Store_Directory $ 'bch_clsd.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00104', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Batches_Open" VALUE = 1>
			<MvFILTER NAME = "Batches" FILTER = "{ NOT Batches.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Create_From_Basket" PARAMETERS = "session_id, total" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.order_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_BasketList() AND _DB_Store_Open_Baskets() AND
				    _DB_Store_Open_BasketOptions() AND _DB_Store_Open_Orders() AND
				    _DB_Store_Open_BasketCharges() AND _DB_Store_Open_OrderCharges() AND
					_DB_Store_Open_OrderItems() AND _DB_Store_Open_OrderOptions() }">
		<MvFIND NAME = "BasketList" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ NOT BasketList.d.EOF }">
			<MvASSIGN NAME = "Orders.d.id" 			VALUE = "{ BasketList.d.order_id }">
			<MvASSIGN NAME = "Orders.d.batch_id" 	VALUE = 0>
			<MvASSIGN NAME = "Orders.d.processed" 	VALUE = 0>
			<MvASSIGN NAME = "Orders.d.date" 		VALUE = "{ s.dyn_time_t }">
			<MvASSIGN NAME = "Orders.d.cust_id" 	VALUE = "{ BasketList.d.cust_id }">
			<MvASSIGN NAME = "Orders.d.ship_fname" 	VALUE = "{ BasketList.d.ship_fname }">
			<MvASSIGN NAME = "Orders.d.ship_lname" 	VALUE = "{ BasketList.d.ship_lname }">
			<MvASSIGN NAME = "Orders.d.ship_email" 	VALUE = "{ BasketList.d.ship_email }">
			<MvASSIGN NAME = "Orders.d.ship_comp" 	VALUE = "{ BasketList.d.ship_comp }">
			<MvASSIGN NAME = "Orders.d.ship_phone" 	VALUE = "{ BasketList.d.ship_phone }">
			<MvASSIGN NAME = "Orders.d.ship_fax" 	VALUE = "{ BasketList.d.ship_fax }">
			<MvASSIGN NAME = "Orders.d.ship_addr" 	VALUE = "{ BasketList.d.ship_addr }">
			<MvASSIGN NAME = "Orders.d.ship_city" 	VALUE = "{ BasketList.d.ship_city }">
			<MvASSIGN NAME = "Orders.d.ship_state" 	VALUE = "{ BasketList.d.ship_state }">
			<MvASSIGN NAME = "Orders.d.ship_zip" 	VALUE = "{ BasketList.d.ship_zip }">
			<MvASSIGN NAME = "Orders.d.ship_cntry" 	VALUE = "{ BasketList.d.ship_cntry }">
			<MvASSIGN NAME = "Orders.d.bill_fname" 	VALUE = "{ BasketList.d.bill_fname }">
			<MvASSIGN NAME = "Orders.d.bill_lname" 	VALUE = "{ BasketList.d.bill_lname }">
			<MvASSIGN NAME = "Orders.d.bill_email" 	VALUE = "{ BasketList.d.bill_email }">
			<MvASSIGN NAME = "Orders.d.bill_comp" 	VALUE = "{ BasketList.d.bill_comp }">
			<MvASSIGN NAME = "Orders.d.bill_phone" 	VALUE = "{ BasketList.d.bill_phone }">
			<MvASSIGN NAME = "Orders.d.bill_fax" 	VALUE = "{ BasketList.d.bill_fax }">
			<MvASSIGN NAME = "Orders.d.bill_addr" 	VALUE = "{ BasketList.d.bill_addr }">
			<MvASSIGN NAME = "Orders.d.bill_city" 	VALUE = "{ BasketList.d.bill_city }">
			<MvASSIGN NAME = "Orders.d.bill_state" 	VALUE = "{ BasketList.d.bill_state }">
			<MvASSIGN NAME = "Orders.d.bill_zip" 	VALUE = "{ BasketList.d.bill_zip }">
			<MvASSIGN NAME = "Orders.d.bill_cntry" 	VALUE = "{ BasketList.d.bill_cntry }">

			<MvASSIGN NAME = "Orders.d.tax" 		VALUE = "{ BasketList.d.tax }">
			<MvASSIGN NAME = "Orders.d.shipping" 	VALUE = "{ BasketList.d.shipping }">
			<MvASSIGN NAME = "Orders.d.total" 		VALUE = "{ l.total }">
			<MvASSIGN NAME = "Orders.d.ship_id" 	VALUE = "{ BasketList.d.ship_id }">
			<MvASSIGN NAME = "Orders.d.ship_data" 	VALUE = "{ BasketList.d.ship_data }">
			<MvASSIGN NAME = "Orders.d.pay_id" 		VALUE = "{ BasketList.d.pay_id }">
			<MvASSIGN NAME = "Orders.d.pay_data" 	VALUE = "{ BasketList.d.pay_data }">

			<MvADD NAME = "Orders">

			<MvASSIGN NAME = "l.order_id" VALUE = "{ Orders.d.id }">

			<MvDO FILE = "{ g.Module_Feature_STA }" NAME = "l.ok" VALUE = "{ Stats_Add_Orders( ) }">
			<MvDO FILE = "{ g.Module_Feature_STA }" NAME = "l.ok" VALUE = "{ Stats_Add_Revenue( l.total ) }">

			<MvIF EXPR = "{ g.Features:Affiliates:Enabled }">
				<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ Affiliate_Create_Order( l.session_id, l.total ) }">
			</MvIF>

			<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvASSIGN NAME = "OrderItems.d.order_id" 	VALUE = "{ l.order_id }">
				<MvASSIGN NAME = "OrderItems.d.line_id" 	VALUE = "{ Baskets.d.line_id }">
				<MvASSIGN NAME = "OrderItems.d.product_id" 	VALUE = "{ Baskets.d.product_id }">
				<MvASSIGN NAME = "OrderItems.d.code" 		VALUE = "{ Baskets.d.code }">
				<MvASSIGN NAME = "OrderItems.d.name" 		VALUE = "{ Baskets.d.name }">
				<MvASSIGN NAME = "OrderItems.d.price" 		VALUE = "{ Baskets.d.price }">
				<MvASSIGN NAME = "OrderItems.d.weight" 		VALUE = "{ Baskets.d.weight }">
				<MvASSIGN NAME = "OrderItems.d.taxable" 	VALUE = "{ Baskets.d.taxable }">
				<MvASSIGN NAME = "OrderItems.d.upsold" 		VALUE = "{ Baskets.d.upsold }">
				<MvASSIGN NAME = "OrderItems.d.quantity" 	VALUE = "{ Baskets.d.quantity }">
				<MvDO FILE = "{ g.Module_Feature_STA }" NAME = "l.ok" VALUE = "{ Stats_Add_Products( Baskets.d.quantity ) }">
				<MvDO FILE = "{ g.Module_Feature_STA }" NAME = "l.ok" VALUE = "{ ProdStats_Add_Counts( Baskets.d.product_id, Baskets.d.quantity ) }">

				<MvADD NAME = "OrderItems">
				
				<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
					<MvASSIGN NAME = "OrderOptions.d.line_id" 	VALUE = "{ OrderItems.d.line_id }">
					<MvASSIGN NAME = "OrderOptions.d.attr_id" 	VALUE = "{ BasketOptions.d.attr_id }">
					<MvASSIGN NAME = "OrderOptions.d.attr_code" VALUE = "{ BasketOptions.d.attr_code }">
					<MvASSIGN NAME = "OrderOptions.d.option_id" VALUE = "{ BasketOptions.d.option_id }">
					<MvASSIGN NAME = "OrderOptions.d.opt_code" 	VALUE = "{ BasketOptions.d.opt_code }">
					<MvASSIGN NAME = "OrderOptions.d.data" 		VALUE = "{ BasketOptions.d.data }">
					<MvASSIGN NAME = "OrderOptions.d.data_long" VALUE = "{ BasketOptions.d.data_long }">
					<MvASSIGN NAME = "OrderOptions.d.price" 	VALUE = "{ BasketOptions.d.price }">

					<MvADD NAME = "OrderOptions">
					<MvDELETE NAME = "BasketOptions">

					<MvSKIP NAME = "BasketOptions" ROWS = 1>
				</MvWHILE>

				<MvDELETE NAME = "Baskets">
				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>

			<MvFIND NAME = "BasketCharges" VALUE = "{ BasketList.d.basket_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT BasketCharges.d.EOF ) AND ( BasketList.d.basket_id EQ BasketCharges.d.basket_id ) }">
				<MvASSIGN NAME = "OrderCharges.d.order_id" 		VALUE = "{ l.order_id }">
				<MvASSIGN NAME = "OrderCharges.d.charge_id" 	VALUE = "{ BasketCharges.d.charge_id }">
				<MvASSIGN NAME = "OrderCharges.d.module_id" 	VALUE = "{ BasketCharges.d.module_id }">
				<MvASSIGN NAME = "OrderCharges.d.type" 			VALUE = "{ BasketCharges.d.type }">
				<MvASSIGN NAME = "OrderCharges.d.desc" 			VALUE = "{ BasketCharges.d.desc }">
				<MvASSIGN NAME = "OrderCharges.d.amount" 		VALUE = "{ BasketCharges.d.amount }">
				<MvASSIGN NAME = "OrderCharges.d.disp_amt" 		VALUE = "{ BasketCharges.d.disp_amt }">
				<MvASSIGN NAME = "OrderCharges.d.tax_exempt" 	VALUE = "{ BasketCharges.d.tax_exempt }">

				<MvADD NAME = "OrderCharges">

				<MvDELETE NAME = "BasketCharges">
				<MvSKIP NAME = "BasketCharges" ROWS = 1>
			</MvWHILE>

			<MvASSIGN NAME = "BasketList.d.cust_id"	VALUE = 0>
			<MvASSIGN NAME = "BasketList.d.order_proc" VALUE = 1>
			<MvUPDATE NAME = "BasketList">

			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Increment_ReferenceCount( Orders.d.ship_id ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Increment_ReferenceCount( Orders.d.pay_id ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.order_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Update" PARAMETERS = "id, cust_id, ship_fname, ship_lname, ship_email, ship_comp, ship_phone, ship_fax, 
												ship_addr, ship_city, ship_state, ship_zip, ship_cntry, bill_fname,
												bill_lname, bill_email, bill_comp, bill_phone, bill_fax, bill_addr,
												bill_city, bill_state, bill_zip, bill_cntry, tax, shipping, total"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Orders() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_id.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Orders.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00089">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00105', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Orders.d.cust_id" 	VALUE = "{ l.cust_id }">
			<MvASSIGN NAME = "Orders.d.ship_fname" 	VALUE = "{ l.ship_fname }">
			<MvASSIGN NAME = "Orders.d.ship_lname" 	VALUE = "{ l.ship_lname }">
			<MvASSIGN NAME = "Orders.d.ship_email" 	VALUE = "{ l.ship_email }">
			<MvASSIGN NAME = "Orders.d.ship_comp" 	VALUE = "{ l.ship_comp }">
			<MvASSIGN NAME = "Orders.d.ship_phone" 	VALUE = "{ l.ship_phone }">
			<MvASSIGN NAME = "Orders.d.ship_fax" 	VALUE = "{ l.ship_fax }">
			<MvASSIGN NAME = "Orders.d.ship_addr" 	VALUE = "{ l.ship_addr }">
			<MvASSIGN NAME = "Orders.d.ship_city" 	VALUE = "{ l.ship_city }">
			<MvASSIGN NAME = "Orders.d.ship_state" 	VALUE = "{ l.ship_state }">
			<MvASSIGN NAME = "Orders.d.ship_zip" 	VALUE = "{ l.ship_zip }">
			<MvASSIGN NAME = "Orders.d.ship_cntry" 	VALUE = "{ l.ship_cntry }">
			<MvASSIGN NAME = "Orders.d.bill_fname" 	VALUE = "{ l.bill_fname }">
			<MvASSIGN NAME = "Orders.d.bill_lname" 	VALUE = "{ l.bill_lname }">
			<MvASSIGN NAME = "Orders.d.bill_email" 	VALUE = "{ l.bill_email }">
			<MvASSIGN NAME = "Orders.d.bill_comp" 	VALUE = "{ l.bill_comp }">
			<MvASSIGN NAME = "Orders.d.bill_phone" 	VALUE = "{ l.bill_phone }">
			<MvASSIGN NAME = "Orders.d.bill_fax" 	VALUE = "{ l.bill_fax }">
			<MvASSIGN NAME = "Orders.d.bill_addr" 	VALUE = "{ l.bill_addr }">
			<MvASSIGN NAME = "Orders.d.bill_city" 	VALUE = "{ l.bill_city }">
			<MvASSIGN NAME = "Orders.d.bill_state" 	VALUE = "{ l.bill_state }">
			<MvASSIGN NAME = "Orders.d.bill_zip" 	VALUE = "{ l.bill_zip }">
			<MvASSIGN NAME = "Orders.d.bill_cntry" 	VALUE = "{ l.bill_cntry }">

			<MvASSIGN NAME = "Orders.d.tax" 		VALUE = "{ l.tax ROUND 2 }">
			<MvASSIGN NAME = "Orders.d.shipping" 	VALUE = "{ l.shipping ROUND 2 }">
			<MvASSIGN NAME = "Orders.d.total" 		VALUE = "{ l.total }">

			<MvUPDATE NAME = "Orders">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Update_Processed" PARAMETERS = "id, processed" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Orders() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_id.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Orders.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00090">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00106', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Orders.d.processed" VALUE = "{ l.processed }">
			<MvUPDATE NAME = "Orders">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Update_Shipping" PARAMETERS = "id, shipping, ship_id, ship_data" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Orders() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_id.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Orders.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00091">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00107', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Orders.d.ship_id GT 0 }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Decrement_ReferenceCount( Orders.d.ship_id ) }">
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "Orders.d.shipping" 	VALUE = "{ l.shipping ROUND 2 }">
				<MvASSIGN NAME = "Orders.d.ship_id" 	VALUE = "{ l.ship_id }">
				<MvASSIGN NAME = "Orders.d.ship_data" 	VALUE = "{ l.ship_data }">
			
				<MvUPDATE NAME = "Orders">

				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Increment_ReferenceCount( l.ship_id ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Update_Payment" PARAMETERS = "id, pay_id, pay_data" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Orders() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_id.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Orders.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00092">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00108', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ Orders.d.pay_id }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Decrement_ReferenceCount( Orders.d.pay_id ) }">
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvASSIGN NAME = "Orders.d.pay_id" 	 VALUE = "{ l.pay_id }">
				<MvASSIGN NAME = "Orders.d.pay_data" VALUE = "{ l.pay_data }">
			
				<MvUPDATE NAME = "Orders">

				<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Increment_ReferenceCount( l.pay_id ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Orders() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_OrderItems() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_OrderOptions() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_id.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Orders.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00093">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00109', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.decremented" VALUE = "{ StoreModule_Decrement_ReferenceCount( Orders.d.ship_id ) }">
			<MvASSIGN NAME = "l.decremented" VALUE = "{ StoreModule_Decrement_ReferenceCount( Orders.d.pay_id ) }">

			<MvIF EXPR = "{ l.ok }">
				<MvFIND NAME = "OrderItems" VALUE = "{ l.id $ ':' }">
				<MvWHILE EXPR = "{ NOT OrderItems.d.EOF }">
					<MvFIND NAME = "OrderOptions" VALUE = "{ OrderItems.d.line_id $ ':' }">
					<MvWHILE EXPR = "{ NOT OrderOptions.d.EOF }">
						<MvDELETE NAME = "OrderOptions">
						<MvFIND NAME = "OrderOptions" VALUE = "{ OrderItems.d.line_id $ ':' }">
					</MvWHILE>

					<MvDELETE NAME = "OrderItems">
					<MvFIND NAME = "OrderItems" VALUE = "{ l.id $ ':' }">
				</MvWHILE>
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvDELETE NAME = "Orders">
				<MvASSIGN NAME = "l.ok" VALUE = "{ OrderCharges_Delete( l.id ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Orders() }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_id.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Orders.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00094">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00110', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_Count_Batch" PARAMETERS = "batch_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.count" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Orders() }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_btch.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "{ l.batch_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT Orders.d.EOF ) AND ( Orders.d.batch_id EQ l.batch_id ) }">
			<MvASSIGN NAME = "l.count" VALUE = "{ l.count + 1 }">

			<MvSKIP NAME = "Orders" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.count }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_FindFirst_Batch" PARAMETERS = "batch_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Orders() }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_btch.mvx' }">

		<MvFIND NAME = "Orders" VALUE = "{ l.batch_id $ ':' }">
		<MvIF EXPR = "{ NOT Orders.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_FindNext_Batch" PARAMETERS = "batch_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Orders" ROWS = 1>
	<MvIF EXPR = "{ Orders.d.EOF OR ( Orders.d.batch_id NE l.batch_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_FindFirst_Batch_Unprocessed" PARAMETERS = "batch_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Orders() }">
		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_prcd.mvx' }">

		<MvFIND NAME = "Orders" VALUE = "{ l.batch_id $ ':0:' }">
		<MvIF EXPR = "{ NOT Orders.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Order_FindNext_Batch_Unprocessed" PARAMETERS = "batch_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Orders" ROWS = 1>
	<MvIF EXPR = "{ Orders.d.EOF OR ( Orders.d.batch_id NE l.batch_id ) OR ( Orders.d.processed ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderItem_FindFirst_Order" PARAMETERS = "order_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_OrderItems() }">
		<MvFIND NAME = "OrderItems" VALUE = "{ l.order_id $ ':' }">
		<MvIF EXPR = "{ NOT OrderItems.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderItem_FindNext_Order" PARAMETERS = "order_id" STANDARDOUTPUTLEVEL = "">	
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "OrderItems" ROWS = 1>
	<MvIF EXPR = "{ ( OrderItems.d.EOF ) OR ( OrderItems.d.order_id NE l.order_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.found }">		
</MvFUNCTION>

<MvFUNCTION NAME = "OrderOption_FindFirst_Line" PARAMETERS = "line_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_OrderOptions() }">
		<MvFIND NAME = "OrderOptions" VALUE = "{ l.line_id $ ':' }">
		<MvIF EXPR = "{ NOT OrderOptions.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderOption_FindNext_Line" PARAMETERS = "line_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "OrderOptions" ROWS = 1>
	<MvIF EXPR = "{ ( OrderOptions.d.EOF ) OR ( OrderOptions.d.line_id NE l.line_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderCharge_FindFirst_Type" PARAMETERS = "order_id, type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_OrderCharges() }">
		<MvPRIMARY NAME = "OrderCharges" INDEX = "{ g._DB_Store_Directory $ 'ochg_typ.mvx' }">
		<MvFIND NAME = "OrderCharges" VALUE = "{ l.order_id $ ':' $ l.type $ ':'}">
		<MvIF EXPR = "{ ( NOT OrderCharges.d.EOF ) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderCharge_FindNext_Type" PARAMETERS = "order_id, type" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "OrderCharges" ROWS = 1>
	<MvIF EXPR = "{ ( OrderCharges.d.EOF ) OR ( OrderCharges.d.order_id NE l.order_id ) OR ( OrderCharges.d.type NE l.type ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderCharge_FindFirst_Charge" PARAMETERS = "order_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_OrderCharges() }">
		<MvPRIMARY NAME = "OrderCharges" INDEX = "{ g._DB_Store_Directory $ 'ochg_oid.mvx' }">
		<MvFIND NAME = "OrderCharges" VALUE = "{ l.order_id $ ':'}">
		<MvIF EXPR = "{ ( NOT OrderCharges.d.EOF ) }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
		</MvIF>	
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "OrderCharge_FindNext_Charge" PARAMETERS = "order_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "OrderCharges" ROWS = 1>
	<MvIF EXPR = "{ ( OrderCharges.d.EOF ) OR ( OrderCharges.d.order_id NE l.order_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Batches
|
</MvCOMMENT>

<MvFUNCTION NAME = "Batch_Create" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.batch_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Orders() AND _DB_Store_Open_Batches() }">
		<MvASSIGN NAME = "Batches.d.id" 	VALUE = "{ StoreKey_Generate( 'Batches' ) }">
		<MvASSIGN NAME = "Batches.d.date" 	VALUE = "{ s.dyn_time_t }">
		<MvASSIGN NAME = "Batches.d.name" 	VALUE = "{ l.name }">
		<MvASSIGN NAME = "Batches.d.closed" VALUE = 0>

		<MvADD NAME = "Batches">

		<MvPRIMARY NAME = "Orders" INDEX = "{ g._DB_Store_Directory $ 'ord_btch.mvx' }">
		<MvFIND NAME = "Orders" VALUE = "0:">
		<MvWHILE EXPR = "{ ( NOT Orders.d.EOF ) AND ( Orders.d.batch_id EQ 0 ) }">
			<MvASSIGN NAME = "Orders.d.batch_id" VALUE = "{ Batches.d.id }">
			<MvUPDATE NAME = "Orders">
				
			<MvFIND NAME = "Orders" VALUE = "0:">
		</MvWHILE>

		<MvASSIGN NAME = "l.batch_id" VALUE = "{ Batches.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.batch_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Batch_FindFirst" PARAMETERS = "closed" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Batches() }">
		<MvPRIMARY NAME = "Batches" INDEX = "{ g._DB_Store_Directory $ 'bch_clsd.mvx' }">
		
		<MvFIND NAME = "Batches" VALUE = "{ l.closed }">
		<MvIF EXPR = "{ NOT Batches.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Batch_FindNext" PARAMETERS = "closed" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Batches" ROWS = 1>
	<MvIF EXPR = "{ Batches.d.EOF OR ( Batches.d.closed NE l.closed ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Batch_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Batches() }">
		<MvPRIMARY NAME = "Batches" INDEX = "{ g._DB_Store_Directory $ 'bch_id.mvx' }">
		
		<MvFIND NAME = "Batches" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT Batches.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00095">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Batch '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00111', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Batch_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvIF EXPR = "{ _DB_Store_Open_Batches() }">
		<MvPRIMARY NAME = "Batches" INDEX = "{ g._DB_Store_Directory $ 'bch_id.mvx' }">
		
		<MvFIND NAME = "Batches" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Batches.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00096">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Batch '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00112', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "Batches">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "CreateDataFiles" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ ( g.MerchantPath ) AND ( NOT fexists( g.MerchantPath ) ) }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ fmkdir( g.MerchantPath ) }">
		<MvIF EXPR = "{ NOT l.ok }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00097">
				<MvLOCALIZED-TOKEN NAME = "merchantpath" VALUE = "{ encodeentities( g.MerchantPath ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Unable to create directory '%merchantpath%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00113', l.error ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Domain"
				  DATABASE = "{ g.MerchantPath $ 'domain.dbf' }"
				  FIELDS = "name		CHAR( 100 ),
							license		CHAR( 25 ),
							version		CHAR( 10 ),
							owner		CHAR( 100 ),
							email		CHAR( 50 ),
							company		CHAR( 100 ),
							address		CHAR( 100 ),
							city		CHAR( 50 ),
							state		CHAR( 50 ),
							zip			CHAR( 50 ),
							country		CHAR( 50 ),
							phone		CHAR( 50 ),
							fax			CHAR( 50 ),
							mm_url		CHAR( 254 ),
							mm_surl		CHAR( 254 ),
							admin_surl	CHAR( 254 ),
							image_root	CHAR( 254 ),
							base_url	CHAR( 254 ),
							base_surl	CHAR( 254 ),
							mod_root	CHAR( 254 ),
							mod_sroot	CHAR( 254 ),
							admexp		NUMBER,
							mailhost	CHAR ( 254 ),
							mailmeth	CHAR ( 50 ),
							mail_angl 	BOOL,
							ui_id		NUMBER,
							d_set		BOOL,
							d_mod		BOOL,
							d_pay		BOOL,
							d_ship		BOOL,
							d_ful		BOOL,
							d_usr		BOOL,
							d_log		BOOL,
							d_sys		BOOL,
							d_utl		BOOL,
							maxstores	NUMBER,
							lo_time		NUMBER,
							li_trys		NUMBER,
							upgd_ignr	CHAR( 10 ),
							img_ext		CHAR( 254)">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00114', MvCREATE_Error ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">	
			<MvASSIGN NAME = "Domain.d.name" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.selection" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.license" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.version" 	VALUE = "{ g.Merchant_Version }">
			<MvASSIGN NAME = "Domain.d.owner" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.email" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.company" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.address" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.city" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.state" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.zip" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.country" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.phone" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.fax" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.mm_url" 		VALUE = "">
			<MvASSIGN NAME = "Domain.d.mm_surl" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.admin_surl" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.image_root" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.base_url" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.base_surl" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.mod_root" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.mod_sroot" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.mailhost" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.mailmeth" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.mail_angl" 	VALUE = "">
			<MvASSIGN NAME = "Domain.d.admexp" 		VALUE = 60>
			<MvASSIGN NAME = "Domain.d.lo_time"		VALUE = 15>
			<MvASSIGN NAME = "Domain.d.li_trys"		VALUE = 3>
			<MvASSIGN NAME = "Domain.d.img_ext"		VALUE = "gif,jpg,jpeg,jpe,xbm">

			<MvADD NAME = "Domain">
		</MvIF>
	</MvIF>
	
	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.ok" VALUE = "{ Create_Notification_Settings() }">
	</MvIF>
		
	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Stores"
				  DATABASE = "{ g.MerchantPath $ 'stores.dbf' }"
				  FIELDS = "id			NUMBER,
							manager_id	NUMBER,
							code		CHAR( 50 ),
							license		CHAR( 25 ),
							name		CHAR( 100 ),
							owner		CHAR( 100 ),
							email		CHAR( 50 ),
							company		CHAR( 100 ),
							address		CHAR( 100 ),
							city		CHAR( 50 ),
							state		CHAR( 50 ),
							zip			CHAR( 50 ),
							phone		CHAR( 50 ),
							fax			CHAR( 50 ),
							country		CHAR( 50 ),
							wtunits		CHAR( 50 ),
							baskexp		NUMBER,
							pgrp_ovlp	CHAR( 10 ),
							tax_id		NUMBER,
							currncy_id	NUMBER,
							ui_id		NUMBER,
							mnt_warn	MEMO,
							mnt_close	MEMO,
							mnt_time	NUMBER,
							mnt_no_new	NUMBER,
							omin_quant	NUMBER,
							omin_price	NUMBER( 10.2 ),
							omin_all	BOOL,
							omin_msg	MEMO">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00115', MvCREATE_Error ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Stores"
						 INDEXFILE = "{ g.MerchantPath $ 'str_id.mvx' }"
						 EXPRESSION = "{ Stores.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00116', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Stores"
						 INDEXFILE = "{ g.MerchantPath $ 'str_code.mvx' }"
						 EXPRESSION = "{ toupper( Stores.d.code ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00117', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Stores"
						 INDEXFILE = "{ g.MerchantPath $ 'str_lic.mvx' }"
						 EXPRESSION = "{ Stores.d.license }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00118', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Keys"
				  DATABASE = "{ g.MerchantPath $ 'keys.dbf' }"
				  FIELDS = "type		CHAR( 50 ),
							maxvalue	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00119', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Keys_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Keys"
						 INDEXFILE = "{ g.MerchantPath $ 'keys.mvx' }"
						 EXPRESSION = "{ Keys.d.type }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00120', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ Key_Insert( 'Modules' ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ Key_Insert( 'Users' ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ Key_Insert( 'Stores' ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Keys">
			<MvASSIGN NAME = "g._DB_Keys_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Modules"
				  DATABASE = "{ g.MerchantPath $ 'modules.dbf' }"
				  FIELDS = "id			NUMBER,
							type		CHAR( 15 ),
							code		CHAR( 50 ),
							name		CHAR( 100 ),
							provider	CHAR( 100 ),
							version		CHAR( 20 ),
							module		CHAR( 100 ),
							refcount	NUMBER,
							active		BOOL">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00121', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Modules_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Modules"
						 INDEXFILE = "{ g.MerchantPath $ 'mod_id.mvx' }"
						 EXPRESSION = "{ Modules.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00122', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Modules"
						 INDEXFILE = "{ g.MerchantPath $ 'mod_code.mvx' }"
						 EXPRESSION = "{ Modules.d.code }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00123', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Modules"
						 INDEXFILE = "{ g.MerchantPath $ 'mod_type.mvx' }"
						 EXPRESSION = "{ Modules.d.type }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00124', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Modules">
			<MvASSIGN NAME = "g._DB_Modules_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Users"
				  DATABASE = "{ g.MerchantPath $ 'users.dbf' }"
				  FIELDS = "id			NUMBER,
							parent_id	NUMBER,
							name		CHAR( 40 ),
							password	CHAR( 40 ),
							page_len	NUMBER,
							admin		BOOL,
							create		BOOL,
							smod		BOOL,
							t_fails		NUMBER,
							c_fails		NUMBER,
							lo_date		CHAR(50)">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00125', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Users_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Users"
						 INDEXFILE = "{ g.MerchantPath $ 'usr_id.mvx' }"
						 EXPRESSION = "{ Users.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00126', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Users"
						 INDEXFILE = "{ g.MerchantPath $ 'usr_name.mvx' }"
						 EXPRESSION = "{ toupper( Users.d.name ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00127', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Users">
			<MvASSIGN NAME = "g._DB_Users_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "UserXStore"
				  DATABASE = "{ g.MerchantPath $ 'usrxstor.dbf' }"
				  FIELDS = "user_id		NUMBER,
							store_id	NUMBER,
							manager		BOOL,
							groupcount	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00128', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_UserXStore_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "UserXStore"
						 INDEXFILE = "{ g.MerchantPath $ 'uxs_stor.mvx' }"
						 EXPRESSION = "{ UserXStore.d.store_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00129', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "UserXStore"
						 INDEXFILE = "{ g.MerchantPath $ 'uxs_user.mvx' }"
						 EXPRESSION = "{ UserXStore.d.user_id $ ':' $ padl( UserXStore.d.store_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00130', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "UserXStore">
			<MvASSIGN NAME = "g._DB_UserXStore_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Privileges"
				  DATABASE = "{ g.MerchantPath $ 'privs.dbf' }"
				  FIELDS = "privilege	CHAR( 20 ),
							name		CHAR( 100 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00131', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Privileges_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Privileges"
						 INDEXFILE = "{ g.MerchantPath $ 'prv_priv.mvx' }"
						 EXPRESSION = "{ Privileges.d.privilege }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00132', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Privileges"
						 INDEXFILE = "{ g.MerchantPath $ 'prv_name.mvx' }"
						 EXPRESSION = "{ Privileges.d.name }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00133', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00141">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store Settings</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'STOR', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00142">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">States</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'STAT', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00143">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Categories</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'CTGY', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00144">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Products</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'PROD', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00146">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Sales Tax</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'STAX', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00147">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Shipping Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'SHIP', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00148">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Payment Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'PMNT', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00149">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order Fulfillment Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'FUFL', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00150">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Order Processing</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'ORDR', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00154">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Logging Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'LOGM', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00155">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">System Extension Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'SYSM', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00156">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Currency Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'CURR', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00157">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Store Utility Configuration</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'SUTL', l.privilege ) }">
			<MvLOCALIZED NAME = "l.privilege" ID = "MER-DTB-00174">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Countries</MvLOCALIZED-TEXT>
			</MvLOCALIZED>
			<MvASSIGN NAME = "l.ok" VALUE = "{ Privilege_Insert( 'STCT', l.privilege ) }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:Affiliates:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ AFF_Create_Data_Files() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:AttributeTemplates:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ ATT_Create_Data_Files() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:Customers:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ CUS_Create_Data_Files() }">

			<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND l.ok }">
				<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AGR_Create_Data_Files() }">
			</MvIF>

			<MvIF EXPR = "{ g.Features:PriceGroups:Enabled AND l.ok }">
				<MvDO FILE = "{ g.Module_Feature_PGR_DB }" NAME = "l.ok" VALUE = "{ PGR_Create_Data_Files() }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ g.Features:Inventory:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.ok" VALUE = "{ INV_Create_Data_Files() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:Upsale:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ USL_Create_Data_Files() }">
		</MvIF>

		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.ok" VALUE = "{ Create_Notes() }">

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Privileges">
			<MvASSIGN NAME = "g._DB_Privileges_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AdminSessions"
				  DATABASE = "{ g.MerchantPath $ 'admsess.dbf' }"
				  FIELDS = "session_id	CHAR( 40 ),
							user_id		NUMBER,
							lastupdate	CHAR( 10 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00134', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_AdminSessions_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AdminSessions"
						 INDEXFILE = "{ g.MerchantPath $ 'ads_sess.mvx' }"
						 EXPRESSION = "{ AdminSessions.d.session_id }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00135', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AdminSessions">
			<MvASSIGN NAME = "g._DB_AdminSessions_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Countries"
		  		  DATABASE = "{ g.MerchantPath $ 'country.dbf' }"
				  FIELDS = "id			NUMBER,
				  			name		CHAR( 50 ),
						    alpha		CHAR( 02 ),
						    numeric		NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00136', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Countries_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Countries"
						 INDEXFILE = "{ g.MerchantPath $ 'cntry_i.mvx' }"
						 EXPRESSION = "{ Countries.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00334', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Countries"
						 INDEXFILE = "{ g.MerchantPath $ 'cntry_a.mvx' }"
						 EXPRESSION = "{ Countries.d.alpha }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00376', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Countries"
						 INDEXFILE = "{ g.MerchantPath $ 'cntry_n.mvx' }"
						 EXPRESSION = "{ toupper( Countries.d.name ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00334', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Countries">
			<MvASSIGN NAME = "g._DB_Countries_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Create" PARAMETERS = "manager_id, code, license, name, owner, email, company, address, city, state, zip, country, phone, fax, wtunits, baskexp, pgrp_ovlp, ui_id, currncy_id, tax_id, order_start, m_mode, m_no_new_cus, m_warn, m_msg, omin_quant, omin_price, omin_all, omin_msg" 
STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvASSIGN NAME = "l.store_id" VALUE = 0>

	<MvASSIGN NAME = "Stores.d.id" 			VALUE = "{ Key_Generate( 'Stores' ) }">
	<MvASSIGN NAME = "Stores.d.manager_id" 	VALUE = "{ l.manager_id }">
	<MvASSIGN NAME = "Stores.d.code" 		VALUE = "{ ltrim( rtrim( l.code ) ) }">
	<MvASSIGN NAME = "Stores.d.license" 	VALUE = "{ l.license }">
	<MvASSIGN NAME = "Stores.d.name" 		VALUE = "{ l.name }">
	<MvASSIGN NAME = "Stores.d.owner" 		VALUE = "{ l.owner }">
	<MvASSIGN NAME = "Stores.d.email" 		VALUE = "{ l.email }">
	<MvASSIGN NAME = "Stores.d.company" 	VALUE = "{ l.company }">
	<MvASSIGN NAME = "Stores.d.address" 	VALUE = "{ l.address }">
	<MvASSIGN NAME = "Stores.d.city" 		VALUE = "{ l.city }">
	<MvASSIGN NAME = "Stores.d.state" 		VALUE = "{ l.state }">
	<MvASSIGN NAME = "Stores.d.zip" 		VALUE = "{ l.zip }">
	<MvASSIGN NAME = "Stores.d.country" 	VALUE = "{ l.country }">
	<MvASSIGN NAME = "Stores.d.phone" 		VALUE = "{ l.phone }">
	<MvASSIGN NAME = "Stores.d.fax" 		VALUE = "{ l.fax }">
	<MvASSIGN NAME = "Stores.d.wtunits" 	VALUE = "{ l.wtunits }">
	<MvASSIGN NAME = "Stores.d.baskexp" 	VALUE = "{ l.baskexp }">
	<MvASSIGN NAME = "Stores.d.pgrp_ovlp" 	VALUE = "{ l.pgrp_ovlp }">
	<MvASSIGN NAME = "Stores.d.ui_id" 		VALUE = "{ l.ui_id }">
	<MvASSIGN NAME = "Stores.d.currncy_id" 	VALUE = "{ l.currncy_id }">
	<MvASSIGN NAME = "Stores.d.tax_id" 		VALUE = "{ l.tax_id }">
	<MvASSIGN NAME = "Stores.d.mnt_time" 	VALUE = "{ l.m_mode }">
	<MvASSIGN NAME = "Stores.d.mnt_warn" 	VALUE = "{ l.m_warn }">
	<MvASSIGN NAME = "Stores.d.mnt_close" 	VALUE = "{ l.m_msg }">

	<MvIF EXPR = "{ NOT len( l.m_no_new_cus ) EQ 0 }">
		<MvASSIGN NAME = "Stores.d.mnt_no_new" 	VALUE = "{ l.m_no_new_cus }">
	<MvELSE>
		<MvASSIGN NAME = "Stores.d.mnt_no_new" 	VALUE = "0">
	</MvIF>

	<MvIF EXPR = "{ NOT len( l.omin_quant ) EQ 0 }">
		<MvASSIGN NAME = "Stores.d.omin_quant" 	VALUE = "{ l.omin_quant }">	
	<MvELSE>
		<MvASSIGN NAME = "Stores.d.omin_quant" 	VALUE = "0">
	</MvIF>

	<MvIF EXPR = "{ NOT len( l.omin_price ) EQ 0 }">
		<MvASSIGN NAME = "Stores.d.omin_price" 	VALUE = "{ l.omin_price }">	
	<MvELSE>
		<MvASSIGN NAME = "Stores.d.omin_price" 	VALUE = "0.00">
	</MvIF>

	<MvIF EXPR = "{ NOT len( l.omin_all ) EQ 0 }">
		<MvASSIGN NAME = "Stores.d.omin_all" 	VALUE = "{ l.omin_all }">	
	<MvELSE>
		<MvASSIGN NAME = "Stores.d.omin_all" 	VALUE = "1">
	</MvIF>

	<MvIF EXPR = "{ NOT len( l.omin_msg ) EQ 0 }">
		<MvASSIGN NAME = "Stores.d.omin_msg" 	VALUE = "{ l.omin_msg }">	
	<MvELSE>
		<MvASSIGN NAME = "Stores.d.omin_msg" 	VALUE = "">
	</MvIF>

	<MvADD NAME = "Stores">
	
	<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Set_Manager( Stores.d.id, l.manager_id, 1 ) }">

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "g._DB_Store_Directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">
		<MvIF EXPR = "{ NOT fmkdir( g._DB_Store_Directory ) }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00100">
				<MvLOCALIZED-TOKEN NAME = "directory" VALUE = "{ encodeentities( g._DB_Store_Directory ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Unable to create directory '%directory%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00227', l.error ) }">
			<MvDELETE NAME = "Stores">

			<MvFUNCTIONRETURN VALUE = "0">
		</MvIF>
	</MvIF>
		
		
		
	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "StoreKeys"
				  DATABASE = "{ g._DB_Store_Directory $ 'storekey.dbf' }"
				  FIELDS = "type		CHAR( 50 ),
							maxvalue	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00137', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_StoreKeys_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "StoreKeys"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'storekey.mvx' }"
						 EXPRESSION = "{ StoreKeys.d.type }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00138', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Categories', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Products', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Attributes', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Options', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Baskets', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'BasketLines', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'BasketCharges', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Orders', l.order_start ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Batches', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Groups', 1 ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Notes', 1 ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "StoreKeys">
			<MvASSIGN NAME = "g._DB_Store_StoreKeys_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Orphans"
				DATABASE = "{ g._DB_Store_Directory $ 'orphans.dbf' }"
				FIELDS = "type		CHAR( 50 ),
						  value		NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00139', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Orphans_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Orphans"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'orphans.mvx' }"
						 EXPRESSION = "{ Orphans.d.type $ ':' $ padl( Orphans.d.value, 10, '0' ) }">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00140', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Orphans">
			<MvASSIGN NAME = "g._DB_Store_Orphans_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Groups"
				  DATABASE = "{ g._DB_Store_Directory $ 'groups.dbf' }"
				  FIELDS = "id			NUMBER,
							name		CHAR( 40 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00141', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Groups_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Groups"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'grp_id.mvx' }"
						 EXPRESSION = "{ Groups.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00142', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Groups"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'grp_name.mvx' }"
						 EXPRESSION = "{ toupper( Groups.d.name ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00143', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Groups">
			<MvASSIGN NAME = "g._DB_Store_Groups_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "GroupPrivileges"
				  DATABASE = "{ g._DB_Store_Directory $ 'grppriv.dbf' }"
				  FIELDS = "group_id	NUMBER,
							privilege	CHAR( 20 ),
							view		BOOL,
							add			BOOL,
							modify		BOOL,
							delete		BOOL">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00144', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_GroupPrivilegess_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "GroupPrivileges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'grppriv.mvx' }"
						 EXPRESSION = "{ GroupPrivileges.d.group_id $ ':' $ GroupPrivileges.d.privilege }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00145', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "GroupPrivileges">
			<MvASSIGN NAME = "g._DB_Store_GroupPrivileges_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "UserXGroup"
				  DATABASE = "{ g._DB_Store_Directory $ 'usrxgrp.dbf' }"
				  FIELDS = "user_id		NUMBER,
							group_id	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00146', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_UserXGroup_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "UserXGroup"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'uxg_user.mvx' }"
						 EXPRESSION = "{ UserXGroup.d.user_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00147', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "UserXGroup"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }"
						 EXPRESSION = "{ UserXGroup.d.group_id $ ':' $ padl( UserXGroup.d.user_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00148', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "UserXGroup">
			<MvASSIGN NAME = "g._DB_Store_UserXGroup_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "States"
				  DATABASE = "{ g._DB_Store_Directory $ 'states.dbf' }"
				  FIELDS = "code		CHAR( 50 ),
							name		CHAR( 100 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00149', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_States_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "States"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'states.mvx' }"
						 EXPRESSION = "{ toupper( States.d.code ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00150', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvLOCALIZED NAME = "l.out" ID = "MER-DTB-00177">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Outside</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( '', l.out $ ' ' $ l.country ) }">

			<MvIF EXPR = "{ l.country EQ 'US' }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'AL', 'Alabama' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'AK', 'Alaska' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'AZ', 'Arizona' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'AR', 'Arkansas' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'CA', 'California' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'CO', 'Colorado' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'CT', 'Connecticut' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'DE', 'Delaware' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'DC', 'District of Columbia' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'FL', 'Florida' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'GA', 'Georgia' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'HI', 'Hawaii' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'ID', 'Idaho' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'IL', 'Illinois' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'IN', 'Indiana' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'IA', 'Iowa' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'KS', 'Kansas' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'KY', 'Kentucky' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'LA', 'Louisiana' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'ME', 'Maine' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MD', 'Maryland' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MA', 'Massachusetts' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MI', 'Michigan' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MN', 'Minnesota' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MS', 'Mississippi' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MO', 'Missouri' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MT', 'Montana' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NE', 'Nebraska' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NV', 'Nevada' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NH', 'New Hampshire' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NJ', 'New Jersey' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NM', 'New Mexico' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NY', 'New York' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NC', 'North Carolina' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'ND', 'North Dakota' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'OH', 'Ohio' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'OK', 'Oklahoma' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'OR', 'Oregon' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'PA', 'Pennsylvania' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'RI', 'Rhode Island' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'SC', 'South Carolina' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'SD', 'South Dakota' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'TN', 'Tennessee' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'TX', 'Texas' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'UT', 'Utah' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'VT', 'Vermont' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'VA', 'Virginia' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'WA', 'Washington' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'WV', 'West Virginia' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'WI', 'Wisconsin' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'WY', 'Wyoming' ) }">
			</MvIF>
			<MvIF EXPR = "{ l.country EQ 'CA' }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'AB', 'Alberta' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'BC', 'British Columbia' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'MB', 'Manitoba' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NB', 'New Brunswick' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NF', 'Newfoundland' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NS', 'Nova Scotia' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NT', 'Northwest Territories' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'NU', 'Nunavut' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'ON', 'Ontario' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'PE', 'Prince Edward Island' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'QC', 'Quebec' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'SK', 'Saskatchewan' ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ State_Insert( 'YT', 'Yukon' ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "States">
			<MvASSIGN NAME = "g._DB_Store_States_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Categories"
				  DATABASE = "{ g._DB_Store_Directory $ 'cats.dbf' }"
				  FIELDS = "id			NUMBER,
							parent_id	NUMBER,
							agrpcount   NUMBER,
							order		NUMBER,
							code		CHAR( 50 ),
							name		CHAR( 100 ),
							active		BOOL">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00151', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Categories"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cat_id.mvx' }"
						 EXPRESSION = "{ Categories.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00152', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Categories"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cat_code.mvx' }"
						 EXPRESSION = "{ toupper( Categories.d.code ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00153', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Categories"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cat_prnt.mvx' }"
						 EXPRESSION = "{ Categories.d.parent_id $ ':' $ padl( Categories.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00154', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Categories"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }"
						 EXPRESSION = "{ padl( Categories.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00155', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Categories">
			<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "CategoryXProduct"
				  DATABASE = "{ g._DB_Store_Directory $ 'catxprod.dbf' }"
				  FIELDS = "cat_id		NUMBER,
							product_id	NUMBER,
							order		NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00156', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_CategoryXProduct_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "CategoryXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cxp_cat.mvx' }"
						 EXPRESSION = "{ CategoryXProduct.d.cat_id $ ':' $ padl( CategoryXProduct.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00157', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "CategoryXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cxp_prod.mvx' }"
						 EXPRESSION = "{ CategoryXProduct.d.product_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00158', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "CategoryXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'cxp_cprd.mvx' }"
						 EXPRESSION = "{ CategoryXProduct.d.cat_id $ ':' $ CategoryXProduct.d.product_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00159', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "CategoryXProduct">
			<MvASSIGN NAME = "g._DB_Store_CategoryXProduct_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Products"
				  DATABASE = "{ g._DB_Store_Directory $ 'products.dbf' }"
				  FIELDS = "id			NUMBER,
							catcount	NUMBER,
							agrpcount	NUMBER,
							pgrpcount   NUMBER,
							order		NUMBER,
							code		CHAR( 50 ),
							name		CHAR( 100 ),
							thumbnail	CHAR( 254 ),
							image		CHAR( 254 ),
							price		NUMBER( 10.2 ),
							cost		NUMBER( 10.2 ),
							desc		MEMO,
							weight		NUMBER( 10.2 ),
							taxable		BOOL,
							active		BOOL"> 
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00160', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Products"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'prd_id.mvx' }"
						 EXPRESSION = "{ Products.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00161', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Products"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }"
						 EXPRESSION = "{ padl( Products.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00162', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Products"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'prd_ccnt.mvx' }"
						 EXPRESSION = "{ Products.d.catcount $ ':' $ padl( Products.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00163', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Products"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'prd_gcnt.mvx' }"
						 EXPRESSION = "{ Products.d.agrpcount $ ':' $ padl( Products.d.id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00164', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Products"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'prd_pgct.mvx' }"
						 EXPRESSION = "{ Products.d.pgrpcount $ ':' $ padl( Products.d.id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00165', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">			
			<MvMAKEINDEX NAME = "Products"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'prd_code.mvx' }"
						 EXPRESSION = "{ toupper( Products.d.code ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00166', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Products">
			<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Attributes"
				  DATABASE = "{ g._DB_Store_Directory $ 'attr.dbf' }"
				  FIELDS = "id			NUMBER,
							product_id	NUMBER,
							default_id	NUMBER,
							order		NUMBER,
							code		CHAR( 50 ),
							type		CHAR( 20 ),
							attemp_id	NUMBER,
							prompt		MEMO,
							price		NUMBER( 10.2 ),
							cost		NUMBER( 10.2 ),
							required	BOOL,
							image		CHAR( 254 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00167', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Attributes_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Attributes"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'atr_id.mvx' }"
						 EXPRESSION = "{ Attributes.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00168', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Attributes"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'atr_code.mvx' }"
						 EXPRESSION = "{ Attributes.d.product_id $ ':' $ toupper( Attributes.d.code ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00169', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Attributes"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'atr_prod.mvx' }"
						 EXPRESSION = "{ Attributes.d.product_id $ ':' $ padl( Attributes.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00170', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Attributes"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'atr_at_p.mvx' }"
						 EXPRESSION = "{ Attributes.d.product_id $ ':' $ padl( Attributes.d.attemp_id, 10, '0' ) $ ':' $ padl( Attributes.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00396', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Attributes"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'atr_at_i.mvx' }"
						 EXPRESSION = "{ Attributes.d.attemp_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00397', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Attributes">
			<MvASSIGN NAME = "g._DB_Store_Attributes_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Options"
				  DATABASE = "{ g._DB_Store_Directory $ 'opts.dbf' }"
				  FIELDS = "id			NUMBER,
							attr_id		NUMBER,
							order		NUMBER,
							code		CHAR( 50 ),
							prompt		MEMO,
							price		NUMBER( 10.2 ),
							cost		NUMBER( 10.2 ),
							image		CHAR( 254 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00171', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Options_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Options"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'opt_id.mvx' }"
						 EXPRESSION = "{ Options.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00172', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Options"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'opt_code.mvx' }"
						 EXPRESSION = "{ Options.d.attr_id $ ':' $ toupper( Options.d.code ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00173', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Options"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'opt_attr.mvx' }"
						 EXPRESSION = "{ Options.d.attr_id $ ':' $ padl( Options.d.order, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00174', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Options">
			<MvASSIGN NAME = "g._DB_Store_Options_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "BasketList"
				  DATABASE = "{ g._DB_Store_Directory $ 'basklist.dbf' }"
				  FIELDS = "session_id	CHAR( 40 ),
							cust_id     NUMBER,
							basket_id	NUMBER,
							order_id	NUMBER,
							order_proc	BOOL,
							ship_fname	CHAR( 50 ),
							ship_lname	CHAR( 50 ),
							ship_email	CHAR( 50 ),
							ship_comp	CHAR( 50 ),
							ship_phone	CHAR( 50 ),
							ship_fax	CHAR( 50 ),
							ship_addr	CHAR( 100 ),
							ship_city	CHAR( 50 ),
							ship_state	CHAR( 50 ),
							ship_zip	CHAR( 50 ),
							ship_cntry	CHAR( 50 ),
							bill_fname	CHAR( 50 ),
							bill_lname	CHAR( 50 ),
							bill_email	CHAR( 50 ),
							bill_comp	CHAR( 50 ),
							bill_phone	CHAR( 50 ),
							bill_fax	CHAR( 50 ),
							bill_addr	CHAR( 100 ),
							bill_city	CHAR( 50 ),
							bill_state	CHAR( 50 ),
							bill_zip	CHAR( 50 ),
							bill_cntry	CHAR( 50 ),
							tax			NUMBER( 10.2 ),
							shipping	NUMBER( 10.2 ),
							ship_id		NUMBER,
							ship_data	CHAR( 100 ),
							pay_id		NUMBER,
							pay_data	CHAR( 100 ),
							total		NUMBER( 10.2 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00179', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketList_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "BasketList"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'blst_ses.mvx' }"
						 EXPRESSION = "{ BasketList.d.session_id }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00180', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "BasketList">
			<MvASSIGN NAME = "g._DB_Store_BasketList_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "BasketLastUpdate"
				  DATABASE = "{ g._DB_Store_Directory $ 'basklupd.dbf' }"
				  FIELDS = "session_id	CHAR( 40 ),
							lastupdate	CHAR( 10 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00404', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketLastUpdate_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "BasketLastUpdate"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'blup_ses.mvx' }"
						 EXPRESSION = "{ BasketLastUpdate.d.session_id }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00405', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "BasketLastUpdate">
			<MvASSIGN NAME = "g._DB_Store_BasketLastUpdate_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Baskets"
				  DATABASE = "{ g._DB_Store_Directory $ 'baskets.dbf' }"
				  FIELDS = "id			NUMBER,
							line_id		NUMBER,
							product_id	NUMBER,
							code		CHAR( 50 ),
							name		CHAR( 100 ),
							price		NUMBER( 10.2 ),
							weight		NUMBER( 10.2 ),
							taxable		BOOL,
							upsold		BOOL,
							quantity	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00181', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Baskets_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Baskets"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }"
						 EXPRESSION = "{ Baskets.d.id $ ':' $ padl( Baskets.d.line_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00182', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Baskets"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bsk_line.mvx' }"
						 EXPRESSION = "{ Baskets.d.line_id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00183', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Baskets">
			<MvASSIGN NAME = "g._DB_Store_Baskets_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "BasketOptions"
				  DATABASE = "{ g._DB_Store_Directory $ 'baskopts.dbf' }"
				  FIELDS = "line_id		NUMBER,
							attr_id		NUMBER,
							attr_code	CHAR( 50 ),
							option_id	NUMBER,
							opt_code	CHAR( 50 ),
							price		NUMBER( 10.2 ),
							data		CHAR( 254 ),
							data_long	MEMO">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00184', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketOptions_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "BasketOptions"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bopt_ln.mvx' }"
						 EXPRESSION = "{ BasketOptions.d.line_id $ ':' $ padl( BasketOptions.d.attr_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00185', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "BasketOptions">
			<MvASSIGN NAME = "g._DB_Store_BasketOptions_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "BasketCharges"
				  DATABASE = "{ g._DB_Store_Directory $ 'baskchrg.dbf' }"
				  FIELDS = "basket_id	NUMBER,
							charge_id   NUMBER,
							module_id	NUMBER,
							type		CHAR( 50 ),
							desc        CHAR( 100 ),
							amount		NUMBER( 10.3 ),
							disp_amt	NUMBER( 10.3 ),
							tax_exempt	BOOL">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00330', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_BasketCharges_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "BasketCharges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bchg_bid.mvx' }"
						 EXPRESSION = "{ BasketCharges.d.basket_id $ ':' $ padl( BasketCharges.d.charge_id, 10, '0' ) }"
						 FLAGS = "unique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00331', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "BasketCharges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bchg_typ.mvx' }"
						 EXPRESSION = "{ BasketCharges.d.basket_id $ ':' $ BasketCharges.d.type $ ':' $ padl( BasketCharges.d.charge_id, 10, '0' ) }"
						 FLAGS = "unique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00339', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "BasketCharges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bchg_mod.mvx' }"
						 EXPRESSION = "{ BasketCharges.d.basket_id $ ':' $ BasketCharges.d.module_id $ ':' $ padl( BasketCharges.d.charge_id, 10, '0' ) }"
						 FLAGS = "unique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00382', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "BasketCharges">
			<MvASSIGN NAME = "g._DB_Store_BasketCharges_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "StoreModules"
				  DATABASE = "{ g._DB_Store_Directory $ 'storemod.dbf' }"
				  FIELDS = "module_id	NUMBER,
							type		CHAR( 15 ),
							refcount	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00186', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "StoreModules"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'smd_id.mvx' }"
						 EXPRESSION = "{ StoreModules.d.module_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00187', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "StoreModules"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'smd_type.mvx' }"
						 EXPRESSION = "{ StoreModules.d.type }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00188', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Insert( l.ui_id, 'UI' ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Insert( l.currncy_id, 'CURRENCY' ) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreModule_Insert( l.tax_id, 'TAX' ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "StoreModules">
			<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Orders"
				  DATABASE = "{ g._DB_Store_Directory $ 'orders.dbf' }"
				  FIELDS = "id			NUMBER,
							batch_id	NUMBER,
							processed	BOOL,
							date		CHAR( 10 ),
							cust_id     NUMBER,
							ship_fname	CHAR( 50 ),
							ship_lname	CHAR( 50 ),
							ship_email	CHAR( 50 ),
							ship_comp	CHAR( 50 ),
							ship_phone	CHAR( 50 ),
							ship_fax	CHAR( 50 ),
							ship_addr	CHAR( 100 ),
							ship_city	CHAR( 50 ),
							ship_state	CHAR( 50 ),
							ship_zip	CHAR( 50 ),
							ship_cntry	CHAR( 50 ),
							bill_fname	CHAR( 50 ),
							bill_lname	CHAR( 50 ),
							bill_email	CHAR( 50 ),
							bill_comp	CHAR( 50 ),
							bill_phone	CHAR( 50 ),
							bill_fax	CHAR( 50 ),
							bill_addr	CHAR( 100 ),
							bill_city	CHAR( 50 ),
							bill_state	CHAR( 50 ),
							bill_zip	CHAR( 50 ),
							bill_cntry	CHAR( 50 ),
							tax			NUMBER( 10.2 ),
							shipping	NUMBER( 10.2 ),
							ship_id		NUMBER,
							ship_data	CHAR( 100 ),
							pay_id		NUMBER,
							pay_data	CHAR( 100 ),
							affil_code	CHAR( 50 ),
							total		NUMBER( 10.2 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00189', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Orders_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Orders"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'ord_id.mvx' }"
						 EXPRESSION = "{ Orders.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00190', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Orders"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'ord_btch.mvx' }"
						 EXPRESSION = "{ Orders.d.batch_id $ ':' $ padl( Orders.d.id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00191', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Orders"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'ord_prcd.mvx' }"
						 EXPRESSION = "{ Orders.d.batch_id $ ':' $ Orders.d.processed $ ':' $ padl( Orders.d.id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00192', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Orders">
			<MvASSIGN NAME = "g._DB_Store_Orders_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "OrderItems"
				  DATABASE = "{ g._DB_Store_Directory $ 'orditems.dbf' }"
				  FIELDS = "order_id	NUMBER,
							line_id		NUMBER,
							product_id	NUMBER,
							code		CHAR( 50 ),
							name		CHAR( 100 ),
							price		NUMBER( 10.2 ),
							weight		NUMBER( 10.2 ),
							taxable		BOOL,
							upsold		BOOL,
							quantity	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00193', MvMAKEINDEX_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_OrderItems_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "OrderItems"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'oit_ord.mvx' }"
						 EXPRESSION = "{ OrderItems.d.order_id $ ':' $ padl( OrderItems.d.line_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00194', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "OrderItems">
			<MvASSIGN NAME = "g._DB_Store_OrderItems_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "OrderOptions"
				  DATABASE = "{ g._DB_Store_Directory $ 'ordopts.dbf' }"
				  FIELDS = "line_id		NUMBER,
							attr_id		NUMBER,
							attr_code	CHAR( 50 ),
							option_id	NUMBER,
							opt_code	CHAR( 50 ),
							price		NUMBER( 10.2 ),
							data		CHAR( 254 ),
							data_long	MEMO">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00195', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_OrderOptions_Open" VALUE = 1>
		</MvIF>

		<MvMAKEINDEX NAME = "OrderOptions"
					 INDEXFILE = "{ g._DB_Store_Directory $ 'oop_line.mvx' }"
					 EXPRESSION = "{ OrderOptions.d.line_id $ ':' $ padl( OrderOptions.d.attr_id, 10, '0' ) }"
					 FLAGS = "nounique, ascending">
		<MvIF EXPR = "{ MvMAKEINDEX_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00196', MvMAKEINDEX_Error ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "OrderOptions">
			<MvASSIGN NAME = "g._DB_Store_OrderOptions_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "OrderCharges"
				  DATABASE = "{ g._DB_Store_Directory $ 'ordrchrg.dbf' }"
				  FIELDS = "order_id	NUMBER,
							charge_id   NUMBER,
							module_id	NUMBER,
							type		CHAR( 50 ),
							desc        CHAR( 100 ),
							amount		NUMBER( 10.3 ),
							disp_amt	NUMBER( 10.3 ),
							tax_exempt	BOOL">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00383', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_OrderCharges_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "OrderCharges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'ochg_oid.mvx' }"
						 EXPRESSION = "{ OrderCharges.d.Order_id $ ':' $ padl( OrderCharges.d.charge_id, 10, '0' ) }"
						 FLAGS = "unique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00333', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "OrderCharges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'ochg_typ.mvx' }"
						 EXPRESSION = "{ OrderCharges.d.Order_id $ ':' $ OrderCharges.d.type $ ':' $ padl( OrderCharges.d.charge_id, 10, '0' ) }"
						 FLAGS = "unique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00336', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "OrderCharges"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'ochg_mod.mvx' }"
						 EXPRESSION = "{ OrderCharges.d.Order_id $ ':' $ OrderCharges.d.module_id $ ':' $ padl( OrderCharges.d.charge_id, 10, '0' ) }"
						 FLAGS = "unique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00384', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "OrderCharges">
			<MvASSIGN NAME = "g._DB_Store_OrderCharges_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Batches"
				  DATABASE = "{ g._DB_Store_Directory $ 'batches.dbf' }"
				  FIELDS = "id			NUMBER,
							date		CHAR( 10 ),
							name		CHAR( 100 ),
							closed		BOOL">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00197', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Batches_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Batches"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bch_id.mvx' }"
						 EXPRESSION = "{ Batches.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00198', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Batches"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'bch_clsd.mvx' }"
						 EXPRESSION = "{ Batches.d.closed $ ':' $ padl( Batches.d.id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00199', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Batches">
			<MvASSIGN NAME = "g._DB_Store_Batches_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "StoreCountries"
			  DATABASE = "{ g._DB_Store_Directory $ 'str_cty.dbf' }"
			  FIELDS = "id			NUMBER,
						name		CHAR( 50 ),
						alpha		CHAR( 02 ),
						numeric		NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00386', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Countries_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "StoreCountries"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'str_cty.mvx' }"
						 EXPRESSION = "{ StoreCountries.d.alpha }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00387', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "StoreCountries"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'str_ctyn.mvx' }"
						 EXPRESSION = "{ toupper( StoreCountries.d.name ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00388', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "StoreCountries"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'str_ctyi.mvx' }"
						 EXPRESSION = "{ StoreCountries.d.id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00389', MvMAKEINDEX_Error ) }">
			<MvELSE>
				<MvASSIGN NAME = "g._DB_StoreCountries_Open" VALUE = 1>
			</MvIF>
		</MvIF>

		<MvASSIGN NAME = "l.country_found" VALUE = "{ Country_FindFirst() }">
		<MvWHILE EXPR = "{ l.country_found AND l.ok}">
			<MvASSIGN NAME = "l.ok" VALUE = "{ StoreCountry_Insert( Countries.d.id, Countries.d.name, Countries.d.alpha, Countries.d.numeric ) }">
			<MvASSIGN NAME = "l.country_found" VALUE = "{ Country_FindNext() }">
		</MvWHILE>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "StoreCountries">
			<MvASSIGN NAME = "g._DB_StoreCountries_Open" VALUE = 0>
		</MvIF>		
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE	NAME = "StandardFields"
					DATABASE = "{ g._DB_Store_Directory $ 'std_fld.dbf' }"
					FIELDS = "	billing		CHAR( 1 ),
								mode_fname	CHAR( 1 ),
								mode_lname	CHAR( 1 ),
								mode_email	CHAR( 1 ),
								mode_comp	CHAR( 1 ),
								mode_phone	CHAR( 1 ),
								mode_fax	CHAR( 1 ),
								mode_addr	CHAR( 1 ),
								mode_city	CHAR( 1 ),
								mode_state	CHAR( 1 ),
								mode_zip	CHAR( 1 ),
								mode_cntry	CHAR( 1 )">

		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00343', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_StandardFields_Open" VALUE = 1>

			<MvASSIGN NAME = "StandardFields.d.billing" 	VALUE = "O">
			<MvASSIGN NAME = "StandardFields.d.mode_fname" 	VALUE = "R">
			<MvASSIGN NAME = "StandardFields.d.mode_lname" 	VALUE = "R">
			<MvASSIGN NAME = "StandardFields.d.mode_email" 	VALUE = "R">
			<MvASSIGN NAME = "StandardFields.d.mode_comp" 	VALUE = "O">
			<MvASSIGN NAME = "StandardFields.d.mode_phone" 	VALUE = "R">
			<MvASSIGN NAME = "StandardFields.d.mode_fax" 	VALUE = "O">
			<MvASSIGN NAME = "StandardFields.d.mode_addr" 	VALUE = "R">
			<MvASSIGN NAME = "StandardFields.d.mode_city" 	VALUE = "R">

			<MvIF EXPR = "{ g.Store_Country EQ 'DE' }">
				<MvASSIGN NAME = "StandardFields.d.mode_state" VALUE = "H">
			<MvELSE>
				<MvASSIGN NAME = "StandardFields.d.mode_state" VALUE = "R">
			</MvIF>
			<MvASSIGN NAME = "StandardFields.d.mode_zip" VALUE = "R">
			<MvIF EXPR = "{ g.Store_Country EQ 'DE' }">
				<MvASSIGN NAME = "StandardFields.d.mode_cntry" VALUE = "H">
			<MvELSE>
				<MvASSIGN NAME = "StandardFields.d.mode_cntry" VALUE = "R">
			</MvIF>
			<MvADD NAME = "StandardFields">

		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "StandardFields">
			<MvASSIGN NAME = "g._DB_Store_StandardFields_Open" VALUE = 0>
		</MvIF>
	</MvIF>
			
	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_STP_DB }" NAME = "l.create" VALUE = "{ CreateStoreTasks( l.code ) }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.foo" VALUE = "{ Create_Store_Notes() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:Affiliates:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ Store_Create_A() }">		
	</MvIF>

	<MvIF EXPR = "{ g.Features:Affiliates:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ Store_Create_B( l.email ) }">		
	</MvIF>
	
	<MvIF EXPR = "{ g.Features:AttributeTemplates:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ ATT_Store_Create() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:Inventory:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.ok" VALUE = "{ INV_Store_Create() }">		
	</MvIF>

	<MvIF EXPR = "{ g.Features:Customers:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ CUS_Store_Create() }">						

		<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AGR_Store_Create() }">						
		</MvIF>

		<MvIF EXPR = "{ g.Features:PriceGroups:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_PGR_DB }" NAME = "l.ok" VALUE = "{ PGR_Store_Create() }">						
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ g.Features:RelatedProducts:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_RPD_DB }" NAME = "l.ok" VALUE = "{ RPD_Store_Create() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_STA_DB }" NAME = "l.ok" VALUE = "{ STA_Store_Create( Stores.d.id ) }">		
	</MvIF>

	<MvIF EXPR = "{ g.Features:Upsale:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ USL_Store_Create() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.store_id" VALUE = "{ Stores.d.id }">
		<MvASSIGN NAME = "g.Admin_Open_Store" VALUE = "{ Stores.d.code }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.store_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "PackDataFiles" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvPACK NAME = "Domain">	
		<MvIF EXPR = "{ MvPACK_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00228', MvPACK_Error ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPACK NAME = "Stores">
		<MvIF EXPR = "{ MvPACK_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00229', MvPACK_Error ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Modules() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Modules">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00230', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Modules">
				<MvASSIGN NAME = "g._DB_Modules_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Keys() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Keys">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00231', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Keys">
				<MvASSIGN NAME = "g._DB_Keys_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Users() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Users">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00232', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Users">
				<MvASSIGN NAME = "g._DB_Users_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "UserXStore">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00233', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "UserXStore">
				<MvASSIGN NAME = "g._DB_UserXStore_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Privileges() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Privileges">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00234', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Privileges">
				<MvASSIGN NAME = "g._DB_Privileges_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_AdminSessions() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AdminSessions">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00235', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AdminSessions">
				<MvASSIGN NAME = "g._DB_AdminSessions_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Countries() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Countries">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00236', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Countries">
				<MvASSIGN NAME = "g._DB_Countries_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.ok" VALUE = "{ NOT_Domain_Pack() }">
	</MvIF>
	
	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_STP_DB }" NAME = "l.ok" VALUE = "{ STP_Domain_Pack() }">
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Pack" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "StoreKeys">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00237', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "StoreKeys">
				<MvASSIGN NAME = "g._DB_Store_StoreKeys_Open" VALUE = 0>
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvPACK NAME = "Orphans">
				<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00238', MvPACK_Error ) }">
				<MvELSE>
					<MvCLOSE NAME = "Orphans">
					<MvASSIGN NAME = "g._DB_Store_Orphans_Open" VALUE = 0>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Groups() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Groups">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00239', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Groups">
				<MvASSIGN NAME = "g._DB_Store_Groups_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_GroupPrivileges() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "GroupPrivileges">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00240', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "GroupPrivileges">
				<MvASSIGN NAME = "g._DB_Store_GroupPrivileges_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_UserXGroup() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "UserXGroup">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00241', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "UserXGroup">
				<MvASSIGN NAME = "g._DB_Store_UserXGroup_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_States() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "States">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00242', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "States">
				<MvASSIGN NAME = "g._DB_Store_States_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_StoreCountries() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "StoreCountries">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00390', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "StoreCountries">
				<MvASSIGN NAME = "g._DB_StoreCountries_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Categories">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00243', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Categories">
				<MvASSIGN NAME = "g._DB_Store_Categories_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_CategoryXProduct() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "CategoryXProduct">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00244', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "CategoryXProduct">
				<MvASSIGN NAME = "g._DB_Store_CategoryXProduct_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Products">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00245', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Products">
				<MvASSIGN NAME = "g._DB_Store_Products_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Attributes() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Attributes">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00246', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Attributes">
				<MvASSIGN NAME = "g._DB_Store_Attributes_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Options() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Options">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00247', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Options">
				<MvASSIGN NAME = "g._DB_Store_Options_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketLastUpdate() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "BasketLastUpdate">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00406', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "BasketLastUpdate">
				<MvASSIGN NAME = "g._DB_Store_BasketLastUpdate_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "BasketList">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00250', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "BasketList">
				<MvASSIGN NAME = "g._DB_Store_BasketList_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Baskets">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00251', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Baskets">
				<MvASSIGN NAME = "g._DB_Store_Baskets_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "BasketOptions">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00252', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "BasketOptions">
				<MvASSIGN NAME = "g._DB_Store_BasketOptions_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreModules() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "StoreModules">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00253', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "StoreModules">
				<MvASSIGN NAME = "g._DB_Store_StoreModules_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Orders() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Orders">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00254', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Orders">
				<MvASSIGN NAME = "g._DB_Store_Orders_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_OrderCharges() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "OrderCharges">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00393', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "OrderCharges">
				<MvASSIGN NAME = "g._DB_Store_OrderCharges_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_OrderItems() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "OrderItems">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00255', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "OrderItems">
				<MvASSIGN NAME = "g._DB_Store_OrderItems_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_OrderOptions() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "OrderOptions">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00256', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "OrderOptions">
				<MvASSIGN NAME = "g._DB_Store_OrderOptions_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Batches() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Batches">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00257', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Batches">
				<MvASSIGN NAME = "g._DB_Store_Batches_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketCharges() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "BasketCharges">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00398', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "BasketCharges">
				<MvASSIGN NAME = "g._DB_Store_BasketCharges" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StandardFields() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "StandardFields">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00399', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "StandardFields">
				<MvASSIGN NAME = "g._DB_Store_StandardFields" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ g.Features:Affiliates:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_AFF_DB }" NAME = "l.ok" VALUE = "{ AFF_Store_Pack() }">		
	</MvIF>

	<MvIF EXPR = "{ g.Features:AttributeTemplates:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.ok" VALUE = "{ ATT_Store_Pack() }">		
	</MvIF>

	<MvIF EXPR = "{ g.Features:Customers:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ CUS_Store_Pack() }">

		<MvIF EXPR = "{ g.Features:AvailabilityGroups:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_AGR_DB }" NAME = "l.ok" VALUE = "{ AGR_Store_Pack() }">
		</MvIF>

		<MvIF EXPR = "{ g.Features:PriceGroups:Enabled AND l.ok }">
			<MvDO FILE = "{ g.Module_Feature_PGR_DB }" NAME = "l.ok" VALUE = "{ PGR_Store_Pack() }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ g.Features:Inventory:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.ok" VALUE = "{ INV_Store_Pack() }">
	</MvIF>

	<MvIF EXPR = "{ g.Features:RelatedProducts:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_RPD_DB }" NAME = "l.ok" VALUE = "{ RPD_Store_Pack() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_STA_DB }" NAME = "l.ok" VALUE = "{ STA_Store_Pack( Stores.d.id ) }">		
	</MvIF>
	
	<MvIF EXPR = "{ g.Features:Upsale:Enabled AND l.ok }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ USL_Store_Pack() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_STP_DB }" NAME = "l.ok" VALUE = "{ STP_Store_Pack() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Feature_NOT_DB }" NAME = "l.ok" VALUE = "{ NOT_Store_Pack() }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_ExpireBaskets" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketLastUpdate() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvGO NAME = "BasketList" ROW = "top">
		<MvWHILE EXPR = "{ NOT BasketList.d.EOF }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ BasketLastUpdate_FindSession( BasketList.d.session_id ) }">
			<MvIF EXPR = "{ ( BasketList.d.order_proc ) OR ( ( s.time_t - BasketLastUpdate.d.lastupdate ) GT ( Stores.d.baskexp * 60 ) ) }">
				<MvIF EXPR = "{ BasketList.d.order_id AND ( NOT BasketList.d.order_proc ) AND ( g.Recover_Order_Number ) }">
					<MvASSIGN NAME = "Orphans.d.type" VALUE = "Orders">
					<MvASSIGN NAME = "Orphans.d.value" VALUE = "{ BasketList.d.order_id }">
					
					<MvADD NAME = "Orphans">
				</MvIF>

				<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
					<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
					<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
						<MvDELETE NAME = "BasketOptions">
						<MvSKIP NAME = "BasketOptions" ROWS = 1>
					</MvWHILE>

					<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
						<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity ) }">
					</MvIF>
					<MvIF EXPR = "{ l.ok }">
						<MvDELETE NAME = "Baskets">
					</MvIF>
					<MvSKIP NAME = "Baskets" ROWS = 1>
				</MvWHILE>

				<MvDELETE NAME = "BasketList">
				<MvDELETE NAME = "BasketLastUpdate">
			</MvIF>

			<MvSKIP NAME = "BasketList" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_DeleteBaskets" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketList() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Baskets() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_BasketOptions() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StoreKeys() }">
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Baskets" INDEX = "{ g._DB_Store_Directory $ 'bsk_id.mvx' }">

		<MvGO NAME = "BasketList" ROW = "top">
		<MvWHILE EXPR = "{ NOT BasketList.d.EOF }">

			<MvIF EXPR = "{ BasketList.d.order_id AND ( NOT BasketList.d.order_proc ) AND ( g.Recover_Order_Number ) }">
				<MvASSIGN NAME = "Orphans.d.type" VALUE = "Orders">
				<MvASSIGN NAME = "Orphans.d.value" VALUE = "{ BasketList.d.order_id }">

				<MvADD NAME = "Orphans">
			</MvIF>
			<MvFIND NAME = "Baskets" VALUE = "{ BasketList.d.basket_id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT Baskets.d.EOF ) AND ( Baskets.d.id EQ BasketList.d.basket_id ) }">
				<MvFIND NAME = "BasketOptions" VALUE = "{ Baskets.d.line_id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT BasketOptions.d.EOF ) AND ( BasketOptions.d.line_id EQ Baskets.d.line_id ) }">
					<MvDELETE NAME = "BasketOptions">
					<MvSKIP NAME = "BasketOptions" ROWS = 1>
				</MvWHILE>

				<MvIF EXPR = "{ g.Features:Inventory:Enabled }">
					<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Baskets.d.product_id, Baskets.d.quantity ) }">
				</MvIF>
				<MvIF EXPR = "{ l.ok }">
					<MvDELETE NAME = "Baskets">
				</MvIF>
				<MvSKIP NAME = "Baskets" ROWS = 1>
			</MvWHILE>

			<MvDELETE NAME = "BasketList">

			<MvSKIP NAME = "BasketList" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| UserXStore
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Open_UserXStore" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_UserXStore_Open }">
		<MvOPEN NAME = "UserXStore"
				DATABASE = "{ g.MerchantPath $ 'usrxstor.dbf' }"
				INDEXES = "{ g.MerchantPath $ 'uxs_stor.mvx, ' $ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00264', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_UserXStore_Open" VALUE = 1>
			<MvFILTER NAME = "UserXStore" FILTER = "{ NOT UserXStore.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXStore_Set_Manager" PARAMETERS = "store_id, user_id, manager" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvFIND NAME = "UserXStore" VALUE = "{ l.user_id $ ':' $ padl( l.store_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ l.manager }">
			<MvIF EXPR = "{ UserXStore.d.EOF }">
				<MvASSIGN NAME = "UserXStore.d.store_id" 	VALUE = "{ l.store_id }">
				<MvASSIGN NAME = "UserXStore.d.user_id" 	VALUE = "{ l.user_id }">
				<MvASSIGN NAME = "UserXStore.d.manager" 	VALUE = 1>
				<MvASSIGN NAME = "UserXStore.d.groupcount" 	VALUE = 0>

				<MvADD NAME = "UserXStore">
			<MvELSE>
				<MvASSIGN NAME = "UserXStore.d.manager" VALUE = 1>
				<MvUPDATE NAME = "UserXStore">
			</MvIF>
		<MvELSE>
			<MvIF EXPR = "{ UserXStore.d.EOF }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00101">
					<MvLOCALIZED-TOKEN NAME = "user_id"  VALUE = "{ encodeentities( l.user_id ) }">
					<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( l.store_id ) }">

					<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%user_id%' not found for store '%store_id%'</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00265', l.error ) }">
			<MvELSE>
				<MvIF EXPR = "{ UserXStore.d.groupcount EQ 0 }">
					<MvDELETE NAME = "UserXStore">
				<MvELSE>
					<MvASSIGN NAME = "UserXStore.d.manager" VALUE = 0>
					<MvUPDATE NAME = "UserXStore">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXStore_Increment_Groups" PARAMETERS = "store_id, user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvFIND NAME = "UserXStore" VALUE = "{ l.user_id $ ':' $ padl( l.store_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ UserXStore.d.EOF }">
			<MvASSIGN NAME = "UserXStore.d.store_id" 	VALUE = "{ l.store_id }">
			<MvASSIGN NAME = "UserXStore.d.user_id" 	VALUE = "{ l.user_id }">
			<MvASSIGN NAME = "UserXStore.d.manager" 	VALUE = 0>
			<MvASSIGN NAME = "UserXStore.d.groupcount" 	VALUE = 1>

			<MvADD NAME = "UserXStore">
		<MvELSE>
			<MvASSIGN NAME = "UserXStore.d.groupcount" VALUE = "{ UserXStore.d.groupcount + 1 }">
			<MvUPDATE NAME = "UserXStore">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXStore_Decrement_Groups" PARAMETERS = "store_id, user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvFIND NAME = "UserXStore" VALUE = "{ l.user_id $ ':' $ padl( l.store_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ UserXStore.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00102">
				<MvLOCALIZED-TOKEN NAME = "user_id" VALUE = "{ encodeentities( l.user_id ) }">
				<MvLOCALIZED-TOKEN NAME = "store_id" VALUE = "{ encodeentities( l.store_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%user_id%' not found for store '%store_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00266', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ ( UserXStore.d.groupcount EQ 1 ) AND ( NOT UserXStore.d.manager ) }">
				<MvDELETE NAME = "UserXStore">
			<MvELSE>
				<MvASSIGN NAME = "UserXStore.d.groupcount" VALUE = "{ UserXStore.d.groupcount - 1 }">
				<MvUPDATE NAME = "UserXStore">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXStore_Delete_Store" PARAMETERS = "store_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_stor.mvx' }">
		<MvFIND NAME = "UserXStore" VALUE = "{ l.store_id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT UserXStore.d.EOF ) AND ( UserXStore.d.store_id EQ l.store_id ) }">
			<MvDELETE NAME = "UserXStore">
			<MvSKIP NAME = "UserXStore" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXStore_Delete_User" PARAMETERS = "user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_UserXStore() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXStore" INDEX = "{ g.MerchantPath $ 'uxs_user.mvx' }">
		<MvPRIMARY NAME = "Stores" INDEX = "{ g.MerchantPath $ 'str_id.mvx' }">

		<MvFIND NAME = "UserXStore" VALUE = "{ l.user_id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT UserXStore.d.EOF ) AND ( UserXStore.d.user_id EQ l.user_id ) }">
			<MvIF EXPR = "{ UserXStore.d.manager }">
				<MvFIND NAME = "Stores" VALUE = "{ UserXStore.d.store_id }" EXACT>
				<MvIF EXPR = "{ NOT Stores.d.EOF }">
					<MvASSIGN NAME = "Stores.d.manager_id" VALUE = 0>
					<MvUPDATE NAME = "Stores">
				</MvIF>
			</MvIF>

			<MvDELETE NAME = "UserXStore">
			<MvSKIP NAME = "UserXStore" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Privileges
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Open_Privileges" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Privileges_Open }">
		<MvOPEN NAME = "Privileges"
				DATABASE = "{ g.MerchantPath $ 'privs.dbf' }"
				INDEXES = "{ g.MerchantPath $ 'prv_priv.mvx, ' $ g.MerchantPath $ 'prv_name.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00267', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Privileges_Open" VALUE = 1>
			<MvFILTER NAME = "Privileges" FILTER = "{ NOT Privileges.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Privilege_Insert" PARAMETERS = "privilege, name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Privileges() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "Privileges.d.privilege" VALUE = "{ l.privilege }">
		<MvASSIGN NAME = "Privileges.d.name" VALUE = "{ l.name }">

		<MvADD NAME = "Privileges">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Privilege_Delete" PARAMETERS = "privilege" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Open_Privileges() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Privileges" INDEX = "{ g.MerchantPath $ 'prv_priv.mvx' }">
		<MvFIND NAME = "Privileges" VALUE = "{ l.privilege }" EXACT>
		<MvIF EXPR = "{ Privileges.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00103">
				<MvLOCALIZED-TOKEN NAME = "privilege" VALUE = "{ encodeentities( l.privilege ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Privilege '%privilege%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00268', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "Privileges">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Privilege_Find" PARAMETERS = "privilege" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Open_Privileges() }">
		<MvPRIMARY NAME = "Privileges" INDEX = "{ g.MerchantPath $ 'prv_priv.mvx' }">
		<MvFIND NAME = "Privileges" VALUE = "{ l.privilege }" EXACT>
		<MvIF EXPR = "{ Privileges.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00104">
				<MvLOCALIZED-TOKEN NAME = "privilege" VALUE = "{ encodeentities( l.privilege ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Privilege '%privilege%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00315', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Privilege_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Privileges() }">
		<MvPRIMARY NAME = "Privileges" INDEX = "{ g.MerchantPath $ 'prv_name.mvx' }">
		<MvGO NAME = "Privileges" ROW = "top">
		<MvIF EXPR = "{ NOT Privileges.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Privilege_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Open_Privileges() }">	
		<MvSKIP NAME = "Privileges" ROWS = 1>
		<MvIF EXPR = "{ NOT Privileges.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Groups
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_Groups" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Groups_Open }">
		<MvOPEN NAME = "Groups" 
				DATABASE = "{ g._DB_Store_Directory $ 'groups.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'grp_id.mvx, ' $ g._DB_Store_Directory $ 'grp_name.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00269', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "Groups" FILTER = "{ NOT Groups.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_Groups_Open" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_Insert" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.group_id" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Groups() }">
		<MvASSIGN NAME = "Groups.d.id" VALUE = "{ StoreKey_Generate( 'Groups' ) }">
		<MvASSIGN NAME = "Groups.d.name" VALUE = "{ l.name }">

		<MvADD NAME = "Groups">

		<MvASSIGN NAME = "l.group_id" VALUE = "{ Groups.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.group_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_Update" PARAMETERS = "id, name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Groups() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Groups" INDEX = "{ g._DB_Store_Directory $ 'grp_id.mvx' }">
		<MvFIND NAME = "Groups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Groups.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00105">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00270', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Groups.d.name" VALUE = "{ l.name }">
			<MvUPDATE NAME = "Groups">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Groups() AND 
									   _DB_Store_Open_GroupPrivileges() AND
									   _DB_Store_Open_UserXGroup() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Groups" INDEX = "{ g._DB_Store_Directory $ 'grp_id.mvx' }">
		<MvFIND NAME = "Groups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Groups.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00106">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00271', l.error ) }">
		<MvELSE>
			<MvFIND NAME = "GroupPrivileges" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT GroupPrivileges.d.EOF ) AND ( GroupPrivileges.d.group_id EQ l.id ) }">
				<MvDELETE NAME = "GroupPrivileges">
				<MvSKIP NAME = "GroupPrivileges" ROWS = 1>
			</MvWHILE>

			<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }">
			
			<MvFIND NAME = "UserXGroup" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ l.ok AND ( NOT UserXGroup.d.EOF ) AND ( UserXGroup.d.group_id EQ l.id ) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Decrement_Groups( Stores.d.id, UserXGroup.d.user_id ) }">

				<MvDELETE NAME = "UserXGroup">
				<MvSKIP NAME = "UserXGroup" ROWS = 1>
			</MvWHILE>

			<MvDELETE NAME = "Groups">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_Find_Name" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Groups() }">
		<MvPRIMARY NAME = "Groups" INDEX = "{ g._DB_Store_Directory $ 'grp_name.mvx' }">
		<MvFIND NAME = "Groups" VALUE = "{ toupper( l.name ) }" EXACT>
		<MvIF EXPR = "{ NOT Groups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00107">
				<MvLOCALIZED-TOKEN NAME = "name" VALUE = "{ encodeentities( l.name ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Group '%name%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00272', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Groups() }">
		<MvGO NAME = "Groups" ROW = "top">
		<MvIF EXPR = "{ NOT Groups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "Groups" ROWS = 1>
	<MvIF EXPR = "{ Groups.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| GroupPrivileges
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_GroupPrivileges" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_GroupPrivileges_Open }">
		<MvOPEN NAME = "GroupPrivileges" 
				DATABASE = "{ g._DB_Store_Directory $ 'grppriv.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'grppriv.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00273', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "GroupPrivileges" FILTER = "{ NOT GroupPrivileges.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_GroupPrivileges_Open" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "GroupPrivilege_Insert" PARAMETERS = "group_id, privilege, view, add, modify, delete" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_GroupPrivileges() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "GroupPrivileges.d.group_id" 	VALUE = "{ l.group_id }">
		<MvASSIGN NAME = "GroupPrivileges.d.privilege" 	VALUE = "{ l.privilege }">
		<MvASSIGN NAME = "GroupPrivileges.d.view" 		VALUE = "{ l.view }">
		<MvASSIGN NAME = "GroupPrivileges.d.add" 		VALUE = "{ l.add }">
		<MvASSIGN NAME = "GroupPrivileges.d.modify" 	VALUE = "{ l.modify }">
		<MvASSIGN NAME = "GroupPrivileges.d.delete" 	VALUE = "{ l.delete }">

		<MvADD NAME = "GroupPrivileges">

		<MvASSIGN NAME = "l.ok" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "GroupPrivilege_Update" PARAMETERS = "group_id, privilege, view, add, modify, delete" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_GroupPrivileges() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "GroupPrivileges" VALUE = "{ l.group_id $ ':' $ l.privilege }" EXACT>
		<MvIF EXPR = "{ GroupPrivileges.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00108">
				<MvLOCALIZED-TOKEN NAME = "privilege" VALUE = "{ encodeentities( l.privilege ) }">
				<MvLOCALIZED-TOKEN NAME = "group_id" VALUE = "{ encodeentities( l.group_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Privilege '%privilege%' for group '%group_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00274', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "GroupPrivileges.d.view" 	VALUE = "{ l.view }">
			<MvASSIGN NAME = "GroupPrivileges.d.add" 	VALUE = "{ l.add }">
			<MvASSIGN NAME = "GroupPrivileges.d.modify" VALUE = "{ l.modify }">
			<MvASSIGN NAME = "GroupPrivileges.d.delete" VALUE = "{ l.delete }">

			<MvUPDATE NAME = "GroupPrivileges">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "GroupPrivilege_Find" PARAMETERS = "group_id, privilege" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_GroupPrivileges() }">
		<MvFIND NAME = "GroupPrivileges" VALUE = "{ l.group_id $ ':' $ l.privilege }" EXACT>
		<MvIF EXPR = "{ NOT GroupPrivileges.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| UserXGroup
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_UserXGroup" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_UserXGroup_Open }">
		<MvOPEN NAME = "UserXGroup" 
				DATABASE = "{ g._DB_Store_Directory $ 'usrxgrp.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'uxg_user.mvx, ' $
							 g._DB_Store_Directory $ 'uxg_grp.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00275', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "UserXGroup" FILTER = "{ NOT UserXGroup.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_UserXGroup_Open" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXGroup_Insert" PARAMETERS = "user_id, group_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_UserXGroup() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "UserXGroup.d.user_id"  VALUE = "{ l.user_id }">
		<MvASSIGN NAME = "UserXGroup.d.group_id" VALUE = "{ l.group_id }">

		<MvADD NAME = "UserXGroup">

		<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Increment_Groups( Stores.d.id, l.user_id ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXGroup_Delete" PARAMETERS = "user_id, group_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_UserXGroup() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }">
		<MvFIND NAME = "UserXGroup" VALUE = "{ l.group_id $ ':' $ padl( l.user_id, 10, '0' ) }">
		<MvIF EXPR = "{ UserXGroup.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-DTB-00109">
				<MvLOCALIZED-TOKEN NAME = "user_id"  VALUE = "{ encodeentities( l.user_id ) }">
				<MvLOCALIZED-TOKEN NAME = "group_id" VALUE = "{ encodeentities( l.group_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">User '%user_id%' is not a member of group '%group_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00276', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "UserXGroup">

			<MvASSIGN NAME = "l.ok" VALUE = "{ UserXStore_Decrement_Groups( Stores.d.id, l.user_id ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXGroup_Find" PARAMETERS = "user_id, group_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_UserXGroup() }">
		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }">
		<MvFIND NAME = "UserXGroup" VALUE = "{ l.group_id $ ':' $ padl( l.user_id, 10, '0' ) }">
		<MvIF EXPR = "{ NOT UserXGroup.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXGroup_FindFirst_Group" PARAMETERS = "group_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_UserXGroup() }">
		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }">
		<MvFIND NAME = "UserXGroup" VALUE = "{ l.group_id $ ':' }">
		<MvIF EXPR = "{ NOT UserXGroup.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXGroup_FindNext_Group" PARAMETERS = "group_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "UserXGroup" ROWS = 1>
	<MvIF EXPR = "{ ( UserXGroup.d.EOF ) OR ( UserXGroup.d.group_id NE l.group_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "UserXGroup_Delete_User" PARAMETERS = "user_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_UserXGroup() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_user.mvx' }">

		<MvFIND NAME = "UserXGroup" VALUE = "{ l.user_id }">
		<MvWHILE EXPR = "{ ( NOT UserXGroup.d.EOF ) AND ( UserXGroup.d.user_id EQ l.user_id ) }">
			<MvDELETE NAME = "UserXGroup">
			<MvSKIP NAME = "UserXGroup" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Group_User_FindOffset_Unassigned" PARAMETERS = "group_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Open_Users() AND _DB_Store_Open_UserXGroup() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">
		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _User_Filter( l.search ) }">
		<MvFILTER NAME = "Users" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Users" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Users.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "UserXGroup" VALUE = "{ l.group_id $ ':' $ padl( Users.d.id, 10, '0' ) }" EXACT>
			<MvIF EXPR = "{ UserXGroup.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Users" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Group_User_FindNext_Unassigned" PARAMETERS = "group_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Users" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Users.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "UserXGroup" VALUE = "{ l.group_id $ ':' $ padl( Users.d.id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ UserXGroup.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Users" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Users" FILTER = "{ NOT Users.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Group_User_FindOffset_Assigned" PARAMETERS = "group_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Open_Users() AND _DB_Store_Open_UserXGroup() }">
		<MvPRIMARY NAME = "Users" INDEX = "{ g.MerchantPath $ 'usr_id.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _User_Filter( l.search ) }">
		<MvFILTER NAME = "Users" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_grp.mvx' }">
		<MvFIND NAME = "UserXGroup" VALUE = "{ l.group_id $ ':' }">
		<MvSKIP NAME = "UserXGroup" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT UserXGroup.d.EOF ) AND ( UserXGroup.d.group_id EQ l.group_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Users" VALUE = "{ UserXGroup.d.user_id }" EXACT>
			<MvIF EXPR = "{ NOT Users.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "UserXGroup" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Group_User_FindNext_Assigned" PARAMETERS = "group_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "UserXGroup" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT UserXGroup.d.EOF ) AND ( UserXGroup.d.group_id EQ l.group_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Users" VALUE = "{ UserXGroup.d.user_id }" EXACT>
		<MvIF EXPR = "{ NOT Users.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "UserXGroup" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Users" FILTER = "{ NOT Users.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvCOMMENT>
|
| User_Check_Privileges
|
</MvCOMMENT>

<MvFUNCTION NAME = "User_Check_Privileges" PARAMETERS = "user_id, privilege, can_view, can_add, can_modify, can_delete" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.has_privileges" VALUE = 0>
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Groups() AND 
									   _DB_Store_Open_UserXGroup() AND
									   _DB_Store_Open_GroupPrivileges() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.need_view"   VALUE = "{ l.can_view }">
		<MvASSIGN NAME = "l.need_add"    VALUE = "{ l.can_add }">
		<MvASSIGN NAME = "l.need_modify" VALUE = "{ l.can_modify }">
		<MvASSIGN NAME = "l.need_delete" VALUE = "{ l.can_delete }">
							  
		<MvPRIMARY NAME = "UserXGroup" INDEX = "{ g._DB_Store_Directory $ 'uxg_user.mvx' }">
		<MvFIND NAME = "UserXGroup" VALUE = "{ l.user_id }" EXACT>
		<MvWHILE EXPR = "{ ( l.need_view OR l.need_add OR l.need_modify OR l.need_delete ) AND
						   ( NOT UserXGroup.d.EOF ) AND ( UserXGroup.d.user_id EQ l.user_id ) }">
			<MvFIND NAME = "GroupPrivileges" VALUE = "{ UserXGroup.d.group_id $ ':' $ l.privilege }">
			<MvIF EXPR = "{ NOT GroupPrivileges.d.EOF }">
				<MvIF EXPR = "{ GroupPrivileges.d.view }">
					<MvASSIGN NAME = "l.need_view" VALUE = 0>
				</MvIF>

				<MvIF EXPR = "{ GroupPrivileges.d.add }">
					<MvASSIGN NAME = "l.need_view" VALUE = 0>
					<MvASSIGN NAME = "l.need_add"  VALUE = 0>
				</MvIF>

				<MvIF EXPR = "{ GroupPrivileges.d.modify }">
					<MvASSIGN NAME = "l.need_view"   VALUE = 0>
					<MvASSIGN NAME = "l.need_modify" VALUE = 0>
				</MvIF>

				<MvIF EXPR = "{ GroupPrivileges.d.delete }">
					<MvASSIGN NAME = "l.need_view"   VALUE = 0>
					<MvASSIGN NAME = "l.need_delete" VALUE = 0>
				</MvIF>
			</MvIF>

			<MvSKIP NAME = "UserXGroup" ROWS = 1>
		</MvWHILE>

		<MvASSIGN NAME = "l.has_privileges" VALUE = "{ NOT ( l.need_view OR l.need_add OR l.need_modify OR l.need_delete ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.has_privileges }">
</MvFUNCTION>

<MvCOMMENT>
|
| StandardFields 
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_StandardFields" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_StandardFields_Open }">
		<MvOPEN NAME = "StandardFields"
				DATABASE = "{ g._DB_Store_Directory $ 'std_fld.dbf' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Library_Filename_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00394', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_StandardFields_Open" VALUE = 1>
			<MvFILTER NAME = "StandardFields" FILTER = "{ NOT StandardFields.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Get_StandardFields" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "">
	<MvFUNCTIONRETURN VALUE = "{ _DB_Store_Open_StandardFields() }">
</MvFUNCTION>

<MvFUNCTION NAME = "StandardFields_Update" PARAMETERS = "bill, fname, lname, email, phone, fax, comp, addr, city, state, zip, cntry" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_StandardFields() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "StandardFields.d.billing" 	VALUE = "{ l.bill }">
		<MvASSIGN NAME = "StandardFields.d.mode_fname" 	VALUE = "{ l.fname }">
		<MvASSIGN NAME = "StandardFields.d.mode_lname" 	VALUE = "{ l.lname }">
		<MvASSIGN NAME = "StandardFields.d.mode_email" 	VALUE = "{ l.email }">
		<MvASSIGN NAME = "StandardFields.d.mode_comp" 	VALUE = "{ l.comp }">
		<MvASSIGN NAME = "StandardFields.d.mode_phone" 	VALUE = "{ l.phone }">
		<MvASSIGN NAME = "StandardFields.d.mode_fax" 	VALUE = "{ l.fax }">
		<MvASSIGN NAME = "StandardFields.d.mode_addr" 	VALUE = "{ l.addr }">
		<MvASSIGN NAME = "StandardFields.d.mode_city" 	VALUE = "{ l.city }">
		<MvASSIGN NAME = "StandardFields.d.mode_state" 	VALUE = "{ l.state }">
		<MvASSIGN NAME = "StandardFields.d.mode_zip" 	VALUE = "{ l.zip }">
		<MvASSIGN NAME = "StandardFields.d.mode_cntry" 	VALUE = "{ l.cntry }">
		<MvUPDATE NAME = "StandardFields">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>
