$(document).ready(function () {		
if ($("table.cart")) {
$("table.cart input.remove").each(function (i) {
$(this).click(function () {
	var dt = new Date();
	var k = "_" + $(this).next("input").eq(0).val();
	var thisq = $(this).parent("td").parent("tr").find("input.qty").val()*1;
					
	var em = $(this).parent("td").parent("tr");
	//get the price for this product as going to change the cart total for this line

	var itempricewotax = $(this).parent('td').parent('tr').find('input.pricewotax').eq(0).val()*1;
	var itempricewtax = $(this).parent('td').parent('tr').find('input.pricewtax').eq(0).val()*1;

	$.post('/index.php?route=module/cart/callback',{d:dt.getTime(),remove:k,removingajax:"true"},function (data) {
		if (data !== "false") {

/*
               		if (itempricewotax !== itempricewtax) {
                		        var vatstr = $('div.vat').text();
		                        var vat = '';
                		        for (i = 1;i<= vatstr.length;i++) {
		                            vat += vatstr[i];
        	       		        }
	                        	//vat is the vat in the system so need to remove the vat of this item!

					if (((vat*1 - (itempricewtax  - itempricewotax)*thisq) < 0) || ((vat*1 - (itempricewtax  - itempricewotax)*thisq) == "NaN") || ((vat*1 - (itempricewtax  - itempricewotax)*thisq) == NaN)) {

					       $('div.vat').html(vatstr[0] + "0.00");

					} else {
	                		        $('div.vat').html(vatstr[0] + (vat*1 - (itempricewtax  - itempricewotax)*thisq).toFixed(2));

					}

			}*/


			em.find("input.qty").removeClass("qty");

			em.remove();

			var s = 0;

			$("input.qty").each(function (u) {

				s += $(this).val()*1;

			});

			$("span.cartnumm").html(s);


			var str = data.split("<>");

			$("div.cartmiddle span.items").html(totalsurroundstart + str[str.length-1] + totalsurroundend);


			$("div.subtotal").html("Total &#163;" + str[0]);

			if (str.length > 2) {
                   		$("div.vat").html("&#163;" + str[1]);

			
			$("div.totalfinal").html("&#163;" + str[2]);

			
			if ((s > 1) || (s == 0)) {

			
					$('a.cartnum span.fl').html(itemspltext + "in your bag");

			
			} else {

			
				$('a.cartnum span.fl').html(itemstext + "in your bag");

			
			}
    
			} else {

				$("div.totalfinal").html("&#163;" + str[1]);

				$("div.vat").html("&#163;0.00");

				if ((s > 1) || (s == 0)) {
		        		$('a.cartnum span.fl').html(itemspltext + "in your bag");

				} else {
		        		$('a.cartnum span.fl').html(itemstext + "in your bag");

				}

			}

			var w = 120 - $("span.cartnumm").width()*1;

			w = (w <= 90)?w:90;


			$("span.cartnumm").next("span").css("width",w+"px");

					if (replacetext === true) {

			
			Cufon.replace(replacement);

			
			Cufon.now();

					}

		}
	});

	return false;
});
});

$("table.cart input.minus").each(function (i) {
$(this).click(function () {
	var q = $(this).next("input").val()*1 - 1;
	var em = $(this).parent("td").parent("tr");

	var dt = new Date();
	var thisq = $(this).parent("td").find("input.qty").val()*1;
					
	var pid = em.find("td").eq(0).find("input.key").val();
	
   //get the price for this product as going to change the cart total for this line

    var itempricewotax = ($(this).parent('td').find('input.pricewotax').eq(0).val()*1).toFixed(2);
    var itempricewtax = ($(this).parent('td').find('input.pricewtax').eq(0).val()*1).toFixed(2);
	
    var td = $(this).parent('td');
	
	$.post('/index.php?route=module/cart/callback',{d:dt.getTime(),quantity:q,product_id:pid,minusq:true},function (data) {
		if (data !== "false") {


			if (parseInt(q) == 0) {

				em.find("input.qty").removeClass("qty");em.remove();

			} else {

				em.find("input.qty").val(q);

			}

			var str = data.split("<>");



			var s = 0;

			$("input.qty").each(function (u) {

				s += $(this).val()*1;

			});

			$("span.cartnumm").html(s);

			$("div.cartmiddle span.items").html(totalsurroundstart + str[str.length-1] + totalsurroundend);


	      		td.next('td').html(td.next('td').text()[0] + (itempricewotax*q).toFixed(2)).next('td').html(td.next('td').text()[0] + (itempricewtax*q).toFixed(2));



			$("div.subtotal").html("&#163;" + str[0]);

			if (str.length > 2) {
		                $("div.vat").html("&#163;" + str[1]);

				$("div.totalfinal").html("&#163;" + str[2]);

				if ((s > 1) || (s == 0)) {
		        		$('a.cartnum span.fl').html(itemspltext + "in your bag");

				} else {
		        		$('a.cartnum span.fl').html(itemstext + "in your bag");

				}
    
			} else {

				$("div.totalfinal").html("&#163;" + str[1]);


				if ((s > 1) || (s == 0)) {
		        		$('a.cartnum span.fl').html(itemspltext + "in your bag");

				} else {
		        		$('a.cartnum span.fl').html(itemstext + "in your bag");

				}

	         	        /* check that the VAT is not still displayed! */
	                        if (itempricewotax !== itempricewtax) {

			                if (q == 0) {
                        
			var vatstr = $('div.vat').text();

			                        var vat = '';
                        
			for (i = 1;i<= vatstr.length;i++) {

			                            vat += vatstr[i];
                        
			}


			                        //vat is the vat in the system so need to remove the vat of this item!
                        
			$('div.vat').html(vatstr[0] + (parseFloat(vat) - parseFloat(itempricewtax*1 - itempricewotax*1)).toFixed(2));

		                      }
                      
                      
	        	       }
	               

			}
/*

			var w = 120 - $("span.cartnumm").width()*1;

			w = (w <= 90)?w:90;


			$("span.cartnumm").next("span").css("width",w+"px");
*/

					if (replacetext === true) {

			
			Cufon.replace(replacement);

			
			Cufon.now();

					}

		}
	});
	return false;});
});

$("table.cart input.plus").each(function (i) {
	$(this).click(function () {
		var q = $(this).prev("input").val()*1 + 1;
		var em = $(this).parent("td").parent("tr");

		var dt = new Date();
		var pid = em.find("td").eq(0).find("input.key").val();

        //get the price for this product as going to change the cart total for this line

        var itempricewotax = ($(this).parent('td').find('input.pricewotax').eq(0).val()*1).toFixed(2);
        var itempricewtax = ($(this).parent('td').find('input.pricewtax').eq(0).val()*1).toFixed(2);

	var thisq = $(this).parent("td").find("input.qty").val()*1;
					

        var td = $(this).parent('td');

		$.post('/index.php?route=module/cart/callback',{d:dt.getTime(),product_id:pid,justone:true},function (data) {

			if (data !== "false") {

				var str = data.split("<>");


				em.find("input.qty").eq(0).val(q);


			var s = 0;

			$("input.qty").each(function (u) {

				s += $(this).val()*1;

			});

				$("span.cartnumm").html(s);

				$("div.cartmiddle span.items").html(totalsurroundstart + str[str.length-1] + totalsurroundend);


			$("div.subtotal").html("&#163;" + str[0]);

			if (str.length > 2) {
                  		 $("div.vat").html("&#163;" + str[1]);

				   $("div.totalfinal").html("&#163;" + str[2]);


				if ((s > 1) || (s == 0)) {

			
			$('a.cartnum span.fl').html(itemspltext + "in your bag");

				} else {
		        		$('a.cartnum span.fl').html(itemstext + "in your bag");

				}
    
			} else {

				$("div.totalfinal").html("&#163;" + str[1]);

				if ((s > 1) || (s == 0)) {
		        		$('a.cartnum span.fl').html(itemspltext + "in your bag");

				} else {
		        		$('a.cartnum span.fl').html(itemstext + "in your bag");

				}


			}
/*
			var w = 120 - $("span.cartnumm").width()*1;

			w = (w <= 90)?w:90;


			$("span.cartnumm").next("span").css("width",w+"px");
*/

					if (replacetext === true) {

			
			Cufon.replace(replacement);

			
			Cufon.now();

					}


                td.next('td').html(td.next('td').text()[0] + (itempricewotax*q).toFixed(2)).next('td').html(td.next('td').text()[0] + (itempricewtax*q).toFixed(2));


			}
		});

		return false;
});	});}});

function IsNumeric(strString) {	var strValidChars = "0123456789";	var strChar;	var blnResult = true;	if (strString.length == 0) {return false;}	for (var i = 0; i < strString.length && blnResult == true; i++) {		strChar = strString.charAt(i);		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;		}	}	return blnResult;}$.removeElement = function (em) {		em.animate({opacity:"0"},250);		setTimeout(function () {if ($("table.cart tbody tr").length >1) {em.prev("tr").find("td").each(function (i) {$(this).css("border-bottom","0px");});} em.remove();},400);		setTimeout(function () {if ($("table.cart tbody tr").length == 0) {$("table.cart tbody").append("<tr><td style='padding:5px;color:#666666' colspan='6'>No items in your cart</td><tr>");}},600);}

