/**
 *	cart_manager
 *  @param  string  url			Cart_ajaxへのURL
 *	@param	string	cart_area	カート表示領域のid
 *
 *
 */
var CartManager = Class.create();
CartManager.prototype = {
	initialize : function ( url, cart_area, template ){	
		this.target = (cart_area)?$(cart_area):$('cart_area');
		this.url = url;
		this.template = template || 'default';
	},
	AddCart : function( id ){
			/* TODO:intチェック */
			try{
				quantity=($F('q_'+id)=='')?1:$F('q_'+id);
			} catch(e){
				console.debug('q_'+id);
			}

		this.AjaxRequest( $H({ 'add' : id, 'q': quantity }).toQueryString() );
		return false;
	},
	ViewCart : function(){
		this.AjaxRequest( $H({ 'view' : 'true' }).toQueryString() );
		return false;
	},
	Delete : function( article_id ){
		this.AjaxRequest( $H({ 'delete' : article_id }).toQueryString() );
		return false;
	},
	Clear : function( article_id ){
		this.AjaxRequest( $H({ 'clear' : 'true' }).toQueryString() );
		if(this.OnClear) this.OnClear();
		return false;
	},
	AjaxRequest : function( pars ){
		if( this.OnRequestBefore ) this.OnRequestBefore();
		this.IndicatorObject=new Indicator({ 'mesg' : '更新中','OnLoadHide' : false });
		this.IndicatorObject.append(this.target);
		var AjaxCart = new Ajax.Updater(
			this.target, 
			this.url,
			{
				method: 'get', 
				parameters: pars+'&template='+this.template,
				onComplete: this.OnComplete.bind(this),
				onFailure: this.OnFailure.bind(this),
				evalScripts: true
			});
	},
	OnComplete : function(){
		if(this.OnCompleteAfter) this.OnCompleteAfter();
		Element.remove( this.IndicatorObject );
	},
	OnFailure : function(){
		Element.remove( this.IndicatorObject );
	}
}