OrderDomain='new.inforcom-co.ru';
BasketUrl='/inc/ordercard.php';


order = new function() {
	
	this.getid=function(id,a) {
		for(var i=0;i<a.length;i++) {
			if(a[i].indexOf(id+':')==0 || a[i]==id) return i;
		}
		return -1;
	}

	this.add=function(id) {
		//alert(id)
		var b=jQuery.cookie("basket");
		//alert(b);
		if(b!=null) b=b.split(',');
		else b=[];
		
		if(this.getid(id,b)==-1) {			
			b[b.length]=id+':1';
			jQuery.cookie("basket", b.join(','), {path: "/"}); // ,domain: OrderDomain
			this.reload();
		} else {
			alert('Эта позиция уже присутствует в заказе.');
		}
		return false;
	}

	this.reload=function() {
		var b=jQuery.cookie("basket");
		if(b!=null) {
			jQuery.post(BasketUrl, {b:b}, function(html){
				jQuery('#cart')[0].innerHTML=html;
			});
		}
	}

	this.clear=function(id) {		
		if(id==null || id=='indefined') {
			jQuery.cookie("basket", null);
			this.reload();
			return false;
		}
		var b=jQuery.cookie("basket");
		b=b.split(',');
		var i=this.getid(id,b);

		if(i!=-1) {
			var a=[];
			for(var j=0;j<b.length;j++) if(j!=i) a[a.length]=b[j];
			jQuery.cookie("basket", a.join(','), {path: "/"}); //,domain: OrderDomain
			this.reload();
		}
		return false;
	}
}

$(document).ready(function(){
	order.reload();
});