var ref = document.referrer;
var url = document.URL;
var today_date = new Date();
var today_year = today_date.getYear();
var today_month = today_date.getMonth();
var today_day = today_date.getDate();
if (today_year < 1900) today_year += 1900;

// クッキーの取得
function getCookie(name) {
  var key = name + '=';
  var value = '';
  var cokies = document.cookie;
  var start = 0;
  var end = 0;
  if (parseInt(cokies.length) > 0) {
    start = parseInt(cokies.indexOf(key));
    if (start >= 0) {
      start += parseInt(key.length);
      end = parseInt(cokies.indexOf(";", start));
      if (end < 0) {
        end = parseInt(document.cookie.length);
       }
      value = unescape(cokies.substring(start, end));
     }
   }
  return(value);
 }

// クッキーの設定
function setCookie(key, value, times, domainpath, secureflag) {
  var domain, path, secure, pos, cokies;
  var expire = new Date();
  domain = domainpath;
  path = cokies = '';
  if (parseInt(secureflag) == 1) {
    secure = 'true';
   }
  else {
    secure = '';
   }
  if (domain == null) {
    domain = '';
   }
  else {
    pos = domain.indexOf("/");
    if (pos < 0) {
      path = '';
     }
    else {
      path = domain.substring(pos, domain.length);
      domain = domain.substring(0, pos);
      if (path == '') {
        path = '/';
       }
     }
   }
  cokies = key + '=' + escape(value);
  if (times != null) {
    if (parseInt(times) > 0) {
      expire.setTime(expire.getTime() + parseInt(times));
      cokies = cokies + '; expires=' + expire.toGMTString();
     }
   }
  if (parseInt(path.length) > 0) {
    cokies = cokies + '; path=' + path;
   } 
  if (parseInt(domain.length) > 0) {
    cokies = cokies + '; domain=' + domain;
   } 
  if (parseInt(secure.length) > 0) {
    cokies = cokies + '; ' + secure;
   }
  document.cookie = cokies;
  return(cokies);
 }

//会員ログオンのチェック
function ck_member_logon(url_ok, url_ng) {
  if (location.protocol != 'file:') {
    if (getCookie('@member_logon') == '' || getCookie(getCookie('@member_logon')) == '') {
      if (url_ng == '') {
        return(0);
       }
      else {
        location.replace(url_ng);
       }
     }
    else if (url_ok == '') {
      return(1);
     }
    else {
      location.replace(url_ok);
     }
   }
  else if (url_ok == '') {
    return(1);
   }
  else {
    location.replace(url_ok);
   }
 }

// 送信ボタンの連続押し防止
var submit_time = 0;
function click_submit() {
  var now = new Date();
  var now_time = now.getTime();
  if (now_time - submit_time < 3000) {
    alert("サーバーが混み合っている可能性があります。\n恐れ入りますが、しばらくお待ちください。");
    return(false);
   }
  else {
    submit_time = now_time;
    return(true);
   }
 }

