function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function doorder(){
	

$.post('/?loadAjaxService=orders&Method=doorder&'+document.cookie.replace(/; /g,'&')+'&'+$('#order_form').serialize(),function(data){
if(data != 'err'){
//чистим куки
$('.cart_items table td span').each(function(){
removeFromCart($(this).attr('id'),this);
});
$('.text_content').html(data);
}else{
	alert('Не заполнены все необходимые поля.')
}
//document.cookie='';
});
}
function addToCart(id){
var date = new Date(); 
date.setTime(date.getTime ()+(30*24*60*60*1000));  
var expires = date.toGMTString();  
document.cookie = 'order['+id+']='+id+'; expires='+expires +';path=/cart';
document.cookie = 'count['+id+']=1; expires='+expires +';path=/cart';
//$(t).parent().parent().remove();
console.log(document.cookie);
}

function removeFromCart(id,t){
	document.cookie = 'order['+id+']=; expires=0;path=/cart';
	document.cookie = 'count['+id+']=; expires=0;path=/cart';
	$(t).parent().parent().remove();


//console.log(sum);


//	console.log(document.cookie);
}
function getsum(){
	var sum=0;
$('.cart_items tr:not(:last):not(:first)').each(function(){
sum+= parseFloat($(this).find('td:eq(2)').html())*parseInt($(this).find('td:eq(3) span').html());
});
//FormatFloat("0.00",flt)
$('.cart_items tr:last td:eq(1)').html(Math.ceil(sum*100)/100);
}
function upcount(id){

var cnt = parseInt($('#'+id).html())+1;
	$('#'+id).html(cnt);
	document.cookie = 'count['+id+']='+cnt+'; expires=0;path=/cart';
	getsum();
}

function downcount(id){

var cnt = parseInt($('#'+id).html())-1;
if(cnt>0){
	$('#'+id).html(cnt);
	document.cookie = 'count['+id+']='+cnt+'; expires=0;path=/cart';	
	}
	getsum();
}














