function shoppingCartUpdations(url,id)
{
		new Ajax.Request(url, {
		   method: "POST",
			onSuccess: function(request)
			{
			  var status = request.responseText;
			  //alert(status);
			  if(status == "removed" || status == "wishlist"){
				document.getElementById('item_'+id).style.display="none";
			  }
			  if(status == "overflow"){
				alert('Enter valid Quantity');
			  }
			}
		});
		grandTotal_ammount();
}

function shoppingCartCancel(url,id){
		new Ajax.Request(url, {
		   method: "POST",
			onSuccess: function(request){
			  var status = request.responseText;
				document.getElementById('total_'+id).value = 0;
				document.getElementById('item_'+id).style.display="none";
				document.getElementById('item_count').innerHTML=status;
                                document.getElementById('item_count_cart').innerHTML=status;
				if(status == 0){
					document.getElementById('place_order').style.display="none";
					document.getElementById('grandTotal').value = 0;
				}
				grandTotal_ammount();			 
			}
		});
}

function shoppingCartWishlist(url,id){
		new Ajax.Request(url, {
		   method: "POST",
			onSuccess: function(request){
			  var status = request.responseText;
				document.getElementById('total_'+id).value = 0;
				document.getElementById('item_'+id).style.display="none";
				document.getElementById('item_count').innerHTML=status;
                                document.getElementById('item_count_cart').innerHTML=status;
				if(status == 0){
					document.getElementById('place_order').style.display="none";
					document.getElementById('grandTotal').value = 0;
				}
				grandTotal_ammount();
			}
		});
}

function count_desc(id,price,shippingcharge)
	{
		var total_item = document.getElementById('quantity_'+id).value;
        if(total_item < 1){
            alert("Please enter valid quantity");
            document.getElementById('quantity_'+id).value = 1;
        }
        else{
            var total_ammount = parseFloat(price*total_item);
            var total_ammountNew = total_ammount.toFixed(2);

            var total_shipping = parseFloat(shippingcharge*total_item);
            var total_shippingNew = total_shipping.toFixed(2);

            var cartTotalValue = parseFloat(total_ammountNew+total_shippingNew);
            var cartTotalValueNew = cartTotalValue.toFixed(2);


            document.getElementById('total_'+id).value = cartTotalValueNew;
            document.getElementById('shipcost_'+id).value =  total_shippingNew;
            var siteURL = document.getElementById('ssiteURL').value;
         
            var url = siteURL+"page_include/inc_updateQuantity.php?itemId="+id+"&quantity="+total_item+"&price="+total_ammountNew+"&shipping="+total_shippingNew;

            shoppingCartUpdations(url,id);
        }
	}
	
function grandTotal_ammount()
{
		document.getElementById('grandTotal').value ="";
		
		var totalCartItems=document.getElementById('bookIds').value;	
		//alert('bookIds'+totalCartItems);
		var total_value=0;
			
			var txt = totalCartItems;
			var arry = txt.split(','); 
			for (i=0;i<arry.length;i++)
			{
				total_value=parseFloat(total_value)+parseFloat(document.getElementById('total_'+arry[i]).value);	 
			}	
			var grandTotal = total_value.toFixed(2)
                        document.getElementById('grandTotal').value = grandTotal;
}

function updateCartItems()
{
	var siteURL = document.getElementById('ssiteURL').value;
	var url = siteURL+"page_include/inc_updateCartItems.php";
	new Ajax.Request(url, {
		   method: "POST",
			onSuccess: function(request)
			{
			  var status = request.responseText;
			  //alert(status);
			  grandTotal_ammount();
			  			 
			}
			
		});
}
