function toCart(Aprodid) {
	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=addcart',
		data: 'productid=' + Aprodid,
		success: function(html){
		//alert(html);
			window.location.reload();
		}
	});
}

function clearCart() {
	$.ajax({
		url: '/ajax.php?way=clearcart',
		success: function(html){
			window.location.reload();
		}
	});

}

function deleteSelectedCart() {
	var tagsArray = new Array();
	$("input:checked").each(function(id) {
		 message = jQuery("input:checked").get(id);
		 tagsArray.push(message.value); 
	});

	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=deletecart',
		data: 'cartid=' + tagsArray,
		success: function(html){
			window.location.reload();
		}
	});
}

function recalculateCart() {
	var post_str = $("#cartform").serialize();
	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=calculatecart',
		data: post_str,
		success: function(html){
			window.location.reload();
		}
	});
}

function sendRequestCart1() {
	var flag = true;
    if (!document.all.yesdelivery.checked && !document.all.nodelivery.checked){
		document.all.delivery.innerHTML = 'Выберите способ доставки'
	   flag = false
	} else {document.all.delivery.innerHTML = ''}
	
	if (!document.all.paycash.checked && !document.all.paycard.checked){
		document.getElementById('pay').innerHTML = 'Выберите способ оплаты'
		flag = false
	} else {document.getElementById('pay').innerHTML  = ''}
	
	if (document.getElementById('dopinfa').value==''){
		document.getElementById('contacts').innerHTML = 'Оставьте контактную информацию'
		flag = false
	} else {document.getElementById('contacts').innerHTML  = ''}
	
	if (flag){		
		recalculateCart();
		sendDopInfa();
		sendPayment();
		sendDostavka();
		document.location='/cartdone.php';
	}
}

function sendRequestCart() {
	recalculateCart();
	sendDopInfa();
	sendPayment();
	sendDostavka();
	document.location='/cartdone.php';
}

function sendDopInfa() {
	var post_str = $("#cartform").serialize();
	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=dopinfa',
		data: post_str,
		success: function(html){
			window.location.reload();
		}
	});
}

function sendPayment() {
var post_str = $("#cartform").serialize();
	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=payment',
		data: post_str,
		success: function(html){
			//alert(html);
			window.location.reload();
		}
	});
}

function sendDostavka() {
var post_str = $("#cartform").serialize();
	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=dostavka',
		data: post_str,
		success: function(html){
			window.location.reload();
		}
	});
}

function closeSelectedCart() {
	var tagsArray = new Array();
	$("input:checked").each(function(id) {
		 message = jQuery("input:checked").get(id);
		 tagsArray.push(message.value); 
	});

	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=closecart',
		data: 'cartid=' + tagsArray,
		success: function(html){
			window.location.reload();
		}
	});
}

function sendPrintCart() {
	window.open('/printcart.php','PrintCart','height=700,width=800');
}

function showZakaz(Aid) {
	window.open('/showcart.php?id='+Aid,'ShowZakaz','height=700,width=800,');
}

//admin

function showAdminZakaz(Aid) {
	window.open('/showzakaz.php?id='+Aid,'ShowZakaz','height=700,width=800,');
}

function closeZakaz(Aid) {
	
	$.ajax({
		type: 'POST',	
		url: '/ajax.php?way=closezakaz',
		data: 'id=' + Aid,
		success: function(html){
			//alert(html);
			window.location.reload();
		}
	});
}
