	function ajaxCartAction(tgt) {
		//if(Ajax.connecting) return;
		var search = tgt.href.substring(tgt.href.indexOf('?')+1);
		var params = search.split('&');

		var param, action, item, album;
		for(var i=0; i<params.length; i++) {
			var pair  = params[i].split('=');
			var key   = pair[0];
			var value = pair[1];
			if(key == 'addItem' || key == 'removeItem' || key == 'incrementItem' || key == 'decrementItem') {
				param  = params[i];
				action = key;
				id   = value;
				
				ajaxCartAction2(param, action, id);
				break;
			}
		}

		return;
	}

	function ajaxCartAction2(param, action, id) {
		var quantity = 1;
		if (document.getElementById('quantity_'+id)) {
			quantity = document.getElementById('quantity_'+id).value;
		}

		if ( action == 'addItem' || action == 'removeItem' ) {
			if ( action == 'addItem' ) {
				var strMsg = '商品をカートに追加しますか?';
				getCartItems({action:action,id:id,quantity:quantity});
				backToTop();
			} else if ( action == 'removeItem' ) {
				var strMsg = '商品をカートから削除しますか?';
				if (window.confirm(strMsg)) {
					getCartItems({action:action,id:id,quantity:quantity});
				}
			}

		} else {
			getCartItems({action:action,id:id,quantity:quantity});
		}
		return;
	}

	function getCartItems(args){
		Ajax.call('getCartItems', args, 'requestGetCartItems');
		return;
	}
	function requestGetCartItems(response){
		var html	= '';
		var total	= '';
		var invoice	= '';
		
		if (response.wint_alart == 'NG') {
			window.alert("予約商品を他の商品と併せてご購入頂くことはできません");
			return;
		}

		document.getElementById('cartArea').style.display = (response.countTotal > 0) ? 'inline' : 'none';
		document.getElementById('cart').style.visibility = (response.countTotal > 0) ? 'visible' : 'hidden';
		if(response.countTotal > 0){
			html += '<table border="0" cellpadding="0" cellspacing="1" width="100%">';
			html += '<tr class="cap">';
			html += '<td>品名</td>';
			html += '<td width="80px">アーティスト名</td>';
			html += '<td width="60px">分類</td>';
			html += '<td width="30px">数量</td>';
			html += '<td width="50px">数量変更</td>';
			html += '<td width="60px">金額</td>';
			html += '<td width="25px" align="center">削除</td>';
			html += '</tr>';

			invoice += '<table border="0" cellpadding="0" cellspacing="0" class="payBox">';
			invoice += '<tr>';
			invoice += '<td class="cap">商品名</td>';
			invoice += '<td class="cap" width="60px" align="center">分類</td>';
			invoice += '<td class="cap" width="60px" align="center">数量</td>';
			invoice += '<td class="cap" width="60px" align="center">数量変更</th>';
			invoice += '<td class="cap" width="70px" align="center">価格</td>';
			invoice += '<td class="cap" width="40px" align="center">削除</td>';
			invoice += '</tr>';

			var items					= response.items;
			var isIndividual	= false;
			var isCod					= false;
			var isNotCod				= false; //代引き以外

			for(var i in items){
				var item = items[i];
alert(item.id);
				if (item.is_individual == 1)	{ isIndividual = true; }
				if (item.is_cod == 1)					{ isCod = true; }
				if (item.is_cod == 0)					{ isNotCod = true; }

				html += '<tr>';
				html += '<td align="left" valign="top">';
				html += '<a href="'+item.url+'" title="goods_name">'+item.name+'</a>';
				html += '</td>';
				html += '<td valign="top">';
				html += item.owner;
				html += '</td>';
				html += '<td valign="top">';
				if(item.category == 'goods'){
					html += 'グッズ';
				}else if(item.category == 'album'){
					html += 'アルバム';
				}else if(item.category == 'track'){
					html += '楽曲';
				}else {
					html += '映像';
				}
				html += '</td>';
				html += '<td align="right" valign="top">';
				html += item.quantity;
				html += '</td>';
				html += '<td align="center" valign="top">';

				if(item.category == 'goods'){
					if(item.stock > item.quantity){
						html += '<a id="_CART_'+item.id+'" href="'+item.increment+'">▲</a>&nbsp;&nbsp;';
					}else{
						html += '<span class="noChange">▲<span>&nbsp;&nbsp;';
					}
					if(item.quantity > 1){
						html += '<a id="_CART_'+item.id+'" href="'+item.decrement+'">▼</a>';
					}else{
						html += '<span class="noChange">▼<span>';
					}
				}else{
					html += '-';
				}

				html += '</td>';
				html += '<td align="right" valign="top">￥'+item.price+'</td>';
				html += '<td align="center" valign="top">';
				html += '<a id="_CART_'+item.id+'" href="'+item.remove+'"><img src="'+response.SITE_SERVER_URL+'/img/common/head_del.gif" alt="削除" border="0" /></a> ';
				html += '</td>';
				html += '</tr>';

				if (document.getElementById('isDeliverCOD') && ( item.category != 'goods' || item.is_cod == '0' ) ) {
				} else {
					invoice += '<tr align="left" class="dateLine">';
					invoice += '<td align="left" valign="top">';
					invoice += '<a href="'+item.url+'" target="_blank">'+item.name+'</a>';
					invoice += (item.is_individual=='1') ? '<img src="'+response.SITE_SERVER_URL+'/img/common/ico_postage_ok.gif" alt="配送料込み" class="payico" border="0" />' : '';
					invoice += (item.is_cod=='0') ? '<img src="'+response.SITE_SERVER_URL+'/img/common/ico_daibiki_ng.gif" alt="代引不可" class="payico" border="0" />' : '';
					invoice += (item.bought) ? '<img src="'+response.SITE_SERVER_URL+'/img/common/ico_bought.gif" alt="以前購入したことのある商品です" class="payico" border="0" />' : "";
					invoice += '</td>';

					invoice += '<td valign="top" align="center">';
					if(item.category == 'goods'){
						invoice += 'グッズ';
					}else if(item.category == 'album'){
						invoice += 'アルバム';
					}else if(item.category == 'track'){
						invoice += '楽曲';
					}else{
						invoice += '映像';
					}
					invoice += '</td>';

					invoice += '<td align="right" valign="top">'+item.quantity+'&nbsp;</td>';

					invoice += '<td valign="top" align="center">';

					if(item.category == 'goods'){
						if(item.stock > item.quantity){
							invoice += '<a id="_CART_'+item.id+'" href="'+item.increment+'">▲</a>&nbsp;&nbsp;';
						}else{
							invoice += '<span class="noChange">▲<span>&nbsp;&nbsp;';
						}
						if(item.quantity > 1){
							invoice += '<a id="_CART_'+item.id+'" href="'+item.decrement+'">▼</a>';
						}else{
							invoice += '<span class="noChange">▼<span>';
						}
					}else{
						invoice += '-';
					}

					invoice += '</td>';

					invoice += '<td valign="top" align="right">￥'+item.price+'</td>';
					invoice += '<td valign="top" align="center" class="delImg">';
					invoice += '&nbsp;<a id="_INVOICE_'+item.id+'" href="'+item.remove+'"><img src="'+response.SITE_SERVER_URL+'/img/common/head_del.gif" alt="削除" border="0" /></a>&nbsp;';
					invoice += '</td>';
					invoice += '</tr>';
				}
			}
			html += '</table>';


			html += '<table width="100%" border="0" cellpadding="5" cellspacing="1" id="totalBox">';
			html += '<tr>';
			html += '<td align="right" class="cap">合計</td>';
			html += '<td align="right" width="30px">'+response['countTotal']+'</td>';
			html += '<td align="right" width="155px"><span class="cartItem">￥'+response['priceTotal']+'（税込）</span></td>';
			html += '</tr>';
			html += '</table>';
			html += '<div class="goInvoice">';
			html += '無料アイテムのみの場合もこちらにお進みください&nbsp;<a href="'+response.invoice_url+'"><img src="'+response.SITE_SERVER_URL+'/img/common/btn_goInvoice.gif" alt="カート内のアイテムを清算する" border="0" OnMouseOver="rollover(1,this.src,this);" OnMouseOut="rollover(0,this.src,this);" /></a>';
			html += '</div>';

			if (document.getElementById('isDeliverCOD')) {
				invoice += '<tr>';
				invoice += '<td colspan="2"></td>';
				invoice += '<td align="right" colspan="2"> 小計</td>';
				invoice += '<td align="right" colspan="2" class="sum">￥<strong>'+response['priceTotalGoods']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '<tr>';
				invoice += '<td colspan="2"></td>';
				invoice += '<td align="right" colspan="2"> 送料</td>';
				invoice += '<td align="right" colspan="2" class="sum">￥<strong>'+response['pricePostage']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '<tr>';
				invoice += '<td colspan="2"></td>';
				invoice += '<td align="right" colspan="2"> 代引き手数料</td>';
				invoice += '<td align="right" colspan="2" class="sum">￥<strong>'+response['priceCOD']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '<tr>';
				invoice += '<td align="right" class="dateLine sum" colspan="2"></td>';
				invoice += '<td align="right" class="dateLine sum" colspan="2">合計</td>';
				invoice += '<td align="right" class="dateLine sum" colspan="2" class="sum">￥<strong>'+response['priceSumCOD']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '</table>';
			} else {
				invoice += '<tr>';
				invoice += '<td colspan="2"></td>';
				invoice += '<td align="right" colspan="2"> 小計</td>';
				invoice += '<td align="right" colspan="2" class="sum">￥<strong>'+response['priceTotal']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '<tr>';
				invoice += '<td colspan="2"></td>';
				invoice += '<td align="right" colspan="2"> 送料</td>';
				invoice += '<td align="right" colspan="2" class="sum">￥<strong>'+response['pricePostage']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '<tr>';
				invoice += '<td align="right" class="dateLine sum" colspan="2"></td>';
				invoice += '<td align="right" class="dateLine sum" colspan="2">合計</td>';
				invoice += '<td align="right" class="dateLine sum" colspan="2" class="sum">￥<strong>'+response['priceSumTotal']+'</strong>（税込）</td>';
				invoice += '</tr>';
				invoice += '</table>';
			}

			// SMARTPHONEなら置き換えない
			if(response.IS_SMARTPHONE != true){
				if(document.getElementById('invoiceTable')){
					document.getElementById('invoiceTable').innerHTML = invoice;
				}
			}else{
				window.location.reload(true);
			}
			if(document.getElementById('cod_area')){
				var cod_btn = '';
				cod_btn += '<input id="btn_cod" type="button" class="formBtn" value="代引きで購入" onClick="location.href=\'/user/payment/cod/\'" style="vertical-align: middle;" ';
				if(isNotCod){
					cod_btn += 'disabled';
				}
				cod_btn += '>';
				//cod_btn += '<div class="attention">';
				if(isNotCod){
					cod_btn += '<div class="attention">';
					cod_btn += '代引き不可の商品が含まれるため、ご利用いただけません。';
				}else{
					//cod_btn += '※送料とは別に代引き手数料が発生します。';
				}
				cod_btn += '<br />';
				cod_btn += '</div>';
				document.getElementById('cod_area').innerHTML = cod_btn;
			}
			if(document.getElementById('trCod1')){
				if (document.getElementById('trCod1').style.display != 'none' && !isCod) {
					document.getElementById('trCod1').style.display = 'none';
					document.getElementById('trCod2').style.display = 'none';
				}
			}

			// SMARTPHONEなら
			if(response.IS_SMARTPHONE == true){
				html    = '';
				invoice = '';
				document.getElementById('cartArea').style.display = 'none';
				document.getElementById('cart').style.visibility = 'hidden';
				window.location.reload(true);
			}
		}else{
			html += '<span class="cartItem">カートの中身は空です</span>';

			html += '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
			html += '<tr>';
			html += '<td align="left"><hr size="1" class="cart-line" /></td>';
			html += '</tr>';
			html += '</table>';

			if(document.getElementById('invoiceTable')){
				window.location.reload();
			}
		}

		document.getElementById('cartCount').innerHTML = response.countTotal;
		if ( response.cartTableHtml) {
			document.getElementById('cartTable').innerHTML = response.cartTableHtml;
		} else {
			document.getElementById('cartTable').innerHTML = html;
		}

//		document.getElementById('totalBox').innerHTML = total;

		var anchors    = document.getElementsByTagName('a');
		var lastAction = response['lastAction'];
		var lastItems   = response['lastItems'];
		var hCount     = 0;

		for(var i=0; i < anchors.length; i++) {
			//alert("anchors:"+ i + "/" + anchors.length);
			var search = anchors[i].href.substring(anchors[i].href.indexOf('?')+1);
			var params = search.split('&');

			for(var n=0; n < params.length; n++) {
				var pair  = params[n].split('=');
				var key   = pair[0];
				var value = pair[1];

				if(key == 'addItem' || key == 'removeItem') {
					param  = params[n];
					action = key;
					id   = value;

					for(var p=0; p<lastItems.length; p++) {
						lastItem = lastItems[p];
						if(id ==  lastItem){
							if(anchors[i].id.indexOf('_INVOICE_') == -1){
								if((lastAction == 'addItem') && anchors[i].id.indexOf('_CART_') == -1 && anchors[i].id.indexOf('_INVOICE_') == -1) {
									anchors[i].style.visibility	= 'hidden';
									anchors[i].style.display		= 'none';
									if (document.getElementById('quantity_'+id)) {
										document.getElementById('quantity_span_'+id).style.visibility = 'hidden';
										document.getElementById('quantity_span_'+id).style.display		= 'none';
									}
									if (document.getElementById('incart_span_'+id)) {
										document.getElementById('incart_span_'+id).style.visibility = 'visible';
										document.getElementById('incart_span_'+id).style.display		= 'inline';
									}
								} else if((lastAction == 'removeItem') && anchors[i].id.indexOf('_CART_') == -1 && anchors[i].id.indexOf('_INVOICE_') == -1) {
									anchors[i].style.visibility	= 'visible';
									anchors[i].style.display		= 'inline';
									anchors[i].href = anchors[i].href.replace('removeItem', 'addItem');
									if (document.getElementById('quantity_'+id)) {
										document.getElementById('quantity_'+id).value = 1;
										document.getElementById('quantity_span_'+id).style.visibility	= 'visible';
										document.getElementById('quantity_span_'+id).style.display		= 'inline';
									}
									if (document.getElementById('incart_span_'+id)) {
										document.getElementById('incart_span_'+id).style.visibility	= 'hidden';
										document.getElementById('incart_span_'+id).style.display		= 'none';
									}
								} else {
								}
								if(anchors[i].href.indexOf('addItem=') != -1 && anchors[i].style.visibility == 'hidden') hCount++;
							}
						}
					}
					break;
				}
			}
		}
		prepCartQueries();

		return;
	}
	function prepCartQueries() {
		var anchors = document.getElementsByTagName('a');
		for(var j=0; j < anchors.length; j++) {
			//alert("anchors:"+ j + "/" + anchors.length);
			if(anchors[j].id.indexOf('_INVOICE_') != -1 && anchors[j].id.indexOf('_CART_') != -1){
				continue;
			}
			//REQUESTにdirect_accessがある場合はajaxモードに行かずに普通にaタグとして機能
			if(((anchors[j].href.indexOf('addItem=') != -1 ) || anchors[j].href.indexOf('removeItem=') != -1 || anchors[j].href.indexOf('incrementItem=') != -1 || anchors[j].href.indexOf('decrementItem=') != -1) && anchors[j].href.indexOf('direct_access=') == -1) {
				anchors[j].onclick = function(){ajaxCartAction(this); return false;};
			}
		}
		return;
	}

	snippets.addEventListener(window, 'load', prepCartQueries);


