/*
 * Place all XMLHttpRequest submissions here. This allows a clean presentation
 * of all functions that requires the use of xml_http_requester.js for
 * sending out XMLHttpRequests.
 */
 
/* For updating the My Cart: XXX items */
function cartStatus(context)
{
	var queryString = context + "/templates/ajax/header_view_cart.jsp?";
	queryString = queryString + "timeStamp=" + new Date().getTime();
	xmlreqGET(queryString, 'cartStatus', 'fill');
	
	queryString = context + "/templates/ajax/header_checkout.jsp?";
	queryString = queryString + "timeStamp=" + new Date().getTime();
	xmlreqGET(queryString, 'cartCheckOut', 'fill');
}

/* For static pages with "Add to your cart" buttons, this function
 * determines whether to display "Notify me when item is in stock" or 
 * "Add to your cart" links */
function inStock(context, product_id, element_id, display_type)
{	
	var queryString = context + "/product/in_stock_request_handler.jsp?";
	queryString = queryString + "timeStamp=" + new Date().getTime() + "&product_id=" + product_id + "&display_type=" + display_type;	
	xmlreqGET(queryString, element_id, 'fill');
}

/* For static pages with "Add to your cart" buttons, this function
 * determines whether to display "Notify me when item is in stock" or 
 * "Add to your cart" links. For sortable search results only */
function inStockAppend(context, product_id, element_id, display_type)
{	
	var queryString = context + "/product/in_stock_request_handler.jsp?";
	queryString = queryString + "timeStamp=" + new Date().getTime() + "&product_id=" + product_id + "&display_type=" + display_type;	
	xmlreqGET(queryString, element_id, 'append');
}

/* Place a product, based on product_id,  into session as a recently viewed item */
function recentlyViewedProduct(context, product_id)
{
	var queryString = context + "/servlet/RecentlyViewedServlet?ref=PRODUCT&max_number_products=2&timeStamp=" + new Date().getTime();
	var data = "product_id=" + product_id;
	xmlreqPOST(queryString, data);	
}

/* Get products from session as a recently viewed item */
function getRecentlyViewedProduct(context, element_id)
{
	var queryString = context + "/templates/most_recently_viewed_handler.jsp?timeStamp=" + new Date().getTime();
	xmlreqGET(queryString, element_id, 'fill');	
}
