//////////////////////////////////////////////////////////////////////
//  function名：check_str_len
//  機能      ：与えられた文字列の長さを求める
//  引数      ：str 文字列
//  戻り値    ：len 文字列strの長さ(byte長)
//  備考      ：なし
//  更新履歴  ：00/05/30 作成
//////////////////////////////////////////////////////////////////////
function check_str_len(str)
{
  var len = 0;
  for (var i = 0; i < str.length; i++){
    if (escape(str.charAt(i)).length >= 4)
      len+=2;
    else
      len++;
  }
  return len;
}

function ShowShoppingCart(url) {
  var win_features = "height=540,width=600,alwaysLowered=0,alwaysRaised=0,channelmode=0," +
    "dependent=0,directories=0,fullscreen=0,hotkeys=0,location=0,menubar=1,resizable=1," +
    "scrollbars=1,status=1,titlebar=0,toolbar=0,z-lock=0";

  if (url.length == 0)
  	url = 'https://shop.atori.co.jp/cart.php?code=&num=';
  ShoppingCartScreen = window.open(url,
				   "ShoppingCartScreen",
				   win_features);
  if (ShoppingCartScreen.opener == null)
    ShoppingCartScreen.opener = window;

  ShoppingCartScreen.focus();

  return true;
}
//////////////////////////////////////////////////////////////////////
function AddToOrder(item_code, num_ordered)
{
  var url_str, cookie_length;

  // Cookieのサイズチェック
  cookie_length = check_str_len( document.cookie );
  if (cookie_length > 4000) {					// 4096byte制限
    alert("これ以上選択できません。");
    return;
  }

  url_str = 'https://shop.atori.co.jp/cart.php?code=' + item_code + '&num=' + num_ordered;

  ShowShoppingCart(url_str);
  return;
}
