// *******************************************************
//
// wbSession
// Copyright 2008 Holodyn Corporation
//
// *******************************************************

// *******************************************************
// wbSession Class
// *******************************************************

  var wbSession = new wbSession_class();
  function wbSession_class(){

    this.today = new Date();
    this.zero_date = new Date(0,0,0);
    this.today.setTime(this.today.getTime() - this.zero_date.getTime());
    this.cookie_expire_date = new Date(this.today.getTime() + (8 * 7 * 86400000));
    this.session_id = null;

    // start
    // *******************************************************
    this.start = function() {
      if (!this.get('session_id'))
        this.session_id = this.get('session_id');
        else this.set('session_id',Math.random(),cookie_expire_date);
    }

    // get
    // *******************************************************
    this.get = function(name) {
      var start = document.cookie.indexOf(name+"=");
      var len = start+name.length+1, end, val;
      if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
      if (start == -1) return null; end = document.cookie.indexOf(";",len);
      if (end == -1) end = document.cookie.length;
      val = unescape(document.cookie.substring(len,end));
      if( /^\d+$/.test(val) ) return (val)*1;
      if( /^true$|^false$/.test(val) ) return (val=='true')?true:false;
      return val;
    }

    // set
    // *******************************************************
    this.set = function(name,value,expires,path,domain,secure) {
      if( !expires ) expires = this.cookie_expire_date;
      var cookieString = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
      document.cookie = cookieString;
    }

    // unset
    // *******************************************************
    this.unset = function(name,path,domain) {
      if (this.get(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-70 00:00:01 GMT";
    }

    // *******************************************************
    this.start();
  }


