$(function(){
    try {
        $('a.tooltip').betterTooltip({speed: 100, delay: 50});
    } catch (e) {

    }
    $('.basket-link').mouseover(
        function() {
            $('#basket-popup').show();
        }
    );
        
        $('.gardenpharmacybasketlink').replaceWith('<tr class="basketProductRow"><td colspan="6"><a href="https://www.gardenpharmacy.co.uk/php/showBasket.php?viewBasket">Click here to view this product</a></td></tr>');
        $('.gardenpharmacybasketsummarylink').replaceWith('<tr><td colspan="2"><a style="color:#000000;" href="https://www.gardenpharmacy.co.uk/php/showBasket.php?viewBasket">Click here to view this product</a></td></tr>');
        
        var total = 0;
        var count = 0;
        $('.gardenpharmacycheckoutlink').each(function() {
            $(this).hide();
            var line = $('td:nth-child(6)', this).text().replace('£','');
            
            if (line == 'FREE') {
                line = 0;
            }
            total += parseFloat(line);
            count++;
            
        });
        
        if (total > 0) {
            var item = 'item';
            if (count > 1) {
                item = 'items';
            }
            $('table.basket').before('<div style="margin-bottom: 10px; border: 1px solid #4D4D4D;"><p style="background-color: #ECECEC; margin: 0; padding: 5px; border-bottom: 1px solid #4D4D4D; color: red;">There are also items in your Dermalogica basket which are <strong>included</strong> in the total below. <a href="https://www.gardenpharmacy.co.uk/php/checkout.php?checkout">Click here to view them.</a></p>'
                + '<p style="text-align: right; margin: 0; padding: 5px;"><strong>Subtotal: &pound;' + total + '</strong></p></div>');
        }
});

function checkFreeGiftSelection()
{
	if (document.getElementById('giftForm'))
	{
		var boxesChecked = false;
		var numCheckBoxes = document.forms["giftChoice"].elements.length;
		
		// do something
		for (i=0; i<numCheckBoxes; i++)
		{
			//var el = document.forms["giftChoice"].elements[i];
			
			if (document.forms["giftChoice"].elements[i].type=="checkbox"){
				if (document.forms["giftChoice"].elements[i].checked) {
					boxesChecked = true;
				}
			}
		}
		
		if (boxesChecked == false)
		{
			alert("You have qualified for a free gift. Please ensure you select your free gift and then click 'Add Gift' to ensure this is placed in your basket.");
			return false;
		}
	}
}

