


/**
 * Desc: removes a product from the cart.
 *
 * @param string $id , product to delete
 * @return false 
 * @uses
 * @author   05-Feb-2007, YDL: 
 */
function addItem(id)
{
     
     new Ajax.Request('index.php?main_page=ajax'
		      
		      
		      , { 
			   
		      method:'post', 
		      parameters:'&rs=add_item' 
				+ '&rsargs[]=' + id
				,
				
				onSuccess: function(transport){
				var response = transport.responseText || "no response text";
//document.getElementById('shipping_quote_debug').innerHTML=response;
				
				//alert("success: " + response);
				getInlineCart();
                                loadViewInDiv('main_total','main_totals');
				
			   }
			   
		      });
     
     return false;
     
}

/**
 * Desc: removes a product from the cart.
 *
 * @param string $id , product to delete
 * @return false 
 * @uses
 * @author   05-Feb-2007, YDL: 
 */
function removeItem(id)
{
     
     new Ajax.Request('index.php?main_page=ajax'
		      
		      
		      , { 
			   
		      method:'post', 
		      parameters:'&rs=remove_item' 
				+ '&rsargs[]=' + id
				,
				
				onSuccess: function(transport){
				var response = transport.responseText || "no response text";
//document.getElementById('shipping_quote_debug').innerHTML=response;
				
				//alert("success: " + response);

                                getInlineCart();
								loadUpsellInDiv("upsales_1.inc","addItem","upsales_1"); 
								loadUpsellInDiv("upsales_2.inc","addItem","upsales_2");
								loadUpsellInDiv("upsales_3.inc","addItem","upsales_3");
								loadUpsellInDiv("upsales_4.inc","addItem","upsales_4");                                 
                                //loadViewInDiv("upseller_left","upseller_left");
//                                loadViewInDiv("upsales_left","upsales_left");
                                //alert(leftUpsellOpen);
                                //alert($('upsales_left').offsetHeight);
//                                leftInner = $('upsales_left').innerHTML;
                                //alert(leftInner.length);
//                                if((leftInner.length > 20) && (leftUpsellOpen == false)){
//                                slideUpsellDown('upsales_left');
//                                }
                                //loadViewInDiv("upseller_right","upseller_right");
//                                loadViewInDiv("upsales_right","upsales_right");
                                //alert(rightUpsellOpen);
                                //alert($('upsales_right').offsetHeight);
//                                rightInner = $('upsales_right').innerHTML;
//                                if((rightInner.length > 20) && (rightUpsellOpen == false)){
//                                slideUpsellDown('upsales_right');
//                                }
                                loadViewInDiv('main_total','main_totals');
				
			   }
			   
		      });
     
     return false;
     
}

function updateQuantity(id,count)
{

new Ajax.Request('index.php?main_page=ajax'


, { 

method:'post', 
parameters:'&rs=update_quantity' 
+ '&rsargs[]=' + id
+ '&rsargs[]=' + count

,

onSuccess: function(transport){
    var response = transport.responseText || "no response text";
//document.getElementById('shipping_quote_debug').innerHTML=response;


//alert("success: " + response);

getInlineCart();
loadViewInDiv('main_total','main_totals');

}

});

return false;

}

function getInlineCart()
{

new Ajax.Request('index.php?main_page=ajax'


, { 

method:'post', 
parameters:'&rs=get_cart_products' 
,

onSuccess: function(transport){
    var response = transport.responseText || "no response text";
//document.getElementById('shipping_quote_debug').innerHTML=response;


rowClasses = ['rowEven','rowOdd'];
rowCount = 0;

eval(response);

  var cart_html = "";

cart_html = 
'          <table border="0" width="100%" cellspacing="0" cellpadding="0" id="cartContentsDisplay">'
+ '            <tr class="cartTableHeading">'
+ '             <td scope="col" id="ccQuantityHeading" width="50" align="center"><b>Qty.</b></th>'
+ '             <td scope="col" id="ccProductsHeading">&nbsp;</th>'
+ '             <td scope="col" id="ccTaxHeading"><b><?php echo HEADING_TAX; ?></b></th>'
+ '             <td scope="col" id="ccTotalHeading" align="right"><b>Total</b></th>'
+ '            </tr>'
;
                                                                                                                                                                                              

//alert("size : " + products.length);
for (x = 0; x < products.length; x++){
    
     cart_html = cart_html 
	  + ' <tr class="' + rowClasses[rowCount] + '">'
	  + '    <td  class="cartQuantity"><input value="' + products[x]['quantity'] + '" size="2" onchange="updateQuantity('+ products[x]['id']+',this.value)">&nbsp;</td>'
	  + '    <td width="50"><img src="images/' + products[x]['image'] + '"  width="50" height="36"></td>'
	  + '    <td class="cartProductDisplay">' + products[x]['name'] + '&nbsp;<a href="#" onClick="javascript:removeItem(' + products[x]['id']  + ');return false;">[remove]</a> </td>'

	  + '    <td class="cartTotalDisplay">' + (Math.round(products[x]['quantity'] * products[x]['final_price'] *100  ) / 100).toFixed(2)  + '</td>'

+ ' </tr> '

;

if(rowCount == 0){rowCount = 1;} else {rowCount = 0;};

}

cart_html = cart_html 
+ '  </table>';

$('cart_contents').innerHTML=cart_html;


//       alert("Success! \n\n" + response);
    },
//         onFailure: function(){ alert('Something went wrong...') }
         onFailure:  function(){ document.getElementById('error-output').innerHTML="get_cart_products failed"; }

});


}

