function getAvailabilityStatus(productCode,quantity){
	
	$.post(sitePath+"availabilitystatus.htm",
	{	
		productCode:productCode,
		quantity:quantity
	},
	function(data)
	{			
		eval(data);
		var productCodeDiv = "#"+productCode+"Avail";		
		$(productCodeDiv).html(obj.message);	
	},
	"html" );
}

function addToBasketWithQuantity(productCode,productId,quantityVar){
	$.post(sitePath+"availabilitystatus.htm",
			{	
				productCode:productCode,
				quantity:quantityVar
			},
			function(data)
			{			
				eval(data);
				var productCodeDiv = "#"+productCode+"Avail";
				
				$(productCodeDiv).html(obj.message.toUpperCase());
				if(obj.message=="Sold Out"){
					alert("Unfortunately this product is not currently in stock and we do not have a delivery date for any replenishment. Sorry!");
				}
				else{

					var showBasket = true;
					if(obj.message != "In Stock"){
						showBasket = true;
						//if(confirm(obj.message)){
							//showBasket = true;
						//}
					}		
						
					if(showBasket == true){
						$.post(sitePath+"additemtobasket.htm",
						{	
							productCode:productCode,
							quantity:quantityVar
						},
						function(data)
						{			
							//addToBasktDivShow(productCode);
							basketboxwrite();
							//alert("Light box starts from product page ....");
							eval(data);	
							//alert(data);
					  		var code = obj.code;
					  		var qty = obj.qty;
							tb_show('The following item has been added to your basket',''+sitePath+'showbasketlightbox.htm?productCode='+code+'&productQuantity='+qty+'&keepThis=true&amp;TB_iframe=true&amp;height=280&amp;width=490');
		
							//scrollBasketDown();
						},
						"html" );
						
						//document.location.href= sitePath+ "additemtobasket.htm?productCode="+productCode+"&quantity="+qtyObj.value;
					}
				}
			},
	"html" );
}

function addToBasket(productCode,productId){	
	
	// var qtyObj = document.getElementById(productId);		
	var qtyObj = document.getElementById(productCode);

	if(qtyObj.value==""){
		alert("Please enter the quantity for each product you would like to add to the basket");
		qtyObj.focus();
	}
	else if(!isNum(qtyObj)){
		qtyObj.value="";
		alert("'The quantity you have entered appears to be invalid. Could you please re-enter the quantity");
		qtyObj.focus();
	}
	else{
		addToBasketWithQuantity(productCode,productId,qtyObj.value);
	}
}

function productAddedCallback(){
	//basketboxwrite();           
	basketboxwrite();
	$("#TB_window").hide();            	
	tb_show('Your selection has been added to your basket',''+sitePath+'showgroupbasketlightbox.htm?keepThis=true&amp;TB_iframe=true&amp;height=240&amp;width=490');
}

function addAllSelectedProducts()
{
	var prodObj = document.frmProductFilterResult.productCode;
	var varAct = "addall";
	//alert(prodObj.length)
	var prodCodeAndQty="";
	var productCode = "";
	if(typeof prodObj.length === "undefined")
	{
		productCode = prodObj.value;
		var productQtyObj = document.getElementById("productQty_"+productCode);
		var productQty = productQtyObj.value;
		if(productQty > 0) 
		{				
			 prodCodeAndQty = prodCodeAndQty + productCode + "_" + productQty + ",";
		}
	}
	else
	{
		for(i=0;i<prodObj.length;i++)
		{	
			productCode = prodObj[i].value;
			var productQtyObj = document.getElementById("productQty_"+productCode);
			var productQty = productQtyObj.value;
			if(productQty > 0) 
			{				
				 prodCodeAndQty= prodCodeAndQty + productCode + "_" + productQty + ",";
			}	
		}
	}	
	//alert("prodCodeAndQty:" + prodCodeAndQty);
	if(prodCodeAndQty == "")
	{
		alert("Please enter the quantity for each product you would like to add to the basket");
	}
	else
	{	
		//alert("sitePath:" + sitePath)
		$.post(sitePath+"additemtobasket.htm",
            {   
                productCode:prodCodeAndQty,
                act:varAct
            },
            function(data)
            { 
            	//basketboxwrite();           	
            	//$("#TB_window").hide();            	
            	//$(".added-basket").hide();            	
            	//tb_show('Your selection has been added to your basket',''+sitePath+'showbasketlightbox.htm?from=productfilter&productCode=' + productCode + '&productQuantity=1&keepThis=true&amp;TB_iframe=true&amp;height=280&amp;width=490');
            	//parent.location.href = sitePath+"basket.htm";
            	parent.productAddedCallback();
            },
            "html" );  
	}
	
}

function setPromoCode(){
	//alert("PromoCode::"+trim(document.frmPromoCode.promoCode.value));
	if(trim(document.frmPromoCode.promoCode.value)!="" && trim(document.frmPromoCode.promoCode.value)!="Promotional Code" ){
    	$.post(sitePath+"checkvalidpromocode.htm",
    	{	
    		promoCode:trim(document.frmPromoCode.promoCode.value)
    	},
    	function(data)
    	{			
    		eval(data);
    		//alert(obj.checkValidPromo);
    		if(obj.checkValidPromo=='true'){
    			document.frmPromoCode.submit();
    		}
    		else{
    			alert("Please Enter the Valid Promo Code");
    		}
    	},
    	"html" );
		
	}
	else{
		alert("Please Enter the Promo Code");
	}
}


