//----------------------------------------------------------------------//
//  !!! WARNING !!!                                                     //
//  Do not alter any code on this or any other pages of this website.   //
//  All prices are checked against the control list. If our server      //
//  suspects that original page has been altered, the sale of           //
//  electronic goods will be automatically refused without any refund.  //
//  Violators will be prosecuted to the maximum extent possible.        //
//  Copyright (c) 2008 Dedoc Software Ltd.                              //
//----------------------------------------------------------------------//
function BulkPricePer1(count)
{
  var modules_price = parseFloat(pDiShell) + parseFloat(pmRemote);
  var discount_price = modules_price - count;
  return parseFloat(discount_price).toFixed(2);
}
//----------------------------------
function BulkPrice(count)
{
  return BulkPricePer1(count) * count;
}
//----------------------------------
function AdiCountPrice(combo_index)
{
  var price;
  switch(combo_index)
  {
    case 0:  price = pAdi001; break;    
    case 1:  price = pAdi003; break;    
    case 2:  price = pAdi005; break;
    case 3:  price = pAdi010; break;
    case 4:  price = pAdi020; break;
    case 5:  price = pAdi050; break;
    case 6:  price = pAdi100; break;
    case 7:  price = pAdi000; break;
    default: price = pAdi000;
  }
  return parseFloat(price).toFixed(2);
}
//----------------------------------
function GetAdiPriceDiff(combo_index)
{
  var price;
  switch(combo_index)
  {
    case 0:  price = pAdi001; break;    
    case 1:  price = pAdi003 - pAdi001; break;    
    case 2:  price = pAdi005 - pAdi003; break;
    case 3:  price = pAdi010 - pAdi005; break;
    case 4:  price = pAdi020 - pAdi010; break;
    case 5:  price = pAdi050 - pAdi020; break;
    case 6:  price = pAdi100 - pAdi050; break;
    case 7:  price = pAdi000 - pAdi100; break;
    default: price = pAdi000;
  }
  return parseFloat(price).toFixed(2);
}
//----------------------------------
function InitPP()
{
    if (document.getElementById("eDiShell"))   {eDiShell   .innerText = pDiShell;}
    if (document.getElementById("eMiniDi"))    {eMiniDi    .innerText = pMiniDi;}

    if (document.getElementById("eDiMiLi"))    {eDiMiLi    .innerText = pDiMiLi;}
    if (document.getElementById("norDiMiLi"))  {norDiMiLi  .innerText = (parseFloat(pDiShell) + parseFloat(pMiniDi) + parseFloat(pmPDAsync)).toFixed(2);}
    if (document.getElementById("norSlave"))   {norSlave   .innerText = (parseFloat(pDiShell) + parseFloat(pmRemote) + parseFloat(pRenta1)).toFixed(2);}

    if (document.getElementById("ePayments"))  {ePayments .innerText = pmPayments;}
    if (document.getElementById("eTools"))     {eTools    .innerText = pmTools;}
    if (document.getElementById("eExport"))    {eExport   .innerText = pmExport;}
    if (document.getElementById("eFilter"))    {eFilter   .innerText = pmFilter;}
    if (document.getElementById("eRemote"))    {eRemote   .innerText = pmRemote;}
    if (document.getElementById("ePDAsync"))   {ePDAsync  .innerText = pmPDAsync;}
    // pMiniDi
    if (document.getElementById("eCDROM"))     {eCDROM    .innerText = pmCDROM;}
    if (document.getElementById("eServer"))    {eServer   .innerText = pmServer;}

    if (document.getElementById("eRenta1"))    {eRenta1    .innerText = pRenta1;}
    if (document.getElementById("eRenta2"))    {eRenta2    .innerText = pRenta2;}
    if (document.getElementById("eRentaX1"))   {eRentaX1   .innerText = pRentaX1;}
    if (document.getElementById("eRentaX2"))   {eRentaX2   .innerText = pRentaX2;}
    if (document.getElementById("eRentaXAL1")) {eRentaXAL1 .innerText = pRentaXAL1;}
    if (document.getElementById("eRentaXAL2")) {eRentaXAL2 .innerText = pRentaXAL2;}

    if (document.getElementById("perP003")) {perP003.innerText = (pAdi003 / 3).toFixed(2);} 
    if (document.getElementById("perP005")) {perP005.innerText = (pAdi005 / 5).toFixed(2);}
    if (document.getElementById("perP010")) {perP010.innerText = (pAdi010 / 10).toFixed(2);}
    if (document.getElementById("perP020")) {perP020.innerText = (pAdi020 / 20).toFixed(2);}
    if (document.getElementById("perP050")) {perP050.innerText = (pAdi050 / 50).toFixed(2);}
    if (document.getElementById("perP100")) {perP100.innerText = (pAdi100 / 100).toFixed(2);}

    if (document.getElementById("norP001")) {norP001.innerText = pAdi001;}
    if (document.getElementById("norP003")) {norP003.innerText = pAdi003;} 
    if (document.getElementById("norP005")) {norP005.innerText = pAdi005;}
    if (document.getElementById("norP010")) {norP010.innerText = pAdi010;}
    if (document.getElementById("norP020")) {norP020.innerText = pAdi020;}
    if (document.getElementById("norP050")) {norP050.innerText = pAdi050;}
    if (document.getElementById("norP100")) {norP100.innerText = pAdi100;}
    if (document.getElementById("norP000")) {norP000.innerText = pAdi000;}

    if (document.getElementById("difP003")) {difP003.innerText = GetAdiPriceDiff(1);} 
    if (document.getElementById("difP005")) {difP005.innerText = GetAdiPriceDiff(2);}
    if (document.getElementById("difP010")) {difP010.innerText = GetAdiPriceDiff(3);}
    if (document.getElementById("difP020")) {difP020.innerText = GetAdiPriceDiff(4);}
    if (document.getElementById("difP050")) {difP050.innerText = GetAdiPriceDiff(5);}
    if (document.getElementById("difP100")) {difP100.innerText = GetAdiPriceDiff(6);}
    if (document.getElementById("difP000")) {difP000.innerText = GetAdiPriceDiff(7);}
}
//----------------------------------
function Recalculate(base_price)
{
    var icount = Array(1, 3, 5, 10, 20, 50, 100, 101);
    var mod_price = 0;
    if (document.getElementById("cDiShell")  && PriceForm.cDiShell  .checked && PriceForm.cDiShell .value!=0) {mod_price += parseFloat(pDiShell);}
    if (document.getElementById("cPayments") && PriceForm.cPayments .checked && PriceForm.cPayments.value!=0) {mod_price += parseFloat(pmPayments);}
    if (document.getElementById("cTools")    && PriceForm.cTools    .checked && PriceForm.cTools   .value!=0) {mod_price += parseFloat(pmTools);}
    if (document.getElementById("cExport")   && PriceForm.cExport   .checked && PriceForm.cExport  .value!=0) {mod_price += parseFloat(pmExport);}
    if (document.getElementById("cFilter")   && PriceForm.cFilter   .checked && PriceForm.cFilter  .value!=0) {mod_price += parseFloat(pmFilter);}
    if (document.getElementById("cRemote")   && PriceForm.cRemote   .checked && PriceForm.cRemote  .value!=0) {mod_price += parseFloat(pmRemote);}
    if (document.getElementById("cPDAsync")  && PriceForm.cPDAsync  .checked && PriceForm.cPDAsync .value!=0) {mod_price += parseFloat(pmPDAsync);}
    if (document.getElementById("cMiniDi")   && PriceForm.cMiniDi   .checked && PriceForm.cMiniDi  .value!=0) {mod_price += parseFloat(pMiniDi);}
    if (document.getElementById("cCDROM")    && PriceForm.cCDROM    .checked && PriceForm.cCDROM   .value!=0) {mod_price += parseFloat(pmCDROM);}
 // if (document.getElementById("cServer")   && PriceForm.cServer   .checked && PriceForm.cServer  .value!=0) {mod_price += parseFloat(pmServer);}

    if (document.getElementById("cRenta1")    && PriceForm.cRenta1    .checked) {mod_price += parseFloat(pRenta1);}
    if (document.getElementById("cRenta2")    && PriceForm.cRenta2    .checked) {mod_price += parseFloat(pRenta2);}
    if (document.getElementById("cRentaX1")   && PriceForm.cRentaX1   .checked) {mod_price += parseFloat(pRentaX1);}
    if (document.getElementById("cRentaX2")   && PriceForm.cRentaX2   .checked) {mod_price += parseFloat(pRentaX2);}
    if (document.getElementById("cRentaXAL1") && PriceForm.cRentaXAL1 .checked) {mod_price += parseFloat(pRentaXAL1);}
    if (document.getElementById("cRentaXAL2") && PriceForm.cRentaXAL2 .checked) {mod_price += parseFloat(pRentaXAL2);}

    if (document.getElementById("cAdiCount"))
    {
      var adi_price = AdiCountPrice(PriceForm.cAdiCount.selectedIndex);
      eAdiCount.innerText = parseFloat(adi_price).toFixed(2);
      mod_price += parseFloat(adi_price);
    }
    if (document.getElementById("eModPrice"))
    {
      eModPrice.innerText = parseFloat(mod_price).toFixed(2);
    }

    var total = parseFloat(base_price) + parseFloat(mod_price);
    if (document.getElementById("eTotPrice"))
    {
      eTotPrice.innerText = total.toFixed(2);
    }
    return total.toFixed(2);
}
//----------------------------------
function GetModules(upgrade, page_prefix)
{
  var mDiShell  = 1;
  var mPayments = 0;
  var mTools    = 0;
  var mExport   = 0;
  var mFilter   = 0;
  var mRemote   = 0;
  var mPDAsync  = 0;
  var mMiniDi   = 0;
  var mCDROM    = 0;
  var mServer   = 3;
  var mAdiCount = 1;
  var mRemonet  = 0;
  var MCode     = '';
  var icount = Array(1, 3, 5, 10, 20, 50, 100, 0);

  if (!upgrade) {MCode = "DI,";}
  if (document.getElementById("cPayments") && PriceForm.cPayments .checked) {mPayments = 1; MCode = MCode + "PY,";}
  if (document.getElementById("cTools")    && PriceForm.cTools    .checked) {mTools    = 1; MCode = MCode + "TL,";}
  if (document.getElementById("cExport")   && PriceForm.cExport   .checked) {mExport   = 1; MCode = MCode + "EX,";}
  if (document.getElementById("cFilter")   && PriceForm.cFilter   .checked) {mFilter   = 1; MCode = MCode + "FI,";}
  if (document.getElementById("cRemote")   && PriceForm.cRemote   .checked) {mRemote   = 1; MCode = MCode + "RN,";}
  if (document.getElementById("cPDAsync")  && PriceForm.cPDAsync  .checked) {mPDAsync  = 1; MCode = MCode + "PL,";}
  if (document.getElementById("cMiniDi")   && PriceForm.cMiniDi   .checked) {mMiniDi   = 1; MCode = MCode + "MD,";}
  if (document.getElementById("cCDROM")    && PriceForm.cCDROM    .checked) {mCDROM    = 1; MCode = MCode + "CD,";}
  if (document.getElementById("cServer")   && PriceForm.cServer   .checked) {mServer   = 3; MCode = MCode + "SV,";}

  if (document.getElementById("cAdiCount")) {mAdiCount = icount[PriceForm.cAdiCount.selectedIndex];} else
  if (document.getElementById("ICount"))    {mAdiCount = icount[PriceForm.ICount.selectedIndex];} // upage.htm UPGRADE

  if (document.getElementById("cRenta1") && PriceForm.cRenta1.checked) {mRemonet = 1; MCode = MCode + "R1,";} else
  if (document.getElementById("cRenta2") && PriceForm.cRenta2.checked) {mRemonet = 2; MCode = MCode + "R2,";}

  MCode = MCode.substr(0, MCode.length-1);

  var modules = mDiShell.toString() + mPayments.toString() + mTools .toString() + '-' +
                mExport .toString() + mFilter  .toString() + mRemote.toString() + '-' +
                mPDAsync.toString() + mMiniDi  .toString() + mCDROM .toString() + '-' +
                mServer .toString() + '-' + mAdiCount.toString() + '-' + mRemonet.toString();

  var pack_name = "ADI-diary.NET";
  if (upgrade)
     {pack_name = pack_name + " Upgrade";}

  if (mAdiCount == 0)
     {pack_name = pack_name + " - Instructors: No limit";}

  else
  if (mAdiCount == 1)
    {pack_name = pack_name + " for 1 instructor";} else
    {pack_name = pack_name + " for " + mAdiCount + " instructors";}

  if (MCode != '')
      pack_name = pack_name + " - Modules: " + MCode;

  return pack_name + "|" + modules + "-" + page_prefix;
}
//----------------------------------
function Buy1(base_price, upgrade, page_prefix)
{
  var price = Recalculate(base_price);
  if (price == 0)
  {
    alert("Please select some modules");
    return false;
  }
  var pack = GetModules(upgrade, page_prefix).split("|");
  return BuyPack(pack[0], pack[1], price);
}
//----------------------------------
function BuyPack(pack_name, pack, price)
{
  PayPalForm.action="https://www.paypal.com/cgi-bin/webscr";
  PayPalForm.item_name  .value = pack_name;
  PayPalForm.item_number.value = pack;
  PayPalForm.amount     .value = parseFloat(price).toFixed(2);
  PayPalForm.submit();
  return false;
}
//----------------------------------
