		$(document).ready(function() {

		   // Sets the current page's menu item to have class "active"
		   // Assumes: #menu > li > a > href==request_uri - so be consistent!
		   //$("#menu").find("li").each(function(i) {
			//	var childLink = $(this).children().get(0);
			//	var currentPage = "<?=$_SERVER['REQUEST_URI']?>";

			//	if ($(childLink).attr("href") == currentPage)
			//		$(this).addClass("active");
		   //});


			$("input.number").blur(function() {
				$(this).val($(this).val().replace(/[^0-9]/gi, ""));
			});

			$("input[type=radio]").click(function() {
				if ($(this).attr("name")=="paymethod") {
					if ($(this).val()=="Credit Card") $("#carddetails").show();
					else $("#carddetails").hide();
				}
			});

		   $("table.cart").find("td").each(function(i) {
			if ($(this).text().substring(0,1)=="$" || $(this).text().substring(0,2)=="-$") 
			{
				$(this).css("text-align", "right");
				$(this).css("font-size", "14px");
				//console.log("Dunnit!");
			}
		   });

			$('a#select_image').click( function() {
				var str = "<img src='" + $(this).attr("rel") + "'>";
				$("#showimage").text(str);
				return false;
				});


		   $("#btnAddToCart").click(function(e) {
			   var proceed = true;
			   e.preventDefault();

			   var valtouse = $("#quantity").val();

			   if (valtouse < 0.3) {
				   alert("Qty must be specified in increments of 0.1m - minimum amount is 0.3m");
				   proceed = false;
				   return false;
			   }

			   $("#btnAddToCart").attr("href", $("#btnAddToCart").attr("href")+"&quantity="+$("#quantity").val());


			   if (proceed) window.location=$(this).attr("href");
		   });

		   $("#btnAddToCartSale").click(function(e) {
			   var proceed = true;
			   e.preventDefault();

			   var valtouse = $("#quantity").val();

			   if (valtouse < 1) {
				   alert("Qty must be specified in increments of 0.1m - minimum amount is 1.0m");
				   proceed = false;
				   return false;
			   }

			   $("#btnAddToCartSale").attr("href", $("#btnAddToCartSale").attr("href")+"&quantity="+$("#quantity").val());


			   if (proceed) window.location=$(this).attr("href");
		   });

	$("form").submit(function(event) {
		var alertMessage = "";

		//Check the value of each input with class="required"
		$(this).find("input.required").each(function()
		{
			var fieldName = $(this).attr("rel");
			if ($(this).val()=="") {
				alertMessage += fieldName+" is required\n";
			}
			if (fieldName=="Email" && !$(this).val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
				alertMessage += fieldName+" is not a valid email address\n";
			}

		});
		$(this).find("select.required").each(function()
		{
			var fieldName = $(this).attr("rel");
			if ($(this).val()=="") {
				alertMessage += fieldName+" is required\n";
			}
		});		
		
		//If there is an error message, alert it and stop form submission
		if (alertMessage.length > 0) {
			alert(alertMessage);
			return false;
		}
		else return true;
	});



$("#country").change(function(){
		switch($("#country").val()){
			case "Australia":
				$freightvar = $('#freightkeep').val();
				$subtotalvar = $('#totalkeep').val();
				$("#freight").html($freightvar);
				$("#total").html($subtotalvar);
				break;
			default:
				$subtotalvar = $('#subtotalkeep').val();
				$("#freight").html("<i>To be advised</i>");
				$("#total").html($subtotalvar);
				
		}
	});
		startList();
		});
