/*   Functions for price info */

/***********************************************************************
*
* Sellprice	- check for difference between rrp and selling price
*
* Input   - customvar:usualprice, netquotevar:cost
* Returns - sellprice
************************************************************************/

function sellprice(uprice, price)
{
uprice = uprice.replace(/&#44;|&#163;|&#36;|£/g,"");	// remove all commas, £ and $
uprice = uprice.replace(/&#46;/g,".");    		// restore decimal point
if (uprice > 0) 
{
return document.write('<font class="actlargeheading"><b>Today\'s Price: ' + price + '</b></font><br><font color="#666666" size=2><s> Usual Price: £' + uprice + '</s></font><br>')
}
else
{
return document.write('<font class="actlargeheading"><b>Our Price: ' + price + '</b></font><br>');
}
}



/***********************************************************************
*
* Savings - caluclates savings in £ and %
*
* Input   - customvar:rrp, netquotevar:cost
* Returns - displays rrp + savings £ and (%)
************************************************************************/

function Savings(rrp, price)
{
rrp = rrp.replace(/&#44;|&#163;|&#36;|£/g,"");	// remove all commas, £ and $
rrp = rrp.replace(/&#46;/g,".");    		// restore decimal point
price = price.replace(/&#44;|&#163;|&#36;|£/g,"");	// remove all commas, £ and $
price = price.replace(/&#46;/g,".");    		// restore decimal point
if (rrp > 0) 
{save = rrp - price
save = FormatNumber(save,2)
percent = 100 - ((price/rrp)*100)
percent = FormatPercent(percent,0)
if (save > 0)
{
return document.write("List Price: £" + rrp + "&nbsp;&nbsp;" + "You Save: £" + save + "&nbsp;(" + percent + "%)");
}
}
}


/***********************************************************************
*
* FormatNumber	- formats number to decimal places
*
* Input   - raw number, decimal places
* Returns - formated number
************************************************************************/

function FormatNumber(expr, decplaces)
{
var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
while (str.length <= decplaces)
{
str = "0" + str;
}
var decpoint = str.length - decplaces;
return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
} 


/***********************************************************************
*
* FormatPercent	- formats number as percentage
*
* Input   - raw number, decimal places
* Returns - number as percentage
************************************************************************/

function FormatPercent(expr, decplaces)
{
var str2 = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
while (str2.length <= decplaces)
{
str2 = "0" + str2;
}
var decpoint = str2.length - decplaces;
return str2.substring(0,decpoint)
}


/***********************************************************************
*
* Delivery - caluclates free delivery
*
* Input   - netquotevar:cost
* Returns - displays FREE DELIVERY
************************************************************************/

function Delivery(price)
{
price = price.replace(/&#44;|&#163;|&#36;|£/g,"");	// remove all commas, £ and $
price = price.replace(/&#46;/g,".");    		// restore decimal point
if (price >= 50)
{
return document.write('<br><font class="actlargeheading"><b>Includes FREE Delivery*</b></font>');
}
}

