// JavaScript Document

$(document).ready( function ()
{
	calculate();
	
	
	$(".logout").click (function ()
	{
		window.location.href="index.php?lo=true";
	});
	$(".chkRenew").change( function ()
	{
		calculate();
	});
	
});

	function calculate()
	{
		//alert("calc");
		
		var totalPrice = 0;
		var paypalText = "";

		$(".customer_row .customer_product_period_row").each( function (zeroindex)
		{
			var chkBox = $(this).find(".chkRenew");
			
			//Only include those ticked
			if (chkBox.attr("checked") == true)
			{
			
				var index = zeroindex+1;
				var thisPrice = parseFloat($(this).attr("price"));
				totalPrice += thisPrice ;
				
				var groupRow = $(this).parents(".customerProductGroup");
				
	//			alert(groupRow.attr("class"));
				
				var description = groupRow.attr("productDescription") + " " + groupRow.attr("productName") + " " + $(this).attr("periodName") + " " + $(this).attr("startDate") + " to " + $(this).attr("endDate");
	
	
				paypalText += "	<input type='hidden' name='item_name_" + index + "' value='" + description + "'>";
				paypalText += "	<input type='hidden' name='amount_" + index + "' value='" + thisPrice  + "'>";
				paypalText += "	<input type='hidden' id='quantity_" + index + "' name='quantity_1' value='1'>";
			
			}
			
		});
		

		$("#totalPriceValue").html("&pound;" + totalPrice.toFixed(2));
		
		$("#paypalLines").html(paypalText);
		
		//Add PayPal Info
		
		

		

		
		
			
	}
