﻿var G_MAX_ITEMLIST_COUNT = 30;
var strCKItemCodeList, arCkItemCodeList;

strCKItemCodeList = getCookie("etoSrcItemList");
arCkItemCodeList = strCKItemCodeList.split("|");

function getCookie(name) {

	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length ) {
		var y = (x+nameOfCookie.length);

		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 ) break;
	}
	return "";
}

function setCookie( name, value, expiredays ) {
	if(expiredays == 0) {
		document.cookie = name + "=" + escape( value ) + "; path=/;"
	} else {
		var todayDate = new Date();
		todayDate.setDate( todayDate.getDate() + expiredays );
		document.cookie = name + "=" + escape( value ) + "; path=/; domain=.etomato.com; expires=" + todayDate.toGMTString() + ";";
	}
}

function delItemCode(cdItem) {
	var arNewCodeList = new Array;

	for(i=0,index=0; i<arCkItemCodeList.length && i<=G_MAX_ITEMLIST_COUNT; i++) {
		if(cdItem != ""+arCkItemCodeList[i]) {
			arNewCodeList[index] = arCkItemCodeList[i];
			index++;
		}
	}

	arCkItemCodeList = arNewCodeList;

	saveItemList();
    location.reload();
}

function saveItemList () {
	strCKItemCodeList="";
	var strGubun = "";
	for(i=0; i<arCkItemCodeList.length; i++) {
		tempCode = ""+arCkItemCodeList[i];
		if(tempCode != "undefined" && tempCode.length > 0) {
			strCKItemCodeList += strGubun + arCkItemCodeList[i];
			strGubun = "|"
		}
	}

	setCookie("etoSrcItemList",strCKItemCodeList,30);
}
