
//include(cmf.ajax.js);
cmf.basket = new(function() {
    var basket = this;

    basket.add = function(form) {
    	return cmf.ajax.sendForm(cmf.ajax.url +'/basket/add/', form);
    }

    basket.del = function(id, key) {
    	if(!confirm('Удалить?')) return;
    	return cmf.ajax.send(cmf.ajax.url +'/basket/del/', {id:id, key:key});
    }

    basket.changeRegion = function(id) {
    	return cmf.ajax.send(cmf.ajax.url +'/basket/region/', {id: id});
    }

    basket.update = function(form) {
    	return cmf.ajax.sendForm(cmf.ajax.url +'/basket/update/', form);
    }

    basket.setOrder = function() {
    	cmf.setValue('update', 'order');
    }
    basket.setUpdate = function() {
    	cmf.setValue('update', 'update');
    }

    basket.view = function(id, text) {
        style.show(id = '#basket'+ id);
        $(id + '>div').html(text);
        setTimeout("style.hide('"+ id +"');", 1000);
    }

    basket.header = function() {
        basket._header(cmf.getCookie('siteBasketCount'), cmf.getCookie('siteBasketPrice'));
    }

    basket._header = function(count, price) {
        if(count) {
		    $('#basketView2').hide();
		    /*switch(parseInt(count)) {
		        case 1:
		            count += ' товар';
		            break;
		        case 2: case 3: case 4:
		            count += ' товара';
		            break;
		        default:
		            count += ' товаров';
		            break;
		    }*/

		    $('#basketView1>a>span').html(count);
            $('#basketView1').show();
    	} else {
    		$('#basketView1').hide();
    		$('#basketView2').show();
    	}
    }

    basket.onchangeDelivery = function(t) {
        $('option', t).each(function() {
            if(this.value==t.value) {
                if(this.getAttribute("delivery")=='true') {
                    $('.isDelivery').show();
                } else {
                    $('.isDelivery').hide();
                }
            }
        });
    }

});
