
function customPriceResolve(Pstring){


var CPA=Pstring.split("[");

if(CPA[1].indexOf("for")>0) 
	{
	top.B[top.Basketline].XforY=XforY;
	top.B[top.Basketline].XforY(1*CPA[0],CPA[1]);
	return(1*CPA[0]);
	}

if(CPA[1].indexOf("get")>0) 
	{
	top.B[top.Basketline].AgetB=AgetB;
	top.B[top.Basketline].AgetB(1*CPA[0],CPA[1]);
	return(1*CPA[0]);
	}


if(CPA[1].indexOf("case")>0) 
	{
	top.B[top.Basketline].NcaseP=NcaseP;
	return(top.B[top.Basketline].NcaseP(1*CPA[0],CPA[1]));
	}
}


function XforY(Price,xfy){
var tmp=xfy.split("for")
var X=parseInt(tmp[0]);
var Y=parseInt(tmp[1]);

var Q = this.QTY;
if(Q>=Y)
	{
	var pay = Math.floor(Q/X)*Y + (Q%X);
	pay -= (Q%X)>Y ? (Q%X)-Y : 0;
	var free = Math.floor(pay/Y)*(X-Y);
	this.QTY=pay;
	this.Qlock=true;
	this.Quant=this.QTY+";1;1";
	this.VarL2+=(this.VarL2.length>0)?top.CRLF:"";
	this.VarL2+=top.swapstring(top.SL.pfPlusFree,"$#$",""+free);
	this.Price = Price;
	}
}

function AgetB(Price,agb){ 
var tmp=agb.split("get")
var A=parseInt(tmp[0]);
var B=parseInt(tmp[1]);

var Q = this.QTY;
if(Q>=A)
	{
	var free = Math.floor(Q/A)*B
	this.Qlock=true;
	this.Quant=this.QTY+";1;1";
	this.VarL2+=(this.VarL2.length>0)?top.CRLF:"";
	this.VarL2+=top.swapstring(top.SL.pfPlusFree,"$#$",""+free);
	this.Price = Price;
	}
}//

function NcaseP(Price,ncp){

var tmp=ncp.split("case")
var caseQty  =parseInt(tmp[0]);
var casePrice=parseInt(tmp[1]);
var ret=Price;
var Q = this.QTY;
if(Q%caseQty == 0)
	{
	this.QTY=Q/caseQty;
	this.Quant=this.QTY+";1;1";
	this.Descr += " " +top.swapstring(top.SL.pfCaseOf,"$#$",""+caseQty);
	this.Price = ""+casePrice;
	this.Weigh = caseQty * this.Weigh;
	ret=casePrice;
	}

else if( Q>caseQty    &&    Q%caseQty > 0 )
	{

    var nCases = (Q - Q%caseQty)/caseQty;
	this.QTY=Q%caseQty;
	this.Quant=this.QTY+";1;1;"+(caseQty-1);
	this.Qmax=(caseQty-1);
	this.Price = ""+Price;
	top.Basketline++;
	top.B[top.Basketline]=new top.Bobj(this.Descr + " " + "Case of "+caseQty,
										this.Refno,this.VarL1,this.VarL2,""+casePrice,
										nCases+";1;1",
										caseQty * this.Weigh,this.Taxco,1,this.Group,true,this.LinkP);
	top.counter();
	if(!top.msg.AddThenReview){top.reviewbasket();}
	}
else
	{
	this.Price = ""+Price;
	this.Quant=this.QTY+";1;1;"+(caseQty-1);
	this.Qmax=(caseQty-1);
	}
return(ret)
}



