//------------------------------------------------------------------------------
// PROJECT:      Stainless SteelCAL
// VERSION:      2.00.014b
// Copyright:    © The Steel Construction Institute, 2002-2004, All Rights Reserved
// Developed by: FreeSTYLE Software Ltd.
//_____________________________________________________________________________
// FILE NAME:       Scripts/Cookies.js
// FILE LANGUAGE:   [Independent]
// DESCRIPTION:     Cookies handling scripts
// AUTHOR:          Rezo Mesarkishvili
// LATEST REVISION: 26 January 2004
// BY:              Rezo Mesarkishvili
//------------------------------------------------------------------------------

   var CookieExpires = '';

//------------------------------------------------------------/ SetCookie /-----
// Function:    SetCookie
// Description: Creates a cookie with the specified name and value
// Arguments:   Name  - cookie name
//              Value - cookie value
// Returns:     nothing
//------------------------------------------------------------------------------
function SetCookie ( Name, Value )
{
   if ( window.navigator.cookieEnabled )
   {
      if ( CookieExpires == '' )
      {
         CookieExpires = GetExpDate ();
      }
      if ( Value == '' )
      {
         DelCookie ( Name );
      }
      else
      {
         document.cookie = Name + '=' + escape ( Value ) + '; expires=' + CookieExpires;
      }
   }
}

//------------------------------------------------------------/ GetCookie /-----
// Function:    GetCookie
// Description: Retrieves cookie value
// Arguments:   Name - cookie name
// Returns:     Cookie value or null if cookie with specified name does not exist
//------------------------------------------------------------------------------
function GetCookie ( Name )
{
   if ( window.navigator.cookieEnabled )
   {
      var Cookie = document.cookie.split ( '; ' );
      for ( var i in Cookie )
      {
         var Prop = Cookie [i].split ( '=' );
         if ( Prop [0] == Name )
         {
            return unescape ( Prop [1] );
         }
      }
   }
   return '';
}

//------------------------------------------------------------/ DelCookie /-----
// Function:    DelCookie
// Description: Deletes cookie (sets expiration date in the past)
// Arguments:   Name - cookie name
// Returns:     nothing
//------------------------------------------------------------------------------
function DelCookie ( Name )
{
   if ( window.navigator.cookieEnabled )
   {
      var ExpDate = new Date ( 1999, 11, 31, 0, 0, 0, 0 );
      document.cookie = Name + '=expired; expires=' + ExpDate.toUTCString ();
   }
}

//-----------------------------------------------------------/ GetExpDate /-----
// Function:    GetExpDate
// Description: Creates cookie expiration date as a string
// Returns:     Date string in UTC string format
//------------------------------------------------------------------------------
function GetExpDate ()
{
   var CurrDate  = new Date ();

   var CurrMonth = CurrDate.getMonth ();
   if (    CurrMonth           ==  1
        && CurrDate.getDate () == 29
      )
   {
      CurrDate.setDate ( 28 );
   }
   else
   if ( CurrDate.getDate () == 31 )
   {
      CurrDate.setDate ( 30 );
   }
   if ( CurrMonth == 11 )
   {
      CurrDate.setFullYear ( CurrDate.getYear () + 1 );
      CurrDate.setMonth ( 0 );
   }
   else
   {
      CurrDate.setMonth ( CurrMonth + 1 );
   }
   return CurrDate.toUTCString ();
}

//____________________________________________________________ End of File _____
