//**
// * Cookie Read/Write function
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// * rev0  K.Kimura  12Feb08 : 新規作成
// */

////////////////////////////////////////////////////////////////////
// Cookieの無効日を2030/12/31に設定
////////////////////////////////////////////////////////////////////
function maxDate() {
  weeks = new Array("Sun","Mon","Tue","Wen","Thu","Fri","Sat");
  months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  today = new Date("2030/12/31");
  year = today.getFullYear();
  month = months[today.getMonth()];
  day = today.getDate();
  week = weeks[today.getDay()];
  datestr = week + "," + day + "-" + month + "-" + year + " 23:59:59;";
  return datestr;
}

////////////////////////////////////////////////////////////////////
// キーワードを指定してCookieを取得
////////////////////////////////////////////////////////////////////
function getCookie(keyname) {
  tmp = document.cookie + ";";
  index1 = tmp.indexOf(keyname, 0);
  if (index1 != -1) {
    tmp = tmp.substring(index1, tmp.length);
    index2 = tmp.indexOf("=", 0) + 1;
    index3 = tmp.indexOf(";", 0);
    if ( index2 > index3 ) return "";
    return(unescape(tmp.substring(index2, index3)));
  }
  return "";
}

////////////////////////////////////////////////////////////////////
// キーワードを指定してCookieを書き込み
////////////////////////////////////////////////////////////////////
function setCookie(keyname, val) {
  tmp = keyname + "=" + escape(val) + ";";
  // tmp += "expires=" + maxDate();
  tmp += "path=/ns;" + "expires=" + maxDate();
  document.cookie = tmp;
  return;
}

////////////////////////////////////////////////////////////////////
// キーワードを指定してCookieを削除
////////////////////////////////////////////////////////////////////
function eraseCookie(keyname) {
  weeks = new Array("Sun","Mon","Tue","Wen","Thu","Fri","Sat");
  months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  today = new Date();
  year = today.getFullYear() - 1;
  month = months[today.getMonth()];
  day = today.getDate();
  week = weeks[today.getDay()];
  h = today.getHours();
  m = today.getMinutes();
  s = today.getSeconds();
  datestr = week + "," + day + "-" + month + "-" + year + " ";
  datestr += h + ":" + m + ":" + s + ";";
  //
  // 過去の日付を指定するとCookieを削除出来る
  tmp = keyname + "=;";
  // tmp += "expires=" + datestr;
  tmp += "path=/ns;" + "expires=" + datestr;
  document.cookie = tmp;
  return;
}

////////////////////////////////////////////////////////////////////
// Cookie書き込みテスト
////////////////////////////////////////////////////////////////////
//flag= 0:ブラウザ設定のみ確認 / 1:実際に書けるか確認
function cookieOK(flag){
  if(navigator["cookieEnabled"]&&!flag){
    return (navigator.cookieEnabled)
  }else{
    document.cookie="testcookie"
    return (document.cookie.indexOf("testcookie")!=-1)
  }
}


