// These functions are used by Caddie and Order Form [13.12.2004]  [12.08.2002]

var maxNumOfItems = 8

var cookieStrArray = new Array (16)
var itemRefNumIx = 0
var itemTitleIx = 1
var itemAuthorIx = 2
var itemPriceIx = 3
var itemWeightIx = 4
var itemDateTimeIx = 5
var itemNumberIx = 6

var itemDispNumArray = new Array (64)
var itemDispIDArray = new Array (64)
var itemDispNumber = new Number ()
var numOfItemsIndex = new Number ()
var currency = ""


function roundOff (value)
{
   if (value == 0)
   {
      return "0"
      exit
   }
   precision = 2
   precision = parseInt (precision)
   var rounded = Math.round (value * Math.pow (10, precision))
   rounded = rounded / Math.pow (10, precision)
   var result = "" + rounded
   return result
}


function roundOffZero (value)
{
   var result = "" + Math.round (value) + ".00"
   return result
}


function checkNull (value)
{
   if (value == "")
   {
      value = "0"
   }
   return value
}


function parseCookie (cookieString) 
{
   // alert("!parsing |"+cookieString+"|")
   cookieStrArray = cookieString.split("_")
   // for (var i=0; i < cookieStrArray.length; i++)
   // {
   //    alert (cookieStrArray[i])
   // }
}


function formatString (inputStr)
{
   var outputStr = ""
   for (var i=0; i < inputStr.length; i++)
   {
      if (inputStr.charAt(i) == " ") { outputStr = outputStr + "&nbsp;" } 
      else { outputStr = outputStr + inputStr.charAt(i) }
   }
   return outputStr
}


function showCurrency ()
{
   alert("Currency="+currency)
}


function chooseCurrency () 
{
   if (taggedStr=="English") 
   {
      winCurr=open("monnaieEng.htm","CurrencySelect","scrollbars=no,resizable=no,titlebar=yes,height=200,width=300,screenX=400,screenY=300") 
   }
   else 
   {
      winCurr=open("monnaie.htm","CurrencySelect","scrollbars=no,resizable=no,titlebar=yes,height=200,width=300,screenX=400,screenY=300") 
   }
}


function checkCurrency ()
{
   if ((currency == "EUR") || (currency == "GBP") || (currency == "CAD") || (currency == "USD") || (currency == "CHF"))
      return (true)
   else 
      return (false)
}


function openOrderForm ()
{
    if (taggedStr == "English") 
    {
       winCmd=open("CommandeCaddieEng.htm","OrderForm","scrollbars=yes,resizable=yes,titlebar=yes,status=yes,height=600,width=800,screenX=0,screenY=0") 
    }
    else 
    {
       winCmd=open("CommandeCaddie.htm","OrderForm","scrollbars=yes,resizable=yes,titlebar=yes,status=yes,height=600,width=800,screenX=0,screenY=0") 
    }
}


function openManualOrderForm ()
{
    if (taggedStr == "English") 
    {
       winCmdMan=open("CommandeCaddie2Eng.htm","OrderForm","scrollbars=yes,resizable=yes,titlebar=yes,status=yes,height=600,width=800,screenX=0,screenY=0") 
    }
    else 
    {
       winCmdMan=open("CommandeCaddie2.htm","OrderForm","scrollbars=yes,resizable=yes,titlebar=yes,status=yes,height=600,width=800,screenX=0,screenY=0") 
    }
}


function clearCaddie (caddieState) 
{
   var readCookie = ""
   numOfItemsStr = getCookie ("PB_NumItems")
   numOfItemsIndex = eval(numOfItemsStr)
   for (var i = 1; i <= numOfItemsIndex; i++)
   {
      regCookie ("PB_ItemID"+i, "", cookieItemsTime)
   }
   regCookie ("PB_NumItems", "0", cookieItemsTime)
   regCookie ("PB_ParcelType", "", cookieItemsTime)
   numOfItemsStr = getCookie ("PB_NumItems")
   readCookie = getCookie ("PB_ItemID")
   if (debugCaddie) { alert("CLEAR?: IX="+numOfItemsStr+" COOKIE="+readCookie) }
   if (caddieState == "ON") { window.location.reload (true) } // refresh window content
}


function priceTagsInterpreter ()
{
   if ((cookieStrArray [itemPriceIx] == "TAG1") || (cookieStrArray [itemPriceIx] == "CHF2800"))
   {
      if      (currency == "CHF") { itemPrice = priceTag1_CHF }
      else if (currency == "EUR") { itemPrice = priceTag1_EUR }
      else { itemPrice = eval(priceTag1_EUR) / eval(EUR) * eval(currency) }
   } 
   else if ((cookieStrArray [itemPriceIx] == "TAG2") || (cookieStrArray [itemPriceIx] == "CHF3200"))
   {
      if      (currency == "CHF") { itemPrice = priceTag2_CHF }
      else if (currency == "EUR") { itemPrice = priceTag2_EUR }
      else { itemPrice = eval(priceTag2_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG3")
   {
      if      (currency == "CHF") { itemPrice = priceTag3_CHF }
      else if (currency == "EUR") { itemPrice = priceTag3_EUR }
      else { itemPrice = eval(priceTag3_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG4")
   {
      if      (currency == "CHF") { itemPrice = priceTag4_CHF }
      else if (currency == "EUR") { itemPrice = priceTag4_EUR }
      else { itemPrice = eval(priceTag4_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG5")
   {
      if      (currency == "CHF") { itemPrice = priceTag5_CHF }
      else if (currency == "EUR") { itemPrice = priceTag5_EUR }
      else { itemPrice = eval(priceTag5_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG6")
   {
      if      (currency == "CHF") { itemPrice = priceTag6_CHF }
      else if (currency == "EUR") { itemPrice = priceTag6_EUR }
      else { itemPrice = eval(priceTag6_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG7")
   {
      if      (currency == "CHF") { itemPrice = priceTag7_CHF }
      else if (currency == "EUR") { itemPrice = priceTag7_EUR }
      else { itemPrice = eval(priceTag7_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG8")
   {
      if      (currency == "CHF") { itemPrice = priceTag8_CHF }
      else if (currency == "EUR") { itemPrice = priceTag8_EUR }
      else { itemPrice = eval(priceTag8_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG9")
   {
      if      (currency == "CHF") { itemPrice = priceTag9_CHF }
      else if (currency == "EUR") { itemPrice = priceTag9_EUR }
      else { itemPrice = eval(priceTag9_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG10")
   {
      if      (currency == "CHF") { itemPrice = priceTag10_CHF }
      else if (currency == "EUR") { itemPrice = priceTag10_EUR }
      else { itemPrice = eval(priceTag10_EUR) / eval(EUR) * eval(currency) }
   }
   else if ((cookieStrArray [itemPriceIx] == "TAG11") || (cookieStrArray [itemPriceIx] == "CHF3400"))
   {
      if      (currency == "CHF") { itemPrice = priceTag11_CHF }
      else if (currency == "EUR") { itemPrice = priceTag11_EUR }
      else { itemPrice = eval(priceTag11_EUR) / eval(EUR) * eval(currency) }
   }
   else if (cookieStrArray [itemPriceIx] == "TAG12")
   {
      if      (currency == "CHF") { itemPrice = priceTag12_CHF }
      else if (currency == "EUR") { itemPrice = priceTag12_EUR }
      else { itemPrice = eval(priceTag12_EUR) / eval(EUR) * eval(currency) }
   }
   else
   {
      itemPrice = eval(cookieStrArray [itemPriceIx])
   }
}
