//---------------------------------------------------------------------------------------------
// Globals
//---------------------------------------------------------------------------------------------

var objPricePerItem;
var objPriceDisplay;
var objItemSelect;
var nFinalPrice = 0;

var objAdd; // for the paypal add object
var objQuantity; // for the paypal quantity object

//---------------------------------------------------------------------------------------------
// Events
//---------------------------------------------------------------------------------------------

function JS_Order_Update ()
{
	if ( !objPriceDisplay ) objPriceDisplay = document.getElementById("spanPrice"); // element to display price
	if ( !objItemSelect ) objItemSelect = document.getElementById("selItemSelect"); // element to get desired number of items
	
	if ( !objPricePerItem ) objPricePerItem = document.getElementById("amount"); // paypal element to get price of item
	//if ( !objAdd ) objAdd = document.getElementById("add"); // paypal add element
	if ( !objQuantity ) objQuantity = document.getElementById("quantity"); // paypal quantity element
	
	nFinalPrice = JS_Order_FormatPrice ( Number(objPricePerItem.value)*Number(objItemSelect.value) ); // calc price, and format it
	
	//objAdd.value = nFinalPrice; // inject price for paypal
	objQuantity.value = Number(objItemSelect.value); // quantity for paypal
	
	objPriceDisplay.innerHTML =  nFinalPrice; // show price on screen
}

//---------------------------------------------------------------------------------------------
// Formatting
//---------------------------------------------------------------------------------------------

function JS_Order_FormatPrice ( nPrice )
{
	return formatCurrency(nPrice);
}

//---------------------------------------------------------------------------------------------
// Currency format - http://javascript.internet.com/forms/currency-format.html
//---------------------------------------------------------------------------------------------

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/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 (((sign)?'':'-') + '$' + num + '.' + cents);
return (((sign)?'':'-') + num + '.' + cents);
}

//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------

