/*
 * クッキーの読み出し
 * key : 文字列 : キー
 * 戻り値 : 文字列 : キーの値 (未設定なら空文字列を返す)
 */

function getCookie(key){
  key = trim(key) ;

  var cookies = new Array() ;
  cookies = document.cookie.split(";") ;

  var i = 0
  while (cookies[i]) {
    var key_value = new Array()
    key_value = cookies[i].split("=") ;

    if (trim(key_value[0]) == key) {
      return key_value[1] ;
    }
    i++ ;
  }

  return "" ;
}

/*
 * クッキーのセット (有効期限は 30日固定)
 * key : 文字列 : キー
 * val : 文字列 : 値
 */

function setCookie(key, val){
  var expires = new Date() ;
  expires.setTime(expires.getTime() + 1000 * 60 * 60 * 24 * 30) ; /* 30日 */
  document.cookie = key + "=" + escape(val) + ";expires=" + expires.toGMTString() + ";path=/";
}

/*
 * クッキーの消去
 * key : 文字列 : キー
 */

function clearCookie(key){
  var expires = new Date() ;
  document.cookie = key + "=;expires=" + expires.toGMTString() + ";path=/";
}

