////////////////////////////////////////////
// Copyright (C)2002 NTTDATA
// <ID>
// <関数名>クッキー登録
// <概要>
// <パラメータ>
// <返り値>
// <バージョン>1.0
// <更新日付>2002/10/15
// <作成者>
// <修正者>
// <修正内容>
////////////////////////////////////////////
function insertCookie (nm, val)
{
  var clen;
  var loopCount;
  var itemName;
  var itemValue;
  clen = document.cookie.length;
  loopCount = 0;
  if (clen == 0)
  {
    document.cookie = nm + "=" + val;
  }
  else
  {
    while (loopCount < clen)
    {
      itemName = getNextToken (loopCount, "=");
      loopCount += itemName.length + 1;
      itemValue = getNextToken (loopCount, ";");
      if ((strCmp (itemName, nm) == 0) || (strCmp (itemName, " " + nm) == 0))
      {
        document.cookie = nm + "=" + itemValue + val;
        break;
      }
      loopCount = document.cookie.indexOf (";", loopCount) + 1;
      if (loopCount == 0)
      {
        document.cookie = nm + "=" + val;
        break;
      }
      if (loopCount == clen)
      {
        document.cookie = nm + "=" + val;
        break;
      }
    }
  }
}

////////////////////////////////////////////
// Copyright (C)2002 NTTDATA
// <ID>
// <関数名>クッキー更新
// <概要>
// <パラメータ>
// <返り値>
// <バージョン>1.0
// <更新日付>2002/10/15
// <作成者>
// <修正者>
// <修正内容>
////////////////////////////////////////////
function updateCookie (nm, val)
{
  var clen;
  var loopCount;
  var itemName;
  var itemValue;

  clen = document.cookie.length;
  loopCount = 0;
  if (clen == 0)
  {
    document.cookie = nm + "=" + val;
  }
  else
  {
    while (loopCount < clen)
    {
      itemName = getNextToken (loopCount, "=");
      loopCount += itemName.length + 1;
      itemValue = getNextToken (loopCount, ";");

      if ((strCmp (itemName, nm) == 0) || (strCmp (itemName, " " + nm) == 0))
      {
//firefox対応 神林↓
		if ((navigator.userAgent.indexOf("MSIE") != -1))  
		{ 
		    	document.cookie = nm + "=" + (eval(itemValue) + eval(val));
		    	break;
		} else {
			if (itemValue) {
	    	document.cookie = nm + "=" + (eval(itemValue) + eval(val));
	    	break;
			}
		}
//firefox対応 神林↑
      }
      loopCount = document.cookie.indexOf (";", loopCount) + 1;
      if (loopCount == 0)
      {
        document.cookie = nm + "=" + val;
        break;
      }
      if (loopCount == clen)
      {
        document.cookie = nm + "=" + val;
        break;
      }
    }
  }
}

////////////////////////////////////////////
// Copyright (C)2002 NTTDATA
// <ID>
// <関数名>クッキー設定
// <概要>
// <パラメータ>
// <返り値>
// <バージョン>1.0
// <更新日付>2004/1/6
// <作成者>
// <修正者>
// <修正内容>
////////////////////////////////////////////
function setValCookie (nm, val)
{
  var clen;
  var loopCount;
  var itemName;
  var itemValue;
  clen = document.cookie.length;
  loopCount = 0;
  if (clen == 0)
  {
    document.cookie = nm + "=" + val;
  }
  else
  {
    while (loopCount < clen)
    {
      itemName = getNextToken (loopCount, "=");
      loopCount += itemName.length + 1;
      itemValue = getNextToken (loopCount, ";");
      if ((strCmp (itemName, nm) == 0) || (strCmp (itemName, " " + nm) == 0))
      {
        document.cookie = nm + "=" + val;
        break;
      }
      loopCount = document.cookie.indexOf (";", loopCount) + 1;
      if (loopCount == 0)
      {
        document.cookie = nm + "=" + val;
        break;
      }
      if (loopCount == clen)
      {
        document.cookie = nm + "=" + val;
        break;
      }
    }
  }
}

////////////////////////////////////////////
// Copyright (C)2002 NTTDATA
// <ID>
// <関数名>カート登録
// <概要>
// <パラメータ>
// <返り値>
// <バージョン>1.0
// <更新日付>2002/10/15
// <作成者>
// <修正者>
// <修正内容>
////////////////////////////////////////////
function registrationCart (productID, deliveryID, fileSize, settlementMethod)
{
  if (eval(selectCookie ('totalNum') == 0))
  {
//    document.cookie = 'settlementMethod=;expires=-1';
//    updateCookie ('settlementMethod', settlementMethod);
    setValCookie ('settlementMethod', settlementMethod);
  }
  else
  {
    if(selectCookie ('settlementMethod') == 1 || selectCookie ('settlementMethod') == 2)
    {
      if(settlementMethod != 1 && settlementMethod != 2)
      {
        alert("カートに登録されている製品と、この製品は決済方法がことなるため、同時に注文することはできません。");
        return;
      }
    }
    else
    {
      if(selectCookie ('settlementMethod') == settlementMethod)
      {
      }
      else
      {
        alert("カートに登録されている製品と、この製品は決済方法がことなるため、同時に注文することはできません。");
        return;
      }
    }
  }

  if(eval (selectCookie ('totalNum')) < 99)
  {
    if(deliveryID == '1')
    {
      if((eval(selectCookie ('totalFileSize')) + eval(fileSize)) < 200000)
      {
      var arypid;
      var i;
      if( productID.length > 20 ){
        arypid = productID.split(",");

        if (eval (selectCookie ('totalNum')) + arypid.length < 100){

	          for( i = 0; i < arypid.length; i++ ){

	            insertCookie ('productID', arypid[i].substring (0, 20));
	            insertCookie ('deliveryID', deliveryID);
	            updateCookie ('totalPrice', arypid[i].substring (20, arypid[i].length));
	            updateCookie ('totalNum', '1');
	            updateNum = selectCookie ('totalNum');
	            updateprc = selectCookie ('totalPrice');
	          }
          updateCookie ('totalFileSize', fileSize);
        }
        else
        {
          alert("ショッピングカートがいっぱいのため、この注文は受け付けられません。1");
        }
      }
      else{
        insertCookie ('productID', productID.substring (0, 20));
        insertCookie ('deliveryID', deliveryID);
        updateCookie ('totalPrice', productID.substring (20, productID.length));
        	updateCookie ('totalNum', '1');
        updateCookie ('totalFileSize', fileSize);
        updateNum = selectCookie ('totalNum');
        updateprc = selectCookie ('totalPrice');
      }

//      alert ("ご注文ありがとうございます。\nカートには " + updateNum + "個登録されています。\n合計金額は \\" + updateprc + " です。");
        alert ("ご注文ありがとうございます。\nカートには " + updateNum + "個登録されています。");
        //document.shoppingCart.totalPrice.value = "\\" + changeFormat(selectCookie ('totalPrice'));
        //document.shoppingCart.totalNum.value = selectCookie ('totalNum');
// ↓結合試験 2002/12/05 大坪寛明
//        document.shoppingCart.totalFileSize.value = selectCookie ('totalFileSize');
// ↑結合試験 2002/12/05 大坪寛明
      }
      else
      {
        alert("ダウンロードファイルの合計サイズが２００ＭＢを越えるため、この製品はカートに登録できません。");
      }
    }
    else
    {
      // productIDをカンマで区切り、個数分ループする
      var arypid;
      var i;
      if( productID.length > 20 ){
        arypid = productID.split(",");

        for( i = 0; i < arypid.length; i++ ){
          insertCookie ('productID', arypid[i].substring (0, 20));
          insertCookie ('deliveryID', deliveryID);
          updateCookie ('totalPrice', arypid[i].substring (20, arypid[i].length));
          updateCookie ('totalNum', '1');
          updateNum = selectCookie ('totalNum');
          updateprc = selectCookie ('totalPrice');
        }
        alert ("ご注文ありがとうございます。\nカートには " + updateNum + "個登録されています。\n数量の変更は「カートの中をみる」から行ってください。");
      }

    }
  }
  else
  {
		
    alert("ショッピングカートがいっぱいのため、この注文は受け付けられません。2");
  }
}
