function set_cookie(comodity_id)
{

	var time = new Date();
	var cookie_get = false;
	var cookies = document.cookie.split(';');
	
    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        
    	if (cookie.indexOf("PHPSESSID") != "-1" || cookie.indexOf("__utm") != "-1") {
    		continue;
    	}
    	
        //if (typeof cookie != 'undefined') {

	        if (cookie.indexOf("check_id") != "-1") {
	        	var name_value = cookie.split('=');
	        	//alert(name_value[1]);
	        	var values = name_value[1].split(',');
	        	
	        	if (values.length < 10) {
		        	// 10個以内なら、カンマ区切りで追加
	        		name_value[1] += ','+comodity_id;
	        		//alert(name_value[1]);
	        		cookie_value('check_id', name_value[1], { expires: 30});
	        	} else {
		        	// 10個以上なら、頭から削除
	        		values.splice(0, 1);
	        		values.push(comodity_id);
	        		
	        		// カンマ区切りの文字列に変換
	        		var new_values = values.join(',');
	        		
	        		cookie_value('check_id', new_values, { expires: 30});
	        	}
	        	cookie_get = true;
	        } else {
	        	// COOKIEがなければそのままIDを保存
	        	cookie_value('check_id', comodity_id, { expires: 30});
	        	cookie_get = true;
	        }
        //}
    }
    
    if (cookie_get == false) {
    	cookie_value('check_id', comodity_id, { expires: 30});    	
    }
    
}

function cookie_value(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        //document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        document.cookie = [name, '=', value, expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i];
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

