/* dom price switcher for all ecom products. this should be called AFTER the switcher for the individual product.
EX: 
jp-dom-jobprice.js
jp-dom-priceswitcher.js */

priceTiers = new Array();
costs = new Array();
savings = new Array();

function formatCurrency(strValue) {
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);
	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	dblValue = Math.floor(dblValue/100).toString();
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue);
}
function changeSelect() {
	var priceSwitcher = document.getElementById("productid") || document.getElementById("Package_DID");
	// values for costs and savings based on the seleted item
	var currencyCost = formatCurrency(costs[priceSwitcher.selectedIndex]);
	var currencySavings = formatCurrency(savings[priceSwitcher.selectedIndex]);
	// get id of div that holds cost
	var priceHolder = document.getElementById("costValue");
	// give it the value of the current selected cost
	priceHolder.innerHTML="Total Cost: "+currencyCost+" ";
	// get id of div that holds savings
	var savingsHolder = document.getElementById("savingsValue");
	// give it the value of the current selected cost
	savingsHolder.innerHTML="[ "+currencySavings+" Savings ]";
	// when the user clicks one of the select values
	priceSwitcher.onchange = function() {
		switchValues();
	}
}
function switchValues() {
	var priceSwitcher=document.getElementById("productid") || document.getElementById("Package_DID");
	// get values of selected item
	var currencyCost = formatCurrency(costs[priceSwitcher.selectedIndex]);
	var currencySavings = formatCurrency(savings[priceSwitcher.selectedIndex]);
	// get id of div that holds cost
	var priceHolder = document.getElementById("costValue");
	// give it the value of the current selected cost
	priceHolder.firstChild.nodeValue="Total Cost: "+currencyCost+" ";
	// get id of div that holds savings
	var savingsHolder = document.getElementById("savingsValue");
	// give it the value of the current selected cost
	savingsHolder.firstChild.nodeValue="[ "+currencySavings+" Savings ]";
}
$(document).ready(function(){
	getPriceValues();
  	changeSelect();
});