<cfquery name="check_for_children" datasource="#application.datasource#">
	SELECT	    *
    FROM	    Items
	WHERE		ItemParentItemID = #attributes.sending_ItemID#
					AND
				ItemIsActive = 1
</cfquery>

<cfif check_for_children.recordcount gt 0>

	<cfoutput query="check_for_children">
    
        <cfquery name="get_main_item" datasource="#application.datasource#">
            SELECT	    *
            FROM	    Items
            WHERE		ItemID = #check_for_children.ItemID#
        </cfquery>
        
        <CFQUERY name="insert_item" datasource="#application.datasource#">
            INSERT INTO 	Items
                            (
                            ItemCategoryID,
							ItemName,
							ItemDescription,
							ItemParentItemID,
							ItemPrice,
							ItemIsActive,
							ItemIsCheckedByDefault,
							ItemRequiresChildSelection,
							ItemMaxNumSelectionReq,
							ItemIsCollapsible,
							ItemSortOrder,
							ItemAddedOn
                            )
            VALUES 			(
                             #get_main_item.ItemCategoryID#,
							'#get_main_item.ItemName#',
							'#get_main_item.ItemDescription#',
							 #attributes.ParentID#,
							 #get_main_item.ItemPrice#,
							 #get_main_item.ItemIsActive#,
							 #get_main_item.ItemIsCheckedByDefault#,
							 #get_main_item.ItemRequiresChildSelection#,
							 #get_main_item.ItemMaxNumSelectionReq#,
							 #get_main_item.ItemIsCollapsible#,
							 #get_main_item.ItemSortOrder#,
							 #createODBCDateTime(now())#
                            )
        </CFQUERY>
			
        <CFQUERY name="get_last_inserted" datasource="#application.datasource#">
            SELECT 			ItemID
            FROM 		 	Items
            ORDER BY		ItemID DESC 
            Limit 			1
        </CFQUERY>

        <cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_clone_do.cfm" sending_ItemID=#get_main_item.ItemID# ParentID=#get_last_inserted.ItemID#>

	</cfoutput>
	
</cfif>