/******************************************************************************
 * Standard JavaScript routines.
 *
 * kp, 07/08
 */

/**
 * Namespace placeholder.
 * All functions are called as stdjs.xxxx(args)
 */
stdjs = {};

/******************************************************************************
/**
 * Include a javascript file by another javascript file.
 */
stdjs.include = function(filename)
{
    var head = document.getElementsByTagName('head')[0];
    
    script = document.createElement('script');
    script.src = filename;
    script.type = 'text/javascript';
    
    head.appendChild(script)
}

/******************************************************************************
 *
 * Cookie handling
 *
 */

stdjs.setCookie = function(name, value, days, path, domain, secure)
{
  var cookie_string = name + "=" + escape ( value );

  if ( days )
  {
    var expires = new Date();
    expires.setTime(expires.getTime() + 3600000*24*days);
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

stdjs.deleteCookie = function(cookie_name)
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

stdjs.getCookie = function(cookie_name)
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}
