/*утф8*/
function cart_add(names_id){
	$.post("/cart/cart.php",
		{mode:'add', names_id:names_id},
		function resfun(data){
			if(data=='ok'){
				show_cart_small();
				show_cart_table();
				if(document.location.pathname!='/cart.php'){
					set_cookie('back_url',document.location.pathname);
					document.location='/cart.php';
				}
			}else{
				alert(data);
			}
		},'text');
}

function cart_del(names_id){
	$.post("/cart/cart.php",
		{mode:'del', names_id:names_id},
		function resfun(data){
			if(data=='ok'){
				show_cart_small();
				show_cart_table();
			}else if(data=='reload'){
				document.location='/cart.php';
			}else{
				alert(data);
			}
		},'text');
}

function show_cart_small(){
	$.post("/cart/cart.php",
	{mode:'show_cart_small'},
	function resfun(data){
		document.getElementById('cart_small').innerHTML=data;
	});
}

function show_cart_table(){
	if(document.getElementById('cart_table')){
		$(".upd1").html("<div style='text-align:center;'><img src='/img/waiting_small.gif' alt='...'/></div>");
		$.post("/cart/cart.php",
		{mode:'show_cart_table'},
		function resfun(data){
			document.getElementById('cart_table').innerHTML=data;
		},'text');
	}
}

function get_offices(city){
	$.post("/cart/get_offices.php",
	{city:city},function resfun(data){
		if(data){
			document.getElementById('delivery_offices').innerHTML=data;
		}
	},'text');
	set_cookie('city',my_encode(city));
	show_cart_table();
}

function set_pay_type2(city){
	if(city=='other'){
		document.forms['order_form'].elements['pay_type2'][0].disabled=true;
		document.forms['order_form'].elements['pay_type1'][0].disabled=true;
		set_cookie("pay_type_lock",1);
		set_pay_type(2);
	}else{
		document.forms['order_form'].elements['pay_type2'][0].disabled=false;
		document.forms['order_form'].elements['pay_type1'][0].disabled=false;
		del_cookie("pay_type_lock");
	}
}
function set_pay_type(pay_type){
	
	document.forms['order_form'].elements['pay_type1'][pay_type-1].checked=true;
	document.forms['order_form'].elements['pay_type2'][pay_type-1].checked=true;
	set_cookie("pay_type",pay_type);
	show_cart_table();
}

function set_recallme(th){
	if(th.checked){
		set_cookie('recallme',1);
	}else{
		del_cookie('recallme');
	}
}

function send_order(){
	var message='';
	if(document.forms['order_form'].elements['city2']){
		var city=document.forms['order_form'].elements['city2'].value;
		var service=document.forms['order_form'].elements['service'].value;
		if(!city){
			message+="Введите название Вашего города\n";
		}
		if(!service){
			message+="Введие службу доставки, которой Вы хотите получить заказ";
		}
	}else{
		var office=document.forms['order_form'].elements['office'].value;
		if(!office){
			message+="Выберите офис доставки\n";
		}
	}
	var fio=document.forms['order_form'].elements['user_name'].value;
	var phone=document.forms['order_form'].elements['user_phone'].value;

	if(!fio){
		message+="Введите ФИО получателя\n";
	}
	if(!phone){
		message+="Введите номер мобильного телефона получателя";
	}
	if(message){
		alert(message);
	}else{
		document.forms['order_form'].submit();
	}
}
