

//Ajax Product Listing Functions
function pageload(hash) {
	// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser

	if(hash) {
		// restore ajax loaded state
		if($.browser.msie) {
			// jquery's $.load() function does't work when hash include special characters like åäö.
			hash = encodeURIComponent(hash);
		}
		var checkHash = hash.indexOf("-");
		if (checkHash >= 0) {
			var arrCallbackInfo
			arrCallbackInfo = hash.split("-");
			
			var rParCateID 	= arrCallbackInfo[0]
			var rCateID 	= arrCallbackInfo[1]
			var rPageNum 	= arrCallbackInfo[2]
			
			if (rCateID.length == 0) {
				rCateID = ''	
			}
			
			if (rPageNum.length == 0) {
				rPageNum = ''	
			}
			
			ajaxLoadProductList(rParCateID,"" + rCateID + "","" + rPageNum + "");
		}
	} else {
		// start page
		//$("#load").empty();
	}
}


function addProductToCart(prodID,prodQty,prodColour,prodSize) {
	//alert(prodID + "," + prodQty + "," + prodColour + "," + prodSize);
	$("div.miniCartButton span a").load(rootFolder + "/ajax/addProductToCart.asp",{productID:prodID,productQty:prodQty,productColour:prodColour,productSize:prodSize}, function(data) {
		
		$("#shoppingCartForm").load(rootFolder + "/ajax/getCartSummary.asp");	
	});
}

function deleteProductFromCart(delCartID) {
	//alert(prodID + "," + prodQty + "," + prodColour + "," + prodSize);
	$("div.miniCartButton span a").load(rootFolder + "/ajax/deleteProductFromCart.asp",{delCartID:delCartID,action:"delete"}, function(data) {
		
		$("#shoppingCartForm").load(rootFolder + "/ajax/getCartSummary.asp");	
	});
}

function addVoucherToCart(prodID,prodQty,rVoucherTo,rVoucherFrom,rVoucherAddress,rVoucherMessage)  {
	//alert(prodID + "," + prodQty + "," + prodColour + "," + prodSize);
	$("div.miniCartButton span a").load(rootFolder + "/ajax/addVoucherToCart.asp",{productID:prodID,productQty:prodQty,voucherTo:rVoucherTo,voucherFrom:rVoucherFrom,voucherAddress:rVoucherAddress,voucherMessage:rVoucherMessage}, function(data) {
		
		$("#shoppingCartForm").load(rootFolder + "/ajax/getCartSummary.asp");	
	});
}

var tO = null;
function ajaxLoadProductList(parentCID,cID,pageNum) {
	$("div#ajaxReplaceList").fadeOut(300);
	
	if (cID.length == 0) {
		cID = ""	
	}
	
	// Cancel previous animations.
	if(tO != null)
	{
		clearTimeout(tO);
		tO = null;
	}
	
	tO = setTimeout(function()
	{
		ajaxLoadProductListCode(parentCID, cID, pageNum);
		tO = null;
	}, 300);
}

function ajaxLoadProductListCode(parentCID,cID,pageNum) {
	
	var f_cid 		= $("#f_cid").val();
	var f_brand 	= $("#f_brand").val();
	var f_condition = $("#f_condition").val();
	var f_keyword 	= $("#f_keyword").val();
	var f_attrID 	= $("#f_attrID").val();
	var f_isNew		= $("#f_isNew").val();
	var f_isBS		= $("#f_isBS").val();
	//var f_p			= $("#f_p").val();
	
	var minPrice = $("#amountFr").val();
	var maxPrice = $("#amountTo").val();
	
	var searchItem = $("#productSearchItem").val();
	
	var filterAdvice = new Array();
	
	$refineData = $('input[name=Refine]:checked');
	$refineData.each(function(index) {
		filterAdvice.push($(this).val());
	});

	$("div#ajaxReplaceList").load(rootFolder + "/ajax/load_prod_list.asp",{'cid':f_cid,'brand':f_brand,'condition':f_condition,'keyword':f_keyword,'attrID':f_attrID,'isNew':f_isNew,'isBS':f_isBS,'minPrice':minPrice,'maxPrice':maxPrice,'refineFilters':filterAdvice,'p':pageNum},
	function(data)
	{
		$('div#ajaxReplaceList').fadeIn(500);
			
	});
	
	$("div.ajaxReplacePage").load(rootFolder + "/ajax/load_pager.asp",{'cid':f_cid,'brand':f_brand,'condition':f_condition,'keyword':f_keyword,'attrID':f_attrID,'isNew':f_isNew,'isBS':f_isBS,'minPrice':minPrice,'maxPrice':maxPrice,'refineFilters':filterAdvice,'p':pageNum},
	function(data)
	{
		$('div.ajaxReplacePage').fadeIn(500);
			
	});
}

function removeItemFromCart(cartID) {
	$("#replaceAjaxCart").load("ajax/del_item_from_cart.asp",{"delID":cartID});
}

function addItemViaAjax(prodID) {
	
	var intPurcProdID	= prodID;
	var intPurcQty		= $("#pQtyID" + prodID).val();
	var intPurcClrID	= null;
	var intPurcSizeID	= null;
	
	$("#replaceAjaxCart").load("ajax/add_item_to_cart.asp",{"productIDValue":intPurcProdID,"productQty":intPurcQty,"productColour":intPurcClrID,"productSize":intPurcSizeID,"purchaseProduct":"1"},function() {
		$("#updateItem a").load("ajax/cart_summary_load.asp?summType=items");
		$("#updateTotal").load("ajax/cart_summary_load.asp?summType=price");
		
		toggleCart(true);
	});
	
}

function updateSortByCookie(currentID) {
	var sortByAction = $(currentID).val();	
	$("#compareCookieAjaxArea").load(rootFolder + "/ajax/setOrderByCookie.asp",{'action':sortByAction});
}



