/* ! Copyright 2009 Webroot Software, Inc. All rights reserved */ 

var productID; 

//prices arrays broken down by number of years, and further by price breaks 
var WASCEPrices = [ 
    [24.0400,21.7900,19.8900], 
    [31.2490,28.3243,25.8545], 
    [38.4580,34.8585,31.8190] 
]; 
var WASceAVPrices = [ 
    [37.7700,34.2400,31.2500], 
    [49.1042,44.5149,40.6276], 
    [60.4320,54.7840,50.0000] 
]; 

var baseURL = 'http://www.webroot.com/shoppingcart/update_cart.php?'; 
var priceBreakIndex; 

/** 
* Populate the prices and cart links 
*/ 
function getPrice( product ) 
{ 
productID = product; 
var numberOfSeats = $('div#'+product+'numberOfSeatsSlider').slider("value"); 
var zeroBasedYears = $('#'+product+'numberOfYearsSlider').slider("value") - 1; 

switch( product ) 
{ 
case "WASCE": 
populatePrices ( getPriceBreakPrice( product ), numberOfSeats ); 
cartLink = baseURL + '71151_quantity='+numberOfSeats+'&71151_years='+zeroBasedYears+'&clr=y'; 
$('a#'+product+'CartLink').attr("href", cartLink); 
break; 

case "WASCEAV": 
populatePrices ( getPriceBreakPrice( product ), numberOfSeats ); 
cartLink = baseURL + '72151_quantity='+numberOfSeats+'&72151_years='+zeroBasedYears+'&clr=y'; 
$('a#'+product+'CartLink').attr("href", cartLink); 
break; 
} 
} 

/** 
* Figure out which array index the user is at based on number of seats 
*/ 
function getPriceBreakIndex() 
{ 
var numberOfSeats = $('div#'+productID+'numberOfSeatsSlider').slider("value"); 

var priceBreakIndex; 

// get price break 
if (numberOfSeats < 25) 
{ 
priceBreakIndex = 0; 
} 
if (numberOfSeats >= 25 && numberOfSeats <100) 
{ 
priceBreakIndex = 1; 
} 
if (numberOfSeats >= 100) 
{ 
priceBreakIndex = 2; 
} 

return priceBreakIndex; 
} 

/** 
* Figures out what price break level the user is at based on the number of PCs 
*/ 
function getPriceBreakPrice( product ) 
{ 
var numberOfYears = $('#'+product+'numberOfYearsSlider').slider("value"); 
var priceBreakNumber; 
if (product == "WASCE") 
{ 
priceBreakNumber = WASCEPrices[ numberOfYears - 1 ][getPriceBreakIndex()]; 


if (numberOfYears < 3) {getSavingsPrice ( numberOfYears, product, priceBreakNumber, WASCEPrices[ numberOfYears ][getPriceBreakIndex()] ) } 
else { $('#'+product+'SavingsBox').html('&nbsp;<br/>&nbsp;<br/>'); } 

} 
else if (product == "WASCEAV") 
{ 
priceBreakNumber = WASceAVPrices[ numberOfYears - 1 ][getPriceBreakIndex()]; 

if (numberOfYears < 3) {getSavingsPrice ( numberOfYears, product, priceBreakNumber, WASceAVPrices[ numberOfYears ][getPriceBreakIndex()] ) } 
else { $('#'+product+'SavingsBox').html(''); } 
} 
var ppu = (priceBreakNumber / numberOfYears).toFixed(2); 
$("span#"+product+"PPU").html('$' + ppu); 

return priceBreakNumber; 
} 

/** 
* Get the "if you choose one more year, save blah blah" 
*/ 
function getSavingsPrice (numYears, product, priceBreakNumber, nextPriceBreak) 
{ 
var numberOfSeats = $('div#'+productID+'numberOfSeatsSlider').slider("value"); 
//var savings = nextPriceBreak - priceBreakNumber; 
var thisCost = priceBreakNumber * numberOfSeats; 
var nextHighest = nextPriceBreak * numberOfSeats; 
var savings = nextHighest - thisCost; 

if (numYears == 1) 
{ 
$('#'+product+'SavingsBox').html('<strong>Protect All of Your PCs for Two Years<br/>For Only $'+savings.toFixed(2)+' More!</strong>'); 
} 
if (numYears == 2) 
{ 
$('#'+product+'SavingsBox').html('<strong>Protect All of Your PCs for Three Years<br/>For Only $'+savings.toFixed(2)+' More!</strong>'); 
} 
if (numYears == 3) 
{ 
$('#'+product+'SavingsBox').html('&nbsp;<br/>&nbsp;<br/>'); 
} 
} 

/** 
* Populates all of the HTML with the prices 
*/ 
function populatePrices( pricePerUnit, numberOfSeats ) 
{ 
var totalPrice = (pricePerUnit * numberOfSeats).toFixed(2); 
var totalPriceString = totalPrice.toString(); 
$('h3#'+productID+'Price').html('$' + totalPriceString); 
}
