///////////////////////////////////////////////////////////////////////////
// Module:  rr_prod_info.js
// Purpose: Utility functions for determining price info of a particular
//          product.
/////////////////////////////////////////////////////////////////////////// 

// Common Variables
var standardBrowserFlag = (document.getElementById) ? true : false;

// Specific Variables
var priceTableHash = new Array();

////////////////////////////////////////////////
// Individuals
////////////////////////////////////////////////
priceTableHash["rr1000_retail"] = "79.95";    // RR6 Pro for Win
priceTableHash["rr1000_discount"] = "49.95";  // RR6 Pro for Win
priceTableHash["rr1001_retail"] = "29.95";    // RR6 Std for Win
priceTableHash["rr1002_retail"] = "29.95";    // RR6 Std for Mac
priceTableHash["rr1003_retail"] = "24.95";    // RR4 for Palm
priceTableHash["rr1004_retail"] = "29.95";    // RR1 for WinCE Mobile 5
priceTableHash["rr1005_retail"] = "29.95";    // RR4 for Symbian/Nokia
priceTableHash["rr1006_retail"] = "99.95";    // RR6 Pro for Win Upgrade
priceTableHash["rr1006_discount"] = "49.95";  // RR6 Pro for Win Upgrade
priceTableHash["rr1007_retail"] = "29.95";    // RR6 Std for Win Upgrade
priceTableHash["rr1007_discount"] = "19.95";  // RR6 Std for Win Upgrade
priceTableHash["rr1008_retail"] = "79.95";    // RR6 Pro for Win MarketTest1
priceTableHash["rr1008_discount"] = "49.95";  // RR6 Std for Win MarketTest1

////////////////////////////////////////////////
// Bundles
////////////////////////////////////////////////
priceTableHash["rr2000_retail"] = "164.95";   // RR6 Pro Win + RR1 Mobile 5
priceTableHash["rr2000_discount"] = "149.95"; // RR6 Pro Win + RR1 Mobile 5
priceTableHash["rr2001_retail"] = "104.95";   // RR6 Pro Win + RR4 Palm 
priceTableHash["rr2001_discount"] = "66.95";  // RR6 Pro Win + RR4 Palm 
priceTableHash["rr2002_retail"] = "69.95";    // RR6 Std Mac + RR1 Mobile 5
priceTableHash["rr2002_discount"] = "62.95";  // RR6 Std Mac + RR1 Mobile 5
priceTableHash["rr2003_retail"] = "59.95";    // RR6 Std Win + RR1 Mobile 5
priceTableHash["rr2003_discount"] = "53.95";  // RR6 Std Win + RR1 Mobile 5
priceTableHash["rr2004_retail"] = "59.95";    // RR6 Std Win + RR4 Palm
priceTableHash["rr2004_discount"] = "49.95";  // RR6 Std Win + RR4 Palm
priceTableHash["rr2005_retail"] = "149.95";   // RR6 Pro Win + RR4 Symbian
priceTableHash["rr2005_discount"] = "71.95";  // RR6 Pro Win + RR4 Symbian
priceTableHash["rr2006_retail"] = "69.95";    // RR6 Std Win + RR4 Symbian
priceTableHash["rr2006_discount"] = "53.95";  // RR6 Std Win + RR4 Symbian
priceTableHash["rr2007_retail"] = "59.95";    // RR6 Std Mac + RR4 Symbian
priceTableHash["rr2007_discount"] = "53.95";  // RR6 Std Mac + RR4 Symbian

////////////////////////////////////////////////
// Volume Discounts
////////////////////////////////////////////////
priceTableHash["rr3000_retail"] = "699.50";     // RR6 Pro Win Qty 10
priceTableHash["rr3000_discount"] = "629.55";   // RR6 Pro Win Qty 10
priceTableHash["rr3001_retail"] = "1399.00";    // RR6 Pro Win Qty 20
priceTableHash["rr3001_discount"] = "1245.11";  // RR6 Pro Win Qty 20
priceTableHash["rr3002_retail"] = "3497.50";    // RR6 Pro Win Qty 50
priceTableHash["rr3002_discount"] = "3077.80";  // RR6 Pro Win Qty 50

priceTableHash["rr3003_retail"] = "299.50";     // RR6 Std Win Qty 10
priceTableHash["rr3003_discount"] = "269.55";   // RR6 Std Win Qty 10
priceTableHash["rr3004_retail"] = "599.00";     // RR6 Std Win Qty 20
priceTableHash["rr3004_discount"] = "533.11";   // RR6 Std Win Qty 20
priceTableHash["rr3005_retail"] = "1497.50";    // RR6 Std Win Qty 50
priceTableHash["rr3005_discount"] = "1317.80";  // RR6 Std Win Qty 50

priceTableHash["rr3006_retail"] = "299.50";     // RR6 Std Mac Qty 10
priceTableHash["rr3006_discount"] = "269.55";   // RR6 Std Mac Qty 10
priceTableHash["rr3007_retail"] = "599.00";     // RR6 Std Mac Qty 20
priceTableHash["rr3007_discount"] = "533.11";   // RR6 Std Mac Qty 20
priceTableHash["rr3008_retail"] = "1497.50";    // RR6 Std Mac Qty 50
priceTableHash["rr3008_discount"] = "1317.80";  // RR6 Std Mac Qty 50

priceTableHash["rr3009_retail"] = "299.50";     // Palm Qty 10
priceTableHash["rr3009_discount"] = "269.55";   // Palm Qty 10
priceTableHash["rr3010_retail"] = "599.00";     // Palm Qty 20
priceTableHash["rr3010_discount"] = "533.11";   // Palm Qty 20
priceTableHash["rr3011_retail"] = "1497.50";    // Palm Qty 50
priceTableHash["rr3011_discount"] = "1317.80";  // Palm Qty 50

priceTableHash["rr3012_retail"] = "399.50";     // Nokia/Symbian Qty 10
priceTableHash["rr3012_discount"] = "359.55";   // Nokia/Symbian Qty 10
priceTableHash["rr3013_retail"] = "799.00";     // Nokia/Symbian Qty 20
priceTableHash["rr3013_discount"] = "711.11";   // Nokia/Symbian Qty 20
priceTableHash["rr3014_retail"] = "1997.50";    // Nokia/Symbian Qty 50
priceTableHash["rr3014_discount"] = "1757.80";  // Nokia/Symbian Qty 50

priceTableHash["rr3015_retail"] = "899.50";     // RR6 Pro + Palm Qty 10
priceTableHash["rr3015_discount"] = "809.55";   // RR6 Pro + Palm Qty 10
priceTableHash["rr3016_retail"] = "1799.00";    // RR6 Pro + Palm Qty 20
priceTableHash["rr3016_discount"] = "1601.11";  // RR6 Pro + Palm Qty 20
priceTableHash["rr3017_retail"] = "4497.50";    // RR6 Pro + Palm Qty 50
priceTableHash["rr3017_discount"] = "3957.80";  // RR6 Pro + Palm Qty 50

priceTableHash["rr3018_retail"] = "999.50";     // RR6 Pro + Symbian Qty 10
priceTableHash["rr3018_discount"] = "899.55";   // RR6 Pro + Symbian Qty 10
priceTableHash["rr3019_retail"] = "1999.00";    // RR6 Pro + Symbian Qty 20
priceTableHash["rr3019_discount"] = "1779.11";  // RR6 Pro + Symbian Qty 20
priceTableHash["rr3020_retail"] = "4997.50";    // RR6 Pro + Symbian Qty 50
priceTableHash["rr3020_discount"] = "4397.80";  // RR6 Pro + Symbian Qty 50

////////////////////////////////////////////////
// Reseller Indiv
////////////////////////////////////////////////
priceTableHash["rr4000_retail"] = "71.95";    // RR6 Pro for Win
priceTableHash["rr4000_discount"] = "44.95";  // RR6 Pro for Win
priceTableHash["rr4001_retail"] = "26.95";    // RR6 Std for Win
priceTableHash["rr4002_retail"] = "26.95";    // RR6 Std for Mac
priceTableHash["rr4003_retail"] = "22.95";    // RR4 for Palm
priceTableHash["rr4004_retail"] = "26.95";    // RR1 for WinCE Mobile 5
priceTableHash["rr4005_retail"] = "26.95";    // RR4 for Symbian/Nokia

////////////////////////////////////////////////
// Reseller Bundles
////////////////////////////////////////////////
priceTableHash["rr5000_retail"] = "148.95";   // RR6 Pro Win + RR1 Mobile 5
priceTableHash["rr5000_discount"] = "134.95"; // RR6 Pro Win + RR1 Mobile 5
priceTableHash["rr5001_retail"] = "94.95";   // RR6 Pro Win + RR4 Palm 
priceTableHash["rr5001_discount"] = "60.95";  // RR6 Pro Win + RR4 Palm 
priceTableHash["rr5002_retail"] = "62.95";    // RR6 Std Mac + RR1 Mobile 5
priceTableHash["rr5002_discount"] = "56.95";  // RR6 Std Mac + RR1 Mobile 5
priceTableHash["rr5003_retail"] = "53.95";    // RR6 Std Win + RR1 Mobile 5
priceTableHash["rr5003_discount"] = "48.95";  // RR6 Std Win + RR1 Mobile 5
priceTableHash["rr5004_retail"] = "53.95";    // RR6 Std Win + RR4 Palm
priceTableHash["rr5004_discount"] = "44.95";  // RR6 Std Win + RR4 Palm
priceTableHash["rr5005_retail"] = "134.95";   // RR6 Pro Win + RR4 Symbian
priceTableHash["rr5005_discount"] = "64.95";  // RR6 Pro Win + RR4 Symbian
priceTableHash["rr5006_retail"] = "62.95";    // RR6 Std Win + RR4 Symbian
priceTableHash["rr5006_discount"] = "48.95";  // RR6 Std Win + RR4 Symbian
priceTableHash["rr5007_retail"] = "53.95";    // RR6 Std Mac + RR4 Symbian
priceTableHash["rr5007_discount"] = "48.95";  // RR6 Std Mac + RR4 Symbian


////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////

function getPrice(iProductID, iIncludeDollarSignFlag)
{
  var strPrice = priceTableHash[iProductID];

  if (strPrice != undefined && iIncludeDollarSignFlag == true)
  {
    strPrice = "$" + strPrice;
  }

  return strPrice;
}

function writePrice(iProductID, iIncludeDollarSignFlag)
{
  var strValue = getPrice(iProductID, iIncludeDollarSignFlag);
  document.write(strValue);
  return;
}

function writePriceUsingIDRef(iProductID, iIncludeDollarSignFlag)
{
  var strPrice = getPrice(iProductID, iIncludeDollarSignFlag);
  document.getElementById(iProductID + "_price_id").innerHTML = strPrice;
  return;
}

function writePriceIntoIDRef(iProductID, iIncludeDollarSignFlag, iElementID)
{
  var strPrice = getPrice(iProductID, iIncludeDollarSignFlag);
  document.getElementById(iElementID).innerHTML = strPrice;
  return;
}

function writePriceSavingsUsingIDRef(iProductID, iIncludeDollarSignFlag)
{
  var retailPrice = getPrice(iProductID + "_retail", false);
  var discountPrice = getPrice(iProductID + "_discount", false);

//  alert("retailPrice: " + retailPrice + ", discountPrice: " + discountPrice);

  if (discountPrice == undefined)
  {
    discountPrice = retailPrice;
  }

  var savingsPrice = retailPrice - discountPrice;

  // Create a String object for performing string specific functions.
  var strSavingsPrice = formatPrice(savingsPrice);
//  alert("savingsPrice: " + savingsPrice);

  if (iIncludeDollarSignFlag)
  {
    strSavingsPrice = "$" + strSavingsPrice;
  }

  document.getElementById(
    iProductID + "_price_savings_id").innerHTML = strSavingsPrice;

  return;
}

function formatPrice(iValue)
{
  var floatPrice = parseFloat(iValue);

  // Shift the decimal over two places so we can round to the 2nd decimal.
  var priceShifted = floatPrice * 100;

  // Round the value to convert from a float to a whole number.
  var roundedPrice = Math.round(priceShifted);

  // Convert the whole number back to a floating point value.
  floatPrice = roundedPrice / 100;

  var strPrice = floatPrice.toString();
  var nDecimalPosition = strPrice.indexOf(".");

  if (nDecimalPosition == -1) 
  {
    // No decimal value exists, so add trailing information.
    strPrice += ".00";
  }

  var numZerosNeeded = 2 - (strPrice.length - nDecimalPosition - 1);
  for (var i = 0; i < numZerosNeeded; i ++)
  {
    strPrice += "0";
  }

  return strPrice;
}


