
/*-----------------------------------------------------------------------------------------

Make sure to call the function with this arguments:

1 - listPrice: 	list price for items, in NS tag format, with a third value of "0" 
2 - salesPrice: sales price for items, in NS tag format, with a third value of "0" 
3 - asCurrency: Boolean value, true - display as currency, false - display as percentage
4 - postText: 	text to add after  the discount

Example:
--------

writeDiscount(	'<%=getCurrentAttribute("item","priceLevel2","0")%>', 
				'<%=getCurrentAttribute("item","salesPrice","0")%>', 
				[true/false], 
				"text to display after discount")


------------------------------------------------------------------------------------------*/											

//writeDiscount('<%=getCurrentAttribute("item","priceLevel2","0")%>','<%=getCurrentAttribute("item","salesPrice","0")%>','less');

function writeDiscount(listPrice, salesPrice, postText) {
	// Calculate discount if there's any, if not display nothing.
	var listP = parseFloat((listPrice.substr(1)).replace(",",""));
	var salesP = parseFloat((salesPrice.substr(1)).replace(",",""));
	var discount = 0;
	var discountMsg = '';
	if (listP > 0 && salesP > 0 && listP > salesP)
		discount = parseInt(((listP-salesP)/listP)*100);
	if (discount > 0) 
		discountMsg = discount+"% "+postText;

document.write(discountMsg);
}
