<?php
chdir($_SERVER['DOCUMENT_ROOT']);
require_once($_SERVER['DOCUMENT_ROOT'].'/library/beginc.php');
$user = new maguser();
$list_basket = list_basket("basket",false);
$list_note = list_basket("note",false);
$headPrice = intval(@$list_basket["price"]);
?>
var head_basket_count = <?=intval(@$list_basket["count"])?>;
var head_note_count = <?=intval(@$list_note["count"])?>;
var head_price = <?=intval($headPrice)?>;
var update_basket_type = "basket";

var note_data = new Object();
<?php
	$note_data = $user->getBasketItems("note");
	foreach ($note_data as $key=>$value) {
		echo "note_data[{$key}] = {$key};
";
	}
?>
function add_to_basket_cb(z) {
	eval(z);
	document.getElementById('alrt').style.display = 'block';
	document.getElementById('alrt_name').innerHTML = result[2];
	if (result[1]=="basket") {
		document.getElementById('alrt_type').innerHTML = "корзину";
		document.getElementById('alrt_type2').innerHTML = "к оформлению";
		document.getElementById('alrt_type3').innerHTML = "в корзину для оформления заказа или продолжить покупки";
		

	} else {
		document.getElementById('alrt_type').innerHTML = "блокнот";
		document.getElementById('alrt_type2').innerHTML = "в блокнот";
		document.getElementById('alrt_type3').innerHTML = "к просмотру отложенных товаров и их сравнению или продолжить работу с каталогом";
	}
}
function add_to_basket(x, y) {
	if(typeof(note_data[x])!="undefined" && y=="note") {
		
		document.getElementById('stop_alrt').style.display = 'block';
	} else {
		if(typeof(note_data[x])=="undefined" && y=="note") {
			note_data[x] = x;
			update_head_basket('add',1,'note',0);
		}
		x_add_to_basket(x, y, add_to_basket_cb);
	}
}
function move_to_basket_cb(type) {
	update_basket_items("basket");
	window.setTimeout("update_basket_items(\"note\")", 1000);
}
function move_to_basket(x) {
	x_move_to_basket(x, move_to_basket_cb);
}
function delete_from_basket_cb(type) {
	update_basket_items(type);
}
function delete_from_basket(x,y,z) {
	x_delete_from_basket(x,y,z, delete_from_basket_cb);
}
function update_basket_items(type) {
	update_basket_type = type;
	x_update_basket_items(type, update_basket_items_cb);
}
function update_basket_items_cb(result) {
	document.getElementById(update_basket_type+'_container').innerHTML = result;
}
function update_head_basket (act,col,type,price) {
	//alert(act);return false;
	if (act == 'add') {
		if (type == 'basket') {
			head_basket_count += col;
			document.getElementById(type+'_count').innerHTML = head_basket_count;
			head_price += price;
			document.getElementById('head_price').innerHTML = head_price;
		} else {
			head_note_count += col;
			document.getElementById(type+'_count').innerHTML = head_note_count;
		}
	} else {
		if (type == 'basket') {
			head_basket_count -= col;
			document.getElementById(type+'_count').innerHTML = head_basket_count;
			head_price -= price;
			document.getElementById('head_price').innerHTML = head_price;

		} else {
			head_note_count -= col;
			document.getElementById(type+'_count').innerHTML = head_note_count;
		}
	}
}