//-----------------------------------------------------------------------------
// shopcart0.js
//-----------------------------------------------------------------------------
// Copyright 2000 - 2006 GalaSoft Laurent Bugnion
//-----------------------------------------------------------------------------
// Website                : www.galasoft.ch
// Language               : JavaScript
// Author                 : Laurent Bugnion (laurent@galasoft.ch)
//-----------------------------------------------------------------------------
// Description:
//   Defines the shopping cart functionalities.
//   Part 0: functions used in the main shop window
//
// History:
//   06.10.2000 Lbu : Created in this version.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Global variables

//-----------------------------------------------------------------------------
// This function adds an article to the cart

function getItem( artNumber )
{
  artNumber = ( ( artNumber < 100 ) ? '0' : '' )
            + ( ( artNumber < 10 ) ? '0' : '' )
            + artNumber;

  if ( cookieOK )
  {
    var theCookie = gslb.Cookie.getCookie( cookieShopId );

    if ( ( theCookie == null ) || ( theCookie == "" ) )
    {
      theCookie = artNumber + "_1";
    }
    else
    {
      var indexOfArticle = theCookie.indexOf( artNumber + "_" );

      if ( indexOfArticle != -1 )
      {
        alert( alert001 );

        var index1 = theCookie.indexOf( "_", indexOfArticle );
        var index2 = theCookie.indexOf( ",", indexOfArticle );

        var theSubStr1 = theCookie.substring( 0, index1 + 1 );

        var theSubStr2 = "";
        var theSubStr3 = "";

        if ( index2 == -1 )
        {
          theSubStr2 = theCookie.substring( index1 + 1 );
        }
        else
        {
          theSubStr2 = theCookie.substring( index1 + 1, index2 );
          theSubStr3 = theCookie.substring( index2 );
        }

        var theQuantity = parseInt( theSubStr2, 10 );
        theQuantity++;
        theCookie = theSubStr1 + theQuantity + theSubStr3;
      }
      else
      {
        theCookie += "," + artNumber + "_1";
      }
    }

    var expDate = new Date();
    //valid 1 year
    expDate.setTime( expDate.getTime() + ( 365 * 24 * 60 * 60 * 1000 ) );
    gslb.Cookie.setCookie( cookieShopId, theCookie, expDate, gslb.Cookie.PATH );
    showCart( true );
  }
  else
  {
    alert( alert002 );
  }
}

//-----------------------------------------------------------------------------
// This function shows the shopping cart

function showCart( reload )
{
  var locX = ( screen.width - 700 ) / 2;
  var locY = 20;
  var theURL = "shopcart1_" + strLanguage + ".html";

  if ( ( buyWin == null ) || buyWin.closed )
  {

    buyWin = open( theURL, "buyWin", "status=1,toolbar=1,scrollbars=1,width=700,height=500,"
                 + "screenX=" + locX + ",screenY=" + locY
                 + ",left=" + locX + ",top=" + locY );
  }
  else
  {
    if ( reload )
    {
      buyWin.location.replace( theURL );
    }
    buyWin.focus();
  }
}

