/**
 * Cookie object
 */
function cCookie() {
  /**
   * Cookie setzen
   * expires in days
   */
  cCookie.prototype.set = function(name, value, expires, path, domain, secure ) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
  }

  /**
   * Cookie auslesen
   */
  cCookie.prototype.get = function(c_name) {
    if (document.cookie.length>0) {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1){
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
      }
    }
    return "";
  }
  
  /**
   * Cookie prüffen
   */
  this.check = function(c_name) {
    username=getCookie('username');
    if (username!=null && username!="") {
      alert('Welcome again '+username+'!');
    } else {
      username=prompt('Please enter your name:',"");
      if (username!=null && username!="") {
        setCookie('username',username,365);
      }
    }
  }
}

var cCookie = new cCookie();