function setCookie(name,value,days) {
	var date = new Date();
	date.setTime(date.getTime()+(1000*60*60*24*days));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+encodeURIComponent(value)+expires+"; path=/;";
}
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return decodeURIComponent(c.substring(nameEQ.length,c.length));
	}
	return null;
}	
function delCookie(name) {
	setCookie(name,"",-1);
}
function basket_add(id,article,price,qty,info) {
	if (!getCookie("item-"+id)) {
		setCookie("item-"+id,id+"|"+article+"|"+price+"|"+qty+"|"+info,30);
	}
	if (confirm("Товар добавлен в корзину.\nПерейти к оформлению заказа?")) {
		location.href="/basket/";
	}
}



function basket_item_add2 (detail) {
	if ($.cookie('details['+detail[0]+'][qty]')) {
		qty = parseInt($.cookie('details['+detail[0]+'][qty]'));
		$.cookie('details['+detail[0]+'][qty]',qty+1);
	}
	else {
		$.cookie('details['+detail[0]+'][Art_id]', detail[0]);
		$.cookie('details['+detail[0]+'][marka_name]', detail[1]);
		$.cookie('details['+detail[0]+'][model_name]', detail[2]);
		$.cookie('details['+detail[0]+'][fuel_name]', detail[3]);
		$.cookie('details['+detail[0]+'][year]', detail[4]);
		$.cookie('details['+detail[0]+'][modification_name]', detail[5]);
		$.cookie('details['+detail[0]+'][detail_des]', detail[6]+detail[7]);
		$.cookie('details['+detail[0]+'][price]', detail[8]);
		$.cookie('details['+detail[0]+'][qty]', 1);
		$.cookie('details['+detail[0]+'][Article_NR]', detail[9]);
	}
	if (confirm("товар добавлен в корзину.\nперейти к оформлению заказа?")) {
		location.href="/basket/";
	}
}
function basket_show() {
$.ajax({
			url: "/proxy.php",
			data: {
							"action" : "show_basket"
						},
			beforeSend: function(){
										$("#area").html('<img src="/images/ajax.gif" id="loading">');
									},
			success: 	function(data) {
									$("#area").html(data);
								}
	});
}
function basket_item_delete(id) {
	$.cookie('details['+id+'][qty]', null, { path: '/' });
	$.cookie('details['+id+'][Art_id]', null, { path: '/' });
	$.cookie('details['+id+'][Article_NR]', null, { path: '/' });
	$.cookie('details['+id+'][marka_name]', null, { path: '/' });
	$.cookie('details['+id+'][model_name]', null, { path: '/' });
	$.cookie('details['+id+'][fuel_name]', null, { path: '/' });
	$.cookie('details['+id+'][year]', null, { path: '/' });
	$.cookie('details['+id+'][modification_name]', null, { path: '/' });
	$.cookie('details['+id+'][detail_des]', null, { path: '/' });
	$.cookie('details['+id+'][price]', null, { path: '/' });
	basket_show();
}
function basket_item_update(id,qty) {
	if ($.cookie('details['+id+'][qty]')!=qty) {
		$.cookie('details['+id+'][qty]', qty, { path: '/' });
		basket_show();	
	}
}
function kurs(currency) {
	$(".euro").hide();
	$(".baks").hide();
	$(".blrr").hide();
	$("."+currency).show();
	$("#euro").css("font-weight","normal");
	$("#baks").css("font-weight","normal");
	$("#blrr").css("font-weight","normal");
	$("#"+currency).css("font-weight","bold");
	setCookie("kurs",currency,30)
}

