// Cookie Processing


//---------------------------------------------------------------------------------------------------------------------------
function SetCookie( asCookieName, asCookieValue ) 
{ 

  //1.  Expire the cookie in 1 year.
  var expdate = new Date();
  expdate.setTime ( expdate.getTime() + ( 24 * 60 * 60 * 1000 * 365 ) ); 

  //2.  Set The cookie.
  document.cookie = asCookieName + "=" + escape( asCookieValue ) + ";expires=" + expdate.toGMTString(); 

} 


//---------------------------------------------------------------------------------------------------------------------------
function GetCookie( name ) 
{ 

  //1.  Read the cookie string.

  var dc = document.cookie; 

  //2.  Get the index of the beginning of the cookie.

  var prefix = name + "="; 
  var begin = dc.indexOf("; " + prefix); 

  if (begin == -1) 
  { 
    begin = dc.indexOf(prefix); 
    if (begin != 0) 
      return null; 
  } 
  else 
  { 
    begin += 2; 
  } 

  //3.  Get the index of the end of the cookie.

  var end = document.cookie.indexOf(";", begin); 

  if (end == -1) 
  { 
    end = dc.length; 
  } 

  //4.  Return the cookie.

  return unescape(dc.substring(begin + prefix.length, end)); 

} 
