window.onerror = null;
shopping_cart = {
	request : Object(),
        AJAXscript : '/shopping_cart_ajax.php?method=ajax',
	sortField: '',
	sortDirection: '',
	tableIssues: null,
	init : function(sortCol,sortDirection){
		if(typeof(sortCol) == 'undefined') sortCol = 'sort';
		if(typeof(sortDirection) == 'undefined') sortDirection = 'asc';
		shopping_cart.sortField = sortCol;
		shopping_cart.sortDirection = sortDirection;
		shopping_cart.tableIssues = typeof tableIssues != 'undefined' ? tableIssues : new Array('itemRow');
	},
	send : function(arr,method){
		ajaxSender.send('shopping_cart', arr, method, false);
	},

	d : function(o, e, a){
      if (o.addEventListener) return o.addEventListener(e, a, false);
      else if (o.attachEvent) return o.attachEvent("on" + e, a);
      else return false;
    },

    inCart: function(pID,param){
        var id=new Array();
        $("input[name^='id['],select[name^='id[']").each(function(i,el){
            key=(($(el).attr('name')).replace('id[','')).replace(']','');
            id[key]=$(el).val();
        });
        qty=$("input[name^='products_qty']").val();
        if(qty==0)qty=1;
        $.fn.colorbox({title:"В корзине:",width:"445px",height:"450px",html:'<div id="ajax_shopping_cart"></div>'});
        this.send({'pID':pID,'param':param,'qty':qty,'id':id},'inCart');


    },
    ansinCart: function(data){
        if(data.col_p==true){
         $.fn.colorbox({width:"80%",height:"335px",title:"В корзине:",html:data.main});
        }else{
         $.fn.colorbox({width:"80%",title:"В корзине:",html:data.main});
        }
    },

    updateCart:function(param){

        var post=new Object();
        post.products_id=new Array();
        post.cart_quantity=new Array();
        post.old_qty=new Array();
        post.id=new Array();
        post.cart_delete=new Array();
        $("input[name^='products_id[']").each(function(i,el){
        key=(($(el).attr('name')).replace('products_id[','')).replace(']','');
        post.products_id[key]=$(el).val();
        });

        $("input[name^='cart_quantity[']").each(function(i,el){
            key=(($(el).attr('name')).replace('cart_quantity[','')).replace(']','');
            post['cart_quantity'][key]=$(el).val();
        });

        $("input[name^='old_qty[']").each(function(i,el){
            key=(($(el).attr('name')).replace('old_qty[','')).replace(']','');
            post['old_qty'][key]=$(el).val();
        });

        $("input[name^='cart_delete[']").each(function(i,el){
            key=(($(el).attr('name')).replace('cart_delete[','')).replace(']','');
            if($(el).is(':checked'))
                post['cart_delete'][key]=$(el).val();
        });

        $("input[name^='id[']").each(function(i,el){
            key=($(el).attr('name')).replace('id[','');
            post['id'][key]=$(el).val();
        });



        this.send({'param':param,'post':post},'inCart');
    },

    ansupdateCart:function(data){
         $.fn.colorbox({width:"80%",title:"В корзине:",html:data});
    },

    buynowCart: function(pID,param){
        $.fn.colorbox({title:"В корзине:",width:"445px",height:"450px",html:'<div id="ajax_shopping_cart"></div>'});
        this.send({'pID':pID,'param':param},'inCart');


    },
    ansbuynowCart: function(data){
         $.fn.colorbox({width:"80%",title:"В корзине:",html:data});
    }


}
