/*!
 * @author Gproxy Design Inc.
 * @copyright (c) 2010, Gproxy Design Inc. All rights reserved.
 * @version 2.0
 *
 * Gproxy doesn't allow to copy or change this code without Gproxy authorization. 
 * See http://www.gproxy.com/licenses/license01.pdf for the full license governing this code. 
 */

/**
 * Get the items in the Shopping Cart
 * @param {Object} strCartURL
 */

/* define the position starting on 0, for the columns in the shopping cart page */
var pos = new function cartColPos(){
	this.name 		= '1';
	this.image 		= '0';
	this.opts	 	= '4';
	this.qty 		= '2';
	this.price 		= '5';
}
 
function mcartGetItems(strCartURL,strMCartContainer) {
	$j.ajax({
	    url: strCartURL,
	    type: "GET",
	    success: function(data){
			var cartRows = $j(data).find("tr[id^=carttablerow]");	
			$j('<ul>').attr('id', 'mcart_list').appendTo('#'+strMCartContainer);
			for (var i=0; i<cartRows.length; i++) {		
				//Retrieve qty from input
				var strItemImage 	= cartRows[i].cells[pos.image].innerHTML;
				var strItemName 	= cartRows[i].cells[pos.name].innerHTML;
				var strItemOptions 	= cartRows[i].cells[pos.opts].innerHTML;
				var cartRowCell 	= cartRows[i].cells[pos.qty].getElementsByTagName('input');
				var strItemQty 		= cartRowCell[0].value;
				var strItemPrice 	= cartRows[i].cells[pos.price].innerHTML;
				$j('<li>').attr('id', 'mcart_list_item' + i).appendTo('#mcart_list');
				$j('<div class="mini-image">').html(strItemImage).appendTo('#mcart_list_item' + i);
				$j('<div class="mini-name">').html(strItemName).appendTo('#mcart_list_item' + i);
				$j('<div class="mini-price">').html('<span class="miniprice">'+ strItemPrice +'</span>').appendTo('#mcart_list_item' + i);
		//		$j('<div class="mini-qty">').html('<span class="miniqty">Qty:' + strItemQty + '</span>').appendTo('#mcart_list_item' + i);
			}	       
	    },
	    error: function(XMLHttpRequest, textStatus, errorThrown){
	        alert('Show Items: ' + textStatus + ', ' + errorThrown);
	    }
	});
}
