function loadTypes(){
	$("#types").val(0);
	$("#subTypes").val(0);
	$("#brands").val(0);
	$("#colours").val(0);
	/* Disable selects in the hierachy */
	$("#subTypes").attr("disabled", "disabled");
	$("#brands").attr("disabled", "disabled");
	$("#colours").attr("disabled", "disabled");
	
	if($("#products").val() > 0){

		$.get('ajax.php?action=getTypes&ProductCatID=' + $("#products").val(), function(data) {
				  $('#typeSelect').html(data);
			});
		
	} else $("#types").attr("disabled", "disabled");

}

function loadSubTypes(){
	$("#subTypes").val(0);
	$("#brands").val(0);
	$("#colours").val(0);
	/* Disable selects in the hierachy */
	$("#brands").attr("disabled", "disabled");
	$("#colours").attr("disabled", "disabled");
	
	if($("#types").val() > 0){

		$.get('ajax.php?action=getSubTypes&ProductCatID=' + $("#products").val() + '&typeID=' + $("#types").val(), function(data) {
				  $('#subTypeSelect').html(data);
			});
		
	} else $("#subTypes").attr("disabled", "disabled");

}

function loadBrands(){
	$("#brands").val(0);
	$("#colours").val(0);
	/* Disable selects in the hierachy */
	$("#colours").attr("disabled", "disabled");
	
	if($("#subTypes").val() > 0){

		$.get('ajax.php?action=getBrands&ProductCatID=' + $("#products").val() + '&typeID=' + $("#types").val() + '&subTypeID=' + $("#subTypes").val(), function(data) {
				  $('#brandSelect').html(data);
			});
		
	} else $("#brands").attr("disabled", "disabled");

}

function loadColours(){
	
	/* Disable selects in the hierachy */
	$("#colours").val(0);
	
	if($("#brands").val() > 0){

		$.get('ajax.php?action=getColours&ProductCatID=' + $("#products").val() + '&typeID=' + $("#types").val() + '&subTypeID=' + $("#subTypes").val() + '&brandID=' + $("#brands").val(), function(data) {
				  $('#colourSelect').html(data);
			});
		
	} else $("#colours").attr("disabled", "disabled");

}

function bindSearch(){
	
	var cat = 0;
	var type = 0;
	var subType = 0;
	var brand = 0;
	var colour = 0;
	
	if($("#products").val())
	cat = $("#products").val();
	
	if($("#types").val() > 0)
	type = $("#types").val();
	
	if($("#subTypes").val() > 0)
	subType = $("#subTypes").val();
	
	if($("#brands").val() > 0)
	brand = $("#brands").val();
	
	if($("#colours").val() > 0)
	colour = $("#colours").val();
	
	location.href = 'products.php?cat=' + cat + '&typeID=' + type + '&subTypeID=' + subType + '&brandID=' + brand + '&colourID=' + colour;

}

function updatePrice(obj){
	if($(obj).val() > 0){
		$.get('ajax.php?action=getProductPrice&ProductStockID=' + $(obj).val(), function(data) {
				  $('#ProductPriceReplacement').html(data);
		});
	}
}

function updateQuantity(obj){
	if($(obj).val() > 0){
		$.get('ajax.php?action=getStockQuantity&ProductStockID=' + $(obj).val(), function(data) {
				  $('#ProductQuantityReplacement').html(data);
		});
		
	} else $('#ProductQuantityReplacement').html('<select disabled="disabled"><option value="0">Select Size First</option></select>');
}

function addAccessoryToCart(productID, globalStockID){
	
		var quantity = document.getElementById("quantityChooser").value;
		if(quantity > 0)
			$.get("ajax.php?action=addToCart&productID=" + productID + "&quantity=" + quantity + "&stockID=" + globalStockID, function(){
				Ext.Msg.alert("Add to Cart", "Added to cart successfully.");
			});
		else Ext.Msg.alert("Please choose a quantity from the list provided.");
}

var cartEnabled = false; var globalStockID;
function updateCartButton(obj){
	if($(obj).val() !== 0){
		cartEnabled = true;
		globalStockID = $(obj).val();
	}
}

function addToCart(productID){
	if($("#sizeChooser").val() > 0){
		if($("#quantityChooser").val() > 0){
			var quantity = $("#quantityChooser").val();
			$.get("ajax.php?action=addToCart&productID=" + productID + "&stockID=" + globalStockID + "&quantity=" + quantity, function(){
				Ext.Msg.alert("Add to Cart", "Added to cart successfully.");
			});
		}
		else Ext.Msg.alert("Add to Cart", "Please choose an available quantity from the list.");
	}
	else Ext.Msg.alert("Add to Cart", "Please choose an available size from the list.");
	
}

/* ANALYTICS */

var _gaq = _gaq || [];

  _gaq.push(['_setAccount', 'UA-7114294-1']);

  _gaq.push(['_trackPageview']);

(function() {

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

})();
