// ----
// ---- Display elements from Product Arrays and form with JS
// ----
// ---- Designed and created by Active Media, 2001
// ---- (Daniel Saw; Freelance Mouse Pilot - Aust)
// ---- http://www.active-media.com.au/
// ---- If you use this script, include the above credits.
// ----
//**Start Encode**

// Write product price to page
function prodPriceDisplay(prodValue) {
for (var i = 0; i < parseInt(prodCode.length); i++)  {
  if (prodCode[i] == prodValue)  {
    document.write("$" + prodPrice[i] + ".00");
    return true;
    }
  }
document.write("Code: "+prodValue+"<br>Price N\/A");
}
// -------------------------------------------------------------------

// Write product RRP price to page
function prodRRPDisplay(prodValue) {
for (var i = 0; i < parseInt(prodCode.length); i++)  {
  if (prodCode[i] == prodValue)    {
    document.write("$" + prodRRP[i] + ".00");
    return true;
    }
  }
document.write("Code: "+prodValue+"<br>RRP N\/A");
}
// -------------------------------------------------------------------

// Write product code to page based on first instance of price
function prodCodeDisplay(prodValue) {  
for (var i = 0; i < parseInt(prodCode.length); i++)
  { 
  if (prodPrice[i] == prodValue)
    {
    document.write(prodCode[i]);
    return true;
    }
  }
document.write("Price: "+prodValue+"<br>Code N\/A");
}
// -------------------------------------------------------------------

// Does product exist? Return true or false
function prodCodeExists(productcode) {  
	for (var i = 0; i < parseInt(prodCode.length); i++)  { 
		if (prodCode[i] == productcode) {
			return true;
		}
	}
return false;
}
// -------------------------------------------------------------------

// Return product price into variable
function prodPriceReturn(prodValue) {  
var foundPrice;
foundPrice = 0
for (var i = 0; i < parseInt(prodCode.length); i++) { 
	if (prodCode[i] == prodValue){
		foundPrice = parseFloat(prodPrice[i]);
	}
}
return foundPrice;
}
// -------------------------------------------------------------------

// Format price function
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)){
	num = "0"
	};
cents = Math.floor((num * 100 + 0.5) % 100);
num = Math.floor((num * 100 + 0.5) / 100).toString();
if(cents < 10) {
	cents = "0" + cents
	};
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++){
	num = num.substring(0,num.length - (4 * i + 3))+','+num.substring(num.length-(4 * i + 3));
	};
return ("$" + num + "." + cents);
}
// -------------------------------------------------------------------

